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