1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: valid.c 552 2007-03-01 06:24:47Z gyoung $
|
---|
5 |
|
---|
6 | File name manipulation routines
|
---|
7 |
|
---|
8 | Copyright (c) 1993, 1998 M. Kimes
|
---|
9 | Copyright (c) 2002, 2006 Steven H.Levine
|
---|
10 |
|
---|
11 | 23 Nov 02 SHL RootName: rework for sanity
|
---|
12 | 27 Nov 02 SHL MakeFullName: correct typo
|
---|
13 | 11 Jun 03 SHL Add JFS and FAT32 support
|
---|
14 | 15 Jun 04 SHL Implement Jim Read's removable logic
|
---|
15 | 31 Jul 04 SHL Comments
|
---|
16 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
17 | 03 Jun 05 SHL Drop CD_DEBUG logic
|
---|
18 | 28 Nov 05 SHL MakeValidDir: correct DosQuerySysInfo args
|
---|
19 | 22 Jul 06 SHL Use Runtime_Error
|
---|
20 | 22 Oct 06 GKY Add NDFS32 support
|
---|
21 | 22 Oct 06 GKY Increased BUFFER_BYTES in CheckDrive to 8192 to fix NDFS32 scan failure
|
---|
22 | 07 Jan 07 GKY Move error strings etc. to string file
|
---|
23 | 18 Feb 07 GKY Add more drive types and icons
|
---|
24 |
|
---|
25 | ***********************************************************************/
|
---|
26 |
|
---|
27 | #define INCL_DOS
|
---|
28 | #define INCL_WIN
|
---|
29 | #define INCL_DOSDEVICES // DosDevIOCtl
|
---|
30 | #define INCL_DOSDEVIOCTL // DosDevIOCtl
|
---|
31 | #include <os2.h>
|
---|
32 |
|
---|
33 | #include <stdlib.h>
|
---|
34 | #include <stdio.h>
|
---|
35 | #include <string.h>
|
---|
36 | #include <ctype.h>
|
---|
37 |
|
---|
38 | #include "fm3dll.h"
|
---|
39 | #include "fm3str.h"
|
---|
40 |
|
---|
41 | static PSZ pszSrcFile = __FILE__;
|
---|
42 |
|
---|
43 | #pragma alloc_text(VALID,CheckDrive,IsRoot,IsFile,IsFullName,needsquoting)
|
---|
44 | #pragma alloc_text(VALID,IsValidDir,IsValidDrive,MakeValidDir,IsVowel)
|
---|
45 | #pragma alloc_text(VALID,IsFileSame,IsNewer,TestDates,RootName,MakeFullName)
|
---|
46 | #pragma alloc_text(VALID,IsExecutable,IsBinary,IsDesktop,ParentIsDesktop)
|
---|
47 | #pragma alloc_text(FILLFLAGS,FillInDriveFlags,assign_ignores)
|
---|
48 | #pragma alloc_text(FILLFLAGS,ArgDriveFlags,DriveFlagsOne)
|
---|
49 | #pragma alloc_text(FINDDESK,GetDesktopName)
|
---|
50 |
|
---|
51 | APIRET MakeFullName(char *pszFileName)
|
---|
52 | {
|
---|
53 | /* pszFileName must be CCHMAXPATH long minimum! */
|
---|
54 |
|
---|
55 | char szPathName[CCHMAXPATH];
|
---|
56 | APIRET rc;
|
---|
57 |
|
---|
58 | DosError(FERR_DISABLEHARDERR);
|
---|
59 | rc = DosQueryPathInfo(pszFileName,
|
---|
60 | FIL_QUERYFULLNAME, szPathName, sizeof(szPathName));
|
---|
61 | if (!rc)
|
---|
62 | strcpy(pszFileName, szPathName); // Pass back actual name
|
---|
63 | return rc;
|
---|
64 | }
|
---|
65 |
|
---|
66 | char *RootName(char *filename)
|
---|
67 | {
|
---|
68 | char *p = NULL, *pp;
|
---|
69 |
|
---|
70 | // Return filename, strip path parts
|
---|
71 | // Return empty string when filename ends with \
|
---|
72 |
|
---|
73 | if (filename) {
|
---|
74 | p = strrchr(filename, '\\');
|
---|
75 | pp = strrchr(filename, '/');
|
---|
76 | p = (p) ? (pp) ? (p > pp) ? p : pp : p : pp;
|
---|
77 | }
|
---|
78 | if (!p) /* name is itself a root */
|
---|
79 | p = filename;
|
---|
80 | else /* skip past backslash */
|
---|
81 | p++;
|
---|
82 | return p;
|
---|
83 | }
|
---|
84 |
|
---|
85 | int TestDates(char *file1, char *file2)
|
---|
86 | {
|
---|
87 | /*
|
---|
88 | * return 1 (file2 newer than file1),
|
---|
89 | * 0 (files same)
|
---|
90 | * or -1 (file1 newer than file2)
|
---|
91 | */
|
---|
92 |
|
---|
93 | int comp = 0;
|
---|
94 | FILESTATUS3 fs3o, fs3n;
|
---|
95 |
|
---|
96 | DosError(FERR_DISABLEHARDERR);
|
---|
97 | if (!DosQueryPathInfo(file1, FIL_STANDARD, &fs3o, sizeof(fs3o))) {
|
---|
98 | DosError(FERR_DISABLEHARDERR);
|
---|
99 | if (!DosQueryPathInfo(file2, FIL_STANDARD, &fs3n, sizeof(fs3n))) {
|
---|
100 | comp = (fs3n.fdateLastWrite.year >
|
---|
101 | fs3o.fdateLastWrite.year) ? 1 :
|
---|
102 | (fs3n.fdateLastWrite.year <
|
---|
103 | fs3o.fdateLastWrite.year) ? -1 :
|
---|
104 | (fs3n.fdateLastWrite.month >
|
---|
105 | fs3o.fdateLastWrite.month) ? 1 :
|
---|
106 | (fs3n.fdateLastWrite.month <
|
---|
107 | fs3o.fdateLastWrite.month) ? -1 :
|
---|
108 | (fs3n.fdateLastWrite.day >
|
---|
109 | fs3o.fdateLastWrite.day) ? 1 :
|
---|
110 | (fs3n.fdateLastWrite.day <
|
---|
111 | fs3o.fdateLastWrite.day) ? -1 :
|
---|
112 | (fs3n.ftimeLastWrite.hours >
|
---|
113 | fs3o.ftimeLastWrite.hours) ? 1 :
|
---|
114 | (fs3n.ftimeLastWrite.hours <
|
---|
115 | fs3o.ftimeLastWrite.hours) ? -1 :
|
---|
116 | (fs3n.ftimeLastWrite.minutes >
|
---|
117 | fs3o.ftimeLastWrite.minutes) ? 1 :
|
---|
118 | (fs3n.ftimeLastWrite.minutes <
|
---|
119 | fs3o.ftimeLastWrite.minutes) ? -1 :
|
---|
120 | (fs3n.ftimeLastWrite.twosecs >
|
---|
121 | fs3o.ftimeLastWrite.twosecs) ? 1 :
|
---|
122 | (fs3n.ftimeLastWrite.twosecs < fs3o.ftimeLastWrite.twosecs) ? -1 : 0;
|
---|
123 | }
|
---|
124 | }
|
---|
125 | return comp;
|
---|
126 | }
|
---|
127 |
|
---|
128 | BOOL IsNewer(char *file1, char *file2)
|
---|
129 | {
|
---|
130 | /* return TRUE if file2 is newer than file1 */
|
---|
131 |
|
---|
132 | return (TestDates(file1, file2) > 0);
|
---|
133 | }
|
---|
134 |
|
---|
135 | BOOL IsDesktop(HAB hab, HWND hwnd)
|
---|
136 | {
|
---|
137 | HWND hwndDesktop;
|
---|
138 |
|
---|
139 | if (hwnd == HWND_DESKTOP)
|
---|
140 | return TRUE;
|
---|
141 | hwndDesktop = WinQueryDesktopWindow(hab, NULLHANDLE);
|
---|
142 | if (hwnd == hwndDesktop)
|
---|
143 | return TRUE;
|
---|
144 | return FALSE;
|
---|
145 | }
|
---|
146 |
|
---|
147 | BOOL ParentIsDesktop(HWND hwnd, HWND hwndParent)
|
---|
148 | {
|
---|
149 | HWND hwndDesktop;
|
---|
150 | BOOL ret = FALSE;
|
---|
151 |
|
---|
152 | if (!hwndParent)
|
---|
153 | hwndParent = WinQueryWindow(hwnd, QW_PARENT);
|
---|
154 | if (hwndParent == HWND_DESKTOP)
|
---|
155 | ret = TRUE;
|
---|
156 | else {
|
---|
157 | hwndDesktop = WinQueryDesktopWindow(WinQueryAnchorBlock(hwnd), (HWND) 0);
|
---|
158 | if (hwndDesktop == hwndParent)
|
---|
159 | ret = TRUE;
|
---|
160 | }
|
---|
161 | return ret;
|
---|
162 | }
|
---|
163 |
|
---|
164 | /* CheckDrive
|
---|
165 | * @param chDrive drive letter
|
---|
166 | * @param pszFileSystem pointer to buffer to return file system type or NULL
|
---|
167 | * @param pulType pointer to long word to return drive flags or NULL
|
---|
168 | * @returns removability flag, 1 = removable, 0 = not removable, -1 = error
|
---|
169 | */
|
---|
170 |
|
---|
171 | INT CheckDrive(CHAR chDrive, CHAR * pszFileSystem, ULONG * pulType)
|
---|
172 | {
|
---|
173 | CHAR szPath[3];
|
---|
174 | VOID *pvBuffer = NULL;
|
---|
175 | CHAR *pfsn;
|
---|
176 | CHAR *pfsd;
|
---|
177 | ULONG clBufferSize;
|
---|
178 | APIRET rc;
|
---|
179 | ULONG ulAction;
|
---|
180 | ULONG clParmBytes;
|
---|
181 | ULONG clDataBytes;
|
---|
182 | HFILE hDev;
|
---|
183 |
|
---|
184 | # pragma pack(1)
|
---|
185 | struct
|
---|
186 | {
|
---|
187 | BYTE Cmd;
|
---|
188 | BYTE Unit;
|
---|
189 | }
|
---|
190 | parmPkt =
|
---|
191 | {
|
---|
192 | 0, 0};
|
---|
193 | # define BPB_REMOVABLE_MEDIA 0x08 // 3 - Media is removable
|
---|
194 | struct
|
---|
195 | {
|
---|
196 | BIOSPARAMETERBLOCK bpb;
|
---|
197 | USHORT cCylinders; // Documented but not implemented
|
---|
198 | BYTE bDeviceType; // Documented but not implemented
|
---|
199 | USHORT fsDeviceAttr; // Documented but not implemented
|
---|
200 | }
|
---|
201 | dataPkt;
|
---|
202 |
|
---|
203 | # pragma pack()
|
---|
204 | BYTE NonRemovable;
|
---|
205 | PFSQBUFFER2 pfsq;
|
---|
206 |
|
---|
207 | if (pszFileSystem)
|
---|
208 | *pszFileSystem = 0;
|
---|
209 |
|
---|
210 | if (pulType)
|
---|
211 | *pulType = 0;
|
---|
212 |
|
---|
213 | # define BUFFER_BYTES 8192
|
---|
214 | rc = DosAllocMem(&pvBuffer, BUFFER_BYTES,
|
---|
215 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
|
---|
216 | if (rc) {
|
---|
217 | Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
218 | GetPString(IDS_OUTOFMEMORY));
|
---|
219 | return -1; // Say failed
|
---|
220 | }
|
---|
221 |
|
---|
222 | szPath[0] = chDrive;
|
---|
223 | szPath[1] = ':';
|
---|
224 | szPath[2] = 0;
|
---|
225 | clBufferSize = BUFFER_BYTES;
|
---|
226 | DosError(FERR_DISABLEHARDERR);
|
---|
227 | rc = DosQueryFSAttach(szPath, 0, FSAIL_QUERYNAME,
|
---|
228 | (PFSQBUFFER2) pvBuffer, &clBufferSize);
|
---|
229 | if (rc) {
|
---|
230 | /* can't get any info at all */
|
---|
231 | DosFreeMem(pvBuffer);
|
---|
232 | DosError(FERR_DISABLEHARDERR);
|
---|
233 | return -1; // Say failed
|
---|
234 | }
|
---|
235 |
|
---|
236 | pfsq = (PFSQBUFFER2) pvBuffer;
|
---|
237 | pfsn = pfsq->szName + pfsq->cbName + 1;
|
---|
238 | pfsd = pfsn + pfsq->cbFSDName + 1;
|
---|
239 |
|
---|
240 | if (pszFileSystem) {
|
---|
241 | strncpy(pszFileSystem, pfsn, CCHMAXPATH);
|
---|
242 | pszFileSystem[CCHMAXPATH - 1] = 0;
|
---|
243 | }
|
---|
244 |
|
---|
245 | if (pulType && (!strcmp(pfsn, CDFS) || !strcmp(pfsn, ISOFS)))
|
---|
246 | *pulType |= DRIVE_NOTWRITEABLE | DRIVE_CDROM | DRIVE_REMOVABLE;
|
---|
247 | if (pulType && !strcmp(pfsn, NDFS32)){
|
---|
248 | *pulType |= DRIVE_VIRTUAL;
|
---|
249 | }
|
---|
250 | if (pulType && !strcmp(pfsn, RAMFS)){
|
---|
251 | *pulType |= DRIVE_RAMDISK;
|
---|
252 | }
|
---|
253 | if (((PFSQBUFFER2) pvBuffer)->iType == FSAT_REMOTEDRV &&
|
---|
254 | (strcmp(pfsn, CDFS) && strcmp(pfsn, ISOFS))) {
|
---|
255 | if (pulType)
|
---|
256 | *pulType |= DRIVE_REMOTE;
|
---|
257 |
|
---|
258 | if (pulType && !strcmp(pfsn, CBSIFS)) {
|
---|
259 | *pulType |= DRIVE_ZIPSTREAM;
|
---|
260 | *pulType &= ~DRIVE_REMOTE;
|
---|
261 | *pulType |= DRIVE_NOLONGNAMES;
|
---|
262 | if (pfsq->cbFSAData) {
|
---|
263 | ULONG FType;
|
---|
264 |
|
---|
265 | if (CheckDrive(*pfsd, NULL, &FType) != -1) {
|
---|
266 | if (FType & DRIVE_REMOVABLE)
|
---|
267 | *pulType |= DRIVE_REMOVABLE;
|
---|
268 | if (~FType & DRIVE_NOLONGNAMES)
|
---|
269 | *pulType &= ~DRIVE_NOLONGNAMES;
|
---|
270 | }
|
---|
271 |
|
---|
272 | }
|
---|
273 | }
|
---|
274 | if (pulType &&
|
---|
275 | (!strcmp(pfsn, HPFS) ||
|
---|
276 | !strcmp(pfsn, JFS) ||
|
---|
277 | !strcmp(pfsn, FAT32) ||
|
---|
278 | !strcmp(pfsn, RAMFS) ||
|
---|
279 | !strcmp(pfsn, NDFS32) ||
|
---|
280 | !strcmp(pfsn, HPFS386))) {
|
---|
281 | *pulType &= ~DRIVE_NOLONGNAMES;
|
---|
282 | }
|
---|
283 |
|
---|
284 | DosFreeMem(pvBuffer);
|
---|
285 | return 0; // Remotes are non-removable
|
---|
286 | }
|
---|
287 |
|
---|
288 | // Local drive
|
---|
289 | if (strcmp(pfsn, HPFS) &&
|
---|
290 | strcmp(pfsn, JFS) &&
|
---|
291 | strcmp(pfsn, CDFS) &&
|
---|
292 | strcmp(pfsn, ISOFS) &&
|
---|
293 | strcmp(pfsn, RAMFS) &&
|
---|
294 | strcmp(pfsn, FAT32) &&
|
---|
295 | strcmp(pfsn, NDFS32) &&
|
---|
296 | strcmp(pfsn, HPFS386)) {
|
---|
297 | if (pulType)
|
---|
298 | (*pulType) |= DRIVE_NOLONGNAMES; // Others can not have long names
|
---|
299 | }
|
---|
300 |
|
---|
301 |
|
---|
302 | DosError(FERR_DISABLEHARDERR);
|
---|
303 | rc = DosOpen(szPath, &hDev, &ulAction, 0, 0, FILE_OPEN,
|
---|
304 | OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE |
|
---|
305 | OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR, 0);
|
---|
306 | if (rc) {
|
---|
307 | DosError(FERR_DISABLEHARDERR);
|
---|
308 | if (pulType)
|
---|
309 | *pulType |= DRIVE_REMOVABLE; // Assume removable if can not access
|
---|
310 | DosFreeMem(pvBuffer);
|
---|
311 | return 1; // Say removable
|
---|
312 | }
|
---|
313 |
|
---|
314 | clParmBytes = sizeof(parmPkt.Cmd);
|
---|
315 | clDataBytes = sizeof(NonRemovable);
|
---|
316 | NonRemovable = 1; // Preset as non removable
|
---|
317 | DosError(FERR_DISABLEHARDERR);
|
---|
318 | rc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_BLOCKREMOVABLE, &parmPkt.Cmd, /* Address of the command-specific argument list. */
|
---|
319 | sizeof(parmPkt.Cmd), /* Length, in bytes, of pParams. */
|
---|
320 | &clParmBytes, /* Pointer to the length of parameters. */
|
---|
321 | &NonRemovable, /* Address of the data area. */
|
---|
322 | sizeof(NonRemovable), /* Length, in bytes, of pData. */
|
---|
323 | &clDataBytes); /* Pointer to the length of data. */
|
---|
324 |
|
---|
325 | if (!rc && NonRemovable) {
|
---|
326 | // Could be USB so check BPB flags
|
---|
327 | clParmBytes = sizeof(parmPkt.Cmd);
|
---|
328 | clDataBytes = sizeof(dataPkt);
|
---|
329 | memset(&dataPkt, 0xff, sizeof(dataPkt));
|
---|
330 | DosError(FERR_DISABLEHARDERR);
|
---|
331 | rc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_GETDEVICEPARAMS, &parmPkt.Cmd, /* Address of the command-specific argument list. */
|
---|
332 | sizeof(parmPkt.Cmd), /* Length, in bytes, of pParams. */
|
---|
333 | &clParmBytes, /* Pointer to the length of parameters. */
|
---|
334 | &dataPkt, /* Address of the data area. */
|
---|
335 | sizeof(dataPkt), /* Length, in bytes, of pData. */
|
---|
336 | &clDataBytes); /* Pointer to the length of data. */
|
---|
337 |
|
---|
338 | if (!rc && (dataPkt.bpb.fsDeviceAttr & BPB_REMOVABLE_MEDIA))
|
---|
339 | NonRemovable = 0;
|
---|
340 | }
|
---|
341 |
|
---|
342 | DosClose(hDev);
|
---|
343 |
|
---|
344 | if (!NonRemovable && pulType)
|
---|
345 | *pulType |= DRIVE_REMOVABLE;
|
---|
346 |
|
---|
347 | DosFreeMem(pvBuffer);
|
---|
348 |
|
---|
349 | return NonRemovable ? 0 : 1;
|
---|
350 | }
|
---|
351 |
|
---|
352 | BOOL IsFileSame(CHAR * filename1, CHAR * filename2)
|
---|
353 | {
|
---|
354 | /* returns: -1 (error), 0 (is a directory), or 1 (is a file) */
|
---|
355 |
|
---|
356 | FILESTATUS3 fsa1, fsa2;
|
---|
357 | APIRET ret;
|
---|
358 |
|
---|
359 | if (filename1 && filename2) {
|
---|
360 | DosError(FERR_DISABLEHARDERR);
|
---|
361 | ret = DosQueryPathInfo(filename1, FIL_STANDARD, &fsa1,
|
---|
362 | (ULONG) sizeof(fsa1));
|
---|
363 | if (!ret) {
|
---|
364 | DosError(FERR_DISABLEHARDERR);
|
---|
365 | ret = DosQueryPathInfo(filename2, FIL_STANDARD, &fsa2,
|
---|
366 | (ULONG) sizeof(fsa2));
|
---|
367 | if (!ret) {
|
---|
368 | if (fsa1.cbFile == fsa2.cbFile &&
|
---|
369 | (fsa1.attrFile & (~FILE_ARCHIVED)) ==
|
---|
370 | (fsa2.attrFile & (~FILE_ARCHIVED)))
|
---|
371 | return TRUE;
|
---|
372 | }
|
---|
373 | }
|
---|
374 | }
|
---|
375 | return FALSE;
|
---|
376 | }
|
---|
377 |
|
---|
378 | INT IsFile(CHAR * filename)
|
---|
379 | {
|
---|
380 | /* returns: -1 (error), 0 (is a directory), or 1 (is a file) */
|
---|
381 |
|
---|
382 | FILESTATUS3 fsa;
|
---|
383 | APIRET ret;
|
---|
384 |
|
---|
385 | if (filename && *filename) {
|
---|
386 | DosError(FERR_DISABLEHARDERR);
|
---|
387 | ret = DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa));
|
---|
388 | if (!ret)
|
---|
389 | return ((fsa.attrFile & FILE_DIRECTORY) == 0);
|
---|
390 | else if (IsValidDrive(*filename) && IsRoot(filename))
|
---|
391 | return 0;
|
---|
392 | }
|
---|
393 | return -1; /* error; doesn't exist or can't read or null filename */
|
---|
394 | }
|
---|
395 |
|
---|
396 | BOOL IsFullName(CHAR * filename)
|
---|
397 | {
|
---|
398 | return (filename) ?
|
---|
399 | (isalpha(*filename) && filename[1] == ':' && filename[2] == '\\') : 0;
|
---|
400 | }
|
---|
401 |
|
---|
402 | BOOL IsRoot(CHAR * filename)
|
---|
403 | {
|
---|
404 | return (filename && isalpha(*filename) && filename[1] == ':' &&
|
---|
405 | filename[2] == '\\' && !filename[3]);
|
---|
406 | }
|
---|
407 |
|
---|
408 | BOOL IsValidDir(CHAR * path)
|
---|
409 | {
|
---|
410 | CHAR fullname[CCHMAXPATH];
|
---|
411 | FILESTATUS3 fs;
|
---|
412 |
|
---|
413 | if (path) {
|
---|
414 | DosError(FERR_DISABLEHARDERR);
|
---|
415 | if (!DosQueryPathInfo(path,
|
---|
416 | FIL_QUERYFULLNAME, fullname, sizeof(fullname))) {
|
---|
417 | if (IsValidDrive(*fullname)) {
|
---|
418 | if (!IsRoot(fullname)) {
|
---|
419 | DosError(FERR_DISABLEHARDERR);
|
---|
420 | if (!DosQueryPathInfo(fullname,
|
---|
421 | FIL_STANDARD,
|
---|
422 | &fs,
|
---|
423 | sizeof(fs)) && (fs.attrFile & FILE_DIRECTORY))
|
---|
424 | return TRUE;
|
---|
425 | }
|
---|
426 | else
|
---|
427 | return TRUE;
|
---|
428 | }
|
---|
429 | }
|
---|
430 | }
|
---|
431 | return FALSE;
|
---|
432 | }
|
---|
433 |
|
---|
434 | BOOL IsValidDrive(CHAR drive)
|
---|
435 | {
|
---|
436 | CHAR Path[] = " :", Buffer[256];
|
---|
437 | APIRET Status;
|
---|
438 | ULONG Size;
|
---|
439 | ULONG ulDriveNum, ulDriveMap;
|
---|
440 |
|
---|
441 | if (!isalpha(drive) ||
|
---|
442 | (driveflags[toupper(drive) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)))
|
---|
443 | return FALSE;
|
---|
444 | DosError(FERR_DISABLEHARDERR);
|
---|
445 | Status = DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
446 | if (!Status) {
|
---|
447 | if (!(ulDriveMap & (1L << (ULONG) (toupper(drive) - 'A'))))
|
---|
448 | return FALSE;
|
---|
449 | Path[0] = toupper(drive);
|
---|
450 | Size = sizeof(Buffer);
|
---|
451 | DosError(FERR_DISABLEHARDERR);
|
---|
452 | Status = DosQueryFSAttach(Path,
|
---|
453 | 0,
|
---|
454 | FSAIL_QUERYNAME, (PFSQBUFFER2) Buffer, &Size);
|
---|
455 | }
|
---|
456 | return (Status == 0);
|
---|
457 | }
|
---|
458 |
|
---|
459 | //=== MakeValidDir() build valid directory name ===
|
---|
460 |
|
---|
461 | CHAR *MakeValidDir(CHAR * path)
|
---|
462 | {
|
---|
463 | ULONG ulDrv;
|
---|
464 | CHAR *p;
|
---|
465 | FILESTATUS3 fs;
|
---|
466 | APIRET rc;
|
---|
467 |
|
---|
468 | if (!MakeFullName(path)) {
|
---|
469 | if (IsValidDrive(*path)) {
|
---|
470 | // Passed name is valid - trim to directory
|
---|
471 | for (;;) {
|
---|
472 | if (IsRoot(path))
|
---|
473 | return path;
|
---|
474 | DosError(FERR_DISABLEHARDERR);
|
---|
475 | rc = DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs));
|
---|
476 | if (!rc && (fs.attrFile & FILE_DIRECTORY))
|
---|
477 | return path;
|
---|
478 | p = strrchr(path, '\\');
|
---|
479 | if (p) {
|
---|
480 | if (p < path + 3)
|
---|
481 | p++;
|
---|
482 | *p = 0;
|
---|
483 | }
|
---|
484 | else
|
---|
485 | break;
|
---|
486 | }
|
---|
487 | }
|
---|
488 | }
|
---|
489 | // Fall back to boot drive
|
---|
490 | DosError(FERR_DISABLEHARDERR);
|
---|
491 | if (!DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulDrv, sizeof(ulDrv))) {
|
---|
492 | ulDrv += '@';
|
---|
493 | if (ulDrv < 'C')
|
---|
494 | ulDrv = 'C';
|
---|
495 | strcpy(path, " :\\");
|
---|
496 | *path = (CHAR) ulDrv;
|
---|
497 | }
|
---|
498 | else
|
---|
499 | save_dir2(path); // Fall back to fm3.ini drive or current dir - should never occur
|
---|
500 | return path;
|
---|
501 | }
|
---|
502 |
|
---|
503 | BOOL IsExecutable(CHAR * filename)
|
---|
504 | {
|
---|
505 | register CHAR *p;
|
---|
506 | APIRET ret;
|
---|
507 | ULONG apptype;
|
---|
508 |
|
---|
509 | if (filename) {
|
---|
510 | DosError(FERR_DISABLEHARDERR);
|
---|
511 | p = strrchr(filename, '.');
|
---|
512 | if (p)
|
---|
513 | ret = DosQAppType(filename, &apptype);
|
---|
514 | else {
|
---|
515 |
|
---|
516 | char fname[CCHMAXPATH + 2];
|
---|
517 |
|
---|
518 | strcpy(fname, filename);
|
---|
519 | strcat(fname, ".");
|
---|
520 | ret = DosQAppType(fname, &apptype);
|
---|
521 | }
|
---|
522 | if ((!ret && (!apptype ||
|
---|
523 | (apptype &
|
---|
524 | (FAPPTYP_NOTWINDOWCOMPAT |
|
---|
525 | FAPPTYP_WINDOWCOMPAT |
|
---|
526 | FAPPTYP_WINDOWAPI |
|
---|
527 | FAPPTYP_BOUND |
|
---|
528 | FAPPTYP_DOS |
|
---|
529 | FAPPTYP_WINDOWSREAL |
|
---|
530 | FAPPTYP_WINDOWSPROT |
|
---|
531 | FAPPTYP_32BIT |
|
---|
532 | 0x1000)))) ||
|
---|
533 | (p && (!stricmp(p, ".CMD") || !stricmp(p, ".BAT"))))
|
---|
534 | return TRUE;
|
---|
535 | }
|
---|
536 | return FALSE;
|
---|
537 | }
|
---|
538 |
|
---|
539 | VOID ArgDriveFlags(INT argc, CHAR ** argv)
|
---|
540 | {
|
---|
541 | INT x;
|
---|
542 |
|
---|
543 | for (x = 1; x < argc; x++) {
|
---|
544 | if (*argv[x] == '/' && isalpha(argv[x][1])) {
|
---|
545 |
|
---|
546 | CHAR *p = &argv[x][1];
|
---|
547 |
|
---|
548 | while (isalpha(*p)) {
|
---|
549 | driveflags[toupper(*p) - 'A'] |= DRIVE_IGNORE;
|
---|
550 | p++;
|
---|
551 | }
|
---|
552 | }
|
---|
553 | else if (*argv[x] == ';' && isalpha(argv[x][1])) {
|
---|
554 |
|
---|
555 | CHAR *p = &argv[x][1];
|
---|
556 |
|
---|
557 | while (isalpha(*p)) {
|
---|
558 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOPRESCAN;
|
---|
559 | p++;
|
---|
560 | }
|
---|
561 | }
|
---|
562 | else if (*argv[x] == '`' && isalpha(argv[x][1])) {
|
---|
563 |
|
---|
564 | CHAR *p = &argv[x][1];
|
---|
565 |
|
---|
566 | while (isalpha(*p)) {
|
---|
567 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOSTATS;
|
---|
568 | p++;
|
---|
569 | }
|
---|
570 | }
|
---|
571 | else if (*argv[x] == ',' && isalpha(argv[x][1])) {
|
---|
572 |
|
---|
573 | CHAR *p = &argv[x][1];
|
---|
574 |
|
---|
575 | while (isalpha(*p)) {
|
---|
576 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADICONS;
|
---|
577 | p++;
|
---|
578 | }
|
---|
579 | }
|
---|
580 | else if (*argv[x] == '-' && isalpha(argv[x][1])) {
|
---|
581 |
|
---|
582 | CHAR *p = &argv[x][1];
|
---|
583 |
|
---|
584 | while (isalpha(*p)) {
|
---|
585 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADSUBJS;
|
---|
586 | p++;
|
---|
587 | }
|
---|
588 | }
|
---|
589 | else if (*argv[x] == '\'' && isalpha(argv[x][1])) {
|
---|
590 |
|
---|
591 | CHAR *p = &argv[x][1];
|
---|
592 |
|
---|
593 | while (isalpha(*p)) {
|
---|
594 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADLONGS;
|
---|
595 | p++;
|
---|
596 | }
|
---|
597 | }
|
---|
598 | }
|
---|
599 | }
|
---|
600 |
|
---|
601 | VOID DriveFlagsOne(INT x)
|
---|
602 | {
|
---|
603 | INT removable;
|
---|
604 | CHAR szDrive[] = " :\\", FileSystem[CCHMAXPATH];
|
---|
605 | ULONG drvtype;
|
---|
606 |
|
---|
607 | *szDrive = (CHAR) (x + 'A');
|
---|
608 | *FileSystem = 0;
|
---|
609 | drvtype = 0;
|
---|
610 | removable = CheckDrive(*szDrive, FileSystem, &drvtype);
|
---|
611 | driveserial[x] = -1;
|
---|
612 | driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
|
---|
613 | DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
|
---|
614 | DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS);
|
---|
615 | if (removable != -1) {
|
---|
616 | struct
|
---|
617 | {
|
---|
618 | ULONG serial;
|
---|
619 | CHAR volumelength;
|
---|
620 | CHAR volumelabel[CCHMAXPATH];
|
---|
621 | }
|
---|
622 | volser;
|
---|
623 |
|
---|
624 | DosError(FERR_DISABLEHARDERR);
|
---|
625 | if (!DosQueryFSInfo((ULONG) x + 1, FSIL_VOLSER, &volser, sizeof(volser)))
|
---|
626 | driveserial[x] = volser.serial;
|
---|
627 | else
|
---|
628 | DosError(FERR_DISABLEHARDERR);
|
---|
629 | }
|
---|
630 | else
|
---|
631 | driveflags[x] |= DRIVE_INVALID;
|
---|
632 | driveflags[x] |= ((removable == -1 || removable == 1) ?
|
---|
633 | DRIVE_REMOVABLE : 0);
|
---|
634 | if (drvtype & DRIVE_REMOTE)
|
---|
635 | driveflags[x] |= DRIVE_REMOTE;
|
---|
636 | if(!stricmp(FileSystem,NDFS32)){
|
---|
637 | driveflags[x] |= DRIVE_VIRTUAL;
|
---|
638 | driveflags[x] &= (~DRIVE_REMOTE);
|
---|
639 | }
|
---|
640 | if(!stricmp(FileSystem,RAMFS)){
|
---|
641 | driveflags[x] |= DRIVE_RAMDISK;
|
---|
642 | driveflags[x] &= (~DRIVE_REMOTE);
|
---|
643 | }
|
---|
644 | if (strcmp(FileSystem, HPFS) &&
|
---|
645 | strcmp(FileSystem, JFS) &&
|
---|
646 | strcmp(FileSystem, CDFS) &&
|
---|
647 | strcmp(FileSystem, ISOFS) &&
|
---|
648 | strcmp(FileSystem, RAMFS) &&
|
---|
649 | strcmp(FileSystem, FAT32) &&
|
---|
650 | strcmp(FileSystem, HPFS386)) {
|
---|
651 | driveflags[x] |= DRIVE_NOLONGNAMES;
|
---|
652 | }
|
---|
653 |
|
---|
654 | if (!strcmp(FileSystem, CDFS) || !strcmp(FileSystem, ISOFS)) {
|
---|
655 | removable = 1;
|
---|
656 | driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE | DRIVE_CDROM);
|
---|
657 | }
|
---|
658 | else if (!stricmp(FileSystem, CBSIFS)) {
|
---|
659 | driveflags[x] |= DRIVE_ZIPSTREAM;
|
---|
660 | driveflags[x] &= (~DRIVE_REMOTE);
|
---|
661 | if (drvtype & DRIVE_REMOVABLE)
|
---|
662 | driveflags[x] |= DRIVE_REMOVABLE;
|
---|
663 | if (!(drvtype & DRIVE_NOLONGNAMES))
|
---|
664 | driveflags[x] &= (~DRIVE_NOLONGNAMES);
|
---|
665 | }
|
---|
666 | }
|
---|
667 |
|
---|
668 | VOID FillInDriveFlags(VOID * dummy)
|
---|
669 | {
|
---|
670 | ULONG ulDriveNum, ulDriveMap;
|
---|
671 | register INT x;
|
---|
672 |
|
---|
673 | for (x = 0; x < 26; x++)
|
---|
674 | driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
|
---|
675 | DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
|
---|
676 | DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS);
|
---|
677 | memset(driveserial, -1, sizeof(driveserial));
|
---|
678 | DosError(FERR_DISABLEHARDERR);
|
---|
679 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
680 | for (x = 0; x < 26; x++) {
|
---|
681 | if (ulDriveMap & (1L << x) && !(driveflags[x] & DRIVE_IGNORE)) {
|
---|
682 | {
|
---|
683 | CHAR s[80];
|
---|
684 | ULONG flags = 0, size = sizeof(ULONG);
|
---|
685 |
|
---|
686 | sprintf(s, "%c.DriveFlags", (CHAR) (x + 'A'));
|
---|
687 | if (PrfQueryProfileData(fmprof, appname, s, &flags, &size) &&
|
---|
688 | size == sizeof(ULONG))
|
---|
689 | driveflags[x] |= flags;
|
---|
690 | }
|
---|
691 |
|
---|
692 | if (x > 1) {
|
---|
693 | if (!(driveflags[x] & DRIVE_NOPRESCAN))
|
---|
694 | DriveFlagsOne(x);
|
---|
695 | else
|
---|
696 | driveserial[x] = -1;
|
---|
697 | }
|
---|
698 | else {
|
---|
699 | driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES);
|
---|
700 | driveserial[x] = -1;
|
---|
701 | }
|
---|
702 | }
|
---|
703 | else if (!(ulDriveMap & (1L << x)))
|
---|
704 | driveflags[x] |= DRIVE_INVALID;
|
---|
705 | }
|
---|
706 | {
|
---|
707 | ULONG startdrive = 3L;
|
---|
708 |
|
---|
709 | DosError(FERR_DISABLEHARDERR);
|
---|
710 | DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
711 | (PVOID) & startdrive, (ULONG) sizeof(ULONG));
|
---|
712 | if (startdrive)
|
---|
713 | driveflags[startdrive - 1] |= DRIVE_BOOT;
|
---|
714 | }
|
---|
715 | }
|
---|
716 |
|
---|
717 | CHAR *assign_ignores(CHAR * s)
|
---|
718 | {
|
---|
719 | register INT x;
|
---|
720 | register CHAR *p, *pp;
|
---|
721 |
|
---|
722 | *s = '/';
|
---|
723 | s[1] = 0;
|
---|
724 | p = s + 1;
|
---|
725 | if (s) {
|
---|
726 | for (x = 0; x < 26; x++) {
|
---|
727 | if ((driveflags[x] & DRIVE_IGNORE) != 0) {
|
---|
728 | *p = (CHAR) x + 'A';
|
---|
729 | p++;
|
---|
730 | *p = 0;
|
---|
731 | }
|
---|
732 | }
|
---|
733 | }
|
---|
734 | if (!s[1]) {
|
---|
735 | *s = 0;
|
---|
736 | pp = s;
|
---|
737 | }
|
---|
738 | else {
|
---|
739 | pp = &s[strlen(s)];
|
---|
740 | *pp = ' ';
|
---|
741 | pp++;
|
---|
742 | }
|
---|
743 | *pp = ';';
|
---|
744 | pp[1] = 0;
|
---|
745 | p = pp + 1;
|
---|
746 | if (pp) {
|
---|
747 | for (x = 0; x < 26; x++) {
|
---|
748 | if ((driveflags[x] & DRIVE_NOPRESCAN) != 0) {
|
---|
749 | *p = (CHAR) x + 'A';
|
---|
750 | p++;
|
---|
751 | *p = 0;
|
---|
752 | }
|
---|
753 | }
|
---|
754 | }
|
---|
755 | if (!pp[1])
|
---|
756 | *pp = 0;
|
---|
757 | pp = &s[strlen(s)];
|
---|
758 | *pp = ' ';
|
---|
759 | pp++;
|
---|
760 | *pp = ',';
|
---|
761 | pp[1] = 0;
|
---|
762 | p = pp + 1;
|
---|
763 | if (pp) {
|
---|
764 | for (x = 0; x < 26; x++) {
|
---|
765 | if ((driveflags[x] & DRIVE_NOLOADICONS) != 0) {
|
---|
766 | *p = (CHAR) x + 'A';
|
---|
767 | p++;
|
---|
768 | *p = 0;
|
---|
769 | }
|
---|
770 | }
|
---|
771 | }
|
---|
772 | if (!pp[1])
|
---|
773 | *pp = 0;
|
---|
774 | pp = &s[strlen(s)];
|
---|
775 | *pp = ' ';
|
---|
776 | pp++;
|
---|
777 | *pp = '-';
|
---|
778 | pp[1] = 0;
|
---|
779 | p = pp + 1;
|
---|
780 | if (pp) {
|
---|
781 | for (x = 0; x < 26; x++) {
|
---|
782 | if ((driveflags[x] & DRIVE_NOLOADSUBJS) != 0) {
|
---|
783 | *p = (CHAR) x + 'A';
|
---|
784 | p++;
|
---|
785 | *p = 0;
|
---|
786 | }
|
---|
787 | }
|
---|
788 | }
|
---|
789 | if (!pp[1])
|
---|
790 | *pp = 0;
|
---|
791 | pp = &s[strlen(s)];
|
---|
792 | *pp = ' ';
|
---|
793 | pp++;
|
---|
794 | *pp = '`';
|
---|
795 | pp[1] = 0;
|
---|
796 | p = pp + 1;
|
---|
797 | if (pp) {
|
---|
798 | for (x = 0; x < 26; x++) {
|
---|
799 | if ((driveflags[x] & DRIVE_NOSTATS) != 0) {
|
---|
800 | *p = (CHAR) x + 'A';
|
---|
801 | p++;
|
---|
802 | *p = 0;
|
---|
803 | }
|
---|
804 | }
|
---|
805 | }
|
---|
806 | if (!pp[1])
|
---|
807 | *pp = 0;
|
---|
808 | pp = &s[strlen(s)];
|
---|
809 | *pp = ' ';
|
---|
810 | pp++;
|
---|
811 | *pp = '\'';
|
---|
812 | pp[1] = 0;
|
---|
813 | p = pp + 1;
|
---|
814 | if (pp) {
|
---|
815 | for (x = 0; x < 26; x++) {
|
---|
816 | if ((driveflags[x] & DRIVE_NOLOADLONGS) != 0) {
|
---|
817 | *p = (CHAR) x + 'A';
|
---|
818 | p++;
|
---|
819 | *p = 0;
|
---|
820 | }
|
---|
821 | }
|
---|
822 | }
|
---|
823 | if (!pp[1])
|
---|
824 | *pp = 0;
|
---|
825 | bstrip(s);
|
---|
826 | return s;
|
---|
827 | }
|
---|
828 |
|
---|
829 | BOOL needs_quoting(register CHAR * f)
|
---|
830 | {
|
---|
831 | register CHAR *p = " &|<>";
|
---|
832 |
|
---|
833 | while (*p) {
|
---|
834 | if (strchr(f, *p))
|
---|
835 | return TRUE;
|
---|
836 | p++;
|
---|
837 | }
|
---|
838 | return FALSE;
|
---|
839 | }
|
---|
840 |
|
---|
841 | BOOL IsBinary(register CHAR * str, ULONG len)
|
---|
842 | {
|
---|
843 | register ULONG x = 0L;
|
---|
844 |
|
---|
845 | if (str) {
|
---|
846 | while (x < len) {
|
---|
847 | if (str[x] < ' ' && str[x] != '\r' && str[x] != '\n' && str[x] != '\t'
|
---|
848 | && str[x] != '\x1b' && str[x] != '\x1a' && str[x] != '\07'
|
---|
849 | && str[x] != '\x0c')
|
---|
850 | return TRUE;
|
---|
851 | x++;
|
---|
852 | }
|
---|
853 | }
|
---|
854 | return FALSE;
|
---|
855 | }
|
---|
856 |
|
---|
857 | BOOL TestBinary(CHAR * filename)
|
---|
858 | {
|
---|
859 | HFILE handle;
|
---|
860 | ULONG ulAction;
|
---|
861 | ULONG len;
|
---|
862 | APIRET rc;
|
---|
863 | CHAR buff[512];
|
---|
864 |
|
---|
865 | if (filename) {
|
---|
866 | if (!DosOpen(filename, &handle, &ulAction, 0L, 0L,
|
---|
867 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
868 | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT |
|
---|
869 | OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE |
|
---|
870 | OPEN_ACCESS_READONLY, 0L)) {
|
---|
871 | len = 512;
|
---|
872 | rc = DosRead(handle, buff, len, &len);
|
---|
873 | DosClose(handle);
|
---|
874 | if (!rc && len)
|
---|
875 | return IsBinary(buff, len);
|
---|
876 | }
|
---|
877 | }
|
---|
878 | return FALSE;
|
---|
879 | }
|
---|
880 |
|
---|
881 | char *IsVowel(char a)
|
---|
882 | {
|
---|
883 | return (strchr("aeiouAEIOU", a) != NULL) ? "n" : NullStr;
|
---|
884 | }
|
---|
885 |
|
---|
886 | VOID GetDesktopName(CHAR * objectpath, ULONG size)
|
---|
887 | {
|
---|
888 | PFN WQDPath;
|
---|
889 | HMODULE hmod = 0;
|
---|
890 | APIRET rc;
|
---|
891 | ULONG startdrive = 3L;
|
---|
892 | CHAR objerr[CCHMAXPATH];
|
---|
893 |
|
---|
894 | if (!objectpath) {
|
---|
895 | Runtime_Error(pszSrcFile, __LINE__, "null pointer");
|
---|
896 | return;
|
---|
897 | }
|
---|
898 | *objectpath = 0;
|
---|
899 | if (OS2ver[0] > 20 || (OS2ver[0] == 20 && OS2ver[1] >= 30)) {
|
---|
900 | /*
|
---|
901 | * if running under warp, we can get the desktop name
|
---|
902 | * this way...
|
---|
903 | */
|
---|
904 | rc = DosLoadModule(objerr, sizeof(objerr), "PMWP", &hmod);
|
---|
905 | if (!rc) {
|
---|
906 | rc = DosQueryProcAddr(hmod, 262, NULL, &WQDPath);
|
---|
907 | if (!rc)
|
---|
908 | WQDPath(objectpath, size);
|
---|
909 | DosFreeModule(hmod);
|
---|
910 | }
|
---|
911 | }
|
---|
912 | if (!*objectpath) {
|
---|
913 | // Fall back to INI content
|
---|
914 | if (!PrfQueryProfileString(HINI_SYSTEMPROFILE,
|
---|
915 | "FolderWorkareaRunningObjects",
|
---|
916 | NULL,
|
---|
917 | "\0",
|
---|
918 | (PVOID) objectpath, sizeof(objectpath))) {
|
---|
919 | Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
920 | "PrfQueryProfileString");
|
---|
921 | *objectpath = 0;
|
---|
922 | }
|
---|
923 | else if (!*objectpath || IsFile(objectpath)) {
|
---|
924 | Runtime_Error(pszSrcFile, __LINE__, "bad FolderWorkareaRunningObjects");
|
---|
925 | *objectpath = 0;
|
---|
926 | }
|
---|
927 | if (!*objectpath) {
|
---|
928 | // Fall back
|
---|
929 | DosError(FERR_DISABLEHARDERR);
|
---|
930 | DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
931 | (PVOID) & startdrive, (ULONG) sizeof(ULONG));
|
---|
932 | sprintf(objectpath, GetPString(IDS_PATHTODESKTOP), ((CHAR) startdrive) + '@');
|
---|
933 | }
|
---|
934 | }
|
---|
935 | }
|
---|