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