source: trunk/dll/valid.c@ 847

Last change on this file since 847 was 847, checked in by Gregg Young, 18 years ago

Removed large file APIs from code where hey are not needed.

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