1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: mkdir.c 1438 2009-06-28 20:47:00Z 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 |
|
---|
17 | ***********************************************************************/
|
---|
18 |
|
---|
19 | #include <string.h>
|
---|
20 | #include <ctype.h>
|
---|
21 |
|
---|
22 | #define INCL_DOSERRORS
|
---|
23 | #define INCL_WIN
|
---|
24 | #define INCL_LONGLONG // dircnrs.h
|
---|
25 |
|
---|
26 | #include "fm3dll.h"
|
---|
27 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
28 | #include "mkdir.h"
|
---|
29 | #include "common.h" // Data declaration(s)
|
---|
30 | #include "init.h" // Data declaration(s)
|
---|
31 | #include "info.h" // Data declaration(s)
|
---|
32 | #include "mainwnd.h" // Data declaration(s)
|
---|
33 | #include "fm3dlg.h"
|
---|
34 | #include "fm3str.h"
|
---|
35 | #include "errutil.h" // Dos_Error...
|
---|
36 | #include "strutil.h" // GetPString
|
---|
37 | #include "notebook.h" // targetdirectoy
|
---|
38 | #include "walkem.h" // WalkTargetDlgProc
|
---|
39 | #include "misc.h" // Broadcast
|
---|
40 | #include "valid.h" // IsFullName
|
---|
41 | #include "dirs.h" // save_dir2
|
---|
42 | #include "input.h" // InputDlgProc
|
---|
43 | #include "pathutil.h" // AddBackslashToPath
|
---|
44 |
|
---|
45 | // Data definitions
|
---|
46 | #pragma data_seg(GLOBAL2)
|
---|
47 | CHAR targetdir[CCHMAXPATH];
|
---|
48 |
|
---|
49 | //static PSZ pszSrcFile = __FILE__;
|
---|
50 |
|
---|
51 | APIRET MassMkdir(HWND hwndClient, CHAR * dir)
|
---|
52 | {
|
---|
53 | APIRET last, was = 0;
|
---|
54 | CHAR *p;
|
---|
55 | CHAR s[CCHMAXPATH];
|
---|
56 |
|
---|
57 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
|
---|
58 | strcpy(s, dir);
|
---|
59 | p = s;
|
---|
60 | while (*p) {
|
---|
61 | if (*p == '/')
|
---|
62 | *p = '\\';
|
---|
63 | p++;
|
---|
64 | }
|
---|
65 | p = s;
|
---|
66 | do {
|
---|
67 | p = strchr(p, '\\');
|
---|
68 | if (p && p > s && *(p - 1) == ':')
|
---|
69 | p = strchr(p + 1, '\\');
|
---|
70 | if (p && *p) {
|
---|
71 | *p = 0;
|
---|
72 | was = 1;
|
---|
73 | }
|
---|
74 | else
|
---|
75 | was = 0;
|
---|
76 | last = DosCreateDir(s, NULL);
|
---|
77 | if (!last) {
|
---|
78 | Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
|
---|
79 | //DbgMsg(pszSrcFile, __LINE__, "UM_UPDATERECORD %s", s);
|
---|
80 | }
|
---|
81 | else if (last == ERROR_ACCESS_DENIED) {
|
---|
82 | if (!IsFile(s))
|
---|
83 | last = 0;
|
---|
84 | }
|
---|
85 | if (was) {
|
---|
86 | *p = '\\';
|
---|
87 | p++;
|
---|
88 | }
|
---|
89 | }
|
---|
90 | while (p && *p);
|
---|
91 | return last;
|
---|
92 | }
|
---|
93 |
|
---|
94 | APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
|
---|
95 | {
|
---|
96 |
|
---|
97 | /*
|
---|
98 | * bitmapped flags:
|
---|
99 | * 1 = don't ask to create if non-existent
|
---|
100 | */
|
---|
101 |
|
---|
102 | CHAR s[CCHMAXPATH], *p;
|
---|
103 | APIRET ret = 0, error;
|
---|
104 | INT isfile;
|
---|
105 | BOOL fResetVerify = FALSE;
|
---|
106 |
|
---|
107 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
|
---|
108 | strcpy(s, dir);
|
---|
109 | while ((p = strchr(s, '/')) != NULL)
|
---|
110 | *p = '\\';
|
---|
111 | while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
|
---|
112 | s[strlen(s) - 1] = 0;
|
---|
113 | if (IsFullName(s)) {
|
---|
114 | if (driveflags[toupper(*s) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)) {
|
---|
115 | if (!(flags & 1))
|
---|
116 | saymsg(MB_CANCEL,
|
---|
117 | hwnd,
|
---|
118 | GetPString(IDS_NOPETEXT),
|
---|
119 | GetPString(IDS_DRIVEISTEXT),
|
---|
120 | toupper(*s),
|
---|
121 | ((driveflags[toupper(*s) - 'A'] & DRIVE_IGNORE) != 0) ?
|
---|
122 | GetPString(IDS_BEINGIGNOREDTEXT) :
|
---|
123 | GetPString(IDS_INVALIDTEXT));
|
---|
124 | return -5;
|
---|
125 | }
|
---|
126 | }
|
---|
127 | isfile = IsFile(s);
|
---|
128 | if (isfile == -1) {
|
---|
129 | if (IsFullName(s)) {
|
---|
130 | if (driveflags[toupper(*s) - 'A'] & DRIVE_NOTWRITEABLE) {
|
---|
131 | if (!(flags & 1))
|
---|
132 | saymsg(MB_CANCEL,
|
---|
133 | hwnd,
|
---|
134 | GetPString(IDS_NOPETEXT),
|
---|
135 | GetPString(IDS_DRIVEISTEXT),
|
---|
136 | toupper(*s), GetPString(IDS_NOWRITETEXT));
|
---|
137 | return -4;
|
---|
138 | }
|
---|
139 | }
|
---|
140 | if (!(flags & 1)) {
|
---|
141 | if (saymsg(MB_YESNO,
|
---|
142 | hwnd,
|
---|
143 | GetPString(IDS_CONFIRMTEXT),
|
---|
144 | GetPString(IDS_NODIRCREATEDIRTEXT), s) != MBID_YES)
|
---|
145 | return -3;
|
---|
146 | }
|
---|
147 | if (fVerify && driveflags[toupper(*s) - 'A'] & DRIVE_WRITEVERIFYOFF) {
|
---|
148 | DosSetVerify(FALSE);
|
---|
149 | fResetVerify = TRUE;
|
---|
150 | }
|
---|
151 | error = MassMkdir(hwnd, s);
|
---|
152 | if (fResetVerify) {
|
---|
153 | DosSetVerify(fVerify);
|
---|
154 | fResetVerify = FALSE;
|
---|
155 | }
|
---|
156 | if (error) {
|
---|
157 | Dos_Error(MB_CANCEL,
|
---|
158 | error,
|
---|
159 | hwnd,
|
---|
160 | __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
|
---|
161 | ret = -1;
|
---|
162 | }
|
---|
163 | }
|
---|
164 | else if (isfile) {
|
---|
165 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
---|
166 | hwnd,
|
---|
167 | GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
|
---|
168 | ret = -2;
|
---|
169 | }
|
---|
170 | return ret;
|
---|
171 | }
|
---|
172 |
|
---|
173 | BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
|
---|
174 | {
|
---|
175 |
|
---|
176 | STRINGINPARMS sip;
|
---|
177 | CHAR szBuff[CCHMAXPATH];
|
---|
178 | APIRET error;
|
---|
179 | BOOL fResetVerify = FALSE;
|
---|
180 |
|
---|
181 | Over:
|
---|
182 | sip.help = GetPString(IDS_MKDIRHELPTEXT);
|
---|
183 | sip.ret = szBuff;
|
---|
184 | if (filename)
|
---|
185 | strcpy(szBuff, filename);
|
---|
186 | else
|
---|
187 | strcpy(szBuff, pFM2SaveDirectory);
|
---|
188 | MakeValidDir(szBuff);
|
---|
189 | AddBackslashToPath(szBuff);
|
---|
190 | //if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
|
---|
191 | // strcat(szBuff, "\\");
|
---|
192 | sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
|
---|
193 | sip.inputlen = CCHMAXPATH - 1;
|
---|
194 | sip.title = GetPString(IDS_MKDIRTITLETEXT);
|
---|
195 | if (WinDlgBox(HWND_DESKTOP,
|
---|
196 | hwnd,
|
---|
197 | InputDlgProc, FM3ModHandle, STR_FRAME, &sip) && *szBuff) {
|
---|
198 | if ((strchr(szBuff, '?') ||
|
---|
199 | strchr(szBuff, '*')) || IsFile(szBuff) == 1 || IsRoot(szBuff)) {
|
---|
200 | saymsg(MB_ENTER | MB_ICONEXCLAMATION,
|
---|
201 | hwnd,
|
---|
202 | GetPString(IDS_ERRORTEXT),
|
---|
203 | GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
|
---|
204 | goto Over;
|
---|
205 | }
|
---|
206 | if (fVerify && driveflags[toupper(*szBuff) - 'A'] & DRIVE_WRITEVERIFYOFF) {
|
---|
207 | DosSetVerify(FALSE);
|
---|
208 | fResetVerify = TRUE;
|
---|
209 | }
|
---|
210 | error = MassMkdir(hwnd, szBuff);
|
---|
211 | if (fResetVerify) {
|
---|
212 | DosSetVerify(fVerify);
|
---|
213 | fResetVerify = FALSE;
|
---|
214 | }
|
---|
215 | if (error)
|
---|
216 | Dos_Error(MB_ENTER,
|
---|
217 | error,
|
---|
218 | hwnd,
|
---|
219 | __FILE__,
|
---|
220 | __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
|
---|
221 | else {
|
---|
222 | if (copy && filename)
|
---|
223 | strcpy(filename, szBuff);
|
---|
224 | return TRUE;
|
---|
225 | }
|
---|
226 | }
|
---|
227 | return FALSE;
|
---|
228 | }
|
---|
229 |
|
---|
230 | void SetTargetDir(HWND hwnd, BOOL justshow)
|
---|
231 | {
|
---|
232 |
|
---|
233 | char temp[CCHMAXPATH + 12];
|
---|
234 |
|
---|
235 | if (!justshow) {
|
---|
236 | strcpy(temp, targetdir);
|
---|
237 | if (WinDlgBox(HWND_DESKTOP,
|
---|
238 | hwnd,
|
---|
239 | WalkTargetDlgProc,
|
---|
240 | FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) {
|
---|
241 | strcpy(targetdir, temp);
|
---|
242 | if (!fChangeTarget)
|
---|
243 | PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
|
---|
244 | }
|
---|
245 | else {
|
---|
246 | if (*targetdir &&
|
---|
247 | saymsg(MB_YESNOCANCEL,
|
---|
248 | hwnd,
|
---|
249 | GetPString(IDS_CLEARTARGETTITLETEXT),
|
---|
250 | GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
|
---|
251 | *targetdir = 0;
|
---|
252 | PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
|
---|
253 | }
|
---|
254 | }
|
---|
255 | }
|
---|
256 |
|
---|
257 | if (hwndBack) {
|
---|
258 | if (fShowTarget)
|
---|
259 | sprintf(temp,
|
---|
260 | "%s%s%s%s",
|
---|
261 | GetPString(IDS_TARGETDIRTITLETEXT),
|
---|
262 | (*targetdir) ? NullStr : "<",
|
---|
263 | (*targetdir) ?
|
---|
264 | targetdir : GetPString(IDS_NONE), (*targetdir) ? NullStr : ">");
|
---|
265 | else
|
---|
266 | *temp = 0;
|
---|
267 | WinSetWindowText(hwndBack, temp);
|
---|
268 | }
|
---|
269 | }
|
---|
270 |
|
---|
271 | #pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
|
---|