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