source: trunk/dll/valid.c@ 1438

Last change on this file since 1438 was 1438, checked in by Gregg Young, 16 years ago

Improved drivebar changes; Added AddBackslashToPath() to remove repeatative code. replaced "
" with PCSZ variable; ANY_OBJ added the DosAlloc... (experimental)

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