1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: mkdir.c 985 2008-03-01 01:37:14Z gyoung $
|
---|
5 |
|
---|
6 | Make directory dialog
|
---|
7 |
|
---|
8 | Copyright (c) 1993-97 M. Kimes
|
---|
9 | Copyright (c) 2004, 2007 Steven H.Levine
|
---|
10 |
|
---|
11 | 01 Aug 04 SHL Baseline
|
---|
12 | 29 Feb 08 GKY Refactor global command line variables to notebook.h
|
---|
13 |
|
---|
14 | ***********************************************************************/
|
---|
15 |
|
---|
16 | #include <string.h>
|
---|
17 | #include <ctype.h>
|
---|
18 |
|
---|
19 | #define INCL_DOSERRORS
|
---|
20 | #define INCL_WIN
|
---|
21 | #define INCL_LONGLONG // dircnrs.h
|
---|
22 |
|
---|
23 | #include "fm3dlg.h"
|
---|
24 | #include "fm3str.h"
|
---|
25 | #include "errutil.h" // Dos_Error...
|
---|
26 | #include "strutil.h" // GetPString
|
---|
27 | #include "notebook.h" // targetdirectoy
|
---|
28 | #include "fm3dll.h"
|
---|
29 |
|
---|
30 | #pragma alloc_text(MKDIR,MassMkdir,SetDir,PMMkDir,SetTargetDir)
|
---|
31 |
|
---|
32 | APIRET MassMkdir(HWND hwndClient, CHAR * dir)
|
---|
33 | {
|
---|
34 | APIRET last, was = 0;
|
---|
35 | CHAR *p;
|
---|
36 | CHAR s[CCHMAXPATH];
|
---|
37 |
|
---|
38 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
|
---|
39 | strcpy(s, dir);
|
---|
40 | p = s;
|
---|
41 | while (*p) {
|
---|
42 | if (*p == '/')
|
---|
43 | *p = '\\';
|
---|
44 | p++;
|
---|
45 | }
|
---|
46 | p = s;
|
---|
47 | do {
|
---|
48 | p = strchr(p, '\\');
|
---|
49 | if (p && p > s && *(p - 1) == ':')
|
---|
50 | p = strchr(p + 1, '\\');
|
---|
51 | if (p && *p) {
|
---|
52 | *p = 0;
|
---|
53 | was = 1;
|
---|
54 | }
|
---|
55 | else
|
---|
56 | was = 0;
|
---|
57 | last = DosCreateDir(s, NULL);
|
---|
58 | if (!last)
|
---|
59 | Broadcast((HAB) 0, hwndClient, UM_UPDATERECORD, MPFROMP(s), MPVOID);
|
---|
60 | else if (last == ERROR_ACCESS_DENIED) {
|
---|
61 | if (!IsFile(s))
|
---|
62 | last = 0;
|
---|
63 | }
|
---|
64 | if (was) {
|
---|
65 | *p = '\\';
|
---|
66 | p++;
|
---|
67 | }
|
---|
68 | }
|
---|
69 | while (p && *p);
|
---|
70 | return last;
|
---|
71 | }
|
---|
72 |
|
---|
73 | APIRET SetDir(HWND hwndClient, HWND hwnd, CHAR * dir, INT flags)
|
---|
74 | {
|
---|
75 |
|
---|
76 | /*
|
---|
77 | * bitmapped flags:
|
---|
78 | * 1 = don't ask to create if non-existent
|
---|
79 | */
|
---|
80 |
|
---|
81 | CHAR s[CCHMAXPATH], *p;
|
---|
82 | APIRET ret = 0, error;
|
---|
83 | INT isfile;
|
---|
84 |
|
---|
85 | if (DosQueryPathInfo(dir, FIL_QUERYFULLNAME, s, sizeof(s)))
|
---|
86 | strcpy(s, dir);
|
---|
87 | while ((p = strchr(s, '/')) != NULL)
|
---|
88 | *p = '\\';
|
---|
89 | while (strlen(s) > 3 && s[strlen(s) - 1] == '\\')
|
---|
90 | s[strlen(s) - 1] = 0;
|
---|
91 | if (IsFullName(s)) {
|
---|
92 | if (driveflags[toupper(*s) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)) {
|
---|
93 | if (!(flags & 1))
|
---|
94 | saymsg(MB_CANCEL,
|
---|
95 | hwnd,
|
---|
96 | GetPString(IDS_NOPETEXT),
|
---|
97 | GetPString(IDS_DRIVEISTEXT),
|
---|
98 | toupper(*s),
|
---|
99 | ((driveflags[toupper(*s) - 'A'] & DRIVE_IGNORE) != 0) ?
|
---|
100 | GetPString(IDS_BEINGIGNOREDTEXT) :
|
---|
101 | GetPString(IDS_INVALIDTEXT));
|
---|
102 | return -5;
|
---|
103 | }
|
---|
104 | }
|
---|
105 | isfile = IsFile(s);
|
---|
106 | if (isfile == -1) {
|
---|
107 | if (IsFullName(s)) {
|
---|
108 | if (driveflags[toupper(*s) - 'A'] & DRIVE_NOTWRITEABLE) {
|
---|
109 | if (!(flags & 1))
|
---|
110 | saymsg(MB_CANCEL,
|
---|
111 | hwnd,
|
---|
112 | GetPString(IDS_NOPETEXT),
|
---|
113 | GetPString(IDS_DRIVEISTEXT),
|
---|
114 | toupper(*s), GetPString(IDS_NOWRITETEXT));
|
---|
115 | return -4;
|
---|
116 | }
|
---|
117 | }
|
---|
118 | if (!(flags & 1)) {
|
---|
119 | if (saymsg(MB_YESNO,
|
---|
120 | hwnd,
|
---|
121 | GetPString(IDS_CONFIRMTEXT),
|
---|
122 | GetPString(IDS_NODIRCREATEDIRTEXT), s) != MBID_YES)
|
---|
123 | return -3;
|
---|
124 | }
|
---|
125 | error = MassMkdir(hwndClient, s);
|
---|
126 | if (error) {
|
---|
127 | Dos_Error(MB_CANCEL,
|
---|
128 | error,
|
---|
129 | hwnd,
|
---|
130 | __FILE__, __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), s);
|
---|
131 | ret = -1;
|
---|
132 | }
|
---|
133 | }
|
---|
134 | else if (isfile) {
|
---|
135 | saymsg(MB_CANCEL | MB_ICONEXCLAMATION,
|
---|
136 | hwnd,
|
---|
137 | GetPString(IDS_ERRORTEXT), GetPString(IDS_EXISTSNOTDIRTEXT), s);
|
---|
138 | ret = -2;
|
---|
139 | }
|
---|
140 | return ret;
|
---|
141 | }
|
---|
142 |
|
---|
143 | BOOL PMMkDir(HWND hwnd, CHAR * filename, BOOL copy)
|
---|
144 | {
|
---|
145 |
|
---|
146 | STRINGINPARMS sip;
|
---|
147 | CHAR szBuff[CCHMAXPATH];
|
---|
148 | APIRET error;
|
---|
149 |
|
---|
150 | Over:
|
---|
151 | sip.help = GetPString(IDS_MKDIRHELPTEXT);
|
---|
152 | sip.ret = szBuff;
|
---|
153 | if (filename)
|
---|
154 | strcpy(szBuff, filename);
|
---|
155 | else
|
---|
156 | save_dir2(szBuff);
|
---|
157 | MakeValidDir(szBuff);
|
---|
158 | if (*szBuff && szBuff[strlen(szBuff) - 1] != '\\')
|
---|
159 | strcat(szBuff, "\\");
|
---|
160 | sip.prompt = GetPString(IDS_MKDIRPROMPTTEXT);
|
---|
161 | sip.inputlen = CCHMAXPATH - 1;
|
---|
162 | sip.title = GetPString(IDS_MKDIRTITLETEXT);
|
---|
163 | if (WinDlgBox(HWND_DESKTOP,
|
---|
164 | hwnd,
|
---|
165 | InputDlgProc, FM3ModHandle, STR_FRAME, &sip) && *szBuff) {
|
---|
166 | if ((strchr(szBuff, '?') ||
|
---|
167 | strchr(szBuff, '*')) || IsFile(szBuff) == 1 || IsRoot(szBuff)) {
|
---|
168 | saymsg(MB_ENTER | MB_ICONEXCLAMATION,
|
---|
169 | hwnd,
|
---|
170 | GetPString(IDS_ERRORTEXT),
|
---|
171 | GetPString(IDS_DIRNAMEERRORTEXT), szBuff);
|
---|
172 | goto Over;
|
---|
173 | }
|
---|
174 | error = MassMkdir(hwnd, szBuff);
|
---|
175 | if (error)
|
---|
176 | Dos_Error(MB_ENTER,
|
---|
177 | error,
|
---|
178 | hwnd,
|
---|
179 | __FILE__,
|
---|
180 | __LINE__, GetPString(IDS_CREATEDIRFAILEDTEXT), szBuff);
|
---|
181 | else {
|
---|
182 | if (copy && filename)
|
---|
183 | strcpy(filename, szBuff);
|
---|
184 | return TRUE;
|
---|
185 | }
|
---|
186 | }
|
---|
187 | return FALSE;
|
---|
188 | }
|
---|
189 |
|
---|
190 | void SetTargetDir(HWND hwnd, BOOL justshow)
|
---|
191 | {
|
---|
192 |
|
---|
193 | char temp[CCHMAXPATH + 12];
|
---|
194 |
|
---|
195 | if (!justshow) {
|
---|
196 | strcpy(temp, targetdir);
|
---|
197 | if (WinDlgBox(HWND_DESKTOP,
|
---|
198 | hwnd,
|
---|
199 | WalkTargetDlgProc,
|
---|
200 | FM3ModHandle, WALK_FRAME, MPFROMP(temp)) && *temp) {
|
---|
201 | strcpy(targetdir, temp);
|
---|
202 | if (!fChangeTarget)
|
---|
203 | PrfWriteProfileString(fmprof, appname, "Targetdir", targetdir);
|
---|
204 | }
|
---|
205 | else {
|
---|
206 | if (*targetdir &&
|
---|
207 | saymsg(MB_YESNOCANCEL,
|
---|
208 | hwnd,
|
---|
209 | GetPString(IDS_CLEARTARGETTITLETEXT),
|
---|
210 | "%s", GetPString(IDS_CLEARTARGETTEXT)) == MBID_YES) {
|
---|
211 | *targetdir = 0;
|
---|
212 | PrfWriteProfileString(fmprof, appname, "Targetdir", NULL);
|
---|
213 | }
|
---|
214 | }
|
---|
215 | }
|
---|
216 |
|
---|
217 | if (hwndBack) {
|
---|
218 | if (fShowTarget)
|
---|
219 | sprintf(temp,
|
---|
220 | "%s%s%s%s",
|
---|
221 | GetPString(IDS_TARGETDIRTITLETEXT),
|
---|
222 | (*targetdir) ? "" : "<",
|
---|
223 | (*targetdir) ?
|
---|
224 | targetdir : GetPString(IDS_NONE), (*targetdir) ? "" : ">");
|
---|
225 | else
|
---|
226 | *temp = 0;
|
---|
227 | WinSetWindowText(hwndBack, temp);
|
---|
228 | }
|
---|
229 | }
|
---|