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