source: trunk/dll/mkdir.c@ 1877

Last change on this file since 1877 was 1877, checked in by Gregg Young, 10 years ago

Remove debug code

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 7.1 KB
Line 
1
2/***********************************************************************
3
4 $Id: mkdir.c 1877 2015-10-11 21:43:27Z gyoung $
5
6 Make directory dialog
7
8 Copyright (c) 1993-97 M. Kimes
9 Copyright (c) 2004, 2008 Steven H.Levine
10
11 01 Aug 04 SHL Baseline
12 29 Feb 08 GKY Refactor global command line variables to notebook.h
13 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory
14 25 Dec 08 GKY Add code to allow write verify to be turned off on a per drive basis
15 28 Jun 09 GKY Added AddBackslashToPath() to remove repeatative code.
16 23 Oct 10 GKY Add ForwardslashToBackslash function to streamline code
17 30 Dec 12 GKY Enhance traget directory drop to give the option of changing the directory or carrying out an
18 operation to the current target; Added an error message for target=None;
19 Added parameter to SetTargetDir
20
21***********************************************************************/
22
23#include <string.h>
24#include <ctype.h>
25
26#define INCL_DOSERRORS
27#define INCL_WIN
28#define INCL_LONGLONG // dircnrs.h
29
30#include "fm3dll.h"
31#include "fm3dll2.h" // #define's for UM_*, control id's, etc.
32#include "mkdir.h"
33#include "common.h" // Data declaration(s)
34#include "init.h" // Data declaration(s)
35#include "info.h" // Data declaration(s)
36#include "mainwnd.h" // Data declaration(s)
37#include "fm3dlg.h"
38#include "fm3str.h"
39#include "errutil.h" // Dos_Error...
40#include "strutil.h" // GetPString
41#include "notebook.h" // targetdirectoy
42#include "walkem.h" // WalkTargetDlgProc
43#include "misc.h" // Broadcast
44#include "valid.h" // IsFullName
45#include "dirs.h" // save_dir2
46#include "input.h" // InputDlgProc
47#include "pathutil.h" // AddBackslashToPath
48
49// Data definitions
50#pragma data_seg(GLOBAL2)
51CHAR targetdir[CCHMAXPATH];
52
53//static PSZ pszSrcFile = __FILE__;
54
55APIRET MassMkdir(HWND hwndClient, CHAR * dir)
56{
57 APIRET last, was = 0;
58 CHAR *p;
59 CHAR s[CCHMAXPATH];
60
61 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
62 strcpy(s, dir);
63 ForwardslashToBackslash(s);
64 p = s;
65 do {
66 p = strchr(p, '\\');
67 if (p && p > s && *(p - 1) == ':')
68 p = strchr(p + 1, '\\');
69 if (p && *p) {
70 *p = 0;
71 was = 1;
72 }
73 else
74 was = 0;
75 last = DosCreateDir(s, NULL);
76 if (!last) {
77 Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
78 }
79 else if (last == ERROR_ACCESS_DENIED) {
80 if (!IsFile(s))
81 last = 0;
82 }
83 if (was) {
84 *p = '\\';
85 p++;
86 }
87 }
88 while (p && *p);
89 return last;
90}
91
92APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
93{
94
95 /**
96 * bitmapped flags:
97 * 1 = don't ask to create if non-existent
98 */
99
100 CHAR s[CCHMAXPATH], *p;
101 APIRET ret = 0, error;
102 INT isfile;
103 BOOL fResetVerify = FALSE;
104
105 if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
106 strcpy(s, dir);
107 while ((p = strchr(s, '/')) != NULL)
108 *p = '\\';
109 while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
110 s[strlen(s) - 1] = 0;
111 if (IsFullName(s)) {
112 if (driveflags[toupper(*s) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)) {
113 if (!(flags & 1))
114 saymsg(MB_CANCEL,
115 hwnd,
116 GetPString(IDS_NOPETEXT),
117 GetPString(IDS_DRIVEISTEXT),
118 toupper(*s),
119 ((driveflags[toupper(*s) - 'A'] & DRIVE_IGNORE) != 0) ?
120 GetPString(IDS_BEINGIGNOREDTEXT) :
121 GetPString(IDS_INVALIDTEXT));
122 return -5;
123 }
124 }
125 isfile = IsFile(s);
126 if (isfile == -1) {
127 if (IsFullName(s)) {
128 if (driveflags[toupper(*s) - 'A'] & DRIVE_NOTWRITEABLE) {
129 if (!(flags & 1))
130 saymsg(MB_CANCEL,
131 hwnd,
132 GetPString(IDS_NOPETEXT),
133 GetPString(IDS_DRIVEISTEXT),
134 toupper(*s), GetPString(IDS_NOWRITETEXT));
135 return -4;
136 }
137 }
138 if (!(flags & 1)) {
139 if (saymsg(MB_YESNO,
140 hwnd,
141 GetPString(IDS_CONFIRMTEXT),
142 GetPString(IDS_NODIRCREATEDIRTEXT), s) != MBID_YES)
143 return -3;
144 }
145 if (fVerify && driveflags[toupper(*s) - 'A'] & DRIVE_WRITEVERIFYOFF) {
146 DosSetVerify(FALSE);
147 fResetVerify = TRUE;
148 }
149 error = MassMkdir(hwnd, s);
150 if (fResetVerify) {
151 DosSetVerify(fVerify);
152 fResetVerify = FALSE;
153 }
154 if (error) {
155 Dos_Error(MB_CANCEL,
156 error,
157 hwnd,
158 __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
159 ret = -1;
160 }
161 }
162 else if (isfile) {
163 saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
164 hwnd,
165 GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
166 ret = -2;
167 }
168 return ret;
169}
170
171BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
172{
173
174 STRINGINPARMS sip;
175 CHAR szBuff[CCHMAXPATH];
176 APIRET error;
177 BOOL fResetVerify = FALSE;
178
179Over:
180 sip.help = GetPString(IDS_MKDIRHELPTEXT);
181 sip.ret = szBuff;
182 if (filename)
183 strcpy(szBuff, filename);
184 else
185 strcpy(szBuff, pFM2SaveDirectory);
186 MakeValidDir(szBuff);
187 AddBackslashToPath(szBuff);
188 //if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
189 // strcat(szBuff, "\\");
190 sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
191 sip.inputlen = CCHMAXPATH - 1;
192 sip.title = GetPString(IDS_MKDIRTITLETEXT);
193 if (WinDlgBox(HWND_DESKTOP,
194 hwnd,
195 InputDlgProc, FM3ModHandle, STR_FRAME, &sip) && *szBuff) {
196 if ((strchr(szBuff, '?') ||
197 strchr(szBuff, '*')) || IsFile(szBuff) == 1 || IsRoot(szBuff)) {
198 saymsg(MB_ENTER | MB_ICONEXCLAMATION,
199 hwnd,
200 GetPString(IDS_ERRORTEXT),
201 GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
202 goto Over;
203 }
204 if (fVerify && driveflags[toupper(*szBuff) - 'A'] & DRIVE_WRITEVERIFYOFF) {
205 DosSetVerify(FALSE);
206 fResetVerify = TRUE;
207 }
208 error = MassMkdir(hwnd, szBuff);
209 if (fResetVerify) {
210 DosSetVerify(fVerify);
211 fResetVerify = FALSE;
212 }
213 if (error)
214 Dos_Error(MB_ENTER,
215 error,
216 hwnd,
217 __FILE__,
218 __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
219 else {
220 if (copy && filename)
221 strcpy(filename, szBuff);
222 return TRUE;
223 }
224 }
225 return FALSE;
226}
227
228/*
229 * SetTargetDir sets or unsets the target directory
230 * either from the walk dialog or a directory dropped
231 * on the drivesback bar which is passed as "newtarget".
232 * justshow allows you to update the target without opening
233 * the walk dialog.
234 */
235void SetTargetDir(HWND hwnd, BOOL justshow, PSZ newtarget)
236{
237
238 char temp[CCHMAXPATH + 12];
239
240 if (!justshow) {
241 strcpy(temp, targetdir);
242 if (WinDlgBox(HWND_DESKTOP,
243 hwnd,
244 WalkTargetDlgProc,
245 FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) {
246 strcpy(targetdir, temp);
247 if (!fChangeTarget)
248 PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
249 }
250 else {
251 if (*targetdir &&
252 saymsg(MB_YESNOCANCEL,
253 hwnd,
254 GetPString(IDS_CLEARTARGETTITLETEXT),
255 GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
256 *targetdir = 0;
257 PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
258 }
259 }
260 }
261 if (newtarget && justshow)
262 strcpy(targetdir, newtarget);
263 if (hwndBack) {
264 if (fShowTarget)
265 sprintf(temp,
266 "%s%s%s%s",
267 GetPString(IDS_TARGETDIRTITLETEXT),
268 (*targetdir) ? NullStr : "<",
269 (*targetdir) ?
270 targetdir : GetPString(IDS_NONE), (*targetdir) ? NullStr : ">");
271 else
272 *temp = 0;
273 WinSetWindowText(hwndBack, temp);
274 }
275}
276
277#pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
Note: See TracBrowser for help on using the repository browser.