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