[48] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: valid.c 689 2007-06-15 06:33:24Z stevenhl $
|
---|
| 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
|
---|
[689] | 71 | // Return empty string when filename ends with backslash
|
---|
[48] | 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;
|
---|
[689] | 237 | pfsn = (PCHAR)(pfsq->szName) + pfsq->cbName + 1;
|
---|
[2] | 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)))
|
---|
[555] | 246 | *pulType |= DRIVE_NOTWRITEABLE | DRIVE_CDROM | DRIVE_REMOVABLE;
|
---|
| 247 | if (pulType && !strcmp(pfsn, NTFS))
|
---|
| 248 | *pulType |= DRIVE_NOTWRITEABLE;
|
---|
[552] | 249 | if (pulType && !strcmp(pfsn, NDFS32)){
|
---|
| 250 | *pulType |= DRIVE_VIRTUAL;
|
---|
| 251 | }
|
---|
| 252 | if (pulType && !strcmp(pfsn, RAMFS)){
|
---|
| 253 | *pulType |= DRIVE_RAMDISK;
|
---|
| 254 | }
|
---|
| 255 | if (((PFSQBUFFER2) pvBuffer)->iType == FSAT_REMOTEDRV &&
|
---|
[555] | 256 | (strcmp(pfsn, CDFS) || strcmp(pfsn, ISOFS))) {
|
---|
[70] | 257 | if (pulType)
|
---|
| 258 | *pulType |= DRIVE_REMOTE;
|
---|
[552] | 259 |
|
---|
[551] | 260 | if (pulType && !strcmp(pfsn, CBSIFS)) {
|
---|
[70] | 261 | *pulType |= DRIVE_ZIPSTREAM;
|
---|
| 262 | *pulType &= ~DRIVE_REMOTE;
|
---|
| 263 | *pulType |= DRIVE_NOLONGNAMES;
|
---|
[551] | 264 | if (pfsq->cbFSAData) {
|
---|
[103] | 265 | ULONG FType;
|
---|
[2] | 266 |
|
---|
[551] | 267 | if (CheckDrive(*pfsd, NULL, &FType) != -1) {
|
---|
[103] | 268 | if (FType & DRIVE_REMOVABLE)
|
---|
| 269 | *pulType |= DRIVE_REMOVABLE;
|
---|
| 270 | if (~FType & DRIVE_NOLONGNAMES)
|
---|
| 271 | *pulType &= ~DRIVE_NOLONGNAMES;
|
---|
| 272 | }
|
---|
[552] | 273 |
|
---|
[2] | 274 | }
|
---|
| 275 | }
|
---|
[70] | 276 | if (pulType &&
|
---|
[551] | 277 | (!strcmp(pfsn, HPFS) ||
|
---|
| 278 | !strcmp(pfsn, JFS) ||
|
---|
| 279 | !strcmp(pfsn, FAT32) ||
|
---|
[552] | 280 | !strcmp(pfsn, RAMFS) ||
|
---|
| 281 | !strcmp(pfsn, NDFS32) ||
|
---|
[555] | 282 | !strcmp(pfsn, NTFS) ||
|
---|
[552] | 283 | !strcmp(pfsn, HPFS386))) {
|
---|
[70] | 284 | *pulType &= ~DRIVE_NOLONGNAMES;
|
---|
| 285 | }
|
---|
[552] | 286 |
|
---|
[103] | 287 | DosFreeMem(pvBuffer);
|
---|
| 288 | return 0; // Remotes are non-removable
|
---|
[2] | 289 | }
|
---|
| 290 |
|
---|
[70] | 291 | // Local drive
|
---|
[551] | 292 | if (strcmp(pfsn, HPFS) &&
|
---|
| 293 | strcmp(pfsn, JFS) &&
|
---|
| 294 | strcmp(pfsn, CDFS) &&
|
---|
[552] | 295 | strcmp(pfsn, ISOFS) &&
|
---|
| 296 | strcmp(pfsn, RAMFS) &&
|
---|
| 297 | strcmp(pfsn, FAT32) &&
|
---|
| 298 | strcmp(pfsn, NDFS32) &&
|
---|
[555] | 299 | strcmp(pfsn, NTFS) &&
|
---|
[552] | 300 | strcmp(pfsn, HPFS386)) {
|
---|
[551] | 301 | if (pulType)
|
---|
[103] | 302 | (*pulType) |= DRIVE_NOLONGNAMES; // Others can not have long names
|
---|
[2] | 303 | }
|
---|
| 304 |
|
---|
[552] | 305 |
|
---|
[2] | 306 | DosError(FERR_DISABLEHARDERR);
|
---|
[328] | 307 | rc = DosOpen(szPath, &hDev, &ulAction, 0, 0, FILE_OPEN,
|
---|
[551] | 308 | OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE |
|
---|
| 309 | OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR, 0);
|
---|
| 310 | if (rc) {
|
---|
[2] | 311 | DosError(FERR_DISABLEHARDERR);
|
---|
[70] | 312 | if (pulType)
|
---|
| 313 | *pulType |= DRIVE_REMOVABLE; // Assume removable if can not access
|
---|
[103] | 314 | DosFreeMem(pvBuffer);
|
---|
[70] | 315 | return 1; // Say removable
|
---|
[2] | 316 | }
|
---|
[103] | 317 |
|
---|
| 318 | clParmBytes = sizeof(parmPkt.Cmd);
|
---|
| 319 | clDataBytes = sizeof(NonRemovable);
|
---|
| 320 | NonRemovable = 1; // Preset as non removable
|
---|
[2] | 321 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 322 | rc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_BLOCKREMOVABLE, &parmPkt.Cmd, /* Address of the command-specific argument list. */
|
---|
| 323 | sizeof(parmPkt.Cmd), /* Length, in bytes, of pParams. */
|
---|
| 324 | &clParmBytes, /* Pointer to the length of parameters. */
|
---|
| 325 | &NonRemovable, /* Address of the data area. */
|
---|
| 326 | sizeof(NonRemovable), /* Length, in bytes, of pData. */
|
---|
| 327 | &clDataBytes); /* Pointer to the length of data. */
|
---|
[103] | 328 |
|
---|
[328] | 329 | if (!rc && NonRemovable) {
|
---|
[103] | 330 | // Could be USB so check BPB flags
|
---|
| 331 | clParmBytes = sizeof(parmPkt.Cmd);
|
---|
| 332 | clDataBytes = sizeof(dataPkt);
|
---|
| 333 | memset(&dataPkt, 0xff, sizeof(dataPkt));
|
---|
| 334 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 335 | rc = DosDevIOCtl(hDev, IOCTL_DISK, DSK_GETDEVICEPARAMS, &parmPkt.Cmd, /* Address of the command-specific argument list. */
|
---|
| 336 | sizeof(parmPkt.Cmd), /* Length, in bytes, of pParams. */
|
---|
| 337 | &clParmBytes, /* Pointer to the length of parameters. */
|
---|
| 338 | &dataPkt, /* Address of the data area. */
|
---|
| 339 | sizeof(dataPkt), /* Length, in bytes, of pData. */
|
---|
| 340 | &clDataBytes); /* Pointer to the length of data. */
|
---|
[103] | 341 |
|
---|
[328] | 342 | if (!rc && (dataPkt.bpb.fsDeviceAttr & BPB_REMOVABLE_MEDIA))
|
---|
[103] | 343 | NonRemovable = 0;
|
---|
| 344 | }
|
---|
| 345 |
|
---|
| 346 | DosClose(hDev);
|
---|
| 347 |
|
---|
[70] | 348 | if (!NonRemovable && pulType)
|
---|
| 349 | *pulType |= DRIVE_REMOVABLE;
|
---|
[103] | 350 |
|
---|
| 351 | DosFreeMem(pvBuffer);
|
---|
| 352 |
|
---|
[70] | 353 | return NonRemovable ? 0 : 1;
|
---|
[2] | 354 | }
|
---|
| 355 |
|
---|
[551] | 356 | BOOL IsFileSame(CHAR * filename1, CHAR * filename2)
|
---|
[103] | 357 | {
|
---|
[2] | 358 | /* returns: -1 (error), 0 (is a directory), or 1 (is a file) */
|
---|
| 359 |
|
---|
[551] | 360 | FILESTATUS3 fsa1, fsa2;
|
---|
| 361 | APIRET ret;
|
---|
[2] | 362 |
|
---|
[551] | 363 | if (filename1 && filename2) {
|
---|
[2] | 364 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 365 | ret = DosQueryPathInfo(filename1, FIL_STANDARD, &fsa1,
|
---|
| 366 | (ULONG) sizeof(fsa1));
|
---|
| 367 | if (!ret) {
|
---|
[2] | 368 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 369 | ret = DosQueryPathInfo(filename2, FIL_STANDARD, &fsa2,
|
---|
| 370 | (ULONG) sizeof(fsa2));
|
---|
| 371 | if (!ret) {
|
---|
| 372 | if (fsa1.cbFile == fsa2.cbFile &&
|
---|
| 373 | (fsa1.attrFile & (~FILE_ARCHIVED)) ==
|
---|
| 374 | (fsa2.attrFile & (~FILE_ARCHIVED)))
|
---|
[103] | 375 | return TRUE;
|
---|
[2] | 376 | }
|
---|
| 377 | }
|
---|
| 378 | }
|
---|
| 379 | return FALSE;
|
---|
| 380 | }
|
---|
| 381 |
|
---|
[551] | 382 | INT IsFile(CHAR * filename)
|
---|
[103] | 383 | {
|
---|
[2] | 384 | /* returns: -1 (error), 0 (is a directory), or 1 (is a file) */
|
---|
| 385 |
|
---|
| 386 | FILESTATUS3 fsa;
|
---|
[551] | 387 | APIRET ret;
|
---|
[2] | 388 |
|
---|
[551] | 389 | if (filename && *filename) {
|
---|
[2] | 390 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 391 | ret = DosQueryPathInfo(filename, FIL_STANDARD, &fsa, (ULONG) sizeof(fsa));
|
---|
| 392 | if (!ret)
|
---|
[2] | 393 | return ((fsa.attrFile & FILE_DIRECTORY) == 0);
|
---|
[551] | 394 | else if (IsValidDrive(*filename) && IsRoot(filename))
|
---|
[2] | 395 | return 0;
|
---|
| 396 | }
|
---|
[551] | 397 | return -1; /* error; doesn't exist or can't read or null filename */
|
---|
[2] | 398 | }
|
---|
| 399 |
|
---|
[551] | 400 | BOOL IsFullName(CHAR * filename)
|
---|
[103] | 401 | {
|
---|
[2] | 402 | return (filename) ?
|
---|
[551] | 403 | (isalpha(*filename) && filename[1] == ':' && filename[2] == '\\') : 0;
|
---|
[2] | 404 | }
|
---|
| 405 |
|
---|
[551] | 406 | BOOL IsRoot(CHAR * filename)
|
---|
[103] | 407 | {
|
---|
[2] | 408 | return (filename && isalpha(*filename) && filename[1] == ':' &&
|
---|
[103] | 409 | filename[2] == '\\' && !filename[3]);
|
---|
[2] | 410 | }
|
---|
| 411 |
|
---|
[551] | 412 | BOOL IsValidDir(CHAR * path)
|
---|
[103] | 413 | {
|
---|
[551] | 414 | CHAR fullname[CCHMAXPATH];
|
---|
[2] | 415 | FILESTATUS3 fs;
|
---|
| 416 |
|
---|
[551] | 417 | if (path) {
|
---|
[2] | 418 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 419 | if (!DosQueryPathInfo(path,
|
---|
| 420 | FIL_QUERYFULLNAME, fullname, sizeof(fullname))) {
|
---|
| 421 | if (IsValidDrive(*fullname)) {
|
---|
| 422 | if (!IsRoot(fullname)) {
|
---|
[103] | 423 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 424 | if (!DosQueryPathInfo(fullname,
|
---|
| 425 | FIL_STANDARD,
|
---|
| 426 | &fs,
|
---|
| 427 | sizeof(fs)) && (fs.attrFile & FILE_DIRECTORY))
|
---|
[103] | 428 | return TRUE;
|
---|
| 429 | }
|
---|
| 430 | else
|
---|
| 431 | return TRUE;
|
---|
[2] | 432 | }
|
---|
| 433 | }
|
---|
| 434 | }
|
---|
| 435 | return FALSE;
|
---|
| 436 | }
|
---|
| 437 |
|
---|
[551] | 438 | BOOL IsValidDrive(CHAR drive)
|
---|
[103] | 439 | {
|
---|
[551] | 440 | CHAR Path[] = " :", Buffer[256];
|
---|
[2] | 441 | APIRET Status;
|
---|
[551] | 442 | ULONG Size;
|
---|
| 443 | ULONG ulDriveNum, ulDriveMap;
|
---|
[2] | 444 |
|
---|
[551] | 445 | if (!isalpha(drive) ||
|
---|
| 446 | (driveflags[toupper(drive) - 'A'] & (DRIVE_IGNORE | DRIVE_INVALID)))
|
---|
[2] | 447 | return FALSE;
|
---|
| 448 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 449 | Status = DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
| 450 | if (!Status) {
|
---|
| 451 | if (!(ulDriveMap & (1L << (ULONG) (toupper(drive) - 'A'))))
|
---|
[2] | 452 | return FALSE;
|
---|
| 453 | Path[0] = toupper(drive);
|
---|
| 454 | Size = sizeof(Buffer);
|
---|
| 455 | DosError(FERR_DISABLEHARDERR);
|
---|
| 456 | Status = DosQueryFSAttach(Path,
|
---|
[103] | 457 | 0,
|
---|
[551] | 458 | FSAIL_QUERYNAME, (PFSQBUFFER2) Buffer, &Size);
|
---|
[2] | 459 | }
|
---|
| 460 | return (Status == 0);
|
---|
| 461 | }
|
---|
| 462 |
|
---|
[274] | 463 | //=== MakeValidDir() build valid directory name ===
|
---|
[2] | 464 |
|
---|
[551] | 465 | CHAR *MakeValidDir(CHAR * path)
|
---|
[103] | 466 | {
|
---|
[551] | 467 | ULONG ulDrv;
|
---|
| 468 | CHAR *p;
|
---|
| 469 | FILESTATUS3 fs;
|
---|
| 470 | APIRET rc;
|
---|
[2] | 471 |
|
---|
[274] | 472 | if (!MakeFullName(path)) {
|
---|
| 473 | if (IsValidDrive(*path)) {
|
---|
| 474 | // Passed name is valid - trim to directory
|
---|
| 475 | for (;;) {
|
---|
| 476 | if (IsRoot(path))
|
---|
[103] | 477 | return path;
|
---|
| 478 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 479 | rc = DosQueryPathInfo(path, FIL_STANDARD, &fs, sizeof(fs));
|
---|
[274] | 480 | if (!rc && (fs.attrFile & FILE_DIRECTORY))
|
---|
[103] | 481 | return path;
|
---|
[551] | 482 | p = strrchr(path, '\\');
|
---|
[274] | 483 | if (p) {
|
---|
| 484 | if (p < path + 3)
|
---|
[103] | 485 | p++;
|
---|
| 486 | *p = 0;
|
---|
| 487 | }
|
---|
| 488 | else
|
---|
| 489 | break;
|
---|
[2] | 490 | }
|
---|
| 491 | }
|
---|
| 492 | }
|
---|
[274] | 493 | // Fall back to boot drive
|
---|
[2] | 494 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 495 | if (!DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE, &ulDrv, sizeof(ulDrv))) {
|
---|
[274] | 496 | ulDrv += '@';
|
---|
| 497 | if (ulDrv < 'C')
|
---|
| 498 | ulDrv = 'C';
|
---|
[551] | 499 | strcpy(path, " :\\");
|
---|
| 500 | *path = (CHAR) ulDrv;
|
---|
[2] | 501 | }
|
---|
| 502 | else
|
---|
[551] | 503 | save_dir2(path); // Fall back to fm3.ini drive or current dir - should never occur
|
---|
[2] | 504 | return path;
|
---|
| 505 | }
|
---|
| 506 |
|
---|
[551] | 507 | BOOL IsExecutable(CHAR * filename)
|
---|
[103] | 508 | {
|
---|
[2] | 509 | register CHAR *p;
|
---|
[551] | 510 | APIRET ret;
|
---|
| 511 | ULONG apptype;
|
---|
[2] | 512 |
|
---|
[551] | 513 | if (filename) {
|
---|
[2] | 514 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 515 | p = strrchr(filename, '.');
|
---|
| 516 | if (p)
|
---|
| 517 | ret = DosQAppType(filename, &apptype);
|
---|
[2] | 518 | else {
|
---|
| 519 |
|
---|
| 520 | char fname[CCHMAXPATH + 2];
|
---|
| 521 |
|
---|
[551] | 522 | strcpy(fname, filename);
|
---|
| 523 | strcat(fname, ".");
|
---|
| 524 | ret = DosQAppType(fname, &apptype);
|
---|
[2] | 525 | }
|
---|
[551] | 526 | if ((!ret && (!apptype ||
|
---|
| 527 | (apptype &
|
---|
| 528 | (FAPPTYP_NOTWINDOWCOMPAT |
|
---|
| 529 | FAPPTYP_WINDOWCOMPAT |
|
---|
| 530 | FAPPTYP_WINDOWAPI |
|
---|
| 531 | FAPPTYP_BOUND |
|
---|
| 532 | FAPPTYP_DOS |
|
---|
| 533 | FAPPTYP_WINDOWSREAL |
|
---|
| 534 | FAPPTYP_WINDOWSPROT |
|
---|
| 535 | FAPPTYP_32BIT |
|
---|
| 536 | 0x1000)))) ||
|
---|
| 537 | (p && (!stricmp(p, ".CMD") || !stricmp(p, ".BAT"))))
|
---|
[2] | 538 | return TRUE;
|
---|
| 539 | }
|
---|
| 540 | return FALSE;
|
---|
| 541 | }
|
---|
| 542 |
|
---|
[551] | 543 | VOID ArgDriveFlags(INT argc, CHAR ** argv)
|
---|
[103] | 544 | {
|
---|
[2] | 545 | INT x;
|
---|
| 546 |
|
---|
[551] | 547 | for (x = 1; x < argc; x++) {
|
---|
| 548 | if (*argv[x] == '/' && isalpha(argv[x][1])) {
|
---|
[2] | 549 |
|
---|
| 550 | CHAR *p = &argv[x][1];
|
---|
| 551 |
|
---|
[551] | 552 | while (isalpha(*p)) {
|
---|
[103] | 553 | driveflags[toupper(*p) - 'A'] |= DRIVE_IGNORE;
|
---|
| 554 | p++;
|
---|
[2] | 555 | }
|
---|
| 556 | }
|
---|
[551] | 557 | else if (*argv[x] == ';' && isalpha(argv[x][1])) {
|
---|
[2] | 558 |
|
---|
| 559 | CHAR *p = &argv[x][1];
|
---|
| 560 |
|
---|
[551] | 561 | while (isalpha(*p)) {
|
---|
[103] | 562 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOPRESCAN;
|
---|
| 563 | p++;
|
---|
[2] | 564 | }
|
---|
| 565 | }
|
---|
[552] | 566 | else if (*argv[x] == '`' && isalpha(argv[x][1])) {
|
---|
| 567 |
|
---|
| 568 | CHAR *p = &argv[x][1];
|
---|
| 569 |
|
---|
| 570 | while (isalpha(*p)) {
|
---|
| 571 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOSTATS;
|
---|
| 572 | p++;
|
---|
| 573 | }
|
---|
| 574 | }
|
---|
[551] | 575 | else if (*argv[x] == ',' && isalpha(argv[x][1])) {
|
---|
[2] | 576 |
|
---|
| 577 | CHAR *p = &argv[x][1];
|
---|
| 578 |
|
---|
[551] | 579 | while (isalpha(*p)) {
|
---|
[103] | 580 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADICONS;
|
---|
| 581 | p++;
|
---|
[2] | 582 | }
|
---|
| 583 | }
|
---|
[552] | 584 | else if (*argv[x] == '-' && isalpha(argv[x][1])) {
|
---|
[2] | 585 |
|
---|
| 586 | CHAR *p = &argv[x][1];
|
---|
| 587 |
|
---|
[551] | 588 | while (isalpha(*p)) {
|
---|
[103] | 589 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADSUBJS;
|
---|
| 590 | p++;
|
---|
[2] | 591 | }
|
---|
| 592 | }
|
---|
[551] | 593 | else if (*argv[x] == '\'' && isalpha(argv[x][1])) {
|
---|
[2] | 594 |
|
---|
| 595 | CHAR *p = &argv[x][1];
|
---|
| 596 |
|
---|
[551] | 597 | while (isalpha(*p)) {
|
---|
[103] | 598 | driveflags[toupper(*p) - 'A'] |= DRIVE_NOLOADLONGS;
|
---|
| 599 | p++;
|
---|
[2] | 600 | }
|
---|
| 601 | }
|
---|
| 602 | }
|
---|
| 603 | }
|
---|
| 604 |
|
---|
[551] | 605 | VOID DriveFlagsOne(INT x)
|
---|
[70] | 606 | {
|
---|
[551] | 607 | INT removable;
|
---|
| 608 | CHAR szDrive[] = " :\\", FileSystem[CCHMAXPATH];
|
---|
| 609 | ULONG drvtype;
|
---|
[2] | 610 |
|
---|
[551] | 611 | *szDrive = (CHAR) (x + 'A');
|
---|
[2] | 612 | *FileSystem = 0;
|
---|
| 613 | drvtype = 0;
|
---|
[551] | 614 | removable = CheckDrive(*szDrive, FileSystem, &drvtype);
|
---|
[2] | 615 | driveserial[x] = -1;
|
---|
| 616 | driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
|
---|
[103] | 617 | DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
|
---|
[552] | 618 | DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS);
|
---|
[551] | 619 | if (removable != -1) {
|
---|
[70] | 620 | struct
|
---|
| 621 | {
|
---|
[2] | 622 | ULONG serial;
|
---|
[551] | 623 | CHAR volumelength;
|
---|
| 624 | CHAR volumelabel[CCHMAXPATH];
|
---|
| 625 | }
|
---|
| 626 | volser;
|
---|
[2] | 627 |
|
---|
| 628 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 629 | if (!DosQueryFSInfo((ULONG) x + 1, FSIL_VOLSER, &volser, sizeof(volser)))
|
---|
[2] | 630 | driveserial[x] = volser.serial;
|
---|
| 631 | else
|
---|
| 632 | DosError(FERR_DISABLEHARDERR);
|
---|
| 633 | }
|
---|
| 634 | else
|
---|
| 635 | driveflags[x] |= DRIVE_INVALID;
|
---|
| 636 | driveflags[x] |= ((removable == -1 || removable == 1) ?
|
---|
[551] | 637 | DRIVE_REMOVABLE : 0);
|
---|
| 638 | if (drvtype & DRIVE_REMOTE)
|
---|
[2] | 639 | driveflags[x] |= DRIVE_REMOTE;
|
---|
[552] | 640 | if(!stricmp(FileSystem,NDFS32)){
|
---|
| 641 | driveflags[x] |= DRIVE_VIRTUAL;
|
---|
| 642 | driveflags[x] &= (~DRIVE_REMOTE);
|
---|
| 643 | }
|
---|
| 644 | if(!stricmp(FileSystem,RAMFS)){
|
---|
| 645 | driveflags[x] |= DRIVE_RAMDISK;
|
---|
| 646 | driveflags[x] &= (~DRIVE_REMOTE);
|
---|
| 647 | }
|
---|
[555] | 648 | if(!stricmp(FileSystem,NTFS))
|
---|
| 649 | driveflags[x] |= DRIVE_NOTWRITEABLE;
|
---|
[551] | 650 | if (strcmp(FileSystem, HPFS) &&
|
---|
| 651 | strcmp(FileSystem, JFS) &&
|
---|
| 652 | strcmp(FileSystem, CDFS) &&
|
---|
[552] | 653 | strcmp(FileSystem, ISOFS) &&
|
---|
| 654 | strcmp(FileSystem, RAMFS) &&
|
---|
| 655 | strcmp(FileSystem, FAT32) &&
|
---|
[555] | 656 | strcmp(FileSystem, NTFS) &&
|
---|
| 657 | strcmp(FileSystem, NDFS32) &&
|
---|
[552] | 658 | strcmp(FileSystem, HPFS386)) {
|
---|
[2] | 659 | driveflags[x] |= DRIVE_NOLONGNAMES;
|
---|
[70] | 660 | }
|
---|
[552] | 661 |
|
---|
| 662 | if (!strcmp(FileSystem, CDFS) || !strcmp(FileSystem, ISOFS)) {
|
---|
[2] | 663 | removable = 1;
|
---|
[551] | 664 | driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE | DRIVE_CDROM);
|
---|
[2] | 665 | }
|
---|
[551] | 666 | else if (!stricmp(FileSystem, CBSIFS)) {
|
---|
[2] | 667 | driveflags[x] |= DRIVE_ZIPSTREAM;
|
---|
| 668 | driveflags[x] &= (~DRIVE_REMOTE);
|
---|
[551] | 669 | if (drvtype & DRIVE_REMOVABLE)
|
---|
[2] | 670 | driveflags[x] |= DRIVE_REMOVABLE;
|
---|
[551] | 671 | if (!(drvtype & DRIVE_NOLONGNAMES))
|
---|
[2] | 672 | driveflags[x] &= (~DRIVE_NOLONGNAMES);
|
---|
| 673 | }
|
---|
| 674 | }
|
---|
| 675 |
|
---|
[551] | 676 | VOID FillInDriveFlags(VOID * dummy)
|
---|
[103] | 677 | {
|
---|
[551] | 678 | ULONG ulDriveNum, ulDriveMap;
|
---|
[2] | 679 | register INT x;
|
---|
| 680 |
|
---|
[551] | 681 | for (x = 0; x < 26; x++)
|
---|
[2] | 682 | driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
|
---|
[103] | 683 | DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
|
---|
[552] | 684 | DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS);
|
---|
[551] | 685 | memset(driveserial, -1, sizeof(driveserial));
|
---|
[2] | 686 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 687 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
| 688 | for (x = 0; x < 26; x++) {
|
---|
| 689 | if (ulDriveMap & (1L << x) && !(driveflags[x] & DRIVE_IGNORE)) {
|
---|
[2] | 690 | {
|
---|
[551] | 691 | CHAR s[80];
|
---|
| 692 | ULONG flags = 0, size = sizeof(ULONG);
|
---|
[2] | 693 |
|
---|
[551] | 694 | sprintf(s, "%c.DriveFlags", (CHAR) (x + 'A'));
|
---|
| 695 | if (PrfQueryProfileData(fmprof, appname, s, &flags, &size) &&
|
---|
| 696 | size == sizeof(ULONG))
|
---|
[103] | 697 | driveflags[x] |= flags;
|
---|
[2] | 698 | }
|
---|
| 699 |
|
---|
[551] | 700 | if (x > 1) {
|
---|
| 701 | if (!(driveflags[x] & DRIVE_NOPRESCAN))
|
---|
[103] | 702 | DriveFlagsOne(x);
|
---|
| 703 | else
|
---|
| 704 | driveserial[x] = -1;
|
---|
[2] | 705 | }
|
---|
| 706 | else {
|
---|
[103] | 707 | driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES);
|
---|
| 708 | driveserial[x] = -1;
|
---|
[2] | 709 | }
|
---|
| 710 | }
|
---|
[551] | 711 | else if (!(ulDriveMap & (1L << x)))
|
---|
[2] | 712 | driveflags[x] |= DRIVE_INVALID;
|
---|
| 713 | }
|
---|
| 714 | {
|
---|
[551] | 715 | ULONG startdrive = 3L;
|
---|
[2] | 716 |
|
---|
| 717 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 718 | DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
| 719 | (PVOID) & startdrive, (ULONG) sizeof(ULONG));
|
---|
| 720 | if (startdrive)
|
---|
[2] | 721 | driveflags[startdrive - 1] |= DRIVE_BOOT;
|
---|
| 722 | }
|
---|
| 723 | }
|
---|
| 724 |
|
---|
[551] | 725 | CHAR *assign_ignores(CHAR * s)
|
---|
[103] | 726 | {
|
---|
[551] | 727 | register INT x;
|
---|
| 728 | register CHAR *p, *pp;
|
---|
[2] | 729 |
|
---|
| 730 | *s = '/';
|
---|
| 731 | s[1] = 0;
|
---|
| 732 | p = s + 1;
|
---|
[551] | 733 | if (s) {
|
---|
| 734 | for (x = 0; x < 26; x++) {
|
---|
| 735 | if ((driveflags[x] & DRIVE_IGNORE) != 0) {
|
---|
| 736 | *p = (CHAR) x + 'A';
|
---|
[103] | 737 | p++;
|
---|
| 738 | *p = 0;
|
---|
[2] | 739 | }
|
---|
| 740 | }
|
---|
| 741 | }
|
---|
[551] | 742 | if (!s[1]) {
|
---|
[2] | 743 | *s = 0;
|
---|
| 744 | pp = s;
|
---|
| 745 | }
|
---|
| 746 | else {
|
---|
| 747 | pp = &s[strlen(s)];
|
---|
| 748 | *pp = ' ';
|
---|
| 749 | pp++;
|
---|
| 750 | }
|
---|
| 751 | *pp = ';';
|
---|
| 752 | pp[1] = 0;
|
---|
| 753 | p = pp + 1;
|
---|
[551] | 754 | if (pp) {
|
---|
| 755 | for (x = 0; x < 26; x++) {
|
---|
| 756 | if ((driveflags[x] & DRIVE_NOPRESCAN) != 0) {
|
---|
| 757 | *p = (CHAR) x + 'A';
|
---|
[103] | 758 | p++;
|
---|
| 759 | *p = 0;
|
---|
[2] | 760 | }
|
---|
| 761 | }
|
---|
| 762 | }
|
---|
[551] | 763 | if (!pp[1])
|
---|
[2] | 764 | *pp = 0;
|
---|
| 765 | pp = &s[strlen(s)];
|
---|
| 766 | *pp = ' ';
|
---|
| 767 | pp++;
|
---|
| 768 | *pp = ',';
|
---|
| 769 | pp[1] = 0;
|
---|
| 770 | p = pp + 1;
|
---|
[551] | 771 | if (pp) {
|
---|
| 772 | for (x = 0; x < 26; x++) {
|
---|
| 773 | if ((driveflags[x] & DRIVE_NOLOADICONS) != 0) {
|
---|
| 774 | *p = (CHAR) x + 'A';
|
---|
[103] | 775 | p++;
|
---|
| 776 | *p = 0;
|
---|
[2] | 777 | }
|
---|
| 778 | }
|
---|
| 779 | }
|
---|
[551] | 780 | if (!pp[1])
|
---|
[2] | 781 | *pp = 0;
|
---|
| 782 | pp = &s[strlen(s)];
|
---|
| 783 | *pp = ' ';
|
---|
| 784 | pp++;
|
---|
[552] | 785 | *pp = '-';
|
---|
[2] | 786 | pp[1] = 0;
|
---|
| 787 | p = pp + 1;
|
---|
[551] | 788 | if (pp) {
|
---|
| 789 | for (x = 0; x < 26; x++) {
|
---|
| 790 | if ((driveflags[x] & DRIVE_NOLOADSUBJS) != 0) {
|
---|
| 791 | *p = (CHAR) x + 'A';
|
---|
[103] | 792 | p++;
|
---|
| 793 | *p = 0;
|
---|
[2] | 794 | }
|
---|
| 795 | }
|
---|
| 796 | }
|
---|
[551] | 797 | if (!pp[1])
|
---|
[2] | 798 | *pp = 0;
|
---|
| 799 | pp = &s[strlen(s)];
|
---|
| 800 | *pp = ' ';
|
---|
| 801 | pp++;
|
---|
[552] | 802 | *pp = '`';
|
---|
| 803 | pp[1] = 0;
|
---|
| 804 | p = pp + 1;
|
---|
| 805 | if (pp) {
|
---|
| 806 | for (x = 0; x < 26; x++) {
|
---|
| 807 | if ((driveflags[x] & DRIVE_NOSTATS) != 0) {
|
---|
| 808 | *p = (CHAR) x + 'A';
|
---|
| 809 | p++;
|
---|
| 810 | *p = 0;
|
---|
| 811 | }
|
---|
| 812 | }
|
---|
| 813 | }
|
---|
| 814 | if (!pp[1])
|
---|
| 815 | *pp = 0;
|
---|
| 816 | pp = &s[strlen(s)];
|
---|
| 817 | *pp = ' ';
|
---|
| 818 | pp++;
|
---|
[2] | 819 | *pp = '\'';
|
---|
| 820 | pp[1] = 0;
|
---|
| 821 | p = pp + 1;
|
---|
[551] | 822 | if (pp) {
|
---|
| 823 | for (x = 0; x < 26; x++) {
|
---|
| 824 | if ((driveflags[x] & DRIVE_NOLOADLONGS) != 0) {
|
---|
| 825 | *p = (CHAR) x + 'A';
|
---|
[103] | 826 | p++;
|
---|
| 827 | *p = 0;
|
---|
[2] | 828 | }
|
---|
| 829 | }
|
---|
| 830 | }
|
---|
[551] | 831 | if (!pp[1])
|
---|
[2] | 832 | *pp = 0;
|
---|
[123] | 833 | bstrip(s);
|
---|
[2] | 834 | return s;
|
---|
| 835 | }
|
---|
| 836 |
|
---|
[551] | 837 | BOOL needs_quoting(register CHAR * f)
|
---|
[103] | 838 | {
|
---|
[2] | 839 | register CHAR *p = " &|<>";
|
---|
| 840 |
|
---|
[551] | 841 | while (*p) {
|
---|
| 842 | if (strchr(f, *p))
|
---|
[2] | 843 | return TRUE;
|
---|
| 844 | p++;
|
---|
| 845 | }
|
---|
| 846 | return FALSE;
|
---|
| 847 | }
|
---|
| 848 |
|
---|
[551] | 849 | BOOL IsBinary(register CHAR * str, ULONG len)
|
---|
[103] | 850 | {
|
---|
[2] | 851 | register ULONG x = 0L;
|
---|
| 852 |
|
---|
[551] | 853 | if (str) {
|
---|
| 854 | while (x < len) {
|
---|
| 855 | if (str[x] < ' ' && str[x] != '\r' && str[x] != '\n' && str[x] != '\t'
|
---|
| 856 | && str[x] != '\x1b' && str[x] != '\x1a' && str[x] != '\07'
|
---|
| 857 | && str[x] != '\x0c')
|
---|
[103] | 858 | return TRUE;
|
---|
[2] | 859 | x++;
|
---|
| 860 | }
|
---|
| 861 | }
|
---|
| 862 | return FALSE;
|
---|
| 863 | }
|
---|
| 864 |
|
---|
[551] | 865 | BOOL TestBinary(CHAR * filename)
|
---|
[103] | 866 | {
|
---|
[551] | 867 | HFILE handle;
|
---|
| 868 | ULONG ulAction;
|
---|
| 869 | ULONG len;
|
---|
| 870 | APIRET rc;
|
---|
| 871 | CHAR buff[512];
|
---|
[2] | 872 |
|
---|
[551] | 873 | if (filename) {
|
---|
| 874 | if (!DosOpen(filename, &handle, &ulAction, 0L, 0L,
|
---|
| 875 | OPEN_ACTION_FAIL_IF_NEW | OPEN_ACTION_OPEN_IF_EXISTS,
|
---|
| 876 | OPEN_FLAGS_FAIL_ON_ERROR | OPEN_FLAGS_NOINHERIT |
|
---|
| 877 | OPEN_FLAGS_SEQUENTIAL | OPEN_SHARE_DENYNONE |
|
---|
| 878 | OPEN_ACCESS_READONLY, 0L)) {
|
---|
[2] | 879 | len = 512;
|
---|
[551] | 880 | rc = DosRead(handle, buff, len, &len);
|
---|
[2] | 881 | DosClose(handle);
|
---|
[551] | 882 | if (!rc && len)
|
---|
| 883 | return IsBinary(buff, len);
|
---|
[2] | 884 | }
|
---|
| 885 | }
|
---|
| 886 | return FALSE;
|
---|
| 887 | }
|
---|
| 888 |
|
---|
[551] | 889 | char *IsVowel(char a)
|
---|
[103] | 890 | {
|
---|
[551] | 891 | return (strchr("aeiouAEIOU", a) != NULL) ? "n" : NullStr;
|
---|
[2] | 892 | }
|
---|
| 893 |
|
---|
[551] | 894 | VOID GetDesktopName(CHAR * objectpath, ULONG size)
|
---|
[103] | 895 | {
|
---|
[551] | 896 | PFN WQDPath;
|
---|
[2] | 897 | HMODULE hmod = 0;
|
---|
[551] | 898 | APIRET rc;
|
---|
| 899 | ULONG startdrive = 3L;
|
---|
| 900 | CHAR objerr[CCHMAXPATH];
|
---|
[2] | 901 |
|
---|
[328] | 902 | if (!objectpath) {
|
---|
| 903 | Runtime_Error(pszSrcFile, __LINE__, "null pointer");
|
---|
[2] | 904 | return;
|
---|
[328] | 905 | }
|
---|
[2] | 906 | *objectpath = 0;
|
---|
[328] | 907 | if (OS2ver[0] > 20 || (OS2ver[0] == 20 && OS2ver[1] >= 30)) {
|
---|
[2] | 908 | /*
|
---|
| 909 | * if running under warp, we can get the desktop name
|
---|
| 910 | * this way...
|
---|
| 911 | */
|
---|
[551] | 912 | rc = DosLoadModule(objerr, sizeof(objerr), "PMWP", &hmod);
|
---|
| 913 | if (!rc) {
|
---|
| 914 | rc = DosQueryProcAddr(hmod, 262, NULL, &WQDPath);
|
---|
| 915 | if (!rc)
|
---|
| 916 | WQDPath(objectpath, size);
|
---|
[2] | 917 | DosFreeModule(hmod);
|
---|
| 918 | }
|
---|
| 919 | }
|
---|
[328] | 920 | if (!*objectpath) {
|
---|
| 921 | // Fall back to INI content
|
---|
| 922 | if (!PrfQueryProfileString(HINI_SYSTEMPROFILE,
|
---|
| 923 | "FolderWorkareaRunningObjects",
|
---|
| 924 | NULL,
|
---|
| 925 | "\0",
|
---|
[551] | 926 | (PVOID) objectpath, sizeof(objectpath))) {
|
---|
| 927 | Win_Error(HWND_DESKTOP, HWND_DESKTOP, pszSrcFile, __LINE__,
|
---|
| 928 | "PrfQueryProfileString");
|
---|
[2] | 929 | *objectpath = 0;
|
---|
[328] | 930 | }
|
---|
| 931 | else if (!*objectpath || IsFile(objectpath)) {
|
---|
| 932 | Runtime_Error(pszSrcFile, __LINE__, "bad FolderWorkareaRunningObjects");
|
---|
| 933 | *objectpath = 0;
|
---|
| 934 | }
|
---|
| 935 | if (!*objectpath) {
|
---|
[552] | 936 | // Fall back
|
---|
[2] | 937 | DosError(FERR_DISABLEHARDERR);
|
---|
[551] | 938 | DosQuerySysInfo(QSV_BOOT_DRIVE, QSV_BOOT_DRIVE,
|
---|
| 939 | (PVOID) & startdrive, (ULONG) sizeof(ULONG));
|
---|
[552] | 940 | sprintf(objectpath, GetPString(IDS_PATHTODESKTOP), ((CHAR) startdrive) + '@');
|
---|
[2] | 941 | }
|
---|
| 942 | }
|
---|
| 943 | }
|
---|