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