source: trunk/dll/valid.c@ 793

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

Move #pragma alloc_text to end for OpenWatcom compat

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