[48] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: valid.c 1438 2009-06-28 20:47:00Z 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
|
---|
[48] | 37 |
|
---|
| 38 | ***********************************************************************/
|
---|
| 39 |
|
---|
[907] | 40 | #include <string.h>
|
---|
| 41 | #include <ctype.h>
|
---|
| 42 |
|
---|
[2] | 43 | #define INCL_DOS
|
---|
| 44 | #define INCL_WIN
|
---|
[551] | 45 | #define INCL_DOSDEVIOCTL // DosDevIOCtl
|
---|
[841] | 46 | #define INCL_LONGLONG
|
---|
[2] | 47 |
|
---|
[1187] | 48 | #include "fm3dll.h"
|
---|
[1214] | 49 | #include "treecnr.h" // Data declaration(s)
|
---|
| 50 | #include "info.h" // Data declaration(s)
|
---|
| 51 | #include "notebook.h" // Data declaration(s)
|
---|
[907] | 52 | #include "fm3str.h"
|
---|
| 53 | #include "errutil.h" // Dos_Error...
|
---|
| 54 | #include "strutil.h" // GetPString
|
---|
[1162] | 55 | #include "valid.h"
|
---|
[1187] | 56 | #include "dirs.h" // save_dir2
|
---|
| 57 | #include "strips.h" // bstrip
|
---|
[1214] | 58 | #include "init.h" // GetTidForWindow
|
---|
[1438] | 59 | #include "wrappers.h" // xDosAllocMem
|
---|
[2] | 60 |
|
---|
[328] | 61 |
|
---|
[1162] | 62 | //static BOOL IsDesktop(HAB hab, HWND hwnd);
|
---|
| 63 | //static BOOL IsFileSame(CHAR * filename1, CHAR * filename2);
|
---|
[1187] | 64 | //static char *IsVowel(char a);
|
---|
[1162] | 65 |
|
---|
[1214] | 66 | // Data definitions
|
---|
| 67 | static PSZ pszSrcFile = __FILE__;
|
---|
| 68 |
|
---|
| 69 | #pragma data_seg(GLOBAL2)
|
---|
[1402] | 70 | PCSZ HPFS = "HPFS";
|
---|
| 71 | PCSZ JFS = "JFS";
|
---|
| 72 | PCSZ CDFS = "CDFS";
|
---|
| 73 | PCSZ ISOFS = "ISOFS";
|
---|
| 74 | PCSZ FAT32 = "FAT32";
|
---|
| 75 | PCSZ HPFS386 = "HPFS386";
|
---|
| 76 | PCSZ CBSIFS = "CBSIFS";
|
---|
| 77 | PCSZ NDFS32 = "NDFS32";
|
---|
| 78 | PCSZ RAMFS = "RAMFS";
|
---|
| 79 | PCSZ NTFS = "NTFS";
|
---|
[1354] | 80 | BOOL fVerifyOffChecked[26];
|
---|
[1214] | 81 |
|
---|
[551] | 82 | APIRET MakeFullName(char *pszFileName)
|
---|
[103] | 83 | {
|
---|
| 84 | /* pszFileName must be CCHMAXPATH long minimum! */
|
---|
[2] | 85 |
|
---|
[551] | 86 | char szPathName[CCHMAXPATH];
|
---|
[2] | 87 | APIRET rc;
|
---|
| 88 |
|
---|
| 89 | DosError(FERR_DISABLEHARDERR);
|
---|
[103] | 90 | rc = DosQueryPathInfo(pszFileName,
|
---|
[551] | 91 | FIL_QUERYFULLNAME, szPathName, sizeof(szPathName));
|
---|
| 92 | if (!rc)
|
---|
[103] | 93 | strcpy(pszFileName, szPathName); // Pass back actual name
|
---|
[2] | 94 | return rc;
|
---|
| 95 | }
|
---|
| 96 |
|
---|
[551] | 97 | char *RootName(char *filename)
|
---|
[103] | 98 | {
|
---|
[551] | 99 | char *p = NULL, *pp;
|
---|
[2] | 100 |
|
---|
[48] | 101 | // Return filename, strip path parts
|
---|
[689] | 102 | // Return empty string when filename ends with backslash
|
---|
[48] | 103 |
|
---|
[551] | 104 | if (filename) {
|
---|
| 105 | p = strrchr(filename, '\\');
|
---|
| 106 | pp = strrchr(filename, '/');
|
---|
| 107 | p = (p) ? (pp) ? (p > pp) ? p : pp : p : pp;
|
---|
[2] | 108 | }
|
---|
[551] | 109 | if (!p) /* name is itself a root */
|
---|
[2] | 110 | p = filename;
|
---|
[551] | 111 | else /* skip past backslash */
|
---|
[2] | 112 | p++;
|
---|
| 113 | return p;
|
---|
| 114 | }
|
---|
| 115 |
|
---|
[915] | 116 | /** TestFDate
|
---|
[2] | 117 | * return 1 (file2 newer than file1),
|
---|
| 118 | * 0 (files same)
|
---|
| 119 | * or -1 (file1 newer than file2)
|
---|
[897] | 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
|
---|
[2] | 123 | */
|
---|
| 124 |
|
---|
[915] | 125 | int TestFDates(char *file1, char *file2, FDATE *datevar1, FTIME *timevar1,
|
---|
[1394] | 126 | FDATE *datevar2, FTIME *timevar2)
|
---|
[915] | 127 | {
|
---|
[551] | 128 | int comp = 0;
|
---|
[847] | 129 | FILESTATUS3 fs3o, fs3n;
|
---|
[2] | 130 |
|
---|
[897] | 131 | if (file1){
|
---|
[2] | 132 | DosError(FERR_DISABLEHARDERR);
|
---|
[897] | 133 | DosQueryPathInfo(file1, FIL_STANDARD, &fs3o, sizeof(fs3o));
|
---|
| 134 | datevar1 = &fs3o.fdateLastWrite;
|
---|
| 135 | timevar1 = &fs3o.ftimeLastWrite;
|
---|
[2] | 136 | }
|
---|
[897] | 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 >
|
---|
[1394] | 145 | datevar1->year) ? 1 :
|
---|
[897] | 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;
|
---|
[2] | 169 | }
|
---|
| 170 |
|
---|
[915] | 171 | /** TestCDate
|
---|
[897] | 172 | * return 1 (file2 newer than file1),
|
---|
| 173 | * 0 (files same)
|
---|
| 174 | * or -1 (file1 newer than file2)
|
---|
| 175 | */
|
---|
| 176 |
|
---|
[915] | 177 | int TestCDates(CDATE *datevar1, CTIME *timevar1,
|
---|
[1394] | 178 | CDATE *datevar2, CTIME *timevar2)
|
---|
[915] | 179 | {
|
---|
[897] | 180 | int comp = 0;
|
---|
| 181 |
|
---|
| 182 | if (&datevar1 && &datevar2 && &timevar1 && &timevar2) {
|
---|
| 183 | comp = (datevar2->year >
|
---|
[1394] | 184 | datevar1->year) ? 1 :
|
---|
[897] | 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 |
|
---|
[551] | 210 | BOOL IsNewer(char *file1, char *file2)
|
---|
[103] | 211 | {
|
---|
[2] | 212 | /* return TRUE if file2 is newer than file1 */
|
---|
| 213 |
|
---|
[897] | 214 | return (TestFDates(file1, file2, NULL, NULL, NULL, NULL) > 0);
|
---|
[2] | 215 | }
|
---|
| 216 |
|
---|
[1394] | 217 | #if 0 // JBS 11 Sep 08
|
---|
[551] | 218 | BOOL IsDesktop(HAB hab, HWND hwnd)
|
---|
[103] | 219 | {
|
---|
[2] | 220 | HWND hwndDesktop;
|
---|
| 221 |
|
---|
[551] | 222 | if (hwnd == HWND_DESKTOP)
|
---|
[2] | 223 | return TRUE;
|
---|
[551] | 224 | hwndDesktop = WinQueryDesktopWindow(hab, NULLHANDLE);
|
---|
| 225 | if (hwnd == hwndDesktop)
|
---|
[2] | 226 | return TRUE;
|
---|
| 227 | return FALSE;
|
---|
| 228 | }
|
---|
[1162] | 229 | #endif
|
---|
[2] | 230 |
|
---|
[551] | 231 | BOOL ParentIsDesktop(HWND hwnd, HWND hwndParent)
|
---|
[103] | 232 | {
|
---|
[2] | 233 | HWND hwndDesktop;
|
---|
| 234 | BOOL ret = FALSE;
|
---|
| 235 |
|
---|
[551] | 236 | if (!hwndParent)
|
---|
| 237 | hwndParent = WinQueryWindow(hwnd, QW_PARENT);
|
---|
| 238 | if (hwndParent == HWND_DESKTOP)
|
---|
[2] | 239 | ret = TRUE;
|
---|
| 240 | else {
|
---|
[551] | 241 | hwndDesktop = WinQueryDesktopWindow(WinQueryAnchorBlock(hwnd), (HWND) 0);
|
---|
| 242 | if (hwndDesktop == hwndParent)
|
---|
[2] | 243 | ret = TRUE;
|
---|
| 244 | }
|
---|
| 245 | return ret;
|
---|
| 246 | }
|
---|
| 247 |
|
---|
[946] | 248 | /** CheckDrive
|
---|
[109] | 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 | */
|
---|
[2] | 254 |
|
---|
[551] | 255 | INT CheckDrive(CHAR chDrive, CHAR * pszFileSystem, ULONG * pulType)
|
---|
[70] | 256 | {
|
---|
[551] | 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 |
|
---|
[103] | 268 | # pragma pack(1)
|
---|
[551] | 269 | struct
|
---|
| 270 | {
|
---|
| 271 | BYTE Cmd;
|
---|
| 272 | BYTE Unit;
|
---|
| 273 | }
|
---|
| 274 | parmPkt =
|
---|
| 275 | {
|
---|
| 276 | 0, 0};
|
---|
[103] | 277 | # define BPB_REMOVABLE_MEDIA 0x08 // 3 - Media is removable
|
---|
| 278 | struct
|
---|
| 279 | {
|
---|
| 280 | BIOSPARAMETERBLOCK bpb;
|
---|
[551] | 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 |
|
---|
[103] | 287 | # pragma pack()
|
---|
[551] | 288 | BYTE NonRemovable;
|
---|
[2] | 289 | PFSQBUFFER2 pfsq;
|
---|
| 290 |
|
---|
[70] | 291 | if (pszFileSystem)
|
---|
| 292 | *pszFileSystem = 0;
|
---|
[530] | 293 |
|
---|
[70] | 294 | if (pulType)
|
---|
| 295 | *pulType = 0;
|
---|
[2] | 296 |
|
---|
[530] | 297 | # define BUFFER_BYTES 8192
|
---|
[1438] | 298 | rc = xDosAllocMem(&pvBuffer, BUFFER_BYTES,
|
---|
| 299 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
|
---|
[328] | 300 | if (rc) {
|
---|
[551] | 301 | Dos_Error(MB_CANCEL, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
| 302 | GetPString(IDS_OUTOFMEMORY));
|
---|
[70] | 303 | return -1; // Say failed
|
---|
[2] | 304 | }
|
---|
| 305 |
|
---|
[103] | 306 | szPath[0] = chDrive;
|
---|
| 307 | szPath[1] = ':';
|
---|
| 308 | szPath[2] = 0;
|
---|
| 309 | clBufferSize = BUFFER_BYTES;
|
---|
[2] | 310 | DosError(FERR_DISABLEHARDERR);
|
---|
[328] | 311 | rc = DosQueryFSAttach(szPath, 0, FSAIL_QUERYNAME,
|
---|
[551] | 312 | (PFSQBUFFER2) pvBuffer, &clBufferSize);
|
---|
| 313 | if (rc) {
|
---|
[70] | 314 | /* can't get any info at all */
|
---|
[103] | 315 | DosFreeMem(pvBuffer);
|
---|
[2] | 316 | DosError(FERR_DISABLEHARDERR);
|
---|
[70] | 317 | return -1; // Say failed
|
---|
[2] | 318 | }
|
---|
| 319 |
|
---|
[551] | 320 | pfsq = (PFSQBUFFER2) pvBuffer;
|
---|
[689] | 321 | pfsn = (PCHAR)(pfsq->szName) + pfsq->cbName + 1;
|
---|
[2] | 322 | pfsd = pfsn + pfsq->cbFSDName + 1;
|
---|
| 323 |
|
---|
[551] | 324 | if (pszFileSystem) {
|
---|
[70] | 325 | strncpy(pszFileSystem, pfsn, CCHMAXPATH);
|
---|
| 326 | pszFileSystem[CCHMAXPATH - 1] = 0;
|
---|
[2] | 327 | }
|
---|
| 328 |
|
---|
[552] | 329 | if (pulType && (!strcmp(pfsn, CDFS) || !strcmp(pfsn, ISOFS)))
|
---|
[555] | 330 | *pulType |= DRIVE_NOTWRITEABLE | DRIVE_CDROM | DRIVE_REMOVABLE;
|
---|
| 331 | if (pulType && !strcmp(pfsn, NTFS))
|
---|
[1351] | 332 | *pulType |= DRIVE_NOTWRITEABLE;
|
---|
[552] | 333 | if (pulType && !strcmp(pfsn, NDFS32)){
|
---|
[1394] | 334 | *pulType |= DRIVE_VIRTUAL;
|
---|
[552] | 335 | }
|
---|
| 336 | if (pulType && !strcmp(pfsn, RAMFS)){
|
---|
[1394] | 337 | *pulType |= DRIVE_RAMDISK;
|
---|
[552] | 338 | }
|
---|
| 339 | if (((PFSQBUFFER2) pvBuffer)->iType == FSAT_REMOTEDRV &&
|
---|
[555] | 340 | (strcmp(pfsn, CDFS) || strcmp(pfsn, ISOFS))) {
|
---|
[70] | 341 | if (pulType)
|
---|
| 342 | *pulType |= DRIVE_REMOTE;
|
---|
[552] | 343 |
|
---|
[551] | 344 | if (pulType && !strcmp(pfsn, CBSIFS)) {
|
---|
[70] | 345 | *pulType |= DRIVE_ZIPSTREAM;
|
---|
| 346 | *pulType &= ~DRIVE_REMOTE;
|
---|
| 347 | *pulType |= DRIVE_NOLONGNAMES;
|
---|
[551] | 348 | if (pfsq->cbFSAData) {
|
---|
[103] | 349 | ULONG FType;
|
---|
[2] | 350 |
|
---|
[551] | 351 | if (CheckDrive(*pfsd, NULL, &FType) != -1) {
|
---|
[103] | 352 | if (FType & DRIVE_REMOVABLE)
|
---|
| 353 | *pulType |= DRIVE_REMOVABLE;
|
---|
| 354 | if (~FType & DRIVE_NOLONGNAMES)
|
---|
| 355 | *pulType &= ~DRIVE_NOLONGNAMES;
|
---|
| 356 | }
|
---|
[552] | 357 |
|
---|
[2] | 358 | }
|
---|
| 359 | }
|
---|
[70] | 360 | if (pulType &&
|
---|
[551] | 361 | (!strcmp(pfsn, HPFS) ||
|
---|
| 362 | !strcmp(pfsn, JFS) ||
|
---|
| 363 | !strcmp(pfsn, FAT32) ||
|
---|
[1394] | 364 | !strcmp(pfsn, RAMFS) ||
|
---|
| 365 | !strcmp(pfsn, NDFS32) ||
|
---|
| 366 | !strcmp(pfsn, NTFS) ||
|
---|
| 367 | !strcmp(pfsn, HPFS386))) {
|
---|
[70] | 368 | *pulType &= ~DRIVE_NOLONGNAMES;
|
---|
| 369 | }
|
---|
[552] | 370 |
|
---|
[103] | 371 | DosFreeMem(pvBuffer);
|
---|
| 372 | return 0; // Remotes are non-removable
|
---|
[2] | 373 | }
|
---|
| 374 |
|
---|
[70] | 375 | // Local drive
|
---|
[551] | 376 | if (strcmp(pfsn, HPFS) &&
|
---|
| 377 | strcmp(pfsn, JFS) &&
|
---|
| 378 | strcmp(pfsn, CDFS) &&
|
---|
[552] | 379 | strcmp(pfsn, ISOFS) &&
|
---|
| 380 | strcmp(pfsn, RAMFS) &&
|
---|
| 381 | strcmp(pfsn, FAT32) &&
|
---|
| 382 | strcmp(pfsn, NDFS32) &&
|
---|
[555] | 383 | strcmp(pfsn, NTFS) &&
|
---|
[552] | 384 | strcmp(pfsn, HPFS386)) {
|
---|
[551] | 385 | if (pulType)
|
---|
[103] | 386 | (*pulType) |= DRIVE_NOLONGNAMES; // Others can not have long names
|
---|
[2] | 387 | }
|
---|
| 388 |
|
---|
[552] | 389 |
|
---|
[2] | 390 | DosError(FERR_DISABLEHARDERR);
|
---|
[844] | 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);
|
---|
[551] | 394 | if (rc) {
|
---|
[2] | 395 | DosError(FERR_DISABLEHARDERR);
|
---|
[70] | 396 | if (pulType)
|
---|
| 397 | *pulType |= DRIVE_REMOVABLE; // Assume removable if can not access
|
---|
[103] | 398 | DosFreeMem(pvBuffer);
|
---|
[70] | 399 | return 1; // Say removable
|
---|
[2] | 400 | }
|
---|
[103] | 401 |
|
---|
| 402 | clParmBytes = sizeof(parmPkt.Cmd);
|
---|
| 403 | clDataBytes = sizeof(NonRemovable);
|
---|
| 404 | NonRemovable = 1; // Preset as non removable
|
---|
[2] | 405 | DosError(FERR_DISABLEHARDERR);
|
---|
[1394] | 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. */
|
---|
[103] | 412 |
|
---|
[328] | 413 | if (!rc && NonRemovable) {
|
---|
[103] | 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);
|
---|
[1394] | 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. */
|
---|
[103] | 425 |
|
---|
[328] | 426 | if (!rc && (dataPkt.bpb.fsDeviceAttr & BPB_REMOVABLE_MEDIA))
|
---|
[103] | 427 | NonRemovable = 0;
|
---|
| 428 | }
|
---|
| 429 |
|
---|
| 430 | DosClose(hDev);
|
---|
| 431 |
|
---|
[70] | 432 | if (!NonRemovable && pulType)
|
---|
| 433 | *pulType |= DRIVE_REMOVABLE;
|
---|
[103] | 434 |
|
---|
| 435 | DosFreeMem(pvBuffer);
|
---|
| 436 |
|
---|
[70] | 437 | return NonRemovable ? 0 : 1;
|
---|
[2] | 438 | }
|
---|
| 439 |
|
---|
[1193] | 440 | #if 0 // JBS 11 Sep 08
|
---|
[551] | 441 | BOOL IsFileSame(CHAR * filename1, CHAR * filename2)
|
---|
[103] | 442 | {
|
---|
[1394] | 443 | /* returns: -1 (error), 0 (is a directory), or 1 (is a file) */
|
---|
[2] | 444 |
|
---|
[841] | 445 | FILESTATUS3L fsa1, fsa2;
|
---|
[551] | 446 | APIRET ret;
|
---|
[2] | 447 |
|
---|
[551] | 448 | if (filename1 && filename2) {
|
---|
[2] | 449 | DosError(FERR_DISABLEHARDERR);
|
---|
[841] | 450 | ret = DosQueryPathInfo(filename1, FIL_STANDARDL, &fsa1,
|
---|
[551] | 451 | (ULONG) sizeof(fsa1));
|
---|
| 452 | if (!ret) {
|
---|
[2] | 453 | DosError(FERR_DISABLEHARDERR);
|
---|
[841] | 454 | ret = DosQueryPathInfo(filename2, FIL_STANDARDL, &fsa2,
|
---|
[551] | 455 | (ULONG) sizeof(fsa2));
|
---|
| 456 | if (!ret) {
|
---|
| 457 | if (fsa1.cbFile == fsa2.cbFile &&
|
---|
| 458 | (fsa1.attrFile & (~FILE_ARCHIVED)) ==
|
---|
| 459 | (fsa2.attrFile & (~FILE_ARCHIVED)))
|
---|
[103] | 460 | return TRUE;
|
---|
[2] | 461 | }
|
---|
| 462 | }
|
---|
| 463 | }
|
---|
| 464 | return FALSE;
|
---|
| 465 | }
|
---|
[1162] | 466 | #endif
|
---|
[2] | 467 |
|
---|
[1394] | 468 | INT IsFile(PCSZ filename)
|
---|
[103] | 469 | {
|
---|
[1394] | 470 | /* returns: -1 (error), 0 (is a directory), or 1 (is a file) */
|
---|
[2] | 471 |
|
---|
[847] | 472 | FILESTATUS3 fsa;
|
---|
[551] | 473 | APIRET ret;
|
---|
[2] | 474 |
|
---|
[551] | 475 | if (filename && *filename) {
|
---|
[2] | 476 | DosError(FERR_DISABLEHARDERR);
|
---|
[847] | 477 | ret = DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa));
|
---|
[551] | 478 | if (!ret)
|
---|
[2] | 479 | return ((fsa.attrFile & FILE_DIRECTORY) == 0);
|
---|
[551] | 480 | else if (IsValidDrive(*filename) && IsRoot(filename))
|
---|
[2] | 481 | return 0;
|
---|
| 482 | }
|
---|
[551] | 483 | return -1; /* error; doesn't exist or can't read or null filename */
|
---|
[2] | 484 | }
|
---|
| 485 |
|
---|
[551] | 486 | BOOL IsFullName(CHAR * filename)
|
---|
[103] | 487 | {
|
---|
[2] | 488 | return (filename) ?
|
---|
[551] | 489 | (isalpha(*filename) && filename[1] == ':' && filename[2] == '\\') : 0;
|
---|
[2] | 490 | }
|
---|
| 491 |
|
---|
[1394] | 492 | BOOL IsRoot(PCSZ filename)
|
---|
[103] | 493 | {
|
---|
[2] | 494 | return (filename && isalpha(*filename) && filename[1] == ':' &&
|
---|
[103] | 495 | filename[2] == '\\' && !filename[3]);
|
---|
[2] | 496 | }
|
---|
| 497 |
|
---|
[551] | 498 | BOOL IsValidDir(CHAR * path)
|
---|
[103] | 499 | {
|
---|
[551] | 500 | CHAR fullname[CCHMAXPATH];
|
---|
[847] | 501 | FILESTATUS3 fs;
|
---|
[2] | 502 |
|
---|
[551] | 503 | if (path) {
|
---|
[2] | 504 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 505 | if (!DosQueryPathInfo(path,
|
---|
| 506 | FIL_QUERYFULLNAME, fullname, sizeof(fullname))) {
|
---|
| 507 | if (IsValidDrive(*fullname)) {
|
---|
| 508 | if (!IsRoot(fullname)) {
|
---|
[103] | 509 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 510 | if (!DosQueryPathInfo(fullname,
|
---|
[847] | 511 | FIL_STANDARD,
|
---|
[551] | 512 | &fs,
|
---|
| 513 | sizeof(fs)) && (fs.attrFile & FILE_DIRECTORY))
|
---|
[103] | 514 | return TRUE;
|
---|
| 515 | }
|
---|
| 516 | else
|
---|
| 517 | return TRUE;
|
---|
[2] | 518 | }
|
---|
| 519 | }
|
---|
| 520 | }
|
---|
| 521 | return FALSE;
|
---|
| 522 | }
|
---|
| 523 |
|
---|
[551] | 524 | BOOL IsValidDrive(CHAR drive)
|
---|
[103] | 525 | {
|
---|
[551] | 526 | CHAR Path[] = " :", Buffer[256];
|
---|
[2] | 527 | APIRET Status;
|
---|
[551] | 528 | ULONG Size;
|
---|
| 529 | ULONG ulDriveNum, ulDriveMap;
|
---|
[2] | 530 |
|
---|
[551] | 531 | if (!isalpha(drive) ||
|
---|
| 532 | (driveflags[toupper(drive) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)))
|
---|
[2] | 533 | return FALSE;
|
---|
| 534 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 535 | Status = DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
| 536 | if (!Status) {
|
---|
[766] | 537 | if (!(ulDriveMap & (1 << (ULONG) (toupper(drive) - 'A'))))
|
---|
[2] | 538 | return FALSE;
|
---|
| 539 | Path[0] = toupper(drive);
|
---|
| 540 | Size = sizeof(Buffer);
|
---|
| 541 | DosError(FERR_DISABLEHARDERR);
|
---|
| 542 | Status = DosQueryFSAttach(Path,
|
---|
[103] | 543 | 0,
|
---|
[551] | 544 | FSAIL_QUERYNAME, (PFSQBUFFER2) Buffer, &Size);
|
---|
[2] | 545 | }
|
---|
| 546 | return (Status == 0);
|
---|
| 547 | }
|
---|
| 548 |
|
---|
[274] | 549 | //=== MakeValidDir() build valid directory name ===
|
---|
[2] | 550 |
|
---|
[551] | 551 | CHAR *MakeValidDir(CHAR * path)
|
---|
[103] | 552 | {
|
---|
[551] | 553 | ULONG ulDrv;
|
---|
| 554 | CHAR *p;
|
---|
[847] | 555 | FILESTATUS3 fs;
|
---|
[551] | 556 | APIRET rc;
|
---|
[2] | 557 |
|
---|
[274] | 558 | if (!MakeFullName(path)) {
|
---|
| 559 | if (IsValidDrive(*path)) {
|
---|
| 560 | // Passed name is valid - trim to directory
|
---|
| 561 | for (;;) {
|
---|
| 562 | if (IsRoot(path))
|
---|
[103] | 563 | return path;
|
---|
| 564 | DosError(FERR_DISABLEHARDERR);
|
---|
[847] | 565 | rc = DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs));
|
---|
[274] | 566 | if (!rc && (fs.attrFile & FILE_DIRECTORY))
|
---|
[103] | 567 | return path;
|
---|
[551] | 568 | p = strrchr(path, '\\');
|
---|
[274] | 569 | if (p) {
|
---|
| 570 | if (p < path + 3)
|
---|
[103] | 571 | p++;
|
---|
| 572 | *p = 0;
|
---|
| 573 | }
|
---|
| 574 | else
|
---|
| 575 | break;
|
---|
[2] | 576 | }
|
---|
| 577 | }
|
---|
| 578 | }
|
---|
[274] | 579 | // Fall back to boot drive
|
---|
[2] | 580 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 581 | if (!DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulDrv, sizeof(ulDrv))) {
|
---|
[274] | 582 | ulDrv += '@';
|
---|
| 583 | if (ulDrv < 'C')
|
---|
| 584 | ulDrv = 'C';
|
---|
[551] | 585 | strcpy(path, " :\\");
|
---|
| 586 | *path = (CHAR) ulDrv;
|
---|
[2] | 587 | }
|
---|
| 588 | else
|
---|
[1104] | 589 | strcpy(path, pFM2SaveDirectory); // Fall back to fm3.ini drive or current dir - should never occur
|
---|
[2] | 590 | return path;
|
---|
| 591 | }
|
---|
| 592 |
|
---|
[551] | 593 | BOOL IsExecutable(CHAR * filename)
|
---|
[103] | 594 | {
|
---|
[2] | 595 | register CHAR *p;
|
---|
[551] | 596 | APIRET ret;
|
---|
| 597 | ULONG apptype;
|
---|
[2] | 598 |
|
---|
[551] | 599 | if (filename) {
|
---|
[2] | 600 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 601 | p = strrchr(filename, '.');
|
---|
| 602 | if (p)
|
---|
[697] | 603 | ret = DosQueryAppType(filename, &apptype);
|
---|
[2] | 604 | else {
|
---|
| 605 |
|
---|
| 606 | char fname[CCHMAXPATH + 2];
|
---|
| 607 |
|
---|
[551] | 608 | strcpy(fname, filename);
|
---|
| 609 | strcat(fname, ".");
|
---|
[697] | 610 | ret = DosQueryAppType(fname, &apptype);
|
---|
[1369] | 611 | }
|
---|
[1372] | 612 | if (apptype & (FAPPTYP_DLL |
|
---|
[1394] | 613 | FAPPTYP_PHYSDRV |
|
---|
| 614 | FAPPTYP_VIRTDRV |
|
---|
| 615 | FAPPTYP_PROTDLL))
|
---|
[1372] | 616 | return FALSE;
|
---|
| 617 | if (apptype == 0x000b && (!p ||
|
---|
[1398] | 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))))
|
---|
[1372] | 623 | return FALSE;
|
---|
[1369] | 624 | if (!fProtectOnly) {
|
---|
| 625 | if ((!ret && (!apptype ||
|
---|
[1394] | 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)))) ||
|
---|
[1398] | 636 | (p && (!stricmp(p, PCSZ_DOTCMD) || !stricmp(p, PCSZ_DOTBAT) || !stricmp(p, PCSZ_DOTBTM))))
|
---|
[1394] | 637 | return TRUE;
|
---|
[1369] | 638 | }
|
---|
| 639 | else if ((!ret && (!apptype ||
|
---|
[1394] | 640 | (apptype &
|
---|
| 641 | (FAPPTYP_NOTWINDOWCOMPAT |
|
---|
| 642 | FAPPTYP_WINDOWCOMPAT |
|
---|
| 643 | FAPPTYP_WINDOWAPI |
|
---|
| 644 | FAPPTYP_BOUND |
|
---|
| 645 | FAPPTYP_32BIT)))) ||
|
---|
[1398] | 646 | (p && (!stricmp(p, PCSZ_DOTCMD) || !stricmp(p, PCSZ_DOTBTM))))
|
---|
[2] | 647 | return TRUE;
|
---|
[1369] | 648 | if (fProtectOnly && (apptype &
|
---|
[1394] | 649 | (FAPPTYP_DOS |
|
---|
| 650 | FAPPTYP_WINDOWSREAL |
|
---|
| 651 | FAPPTYP_WINDOWSPROT |
|
---|
| 652 | FAPPTYP_WINDOWSPROT31)) &&
|
---|
[1398] | 653 | (p && (!stricmp(p, PCSZ_DOTEXE) || !stricmp(p, PCSZ_DOTCOM) ||
|
---|
| 654 | !stricmp(p, PCSZ_DOTBAT))))
|
---|
[1369] | 655 | saymsg(MB_OK,
|
---|
[1394] | 656 | HWND_DESKTOP,
|
---|
| 657 | NullStr,
|
---|
| 658 | GetPString(IDS_NOTPROTECTONLYEXE),
|
---|
| 659 | filename);
|
---|
[2] | 660 | }
|
---|
| 661 | return FALSE;
|
---|
| 662 | }
|
---|
| 663 |
|
---|
[551] | 664 | VOID ArgDriveFlags(INT argc, CHAR ** argv)
|
---|
[103] | 665 | {
|
---|
[2] | 666 | INT x;
|
---|
| 667 |
|
---|
[551] | 668 | for (x = 1; x < argc; x++) {
|
---|
| 669 | if (*argv[x] == '/' && isalpha(argv[x][1])) {
|
---|
[2] | 670 |
|
---|
| 671 | CHAR *p = &argv[x][1];
|
---|
| 672 |
|
---|
[551] | 673 | while (isalpha(*p)) {
|
---|
[103] | 674 | driveflags[toupper(*p) - 'A'] |= DRIVE_IGNORE;
|
---|
| 675 | p++;
|
---|
[2] | 676 | }
|
---|
| 677 | }
|
---|
[551] | 678 | else 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_NOPRESCAN;
|
---|
| 684 | p++;
|
---|
[2] | 685 | }
|
---|
| 686 | }
|
---|
[552] | 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 | }
|
---|
[551] | 696 | else if (*argv[x] == ',' && isalpha(argv[x][1])) {
|
---|
[2] | 697 |
|
---|
| 698 | CHAR *p = &argv[x][1];
|
---|
| 699 |
|
---|
[551] | 700 | while (isalpha(*p)) {
|
---|
[103] | 701 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADICONS;
|
---|
| 702 | p++;
|
---|
[2] | 703 | }
|
---|
| 704 | }
|
---|
[552] | 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_NOLOADSUBJS;
|
---|
| 711 | p++;
|
---|
[2] | 712 | }
|
---|
| 713 | }
|
---|
[551] | 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_NOLOADLONGS;
|
---|
| 720 | p++;
|
---|
[2] | 721 | }
|
---|
| 722 | }
|
---|
| 723 | }
|
---|
| 724 | }
|
---|
| 725 |
|
---|
[551] | 726 | VOID DriveFlagsOne(INT x)
|
---|
[70] | 727 | {
|
---|
[551] | 728 | INT removable;
|
---|
| 729 | CHAR szDrive[] = " :\\", FileSystem[CCHMAXPATH];
|
---|
| 730 | ULONG drvtype;
|
---|
[2] | 731 |
|
---|
[551] | 732 | *szDrive = (CHAR) (x + 'A');
|
---|
[2] | 733 | *FileSystem = 0;
|
---|
| 734 | drvtype = 0;
|
---|
[551] | 735 | removable = CheckDrive(*szDrive, FileSystem, &drvtype);
|
---|
[2] | 736 | driveserial[x] = -1;
|
---|
| 737 | driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
|
---|
[103] | 738 | DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
|
---|
[1394] | 739 | DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS |
|
---|
| 740 | DRIVE_WRITEVERIFYOFF);
|
---|
[551] | 741 | if (removable != -1) {
|
---|
[70] | 742 | struct
|
---|
| 743 | {
|
---|
[2] | 744 | ULONG serial;
|
---|
[551] | 745 | CHAR volumelength;
|
---|
| 746 | CHAR volumelabel[CCHMAXPATH];
|
---|
| 747 | }
|
---|
| 748 | volser;
|
---|
[2] | 749 |
|
---|
| 750 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 751 | if (!DosQueryFSInfo((ULONG) x + 1, FSIL_VOLSER, &volser, sizeof(volser)))
|
---|
[2] | 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) ?
|
---|
[551] | 759 | DRIVE_REMOVABLE : 0);
|
---|
| 760 | if (drvtype & DRIVE_REMOTE)
|
---|
[2] | 761 | driveflags[x] |= DRIVE_REMOTE;
|
---|
[552] | 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 | }
|
---|
[555] | 770 | if(!stricmp(FileSystem,NTFS))
|
---|
| 771 | driveflags[x] |= DRIVE_NOTWRITEABLE;
|
---|
[551] | 772 | if (strcmp(FileSystem, HPFS) &&
|
---|
| 773 | strcmp(FileSystem, JFS) &&
|
---|
| 774 | strcmp(FileSystem, CDFS) &&
|
---|
[552] | 775 | strcmp(FileSystem, ISOFS) &&
|
---|
| 776 | strcmp(FileSystem, RAMFS) &&
|
---|
| 777 | strcmp(FileSystem, FAT32) &&
|
---|
[555] | 778 | strcmp(FileSystem, NTFS) &&
|
---|
| 779 | strcmp(FileSystem, NDFS32) &&
|
---|
[552] | 780 | strcmp(FileSystem, HPFS386)) {
|
---|
[2] | 781 | driveflags[x] |= DRIVE_NOLONGNAMES;
|
---|
[70] | 782 | }
|
---|
[552] | 783 |
|
---|
| 784 | if (!strcmp(FileSystem, CDFS) || !strcmp(FileSystem, ISOFS)) {
|
---|
[2] | 785 | removable = 1;
|
---|
[551] | 786 | driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE | DRIVE_CDROM);
|
---|
[2] | 787 | }
|
---|
[1351] | 788 | if (!stricmp(FileSystem, CBSIFS)) {
|
---|
[2] | 789 | driveflags[x] |= DRIVE_ZIPSTREAM;
|
---|
| 790 | driveflags[x] &= (~DRIVE_REMOTE);
|
---|
[551] | 791 | if (drvtype & DRIVE_REMOVABLE)
|
---|
[2] | 792 | driveflags[x] |= DRIVE_REMOVABLE;
|
---|
[551] | 793 | if (!(drvtype & DRIVE_NOLONGNAMES))
|
---|
[2] | 794 | driveflags[x] &= (~DRIVE_NOLONGNAMES);
|
---|
| 795 | }
|
---|
| 796 | }
|
---|
| 797 |
|
---|
[551] | 798 | VOID FillInDriveFlags(VOID * dummy)
|
---|
[103] | 799 | {
|
---|
[1354] | 800 | ULONG ulDriveNum, ulDriveMap, size;
|
---|
[2] | 801 | register INT x;
|
---|
| 802 |
|
---|
[551] | 803 | for (x = 0; x < 26; x++)
|
---|
[2] | 804 | driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
|
---|
[103] | 805 | DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
|
---|
[1394] | 806 | DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS |
|
---|
| 807 | DRIVE_WRITEVERIFYOFF);
|
---|
[551] | 808 | memset(driveserial, -1, sizeof(driveserial));
|
---|
[2] | 809 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 810 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
| 811 | for (x = 0; x < 26; x++) {
|
---|
[766] | 812 | if (ulDriveMap & (1 << x) && !(driveflags[x] & DRIVE_IGNORE)) {
|
---|
[2] | 813 | {
|
---|
[1394] | 814 | ULONG flags = 0, size = sizeof(ULONG);
|
---|
| 815 | CHAR FlagKey[80];
|
---|
[2] | 816 |
|
---|
[1394] | 817 | sprintf(FlagKey, "%c.DriveFlags", (CHAR) (x + 'A'));
|
---|
| 818 | if (PrfQueryProfileData(fmprof, appname, FlagKey, &flags, &size) &&
|
---|
| 819 | size == sizeof(ULONG))
|
---|
| 820 | driveflags[x] |= flags;
|
---|
[2] | 821 | }
|
---|
| 822 |
|
---|
[551] | 823 | if (x > 1) {
|
---|
| 824 | if (!(driveflags[x] & DRIVE_NOPRESCAN))
|
---|
[103] | 825 | DriveFlagsOne(x);
|
---|
| 826 | else
|
---|
| 827 | driveserial[x] = -1;
|
---|
[2] | 828 | }
|
---|
| 829 | else {
|
---|
[103] | 830 | driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES);
|
---|
| 831 | driveserial[x] = -1;
|
---|
[2] | 832 | }
|
---|
| 833 | }
|
---|
[766] | 834 | else if (!(ulDriveMap & (1 << x)))
|
---|
[2] | 835 | driveflags[x] |= DRIVE_INVALID;
|
---|
| 836 | }
|
---|
| 837 | {
|
---|
[551] | 838 | ULONG startdrive = 3L;
|
---|
[2] | 839 |
|
---|
| 840 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 841 | DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
| 842 | (PVOID) & startdrive, (ULONG) sizeof(ULONG));
|
---|
| 843 | if (startdrive)
|
---|
[2] | 844 | driveflags[startdrive - 1] |= DRIVE_BOOT;
|
---|
| 845 | }
|
---|
[1354] | 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]) {
|
---|
[1394] | 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 | }
|
---|
[1354] | 861 | }
|
---|
| 862 | }
|
---|
| 863 | }
|
---|
[2] | 864 | }
|
---|
| 865 |
|
---|
[551] | 866 | CHAR *assign_ignores(CHAR * s)
|
---|
[103] | 867 | {
|
---|
[551] | 868 | register INT x;
|
---|
| 869 | register CHAR *p, *pp;
|
---|
[2] | 870 |
|
---|
| 871 | *s = '/';
|
---|
| 872 | s[1] = 0;
|
---|
| 873 | p = s + 1;
|
---|
[551] | 874 | if (s) {
|
---|
| 875 | for (x = 0; x < 26; x++) {
|
---|
| 876 | if ((driveflags[x] & DRIVE_IGNORE) != 0) {
|
---|
| 877 | *p = (CHAR) x + 'A';
|
---|
[103] | 878 | p++;
|
---|
| 879 | *p = 0;
|
---|
[2] | 880 | }
|
---|
| 881 | }
|
---|
| 882 | }
|
---|
[551] | 883 | if (!s[1]) {
|
---|
[2] | 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;
|
---|
[551] | 895 | if (pp) {
|
---|
| 896 | for (x = 0; x < 26; x++) {
|
---|
| 897 | if ((driveflags[x] & DRIVE_NOPRESCAN) != 0) {
|
---|
| 898 | *p = (CHAR) x + 'A';
|
---|
[103] | 899 | p++;
|
---|
| 900 | *p = 0;
|
---|
[2] | 901 | }
|
---|
| 902 | }
|
---|
| 903 | }
|
---|
[551] | 904 | if (!pp[1])
|
---|
[2] | 905 | *pp = 0;
|
---|
| 906 | pp = &s[strlen(s)];
|
---|
| 907 | *pp = ' ';
|
---|
| 908 | pp++;
|
---|
| 909 | *pp = ',';
|
---|
| 910 | pp[1] = 0;
|
---|
| 911 | p = pp + 1;
|
---|
[551] | 912 | if (pp) {
|
---|
| 913 | for (x = 0; x < 26; x++) {
|
---|
| 914 | if ((driveflags[x] & DRIVE_NOLOADICONS) != 0) {
|
---|
| 915 | *p = (CHAR) x + 'A';
|
---|
[103] | 916 | p++;
|
---|
| 917 | *p = 0;
|
---|
[2] | 918 | }
|
---|
| 919 | }
|
---|
| 920 | }
|
---|
[551] | 921 | if (!pp[1])
|
---|
[2] | 922 | *pp = 0;
|
---|
| 923 | pp = &s[strlen(s)];
|
---|
| 924 | *pp = ' ';
|
---|
| 925 | pp++;
|
---|
[552] | 926 | *pp = '-';
|
---|
[2] | 927 | pp[1] = 0;
|
---|
| 928 | p = pp + 1;
|
---|
[551] | 929 | if (pp) {
|
---|
| 930 | for (x = 0; x < 26; x++) {
|
---|
| 931 | if ((driveflags[x] & DRIVE_NOLOADSUBJS) != 0) {
|
---|
| 932 | *p = (CHAR) x + 'A';
|
---|
[103] | 933 | p++;
|
---|
| 934 | *p = 0;
|
---|
[2] | 935 | }
|
---|
| 936 | }
|
---|
| 937 | }
|
---|
[551] | 938 | if (!pp[1])
|
---|
[2] | 939 | *pp = 0;
|
---|
| 940 | pp = &s[strlen(s)];
|
---|
| 941 | *pp = ' ';
|
---|
| 942 | pp++;
|
---|
[552] | 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++;
|
---|
[2] | 960 | *pp = '\'';
|
---|
| 961 | pp[1] = 0;
|
---|
| 962 | p = pp + 1;
|
---|
[551] | 963 | if (pp) {
|
---|
| 964 | for (x = 0; x < 26; x++) {
|
---|
| 965 | if ((driveflags[x] & DRIVE_NOLOADLONGS) != 0) {
|
---|
| 966 | *p = (CHAR) x + 'A';
|
---|
[103] | 967 | p++;
|
---|
| 968 | *p = 0;
|
---|
[2] | 969 | }
|
---|
| 970 | }
|
---|
| 971 | }
|
---|
[551] | 972 | if (!pp[1])
|
---|
[2] | 973 | *pp = 0;
|
---|
[123] | 974 | bstrip(s);
|
---|
[2] | 975 | return s;
|
---|
| 976 | }
|
---|
| 977 |
|
---|
[1394] | 978 | BOOL needs_quoting(PCSZ f)
|
---|
[103] | 979 | {
|
---|
[2] | 980 | register CHAR *p = " &|<>";
|
---|
| 981 |
|
---|
[551] | 982 | while (*p) {
|
---|
| 983 | if (strchr(f, *p))
|
---|
[2] | 984 | return TRUE;
|
---|
| 985 | p++;
|
---|
| 986 | }
|
---|
| 987 | return FALSE;
|
---|
| 988 | }
|
---|
| 989 |
|
---|
[551] | 990 | BOOL IsBinary(register CHAR * str, ULONG len)
|
---|
[103] | 991 | {
|
---|
[766] | 992 | register ULONG x = 0;
|
---|
[2] | 993 |
|
---|
[551] | 994 | if (str) {
|
---|
| 995 | while (x < len) {
|
---|
[1386] | 996 | if ((UINT) str[x] < ' ' && str[x] != '\r' && str[x] != '\n' && str[x] != '\t'
|
---|
| 997 | && str[x] != '\x1b' && str[x] != '\x1a' && str[x] != '\x07'
|
---|
[1394] | 998 | && str[x] != '\x0c') {
|
---|
| 999 | return TRUE;
|
---|
[1386] | 1000 | }
|
---|
[2] | 1001 | x++;
|
---|
| 1002 | }
|
---|
| 1003 | }
|
---|
| 1004 | return FALSE;
|
---|
| 1005 | }
|
---|
| 1006 |
|
---|
[551] | 1007 | BOOL TestBinary(CHAR * filename)
|
---|
[103] | 1008 | {
|
---|
[551] | 1009 | HFILE handle;
|
---|
| 1010 | ULONG ulAction;
|
---|
| 1011 | ULONG len;
|
---|
| 1012 | APIRET rc;
|
---|
[850] | 1013 | CHAR buff[4096]; // 06 Oct 07 SHL protect against NTFS defect
|
---|
[2] | 1014 |
|
---|
[551] | 1015 | if (filename) {
|
---|
[844] | 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)) {
|
---|
[2] | 1021 | len = 512;
|
---|
[551] | 1022 | rc = DosRead(handle, buff, len, &len);
|
---|
[2] | 1023 | DosClose(handle);
|
---|
[551] | 1024 | if (!rc && len)
|
---|
| 1025 | return IsBinary(buff, len);
|
---|
[2] | 1026 | }
|
---|
| 1027 | }
|
---|
| 1028 | return FALSE;
|
---|
| 1029 | }
|
---|
| 1030 |
|
---|
[1193] | 1031 | #if 0 // JBS 11 Sep 08
|
---|
[551] | 1032 | char *IsVowel(char a)
|
---|
[103] | 1033 | {
|
---|
[551] | 1034 | return (strchr("aeiouAEIOU", a) != NULL) ? "n" : NullStr;
|
---|
[2] | 1035 | }
|
---|
[1187] | 1036 | #endif
|
---|
[2] | 1037 |
|
---|
[551] | 1038 | VOID GetDesktopName(CHAR * objectpath, ULONG size)
|
---|
[103] | 1039 | {
|
---|
[551] | 1040 | PFN WQDPath;
|
---|
[2] | 1041 | HMODULE hmod = 0;
|
---|
[551] | 1042 | APIRET rc;
|
---|
[766] | 1043 | ULONG startdrive = 3;
|
---|
[551] | 1044 | CHAR objerr[CCHMAXPATH];
|
---|
[2] | 1045 |
|
---|
[328] | 1046 | if (!objectpath) {
|
---|
| 1047 | Runtime_Error(pszSrcFile, __LINE__, "null pointer");
|
---|
[2] | 1048 | return;
|
---|
[328] | 1049 | }
|
---|
[2] | 1050 | *objectpath = 0;
|
---|
[328] | 1051 | if (OS2ver[0] > 20 || (OS2ver[0] == 20 && OS2ver[1] >= 30)) {
|
---|
[2] | 1052 | /*
|
---|
| 1053 | * if running under warp, we can get the desktop name
|
---|
| 1054 | * this way...
|
---|
| 1055 | */
|
---|
[551] | 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);
|
---|
[2] | 1061 | DosFreeModule(hmod);
|
---|
| 1062 | }
|
---|
| 1063 | }
|
---|
[328] | 1064 | if (!*objectpath) {
|
---|
| 1065 | // Fall back to INI content
|
---|
| 1066 | if (!PrfQueryProfileString(HINI_SYSTEMPROFILE,
|
---|
| 1067 | "FolderWorkareaRunningObjects",
|
---|
| 1068 | NULL,
|
---|
| 1069 | "\0",
|
---|
[551] | 1070 | (PVOID) objectpath, sizeof(objectpath))) {
|
---|
| 1071 | Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
[1398] | 1072 | PCSZ_PRFQUERYPROFILESTRING);
|
---|
[2] | 1073 | *objectpath = 0;
|
---|
[328] | 1074 | }
|
---|
| 1075 | else if (!*objectpath || IsFile(objectpath)) {
|
---|
| 1076 | Runtime_Error(pszSrcFile, __LINE__, "bad FolderWorkareaRunningObjects");
|
---|
| 1077 | *objectpath = 0;
|
---|
| 1078 | }
|
---|
| 1079 | if (!*objectpath) {
|
---|
[552] | 1080 | // Fall back
|
---|
[2] | 1081 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 1082 | DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
| 1083 | (PVOID) & startdrive, (ULONG) sizeof(ULONG));
|
---|
[552] | 1084 | sprintf(objectpath, GetPString(IDS_PATHTODESKTOP), ((CHAR) startdrive) + '@');
|
---|
[2] | 1085 | }
|
---|
| 1086 | }
|
---|
| 1087 | }
|
---|
[793] | 1088 |
|
---|
| 1089 | #pragma alloc_text(VALID,CheckDrive,IsRoot,IsFile,IsFullName,needsquoting)
|
---|
| 1090 | #pragma alloc_text(VALID,IsValidDir,IsValidDrive,MakeValidDir,IsVowel)
|
---|
[897] | 1091 | #pragma alloc_text(VALID,IsFileSame,IsNewer,TestFDates,TestCDates,RootName,MakeFullName)
|
---|
[793] | 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)
|
---|