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