source: trunk/dll/valid.c@ 555

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

Added NTFS support (read only); minor dive icon code cleanup; update help files

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 22.3 KB
Line 
1
2/***********************************************************************
3
4 $Id: valid.c 555 2007-03-04 05:01:14Z 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
41static 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
51APIRET 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
66char *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
85int 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
128BOOL IsNewer(char *file1, char *file2)
129{
130 /* return TRUE if file2 is newer than file1 */
131
132 return (TestDates(file1, file2) > 0);
133}
134
135BOOL 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
147BOOL 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
171INT 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, NTFS))
248 *pulType |= DRIVE_NOTWRITEABLE;
249 if (pulType && !strcmp(pfsn, NDFS32)){
250 *pulType |= DRIVE_VIRTUAL;
251 }
252 if (pulType && !strcmp(pfsn, RAMFS)){
253 *pulType |= DRIVE_RAMDISK;
254 }
255 if (((PFSQBUFFER2) pvBuffer)->iType == FSAT_REMOTEDRV &&
256 (strcmp(pfsn, CDFS) || strcmp(pfsn, ISOFS))) {
257 if (pulType)
258 *pulType |= DRIVE_REMOTE;
259
260 if (pulType && !strcmp(pfsn, CBSIFS)) {
261 *pulType |= DRIVE_ZIPSTREAM;
262 *pulType &= ~DRIVE_REMOTE;
263 *pulType |= DRIVE_NOLONGNAMES;
264 if (pfsq->cbFSAData) {
265 ULONG FType;
266
267 if (CheckDrive(*pfsd, NULL, &FType) != -1) {
268 if (FType & DRIVE_REMOVABLE)
269 *pulType |= DRIVE_REMOVABLE;
270 if (~FType & DRIVE_NOLONGNAMES)
271 *pulType &= ~DRIVE_NOLONGNAMES;
272 }
273
274 }
275 }
276 if (pulType &&
277 (!strcmp(pfsn, HPFS) ||
278 !strcmp(pfsn, JFS) ||
279 !strcmp(pfsn, FAT32) ||
280 !strcmp(pfsn, RAMFS) ||
281 !strcmp(pfsn, NDFS32) ||
282 !strcmp(pfsn, NTFS) ||
283 !strcmp(pfsn, HPFS386))) {
284 *pulType &= ~DRIVE_NOLONGNAMES;
285 }
286
287 DosFreeMem(pvBuffer);
288 return 0; // Remotes are non-removable
289 }
290
291 // Local drive
292 if (strcmp(pfsn, HPFS) &&
293 strcmp(pfsn, JFS) &&
294 strcmp(pfsn, CDFS) &&
295 strcmp(pfsn, ISOFS) &&
296 strcmp(pfsn, RAMFS) &&
297 strcmp(pfsn, FAT32) &&
298 strcmp(pfsn, NDFS32) &&
299 strcmp(pfsn, NTFS) &&
300 strcmp(pfsn, HPFS386)) {
301 if (pulType)
302 (*pulType) |= DRIVE_NOLONGNAMES; // Others can not have long names
303 }
304
305
306 DosError(FERR_DISABLEHARDERR);
307 rc = DosOpen(szPath, &hDev, &ulAction, 0, 0, FILE_OPEN,
308 OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE |
309 OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR, 0);
310 if (rc) {
311 DosError(FERR_DISABLEHARDERR);
312 if (pulType)
313 *pulType |= DRIVE_REMOVABLE; // Assume removable if can not access
314 DosFreeMem(pvBuffer);
315 return 1; // Say removable
316 }
317
318 clParmBytes = sizeof(parmPkt.Cmd);
319 clDataBytes = sizeof(NonRemovable);
320 NonRemovable = 1; // Preset as non removable
321 DosError(FERR_DISABLEHARDERR);
322 rc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_BLOCKREMOVABLE, &parmPkt.Cmd, /* Address of the command-specific argument list. */
323 sizeof(parmPkt.Cmd), /* Length, in bytes, of pParams. */
324 &clParmBytes, /* Pointer to the length of parameters. */
325 &NonRemovable, /* Address of the data area. */
326 sizeof(NonRemovable), /* Length, in bytes, of pData. */
327 &clDataBytes); /* Pointer to the length of data. */
328
329 if (!rc && NonRemovable) {
330 // Could be USB so check BPB flags
331 clParmBytes = sizeof(parmPkt.Cmd);
332 clDataBytes = sizeof(dataPkt);
333 memset(&dataPkt, 0xff, sizeof(dataPkt));
334 DosError(FERR_DISABLEHARDERR);
335 rc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_GETDEVICEPARAMS, &parmPkt.Cmd, /* Address of the command-specific argument list. */
336 sizeof(parmPkt.Cmd), /* Length, in bytes, of pParams. */
337 &clParmBytes, /* Pointer to the length of parameters. */
338 &dataPkt, /* Address of the data area. */
339 sizeof(dataPkt), /* Length, in bytes, of pData. */
340 &clDataBytes); /* Pointer to the length of data. */
341
342 if (!rc && (dataPkt.bpb.fsDeviceAttr & BPB_REMOVABLE_MEDIA))
343 NonRemovable = 0;
344 }
345
346 DosClose(hDev);
347
348 if (!NonRemovable && pulType)
349 *pulType |= DRIVE_REMOVABLE;
350
351 DosFreeMem(pvBuffer);
352
353 return NonRemovable ? 0 : 1;
354}
355
356BOOL IsFileSame(CHAR * filename1, CHAR * filename2)
357{
358 /* returns: -1 (error), 0 (is a directory), or 1 (is a file) */
359
360 FILESTATUS3 fsa1, fsa2;
361 APIRET ret;
362
363 if (filename1 && filename2) {
364 DosError(FERR_DISABLEHARDERR);
365 ret = DosQueryPathInfo(filename1, FIL_STANDARD, &fsa1,
366 (ULONG) sizeof(fsa1));
367 if (!ret) {
368 DosError(FERR_DISABLEHARDERR);
369 ret = DosQueryPathInfo(filename2, FIL_STANDARD, &fsa2,
370 (ULONG) sizeof(fsa2));
371 if (!ret) {
372 if (fsa1.cbFile == fsa2.cbFile &&
373 (fsa1.attrFile & (~FILE_ARCHIVED)) ==
374 (fsa2.attrFile & (~FILE_ARCHIVED)))
375 return TRUE;
376 }
377 }
378 }
379 return FALSE;
380}
381
382INT IsFile(CHAR * filename)
383{
384 /* returns: -1 (error), 0 (is a directory), or 1 (is a file) */
385
386 FILESTATUS3 fsa;
387 APIRET ret;
388
389 if (filename && *filename) {
390 DosError(FERR_DISABLEHARDERR);
391 ret = DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa));
392 if (!ret)
393 return ((fsa.attrFile & FILE_DIRECTORY) == 0);
394 else if (IsValidDrive(*filename) && IsRoot(filename))
395 return 0;
396 }
397 return -1; /* error; doesn't exist or can't read or null filename */
398}
399
400BOOL IsFullName(CHAR * filename)
401{
402 return (filename) ?
403 (isalpha(*filename) && filename[1] == ':' && filename[2] == '\\') : 0;
404}
405
406BOOL IsRoot(CHAR * filename)
407{
408 return (filename && isalpha(*filename) && filename[1] == ':' &&
409 filename[2] == '\\' && !filename[3]);
410}
411
412BOOL IsValidDir(CHAR * path)
413{
414 CHAR fullname[CCHMAXPATH];
415 FILESTATUS3 fs;
416
417 if (path) {
418 DosError(FERR_DISABLEHARDERR);
419 if (!DosQueryPathInfo(path,
420 FIL_QUERYFULLNAME, fullname, sizeof(fullname))) {
421 if (IsValidDrive(*fullname)) {
422 if (!IsRoot(fullname)) {
423 DosError(FERR_DISABLEHARDERR);
424 if (!DosQueryPathInfo(fullname,
425 FIL_STANDARD,
426 &fs,
427 sizeof(fs)) && (fs.attrFile & FILE_DIRECTORY))
428 return TRUE;
429 }
430 else
431 return TRUE;
432 }
433 }
434 }
435 return FALSE;
436}
437
438BOOL IsValidDrive(CHAR drive)
439{
440 CHAR Path[] = " :", Buffer[256];
441 APIRET Status;
442 ULONG Size;
443 ULONG ulDriveNum, ulDriveMap;
444
445 if (!isalpha(drive) ||
446 (driveflags[toupper(drive) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)))
447 return FALSE;
448 DosError(FERR_DISABLEHARDERR);
449 Status = DosQCurDisk(&ulDriveNum, &ulDriveMap);
450 if (!Status) {
451 if (!(ulDriveMap & (1L << (ULONG) (toupper(drive) - 'A'))))
452 return FALSE;
453 Path[0] = toupper(drive);
454 Size = sizeof(Buffer);
455 DosError(FERR_DISABLEHARDERR);
456 Status = DosQueryFSAttach(Path,
457 0,
458 FSAIL_QUERYNAME, (PFSQBUFFER2) Buffer, &Size);
459 }
460 return (Status == 0);
461}
462
463//=== MakeValidDir() build valid directory name ===
464
465CHAR *MakeValidDir(CHAR * path)
466{
467 ULONG ulDrv;
468 CHAR *p;
469 FILESTATUS3 fs;
470 APIRET rc;
471
472 if (!MakeFullName(path)) {
473 if (IsValidDrive(*path)) {
474 // Passed name is valid - trim to directory
475 for (;;) {
476 if (IsRoot(path))
477 return path;
478 DosError(FERR_DISABLEHARDERR);
479 rc = DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs));
480 if (!rc && (fs.attrFile & FILE_DIRECTORY))
481 return path;
482 p = strrchr(path, '\\');
483 if (p) {
484 if (p < path + 3)
485 p++;
486 *p = 0;
487 }
488 else
489 break;
490 }
491 }
492 }
493 // Fall back to boot drive
494 DosError(FERR_DISABLEHARDERR);
495 if (!DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulDrv, sizeof(ulDrv))) {
496 ulDrv += '@';
497 if (ulDrv < 'C')
498 ulDrv = 'C';
499 strcpy(path, " :\\");
500 *path = (CHAR) ulDrv;
501 }
502 else
503 save_dir2(path); // Fall back to fm3.ini drive or current dir - should never occur
504 return path;
505}
506
507BOOL IsExecutable(CHAR * filename)
508{
509 register CHAR *p;
510 APIRET ret;
511 ULONG apptype;
512
513 if (filename) {
514 DosError(FERR_DISABLEHARDERR);
515 p = strrchr(filename, '.');
516 if (p)
517 ret = DosQAppType(filename, &apptype);
518 else {
519
520 char fname[CCHMAXPATH + 2];
521
522 strcpy(fname, filename);
523 strcat(fname, ".");
524 ret = DosQAppType(fname, &apptype);
525 }
526 if ((!ret && (!apptype ||
527 (apptype &
528 (FAPPTYP_NOTWINDOWCOMPAT |
529 FAPPTYP_WINDOWCOMPAT |
530 FAPPTYP_WINDOWAPI |
531 FAPPTYP_BOUND |
532 FAPPTYP_DOS |
533 FAPPTYP_WINDOWSREAL |
534 FAPPTYP_WINDOWSPROT |
535 FAPPTYP_32BIT |
536 0x1000)))) ||
537 (p && (!stricmp(p, ".CMD") || !stricmp(p, ".BAT"))))
538 return TRUE;
539 }
540 return FALSE;
541}
542
543VOID ArgDriveFlags(INT argc, CHAR ** argv)
544{
545 INT x;
546
547 for (x = 1; x < argc; x++) {
548 if (*argv[x] == '/' && isalpha(argv[x][1])) {
549
550 CHAR *p = &argv[x][1];
551
552 while (isalpha(*p)) {
553 driveflags[toupper(*p) - 'A'] |= DRIVE_IGNORE;
554 p++;
555 }
556 }
557 else if (*argv[x] == ';' && isalpha(argv[x][1])) {
558
559 CHAR *p = &argv[x][1];
560
561 while (isalpha(*p)) {
562 driveflags[toupper(*p) - 'A'] |= DRIVE_NOPRESCAN;
563 p++;
564 }
565 }
566 else if (*argv[x] == '`' && isalpha(argv[x][1])) {
567
568 CHAR *p = &argv[x][1];
569
570 while (isalpha(*p)) {
571 driveflags[toupper(*p) - 'A'] |= DRIVE_NOSTATS;
572 p++;
573 }
574 }
575 else if (*argv[x] == ',' && isalpha(argv[x][1])) {
576
577 CHAR *p = &argv[x][1];
578
579 while (isalpha(*p)) {
580 driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADICONS;
581 p++;
582 }
583 }
584 else if (*argv[x] == '-' && isalpha(argv[x][1])) {
585
586 CHAR *p = &argv[x][1];
587
588 while (isalpha(*p)) {
589 driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADSUBJS;
590 p++;
591 }
592 }
593 else if (*argv[x] == '\'' && isalpha(argv[x][1])) {
594
595 CHAR *p = &argv[x][1];
596
597 while (isalpha(*p)) {
598 driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADLONGS;
599 p++;
600 }
601 }
602 }
603}
604
605VOID DriveFlagsOne(INT x)
606{
607 INT removable;
608 CHAR szDrive[] = " :\\", FileSystem[CCHMAXPATH];
609 ULONG drvtype;
610
611 *szDrive = (CHAR) (x + 'A');
612 *FileSystem = 0;
613 drvtype = 0;
614 removable = CheckDrive(*szDrive, FileSystem, &drvtype);
615 driveserial[x] = -1;
616 driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
617 DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
618 DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS);
619 if (removable != -1) {
620 struct
621 {
622 ULONG serial;
623 CHAR volumelength;
624 CHAR volumelabel[CCHMAXPATH];
625 }
626 volser;
627
628 DosError(FERR_DISABLEHARDERR);
629 if (!DosQueryFSInfo((ULONG) x + 1, FSIL_VOLSER, &volser, sizeof(volser)))
630 driveserial[x] = volser.serial;
631 else
632 DosError(FERR_DISABLEHARDERR);
633 }
634 else
635 driveflags[x] |= DRIVE_INVALID;
636 driveflags[x] |= ((removable == -1 || removable == 1) ?
637 DRIVE_REMOVABLE : 0);
638 if (drvtype & DRIVE_REMOTE)
639 driveflags[x] |= DRIVE_REMOTE;
640 if(!stricmp(FileSystem,NDFS32)){
641 driveflags[x] |= DRIVE_VIRTUAL;
642 driveflags[x] &= (~DRIVE_REMOTE);
643 }
644 if(!stricmp(FileSystem,RAMFS)){
645 driveflags[x] |= DRIVE_RAMDISK;
646 driveflags[x] &= (~DRIVE_REMOTE);
647 }
648 if(!stricmp(FileSystem,NTFS))
649 driveflags[x] |= DRIVE_NOTWRITEABLE;
650 if (strcmp(FileSystem, HPFS) &&
651 strcmp(FileSystem, JFS) &&
652 strcmp(FileSystem, CDFS) &&
653 strcmp(FileSystem, ISOFS) &&
654 strcmp(FileSystem, RAMFS) &&
655 strcmp(FileSystem, FAT32) &&
656 strcmp(FileSystem, NTFS) &&
657 strcmp(FileSystem, NDFS32) &&
658 strcmp(FileSystem, HPFS386)) {
659 driveflags[x] |= DRIVE_NOLONGNAMES;
660 }
661
662 if (!strcmp(FileSystem, CDFS) || !strcmp(FileSystem, ISOFS)) {
663 removable = 1;
664 driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE | DRIVE_CDROM);
665 }
666 else if (!stricmp(FileSystem, CBSIFS)) {
667 driveflags[x] |= DRIVE_ZIPSTREAM;
668 driveflags[x] &= (~DRIVE_REMOTE);
669 if (drvtype & DRIVE_REMOVABLE)
670 driveflags[x] |= DRIVE_REMOVABLE;
671 if (!(drvtype & DRIVE_NOLONGNAMES))
672 driveflags[x] &= (~DRIVE_NOLONGNAMES);
673 }
674}
675
676VOID FillInDriveFlags(VOID * dummy)
677{
678 ULONG ulDriveNum, ulDriveMap;
679 register INT x;
680
681 for (x = 0; x < 26; x++)
682 driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
683 DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
684 DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS);
685 memset(driveserial, -1, sizeof(driveserial));
686 DosError(FERR_DISABLEHARDERR);
687 DosQCurDisk(&ulDriveNum, &ulDriveMap);
688 for (x = 0; x < 26; x++) {
689 if (ulDriveMap & (1L << x) && !(driveflags[x] & DRIVE_IGNORE)) {
690 {
691 CHAR s[80];
692 ULONG flags = 0, size = sizeof(ULONG);
693
694 sprintf(s, "%c.DriveFlags", (CHAR) (x + 'A'));
695 if (PrfQueryProfileData(fmprof, appname, s, &flags, &size) &&
696 size == sizeof(ULONG))
697 driveflags[x] |= flags;
698 }
699
700 if (x > 1) {
701 if (!(driveflags[x] & DRIVE_NOPRESCAN))
702 DriveFlagsOne(x);
703 else
704 driveserial[x] = -1;
705 }
706 else {
707 driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES);
708 driveserial[x] = -1;
709 }
710 }
711 else if (!(ulDriveMap & (1L << x)))
712 driveflags[x] |= DRIVE_INVALID;
713 }
714 {
715 ULONG startdrive = 3L;
716
717 DosError(FERR_DISABLEHARDERR);
718 DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
719 (PVOID) & startdrive, (ULONG) sizeof(ULONG));
720 if (startdrive)
721 driveflags[startdrive - 1] |= DRIVE_BOOT;
722 }
723}
724
725CHAR *assign_ignores(CHAR * s)
726{
727 register INT x;
728 register CHAR *p, *pp;
729
730 *s = '/';
731 s[1] = 0;
732 p = s + 1;
733 if (s) {
734 for (x = 0; x < 26; x++) {
735 if ((driveflags[x] & DRIVE_IGNORE) != 0) {
736 *p = (CHAR) x + 'A';
737 p++;
738 *p = 0;
739 }
740 }
741 }
742 if (!s[1]) {
743 *s = 0;
744 pp = s;
745 }
746 else {
747 pp = &s[strlen(s)];
748 *pp = ' ';
749 pp++;
750 }
751 *pp = ';';
752 pp[1] = 0;
753 p = pp + 1;
754 if (pp) {
755 for (x = 0; x < 26; x++) {
756 if ((driveflags[x] & DRIVE_NOPRESCAN) != 0) {
757 *p = (CHAR) x + 'A';
758 p++;
759 *p = 0;
760 }
761 }
762 }
763 if (!pp[1])
764 *pp = 0;
765 pp = &s[strlen(s)];
766 *pp = ' ';
767 pp++;
768 *pp = ',';
769 pp[1] = 0;
770 p = pp + 1;
771 if (pp) {
772 for (x = 0; x < 26; x++) {
773 if ((driveflags[x] & DRIVE_NOLOADICONS) != 0) {
774 *p = (CHAR) x + 'A';
775 p++;
776 *p = 0;
777 }
778 }
779 }
780 if (!pp[1])
781 *pp = 0;
782 pp = &s[strlen(s)];
783 *pp = ' ';
784 pp++;
785 *pp = '-';
786 pp[1] = 0;
787 p = pp + 1;
788 if (pp) {
789 for (x = 0; x < 26; x++) {
790 if ((driveflags[x] & DRIVE_NOLOADSUBJS) != 0) {
791 *p = (CHAR) x + 'A';
792 p++;
793 *p = 0;
794 }
795 }
796 }
797 if (!pp[1])
798 *pp = 0;
799 pp = &s[strlen(s)];
800 *pp = ' ';
801 pp++;
802 *pp = '`';
803 pp[1] = 0;
804 p = pp + 1;
805 if (pp) {
806 for (x = 0; x < 26; x++) {
807 if ((driveflags[x] & DRIVE_NOSTATS) != 0) {
808 *p = (CHAR) x + 'A';
809 p++;
810 *p = 0;
811 }
812 }
813 }
814 if (!pp[1])
815 *pp = 0;
816 pp = &s[strlen(s)];
817 *pp = ' ';
818 pp++;
819 *pp = '\'';
820 pp[1] = 0;
821 p = pp + 1;
822 if (pp) {
823 for (x = 0; x < 26; x++) {
824 if ((driveflags[x] & DRIVE_NOLOADLONGS) != 0) {
825 *p = (CHAR) x + 'A';
826 p++;
827 *p = 0;
828 }
829 }
830 }
831 if (!pp[1])
832 *pp = 0;
833 bstrip(s);
834 return s;
835}
836
837BOOL needs_quoting(register CHAR * f)
838{
839 register CHAR *p = " &|<>";
840
841 while (*p) {
842 if (strchr(f, *p))
843 return TRUE;
844 p++;
845 }
846 return FALSE;
847}
848
849BOOL IsBinary(register CHAR * str, ULONG len)
850{
851 register ULONG x = 0L;
852
853 if (str) {
854 while (x < len) {
855 if (str[x] < ' ' && str[x] != '\r' && str[x] != '\n' && str[x] != '\t'
856 && str[x] != '\x1b' && str[x] != '\x1a' && str[x] != '\07'
857 && str[x] != '\x0c')
858 return TRUE;
859 x++;
860 }
861 }
862 return FALSE;
863}
864
865BOOL TestBinary(CHAR * filename)
866{
867 HFILE handle;
868 ULONG ulAction;
869 ULONG len;
870 APIRET rc;
871 CHAR buff[512];
872
873 if (filename) {
874 if (!DosOpen(filename, &handle, &ulAction, 0L, 0L,
875 OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
876 OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT |
877 OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE |
878 OPEN_ACCESS_READONLY, 0L)) {
879 len = 512;
880 rc = DosRead(handle, buff, len, &len);
881 DosClose(handle);
882 if (!rc && len)
883 return IsBinary(buff, len);
884 }
885 }
886 return FALSE;
887}
888
889char *IsVowel(char a)
890{
891 return (strchr("aeiouAEIOU", a) != NULL) ? "n" : NullStr;
892}
893
894VOID 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, sizeof(objerr), "PMWP", &hmod);
913 if (!rc) {
914 rc = DosQueryProcAddr(hmod, 262, NULL, &WQDPath);
915 if (!rc)
916 WQDPath(objectpath, size);
917 DosFreeModule(hmod);
918 }
919 }
920 if (!*objectpath) {
921 // Fall back to INI content
922 if (!PrfQueryProfileString(HINI_SYSTEMPROFILE,
923 "FolderWorkareaRunningObjects",
924 NULL,
925 "\0",
926 (PVOID) objectpath, sizeof(objectpath))) {
927 Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
928 "PrfQueryProfileString");
929 *objectpath = 0;
930 }
931 else if (!*objectpath || IsFile(objectpath)) {
932 Runtime_Error(pszSrcFile, __LINE__, "bad FolderWorkareaRunningObjects");
933 *objectpath = 0;
934 }
935 if (!*objectpath) {
936 // Fall back
937 DosError(FERR_DISABLEHARDERR);
938 DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
939 (PVOID) & startdrive, (ULONG) sizeof(ULONG));
940 sprintf(objectpath, GetPString(IDS_PATHTODESKTOP), ((CHAR) startdrive) + '@');
941 }
942 }
943}
Note: See TracBrowser for help on using the repository browser.