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