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