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