source: trunk/dll/valid.c@ 1628

Last change on this file since 1628 was 1628, checked in by Gregg Young, 14 years ago

Hard coded the flags for the xDosAlloc* wrappers and added a description for each of them.

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