| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: filldir.c 1402 2009-03-14 17:17:59Z gyoung $
|
|---|
| 5 |
|
|---|
| 6 | Fill Directory Tree Containers
|
|---|
| 7 |
|
|---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
|---|
| 9 | Copyright (c) 2001, 2008 Steven H. Levine
|
|---|
| 10 |
|
|---|
| 11 | 10 Jan 04 SHL ProcessDirectory: avoid most large drive failures
|
|---|
| 12 | 24 May 05 SHL Rework Win_Error usage
|
|---|
| 13 | 24 May 05 SHL Rework for CNRITEM.szSubject
|
|---|
| 14 | 25 May 05 SHL Rework for ULONGLONG
|
|---|
| 15 | 25 May 05 SHL Rework FillInRecordFromFFB
|
|---|
| 16 | 25 May 05 SHL Rework FillTreeCnr
|
|---|
| 17 | 28 May 05 SHL Drop stale debug code
|
|---|
| 18 | 05 Jun 05 SHL Comments
|
|---|
| 19 | 09 Jun 05 SHL Rework WinLoadFileIcon enables
|
|---|
| 20 | 09 Jun 05 SHL Rework IDFile
|
|---|
| 21 | 13 Aug 05 SHL Renames
|
|---|
| 22 | 24 Oct 05 SHL FillInRecordFromFFB: correct longname display enable
|
|---|
| 23 | 24 Oct 05 SHL FillInRecordFromFSA: correct longname display enable
|
|---|
| 24 | 24 Oct 05 SHL Drop obsolete code
|
|---|
| 25 | 22 Jul 06 SHL Check more run time errors
|
|---|
| 26 | 20 Oct 06 SHL Sync . .. check code
|
|---|
| 27 | 22 Oct 06 GKY Add NDFS32 support
|
|---|
| 28 | 17 Feb 07 GKY Additional archive and image file tyoes identifed by extension
|
|---|
| 29 | 17 Feb 07 GKY Add more drive types
|
|---|
| 30 | 09 Mar 07 GKY Use SelectDriveIcon
|
|---|
| 31 | 20 Mar 07 GKY Increase extention check to 4 letters for icon selections
|
|---|
| 32 | 23 Jun 07 GKY Fixed ram disk without a directory not appearing on states drive list
|
|---|
| 33 | 23 Jul 07 SHL Sync with CNRITEM updates (ticket#24)
|
|---|
| 34 | 29 Jul 07 SHL Add CNRITEM free and remove support (ticket#24)
|
|---|
| 35 | 02 Aug 07 SHL Add FileAttrToString
|
|---|
| 36 | 03 Aug 07 GKY Enlarged and made setable everywhere Findbuf (speed file loading)
|
|---|
| 37 | 04 Aug 07 SHL Update #pragma alloc_test for new functions
|
|---|
| 38 | 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
|
|---|
| 39 | 13 Aug 07 SHL Sync code with other FilesToGet usage and optimize
|
|---|
| 40 | 13 Aug 07 SHL Move #pragma alloc_text to end for OpenWatcom compat
|
|---|
| 41 | 04 Nov 07 GKY Use commaFmtULL to display large file sizes
|
|---|
| 42 | 29 Feb 08 GKY Use xfree where appropriate
|
|---|
| 43 | 07 Jul 08 SHL Use NULL rather than NullStr in FreeCnrItemData
|
|---|
| 44 | 16 JUL 08 GKY Use TMP directory for temp files
|
|---|
| 45 | 20 Jul 08 JBS Ticket 114: Support user-selectable env. strings in Tree container.
|
|---|
| 46 | 21 Jul 08 JBS Ticket 114: Change env var separator from blank to semicolon
|
|---|
| 47 | 02 Aug 08 GKY Remove redundant strcpys from inner loop
|
|---|
| 48 | 23 Aug 08 GKY Free pszDisplayName when appropriate
|
|---|
| 49 | 01 Sep 08 GKY Updated FreeCnrItemData to prevent trap in strrchr if pci->pszFileName is NULL.
|
|---|
| 50 | 05 Sep 08 SHL Correct FreeCnrItemData pszDisplayName pointer overlap check
|
|---|
| 51 | 08 Sep 08 SHL Remove extra pszLongName logic in FreeCnrItemData
|
|---|
| 52 | 18 Oct 08 GKY Scan drives in 4 passes (local, virtual, remote, flagged slow) to speed tree scans
|
|---|
| 53 | 19 Nov 08 SHL Correct and sanitize 4 pass scan logic
|
|---|
| 54 | 21 Nov 08 SHL FillTreeCnr: ensure any unchecked drives checked in pass 4
|
|---|
| 55 | 24 Nov 08 GKY Add StubyScanThread to treecnr scan/rescan drives all on separate threads
|
|---|
| 56 | 24 Nov 08 GKY Replace 4 pass drive scan code with StubyScanThread multithread scan
|
|---|
| 57 | 28 Nov 08 SHL FreeCnrItemData: optimize and always NULL pointers
|
|---|
| 58 | 28 Nov 08 SHL StubbyScanThread: add else lost in translation
|
|---|
| 59 | 30 Nov 08 SHL StubbyScanThread: restore else - we want all drives listed
|
|---|
| 60 | 30 Nov 08 SHL FreeCnrItemData: report double free with Runtime_Error
|
|---|
| 61 | 04 Dec 08 GKY Use event semaphore to prevent scan of "last" directory container prior to
|
|---|
| 62 | tree scan completion; prevents duplicate directory names in tree.
|
|---|
| 63 | 10 Dec 08 SHL Integrate exception handler support
|
|---|
| 64 | 25 Dec 08 GKY Add code to allow write verify to be turned off on a per drive basis
|
|---|
| 65 | 25 Dec 08 GKY Add ProcessDirectoryThread to allow optional recursive drive scan at startup.
|
|---|
| 66 | 07 Feb 09 GKY Eliminate Win_Error2 by moving function names to PCSZs used in Win_Error
|
|---|
| 67 | 08 Mar 09 GKY Renamed commafmt.h i18nutil.h
|
|---|
| 68 | 08 Mar 09 GKY Additional strings move to PCSZs
|
|---|
| 69 | 08 Mar 09 GKY Removed variable aurguments from docopyf and unlinkf (not used)
|
|---|
| 70 | 14 Mar 09 GKY Prevent execution of UM_SHOWME while drive scan is occuring
|
|---|
| 71 |
|
|---|
| 72 | ***********************************************************************/
|
|---|
| 73 |
|
|---|
| 74 | #include <stdlib.h>
|
|---|
| 75 | #include <string.h>
|
|---|
| 76 | #include <malloc.h> // _msize _heapchk
|
|---|
| 77 | #include <ctype.h>
|
|---|
| 78 | // #include <process.h> // _beginthread
|
|---|
| 79 |
|
|---|
| 80 | #define INCL_DOS
|
|---|
| 81 | #define INCL_WIN
|
|---|
| 82 | #define INCL_DOSERRORS
|
|---|
| 83 | #define INCL_LONGLONG
|
|---|
| 84 |
|
|---|
| 85 | #include "fm3dll.h"
|
|---|
| 86 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
|---|
| 87 | #include "draglist.h" // Data declaration(s)
|
|---|
| 88 | #include "treecnr.h" // Data declaration(s)
|
|---|
| 89 | #include "info.h" // Data declaration(s)
|
|---|
| 90 | #include "newview.h" // Data declaration(s)
|
|---|
| 91 | #include "fm3str.h"
|
|---|
| 92 | #include "filldir.h"
|
|---|
| 93 | #include "errutil.h" // Dos_Error...
|
|---|
| 94 | #include "strutil.h" // GetPString
|
|---|
| 95 | #include "misc.h" // GetTidForWindow
|
|---|
| 96 | #include "fortify.h" // 06 May 08 SHL
|
|---|
| 97 | #include "notebook.h" // INI file fields
|
|---|
| 98 | #include "flesh.h" // FleshEnv, Stubby
|
|---|
| 99 | #include "update.h" // SelectDriveIcon
|
|---|
| 100 | #include "valid.h" // CheckDrive
|
|---|
| 101 | #include "filter.h" // Filter
|
|---|
| 102 | #include "subj.h" // Subject
|
|---|
| 103 | #include "copyf.h" // unlinkf
|
|---|
| 104 | #include "literal.h" // wildcard
|
|---|
| 105 | #include "i18nutil.h" // CommaFmtULL
|
|---|
| 106 | #include "wrappers.h" // xDosFindNext
|
|---|
| 107 | #include "init.h" // GetTidForWindow
|
|---|
| 108 | #include "common.h" // IncrThreadUsage
|
|---|
| 109 | #include "excputil.h" // xbeginthread
|
|---|
| 110 |
|
|---|
| 111 | VOID StubbyScanThread(VOID * arg);
|
|---|
| 112 |
|
|---|
| 113 | // Data definitions
|
|---|
| 114 | static PSZ pszSrcFile = __FILE__;
|
|---|
| 115 | static BOOL fFirstTime;
|
|---|
| 116 |
|
|---|
| 117 | #pragma data_seg(GLOBAL1)
|
|---|
| 118 | HPOINTER hptrEnv;
|
|---|
| 119 | HPOINTER hptrHidden;
|
|---|
| 120 | HPOINTER hptrReadonly;
|
|---|
| 121 | HPOINTER hptrSystem;
|
|---|
| 122 |
|
|---|
| 123 | #pragma data_seg(GLOBAL2)
|
|---|
| 124 | PCSZ FM3Tools = "<FM3_Tools>";
|
|---|
| 125 | PCSZ WPProgram = "WPProgram";
|
|---|
| 126 | volatile INT StubbyScanCount;
|
|---|
| 127 | volatile INT ProcessDirCount;
|
|---|
| 128 |
|
|---|
| 129 | typedef struct {
|
|---|
| 130 | PCNRITEM pci;
|
|---|
| 131 | HWND hwndCnr; // hwnd you want the message posted to
|
|---|
| 132 | HWND hwndDrivesList;
|
|---|
| 133 | BOOL RamDrive;
|
|---|
| 134 | }
|
|---|
| 135 | STUBBYSCAN;
|
|---|
| 136 |
|
|---|
| 137 | /**
|
|---|
| 138 | * Return display string given standard file attribute mask
|
|---|
| 139 | * @param fileAttr attribute mask in FILEFINDBUF format
|
|---|
| 140 | * @return fixed length string for display
|
|---|
| 141 | */
|
|---|
| 142 |
|
|---|
| 143 | const PSZ FileAttrToString(ULONG fileAttr)
|
|---|
| 144 | {
|
|---|
| 145 | // From os2win.h
|
|---|
| 146 | // FILE_ATTRIBUTE_READONLY 0x00000001
|
|---|
| 147 | // FILE_ATTRIBUTE_HIDDEN 0x00000002
|
|---|
| 148 | // FILE_ATTRIBUTE_SYSTEM 0x00000004
|
|---|
| 149 | // 0x00000008
|
|---|
| 150 | // FILE_ATTRIBUTE_DIRECTORY 0x00000010
|
|---|
| 151 | // FILE_ATTRIBUTE_ARCHIVE 0x00000020
|
|---|
| 152 |
|
|---|
| 153 | static CHAR *apszAttrString[] = {
|
|---|
| 154 | // RHSDA
|
|---|
| 155 | "-----",
|
|---|
| 156 | "R----",
|
|---|
| 157 | "-H---",
|
|---|
| 158 | "RH---",
|
|---|
| 159 | "--S--",
|
|---|
| 160 | "R-S--",
|
|---|
| 161 | "-HS--",
|
|---|
| 162 | "RHS--",
|
|---|
| 163 | "---D-",
|
|---|
| 164 | "R--D-",
|
|---|
| 165 | "-H-D-",
|
|---|
| 166 | "RH-D-",
|
|---|
| 167 | "--SD-",
|
|---|
| 168 | "R-SD-",
|
|---|
| 169 | "-HSD-",
|
|---|
| 170 | "RHSD-",
|
|---|
| 171 | "----A",
|
|---|
| 172 | "R---A",
|
|---|
| 173 | "-H--A",
|
|---|
| 174 | "RH--A",
|
|---|
| 175 | "--S-A",
|
|---|
| 176 | "R-S-A",
|
|---|
| 177 | "-HS-A",
|
|---|
| 178 | "RHS-A",
|
|---|
| 179 | "---DA",
|
|---|
| 180 | "R--DA",
|
|---|
| 181 | "-H-DA",
|
|---|
| 182 | "RH-DA",
|
|---|
| 183 | "--SDA",
|
|---|
| 184 | "R-SDA",
|
|---|
| 185 | "-HSDA",
|
|---|
| 186 | "RHSDA"
|
|---|
| 187 | };
|
|---|
| 188 |
|
|---|
| 189 | fileAttr = ((fileAttr & 0x30) >> 1) | (fileAttr & 7); // Drop don't care bit from index
|
|---|
| 190 |
|
|---|
| 191 | return apszAttrString[fileAttr];
|
|---|
| 192 |
|
|---|
| 193 | }
|
|---|
| 194 |
|
|---|
| 195 | VOID StubbyScanThread(VOID * arg)
|
|---|
| 196 | {
|
|---|
| 197 | STUBBYSCAN *StubbyScan;
|
|---|
| 198 | HAB thab;
|
|---|
| 199 | HMQ hmq = (HMQ) 0;
|
|---|
| 200 | BOOL ret;
|
|---|
| 201 |
|
|---|
| 202 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 203 |
|
|---|
| 204 | # ifdef FORTIFY
|
|---|
| 205 | Fortify_EnterScope();
|
|---|
| 206 | # endif
|
|---|
| 207 |
|
|---|
| 208 | StubbyScan = (STUBBYSCAN *)arg;
|
|---|
| 209 | if (StubbyScan && StubbyScan->pci && StubbyScan->pci->pszFileName && StubbyScan->hwndCnr) {
|
|---|
| 210 | thab = WinInitialize(0);
|
|---|
| 211 | if (thab) {
|
|---|
| 212 | hmq = WinCreateMsgQueue(thab, 0);
|
|---|
| 213 | if (hmq) {
|
|---|
| 214 | StubbyScanCount++;
|
|---|
| 215 | IncrThreadUsage();
|
|---|
| 216 | priority_normal();
|
|---|
| 217 | ret = Stubby(StubbyScan->hwndCnr, StubbyScan->pci);
|
|---|
| 218 | //DbgMsg(pszSrcFile, __LINE__, "Stubby %i ", ret);
|
|---|
| 219 | if (ret == 1) {
|
|---|
| 220 | if (WinIsWindow((HAB)0, StubbyScan->hwndCnr)) {
|
|---|
| 221 | WinSendMsg(StubbyScan->hwndCnr,
|
|---|
| 222 | CM_INVALIDATERECORD,
|
|---|
| 223 | MPFROMP(&StubbyScan->pci),
|
|---|
| 224 | MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
|
|---|
| 225 | if (fRScanLocal) {
|
|---|
| 226 | if (!(driveflags[toupper(*StubbyScan->pci->pszFileName) - 'A'] &
|
|---|
| 227 | ((fRScanNoWrite ? 0 : DRIVE_NOTWRITEABLE) |
|
|---|
| 228 | (fRScanRemote ? 0 : DRIVE_REMOTE) |
|
|---|
| 229 | (fRScanSlow ? 0 : DRIVE_SLOW) |
|
|---|
| 230 | (fRScanVirtual ? 0 : DRIVE_VIRTUAL)))
|
|---|
| 231 | && fInitialDriveScan) {
|
|---|
| 232 | WinSendMsg(StubbyScan->hwndCnr, CM_EXPANDTREE, MPFROMP(StubbyScan->pci), MPVOID);
|
|---|
| 233 | //DbgMsg(pszSrcFile, __LINE__, "expanded %x %s", StubbyScan->hwndCnr, StubbyScan->pci->pszFileName);
|
|---|
| 234 | WinSendMsg(StubbyScan->hwndCnr, CM_COLLAPSETREE, MPFROMP(StubbyScan->pci), MPVOID);
|
|---|
| 235 | }
|
|---|
| 236 | }
|
|---|
| 237 | else if ((fRScanRemote && (driveflags[toupper(*StubbyScan->pci->pszFileName) - 'A'] &
|
|---|
| 238 | DRIVE_REMOTE)) ||
|
|---|
| 239 | (fRScanVirtual && (driveflags[toupper(*StubbyScan->pci->pszFileName) - 'A'] &
|
|---|
| 240 | DRIVE_VIRTUAL)) && fInitialDriveScan) {
|
|---|
| 241 | if (!(driveflags[toupper(*StubbyScan->pci->pszFileName) - 'A'] &
|
|---|
| 242 | ((fRScanNoWrite ? NULL : DRIVE_NOTWRITEABLE) |
|
|---|
| 243 | (fRScanSlow ? NULL : DRIVE_SLOW)))) {
|
|---|
| 244 | WinSendMsg(StubbyScan->hwndCnr, CM_EXPANDTREE, MPFROMP(StubbyScan->pci), MPVOID);
|
|---|
| 245 | //DbgMsg(pszSrcFile, __LINE__, "expanded %x %s", StubbyScan->hwndCnr, StubbyScan->pci->pszFileName);
|
|---|
| 246 | WinSendMsg(StubbyScan->hwndCnr, CM_COLLAPSETREE, MPFROMP(StubbyScan->pci), MPVOID);
|
|---|
| 247 | }
|
|---|
| 248 | }
|
|---|
| 249 | }
|
|---|
| 250 | }
|
|---|
| 251 | if (WinIsWindow((HAB)0, StubbyScan->hwndDrivesList)) {
|
|---|
| 252 | WinSendMsg(StubbyScan->hwndDrivesList,
|
|---|
| 253 | LM_INSERTITEM,
|
|---|
| 254 | MPFROM2SHORT(LIT_SORTASCENDING, 0),
|
|---|
| 255 | MPFROMP(StubbyScan->pci->pszFileName));
|
|---|
| 256 | }
|
|---|
| 257 | StubbyScanCount--;
|
|---|
| 258 | /* if (StubbyScanCount == 0) {
|
|---|
| 259 | if (fInitialDriveScan) {
|
|---|
| 260 | WinShowWindow(StubbyScan->hwndCnr, TRUE);
|
|---|
| 261 | WinShowWindow(StubbyScan->hwndDrivesList, TRUE);
|
|---|
| 262 | }
|
|---|
| 263 | fInitialDriveScan = FALSE;
|
|---|
| 264 | }*/
|
|---|
| 265 | WinDestroyMsgQueue(hmq);
|
|---|
| 266 | }
|
|---|
| 267 | DecrThreadUsage();
|
|---|
| 268 | WinTerminate(thab);
|
|---|
| 269 | }
|
|---|
| 270 | free(StubbyScan);
|
|---|
| 271 | } // if StubbyScan
|
|---|
| 272 | # ifdef FORTIFY
|
|---|
| 273 | Fortify_LeaveScope();
|
|---|
| 274 | # endif
|
|---|
| 275 |
|
|---|
| 276 | // _endthread(); // 10 Dec 08 SHL
|
|---|
| 277 | }
|
|---|
| 278 |
|
|---|
| 279 | VOID ProcessDirectoryThread(VOID * arg)
|
|---|
| 280 | {
|
|---|
| 281 | PROCESSDIR *ProcessDir;
|
|---|
| 282 | HAB thab;
|
|---|
| 283 | HMQ hmq = (HMQ) 0;
|
|---|
| 284 | //BOOL ret;
|
|---|
| 285 |
|
|---|
| 286 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 287 |
|
|---|
| 288 | # ifdef FORTIFY
|
|---|
| 289 | Fortify_EnterScope();
|
|---|
| 290 | # endif
|
|---|
| 291 |
|
|---|
| 292 | ProcessDir = (PROCESSDIR *)arg;
|
|---|
| 293 | if (ProcessDir && ProcessDir->pciParent && ProcessDir->pciParent->pszFileName && ProcessDir->hwndCnr) {
|
|---|
| 294 | thab = WinInitialize(0);
|
|---|
| 295 | if (thab) {
|
|---|
| 296 | hmq = WinCreateMsgQueue(thab, 0);
|
|---|
| 297 | if (hmq) {
|
|---|
| 298 | ProcessDirCount ++;
|
|---|
| 299 | IncrThreadUsage();
|
|---|
| 300 | priority_normal();
|
|---|
| 301 | ProcessDirectory(ProcessDir->hwndCnr,
|
|---|
| 302 | ProcessDir->pciParent,
|
|---|
| 303 | ProcessDir->szDirBase,
|
|---|
| 304 | ProcessDir->filestoo,
|
|---|
| 305 | ProcessDir->recurse,
|
|---|
| 306 | ProcessDir->partial,
|
|---|
| 307 | ProcessDir->stopflag,
|
|---|
| 308 | ProcessDir->dcd, // Optional
|
|---|
| 309 | ProcessDir->pulTotalFiles, // Optional
|
|---|
| 310 | ProcessDir->pullTotalBytes); // Optional
|
|---|
| 311 | ProcessDirCount --;
|
|---|
| 312 | WinDestroyMsgQueue(hmq);
|
|---|
| 313 | }
|
|---|
| 314 | DecrThreadUsage();
|
|---|
| 315 | WinTerminate(thab);
|
|---|
| 316 | }
|
|---|
| 317 | free(ProcessDir);
|
|---|
| 318 | } // if ProcessDir
|
|---|
| 319 | # ifdef FORTIFY
|
|---|
| 320 | Fortify_LeaveScope();
|
|---|
| 321 | # endif
|
|---|
| 322 |
|
|---|
| 323 | // _endthread(); // 10 Dec 08 SHL
|
|---|
| 324 | }
|
|---|
| 325 |
|
|---|
| 326 | static HPOINTER IDFile(PSZ p)
|
|---|
| 327 | {
|
|---|
| 328 | HPOINTER hptr;
|
|---|
| 329 | ULONG cmp;
|
|---|
| 330 | CHAR cmps[5];
|
|---|
| 331 |
|
|---|
| 332 | p = strrchr(p, '.');
|
|---|
| 333 | if (p && !p[5]) {
|
|---|
| 334 | cmps[0] = '.';
|
|---|
| 335 | cmps[1] = toupper(p[1]);
|
|---|
| 336 | cmps[2] = toupper(p[2]);
|
|---|
| 337 | cmps[3] = toupper(p[3]);
|
|---|
| 338 | cmps[4] = toupper(p[4]);
|
|---|
| 339 |
|
|---|
| 340 | cmp = *(ULONG *) cmps;
|
|---|
| 341 |
|
|---|
| 342 | if (cmp == *(ULONG *) PCSZ_DOTEXE || cmp == *(ULONG *) PCSZ_DOTCMD ||
|
|---|
| 343 | cmp == *(ULONG *) PCSZ_DOTBAT || cmp == *(ULONG *) PCSZ_DOTCOM ||
|
|---|
| 344 | cmp == *(ULONG *) PCSZ_DOTBTM)
|
|---|
| 345 | hptr = hptrApp;
|
|---|
| 346 | else if (cmp == *(ULONG *) ".ZIP" || cmp == *(ULONG *) ".LZH" ||
|
|---|
| 347 | cmp == *(ULONG *) ".ARJ" || cmp == *(ULONG *) ".ARC" ||
|
|---|
| 348 | cmp == *(ULONG *) ".ZOO" || cmp == *(ULONG *) ".RAR" ||
|
|---|
| 349 | cmp == *(ULONG *) ".TAR" || cmp == *(ULONG *) ".TGZ" ||
|
|---|
| 350 | cmp == *(ULONG *) ".GZ" || cmp == *(ULONG *) ".Z" ||
|
|---|
| 351 | cmp == *(ULONG *) ".CAB" || cmp == *(ULONG *) ".BZ2")
|
|---|
| 352 | hptr = hptrArc;
|
|---|
| 353 | else if (cmp == *(ULONG *) PCSZ_DOTBMP ||
|
|---|
| 354 | cmp == *(ULONG *) PCSZ_DOTICO ||
|
|---|
| 355 | cmp == *(ULONG *) PCSZ_DOTPTR ||
|
|---|
| 356 | cmp == *(ULONG *) PCSZ_DOTJPEG ||
|
|---|
| 357 | cmp == *(ULONG *) PCSZ_DOTJPG ||
|
|---|
| 358 | cmp == *(ULONG *) ".GIF" ||
|
|---|
| 359 | cmp == *(ULONG *) ".TIF" || cmp == *(ULONG *) ".PCX" ||
|
|---|
| 360 | cmp == *(ULONG *) ".TGA" || cmp == *(ULONG *) ".XBM" ||
|
|---|
| 361 | cmp == *(ULONG *) ".PNG" || cmp == *(ULONG *) ".PSD" ||
|
|---|
| 362 | cmp == *(ULONG *) ".LGO" || cmp == *(ULONG *) ".EPS" ||
|
|---|
| 363 | cmp == *(ULONG *) ".RLE" || cmp == *(ULONG *) ".RAS" ||
|
|---|
| 364 | cmp == *(ULONG *) ".PLC" || cmp == *(ULONG *) ".MSP" ||
|
|---|
| 365 | cmp == *(ULONG *) ".IFF" || cmp == *(ULONG *) ".FIT" ||
|
|---|
| 366 | cmp == *(ULONG *) ".DCX" || cmp == *(ULONG *) ".MAC" ||
|
|---|
| 367 | cmp == *(ULONG *) ".SFF" || cmp == *(ULONG *) ".SGI" ||
|
|---|
| 368 | cmp == *(ULONG *) ".XWD" || cmp == *(ULONG *) ".XPM" ||
|
|---|
| 369 | cmp == *(ULONG *) ".WPG" || cmp == *(ULONG *) ".CUR" ||
|
|---|
| 370 | cmp == *(ULONG *) ".PNM" || cmp == *(ULONG *) ".PPM" ||
|
|---|
| 371 | cmp == *(ULONG *) ".PGM" || cmp == *(ULONG *) ".PBM")
|
|---|
| 372 | hptr = hptrArt;
|
|---|
| 373 | else
|
|---|
| 374 | hptr = (HPOINTER) 0;
|
|---|
| 375 | }
|
|---|
| 376 | else
|
|---|
| 377 | hptr = (HPOINTER) 0;
|
|---|
| 378 |
|
|---|
| 379 | return hptr;
|
|---|
| 380 | }
|
|---|
| 381 |
|
|---|
| 382 | static BOOL IsDefaultIcon(HPOINTER hptr)
|
|---|
| 383 | {
|
|---|
| 384 | HPOINTER hptr2;
|
|---|
| 385 | HPOINTER hptr3;
|
|---|
| 386 | UINT u;
|
|---|
| 387 |
|
|---|
| 388 | static HPOINTER hptrPMFile;
|
|---|
| 389 | static HPOINTER hptrWPSFile;
|
|---|
| 390 |
|
|---|
| 391 | if (!hptrPMFile) {
|
|---|
| 392 | hptrPMFile = WinQuerySysPointer(HWND_DESKTOP, SPTR_FILE, FALSE);
|
|---|
| 393 | }
|
|---|
| 394 |
|
|---|
| 395 | // try to guess WPS default file icon
|
|---|
| 396 | hptr2 = (HPOINTER) 0;
|
|---|
| 397 | for (u = 0; !hptrWPSFile && u < 10; u++) {
|
|---|
| 398 | char szFileName[CCHMAXPATH];
|
|---|
| 399 | char *psz;
|
|---|
| 400 |
|
|---|
| 401 | if (pTmpDir) {
|
|---|
| 402 | psz = pTmpDir;
|
|---|
| 403 | strcpy(szFileName, psz);
|
|---|
| 404 | psz = szFileName + strlen(szFileName) - 1;
|
|---|
| 405 | if (*psz != '\\') {
|
|---|
| 406 | psz++;
|
|---|
| 407 | *psz++ = '\\';
|
|---|
| 408 | }
|
|---|
| 409 | }
|
|---|
| 410 | else
|
|---|
| 411 | psz = szFileName;
|
|---|
| 412 |
|
|---|
| 413 | sprintf(psz, "%08x.%03x", rand() & 0xffffffff, rand() & 0xfff);
|
|---|
| 414 | if (IsFile(szFileName) != 1) {
|
|---|
| 415 | FILE *fp = fopen(szFileName, "w");
|
|---|
| 416 |
|
|---|
| 417 | if (fp) {
|
|---|
| 418 | fclose(fp);
|
|---|
| 419 | hptr3 = WinLoadFileIcon(szFileName, FALSE);
|
|---|
| 420 | unlinkf(szFileName);
|
|---|
| 421 | if (!hptr2)
|
|---|
| 422 | hptr2 = hptr3;
|
|---|
| 423 | else if (hptr3 == hptr3) {
|
|---|
| 424 | hptrWPSFile = hptr3; // Got same icon twice
|
|---|
| 425 | break;
|
|---|
| 426 | }
|
|---|
| 427 | }
|
|---|
| 428 | }
|
|---|
| 429 | DosSleep(rand() % 100);
|
|---|
| 430 |
|
|---|
| 431 | } // for
|
|---|
| 432 |
|
|---|
| 433 | return hptr == hptrPMFile || hptr == hptrWPSFile;
|
|---|
| 434 |
|
|---|
| 435 | } // IsDefaultIcon
|
|---|
| 436 |
|
|---|
| 437 | ULONGLONG FillInRecordFromFFB(HWND hwndCnr,
|
|---|
| 438 | PCNRITEM pci,
|
|---|
| 439 | const PSZ pszDirectory,
|
|---|
| 440 | const PFILEFINDBUF4L pffb,
|
|---|
| 441 | const BOOL partial,
|
|---|
| 442 | DIRCNRDATA *dcd)
|
|---|
| 443 | {
|
|---|
| 444 | // fill in a container record from a FILEFINDBUF4L structure
|
|---|
| 445 |
|
|---|
| 446 | CHAR *p;
|
|---|
| 447 | HPOINTER hptr;
|
|---|
| 448 | ULONG flags;
|
|---|
| 449 |
|
|---|
| 450 | pci->hwndCnr = hwndCnr;
|
|---|
| 451 |
|
|---|
| 452 | /* note that we cheat below, and accept the full pathname in pszDirectory
|
|---|
| 453 | if !*pffb->achName. This speeds up and simplifies processing elsewhere
|
|---|
| 454 | (like in update.c)
|
|---|
| 455 | */
|
|---|
| 456 | if (!*pffb->achName) {
|
|---|
| 457 | pci->pszFileName = xstrdup(pszDirectory, pszSrcFile, __LINE__);
|
|---|
| 458 | //strcpy(pci->pszFileName, pszDirectory);
|
|---|
| 459 | }
|
|---|
| 460 | else {
|
|---|
| 461 | INT c = strlen(pszDirectory);
|
|---|
| 462 | INT c2 = pffb->cchName + 1;
|
|---|
| 463 | if (pszDirectory[c - 1] != '\\')
|
|---|
| 464 | c2++;
|
|---|
| 465 | pci->pszFileName = xmalloc(c + c2, pszSrcFile, __LINE__);
|
|---|
| 466 | # ifdef FORTIFY
|
|---|
| 467 | {
|
|---|
| 468 | if (dcd->type != TREE_FRAME)
|
|---|
| 469 | Fortify_ChangeScope(pci->pszFileName, -1);
|
|---|
| 470 | else {
|
|---|
| 471 | Fortify_SetOwner(pci->pszFileName, 1);
|
|---|
| 472 | Fortify_SetScope(pci->pszFileName, 2);
|
|---|
| 473 | }
|
|---|
| 474 | }
|
|---|
| 475 | # endif
|
|---|
| 476 | memcpy(pci->pszFileName, pszDirectory, c + 1);
|
|---|
| 477 | p = pci->pszFileName + c - 1;
|
|---|
| 478 | if (*p != '\\') {
|
|---|
| 479 | p++;
|
|---|
| 480 | *p = '\\';
|
|---|
| 481 | }
|
|---|
| 482 | p++;
|
|---|
| 483 | memcpy(p, pffb->achName, pffb->cchName + 1);
|
|---|
| 484 | }
|
|---|
| 485 | flags = driveflags[toupper(*pci->pszFileName) - 'A'];
|
|---|
| 486 | // load the object's Subject, if required
|
|---|
| 487 | // pci->pszSubject = NullStr; dubplicate see below 12-05-08 GKY
|
|---|
| 488 | if (pffb->cbList > 4L &&
|
|---|
| 489 | dcd && fLoadSubject &&
|
|---|
| 490 | (isalpha(*pci->pszFileName) &&
|
|---|
| 491 | !(flags & DRIVE_NOLOADSUBJS)))
|
|---|
| 492 | {
|
|---|
| 493 | APIRET rc;
|
|---|
| 494 | EAOP2 eaop;
|
|---|
| 495 | PGEA2LIST pgealist;
|
|---|
| 496 | PFEA2LIST pfealist;
|
|---|
| 497 | PGEA2 pgea;
|
|---|
| 498 | PFEA2 pfea;
|
|---|
| 499 | CHAR *value;
|
|---|
| 500 |
|
|---|
| 501 | pgealist = xmallocz(sizeof(GEA2LIST) + 32, pszSrcFile, __LINE__);
|
|---|
| 502 | if (pgealist) {
|
|---|
| 503 | pgea = &pgealist->list[0];
|
|---|
| 504 | strcpy(pgea->szName, SUBJECT);
|
|---|
| 505 | pgea->cbName = strlen(pgea->szName);
|
|---|
| 506 | pgea->oNextEntryOffset = 0;
|
|---|
| 507 | pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
|
|---|
| 508 | pfealist = xmallocz(1532, pszSrcFile, __LINE__);
|
|---|
| 509 | if (pfealist) {
|
|---|
| 510 | pfealist->cbList = 1024;
|
|---|
| 511 | eaop.fpGEA2List = pgealist;
|
|---|
| 512 | eaop.fpFEA2List = pfealist;
|
|---|
| 513 | eaop.oError = 0;
|
|---|
| 514 | rc = DosQueryPathInfo(pci->pszFileName, FIL_QUERYEASFROMLIST,
|
|---|
| 515 | (PVOID) & eaop, (ULONG) sizeof(EAOP2));
|
|---|
| 516 | if (!rc) {
|
|---|
| 517 | pfea = &eaop.fpFEA2List->list[0];
|
|---|
| 518 | value = pfea->szName + pfea->cbName + 1;
|
|---|
| 519 | value[pfea->cbValue] = 0;
|
|---|
| 520 | if (*(USHORT *) value == EAT_ASCII)
|
|---|
| 521 | pci->pszSubject = xstrdup(value + (sizeof(USHORT) * 2), pszSrcFile, __LINE__);
|
|---|
| 522 | }
|
|---|
| 523 | free(pfealist);
|
|---|
| 524 | }
|
|---|
| 525 | free(pgealist);
|
|---|
| 526 | }
|
|---|
| 527 | }
|
|---|
| 528 | if (!pci->pszSubject)
|
|---|
| 529 | pci->pszSubject = NullStr;
|
|---|
| 530 |
|
|---|
| 531 | // load the object's longname
|
|---|
| 532 | pci->pszLongName = NULL;
|
|---|
| 533 | if (fLoadLongnames &&
|
|---|
| 534 | dcd &&
|
|---|
| 535 | pffb->cbList > 4L &&
|
|---|
| 536 | isalpha(*pci->pszFileName) &&
|
|---|
| 537 | ~flags & DRIVE_NOLONGNAMES &&
|
|---|
| 538 | ~flags & DRIVE_NOLOADLONGS)
|
|---|
| 539 | {
|
|---|
| 540 | APIRET rc;
|
|---|
| 541 | EAOP2 eaop;
|
|---|
| 542 | PGEA2LIST pgealist;
|
|---|
| 543 | PFEA2LIST pfealist;
|
|---|
| 544 | PGEA2 pgea;
|
|---|
| 545 | PFEA2 pfea;
|
|---|
| 546 | CHAR *value;
|
|---|
| 547 |
|
|---|
| 548 | pgealist = xmallocz(sizeof(GEA2LIST) + 32, pszSrcFile, __LINE__);
|
|---|
| 549 | if (pgealist) {
|
|---|
| 550 | pgea = &pgealist->list[0];
|
|---|
| 551 | strcpy(pgea->szName, LONGNAME);
|
|---|
| 552 | pgea->cbName = strlen(pgea->szName);
|
|---|
| 553 | pgea->oNextEntryOffset = 0;
|
|---|
| 554 | pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
|
|---|
| 555 | pfealist = xmallocz(1532, pszSrcFile, __LINE__);
|
|---|
| 556 | if (pfealist) {
|
|---|
| 557 | pfealist->cbList = 1024;
|
|---|
| 558 | eaop.fpGEA2List = pgealist;
|
|---|
| 559 | eaop.fpFEA2List = pfealist;
|
|---|
| 560 | eaop.oError = 0;
|
|---|
| 561 | rc = DosQueryPathInfo(pci->pszFileName, FIL_QUERYEASFROMLIST,
|
|---|
| 562 | (PVOID) & eaop, (ULONG) sizeof(EAOP2));
|
|---|
| 563 | if (!rc) {
|
|---|
| 564 | pfea = &eaop.fpFEA2List->list[0];
|
|---|
| 565 | value = pfea->szName + pfea->cbName + 1;
|
|---|
| 566 | value[pfea->cbValue] = 0;
|
|---|
| 567 | if (*(USHORT *) value == EAT_ASCII) {
|
|---|
| 568 | pci->pszLongName = xstrdup(value + (sizeof(USHORT) * 2), pszSrcFile, __LINE__);
|
|---|
| 569 | # ifdef FORTIFY
|
|---|
| 570 | {
|
|---|
| 571 | unsigned tid = GetTidForWindow(hwndCnr);
|
|---|
| 572 | if (tid == 1)
|
|---|
| 573 | Fortify_ChangeScope(pci->pszLongName, -1);
|
|---|
| 574 | else
|
|---|
| 575 | Fortify_SetOwner(pci->pszLongName, 1);
|
|---|
| 576 | }
|
|---|
| 577 | # endif
|
|---|
| 578 | }
|
|---|
| 579 | }
|
|---|
| 580 | free(pfealist);
|
|---|
| 581 | }
|
|---|
| 582 | free(pgealist);
|
|---|
| 583 | }
|
|---|
| 584 | }
|
|---|
| 585 | if (!pci->pszLongName)
|
|---|
| 586 | pci->pszLongName = NullStr;
|
|---|
| 587 |
|
|---|
| 588 | // do anything required to case of filename
|
|---|
| 589 | if (fForceUpper)
|
|---|
| 590 | strupr(pci->pszFileName);
|
|---|
| 591 | else if (fForceLower)
|
|---|
| 592 | strlwr(pci->pszFileName);
|
|---|
| 593 |
|
|---|
| 594 | // get an icon to use with it
|
|---|
| 595 | if (pffb->attrFile & FILE_DIRECTORY) {
|
|---|
| 596 | // is directory
|
|---|
| 597 | if (fNoIconsDirs ||
|
|---|
| 598 | (flags & DRIVE_NOLOADICONS) ||
|
|---|
| 599 | !isalpha(*pci->pszFileName)) {
|
|---|
| 600 | hptr = (HPOINTER) 0;
|
|---|
| 601 | }
|
|---|
| 602 | else
|
|---|
| 603 | hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
|
|---|
| 604 | }
|
|---|
| 605 | else {
|
|---|
| 606 | // is file
|
|---|
| 607 | if (fNoIconsFiles ||
|
|---|
| 608 | (flags & DRIVE_NOLOADICONS) ||
|
|---|
| 609 | !isalpha(*pci->pszFileName)) {
|
|---|
| 610 | hptr = (HPOINTER) 0;
|
|---|
| 611 | }
|
|---|
| 612 | else
|
|---|
| 613 | hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
|
|---|
| 614 |
|
|---|
| 615 | if (!hptr || IsDefaultIcon(hptr))
|
|---|
| 616 | hptr = IDFile(pci->pszFileName);
|
|---|
| 617 | }
|
|---|
| 618 |
|
|---|
| 619 | if (!hptr) {
|
|---|
| 620 | hptr = pffb->attrFile & FILE_DIRECTORY ?
|
|---|
| 621 | hptrDir : pffb->attrFile & FILE_SYSTEM ?
|
|---|
| 622 | hptrSystem : pffb->attrFile & FILE_HIDDEN ?
|
|---|
| 623 | hptrHidden : pffb->attrFile & FILE_READONLY ?
|
|---|
| 624 | hptrReadonly : hptrFile;
|
|---|
| 625 | }
|
|---|
| 626 |
|
|---|
| 627 | // Tell container what part of pathname to display
|
|---|
| 628 | if (partial) {
|
|---|
| 629 | p = strrchr(pci->pszFileName, '\\');
|
|---|
| 630 | if (!p) {
|
|---|
| 631 | p = strrchr(pci->pszFileName, ':');
|
|---|
| 632 | if (!p)
|
|---|
| 633 | p = pci->pszFileName;
|
|---|
| 634 | else
|
|---|
| 635 | p++;
|
|---|
| 636 | }
|
|---|
| 637 | else if ((dcd && dcd->type == TREE_FRAME) ||
|
|---|
| 638 | (!(pffb->attrFile & FILE_DIRECTORY) || !*(p + 1))) {
|
|---|
| 639 | p++;
|
|---|
| 640 | }
|
|---|
| 641 | if (!*p)
|
|---|
| 642 | p = pci->pszFileName;
|
|---|
| 643 | }
|
|---|
| 644 | else
|
|---|
| 645 | p = pci->pszFileName;
|
|---|
| 646 | pci->pszDisplayName = p;
|
|---|
| 647 |
|
|---|
| 648 | //comma format the file size for large file support
|
|---|
| 649 | {
|
|---|
| 650 | CHAR szBuf[30];
|
|---|
| 651 | CommaFmtULL(szBuf, sizeof(szBuf), pffb->cbFile, ' ');
|
|---|
| 652 | pci->pszFmtFileSize = xstrdup(szBuf, pszSrcFile, __LINE__);
|
|---|
| 653 | # ifdef FORTIFY
|
|---|
| 654 | {
|
|---|
| 655 | unsigned tid = GetTidForWindow(hwndCnr);
|
|---|
| 656 | if (tid == 1)
|
|---|
| 657 | Fortify_ChangeScope(pci->pszFmtFileSize, -1);
|
|---|
| 658 | else
|
|---|
| 659 | Fortify_SetOwner(pci->pszFmtFileSize, 1);
|
|---|
| 660 | }
|
|---|
| 661 | # endif
|
|---|
| 662 | }
|
|---|
| 663 |
|
|---|
| 664 | // now fill the darned thing in...
|
|---|
| 665 | pci->date.day = pffb->fdateLastWrite.day;
|
|---|
| 666 | pci->date.month = pffb->fdateLastWrite.month;
|
|---|
| 667 | pci->date.year = pffb->fdateLastWrite.year + 1980;
|
|---|
| 668 | pci->time.seconds = pffb->ftimeLastWrite.twosecs * 2;
|
|---|
| 669 | pci->time.minutes = pffb->ftimeLastWrite.minutes;
|
|---|
| 670 | pci->time.hours = pffb->ftimeLastWrite.hours;
|
|---|
| 671 | pci->ladate.day = pffb->fdateLastAccess.day;
|
|---|
| 672 | pci->ladate.month = pffb->fdateLastAccess.month;
|
|---|
| 673 | pci->ladate.year = pffb->fdateLastAccess.year + 1980;
|
|---|
| 674 | pci->latime.seconds = pffb->ftimeLastAccess.twosecs * 2;
|
|---|
| 675 | pci->latime.minutes = pffb->ftimeLastAccess.minutes;
|
|---|
| 676 | pci->latime.hours = pffb->ftimeLastAccess.hours;
|
|---|
| 677 | pci->crdate.day = pffb->fdateCreation.day;
|
|---|
| 678 | pci->crdate.month = pffb->fdateCreation.month;
|
|---|
| 679 | pci->crdate.year = pffb->fdateCreation.year + 1980;
|
|---|
| 680 | pci->crtime.seconds = pffb->ftimeCreation.twosecs * 2;
|
|---|
| 681 | pci->crtime.minutes = pffb->ftimeCreation.minutes;
|
|---|
| 682 | pci->crtime.hours = pffb->ftimeCreation.hours;
|
|---|
| 683 | pci->easize = CBLIST_TO_EASIZE(pffb->cbList);
|
|---|
| 684 | pci->cbFile = pffb->cbFile;
|
|---|
| 685 | pci->attrFile = pffb->attrFile;
|
|---|
| 686 | pci->pszDispAttr = FileAttrToString(pci->attrFile);
|
|---|
| 687 | pci->rc.pszIcon = pci->pszDisplayName;
|
|---|
| 688 | pci->rc.hptrIcon = hptr;
|
|---|
| 689 |
|
|---|
| 690 | // check to see if record should be visible
|
|---|
| 691 | if (dcd && (*dcd->mask.szMask || dcd->mask.antiattr ||
|
|---|
| 692 | ((dcd->mask.attrFile &
|
|---|
| 693 | (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED))
|
|---|
| 694 | !=
|
|---|
| 695 | (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED))))
|
|---|
| 696 | {
|
|---|
| 697 | if (*dcd->mask.szMask || dcd->mask.antiattr) {
|
|---|
| 698 | if (!Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask))
|
|---|
| 699 | pci->rc.flRecordAttr |= CRA_FILTERED;
|
|---|
| 700 | }
|
|---|
| 701 | else if ((!(dcd->mask.attrFile & FILE_HIDDEN) &&
|
|---|
| 702 | (pci->attrFile & FILE_HIDDEN)) ||
|
|---|
| 703 | (!(dcd->mask.attrFile & FILE_SYSTEM) &&
|
|---|
| 704 | (pci->attrFile & FILE_SYSTEM)) ||
|
|---|
| 705 | (!(dcd->mask.attrFile & FILE_READONLY) &&
|
|---|
| 706 | (pci->attrFile & FILE_READONLY)) ||
|
|---|
| 707 | (!(dcd->mask.attrFile & FILE_ARCHIVED) &&
|
|---|
| 708 | (pci->attrFile & FILE_ARCHIVED))) {
|
|---|
| 709 | pci->rc.flRecordAttr |= CRA_FILTERED;
|
|---|
| 710 | }
|
|---|
| 711 | }
|
|---|
| 712 |
|
|---|
| 713 | return pffb->cbFile + pci->easize;
|
|---|
| 714 |
|
|---|
| 715 | } // FillInRecordFromFFB
|
|---|
| 716 |
|
|---|
| 717 | ULONGLONG FillInRecordFromFSA(HWND hwndCnr,
|
|---|
| 718 | PCNRITEM pci,
|
|---|
| 719 | const PSZ pszFileName,
|
|---|
| 720 | const PFILESTATUS4L pfsa4,
|
|---|
| 721 | const BOOL partial,
|
|---|
| 722 | DIRCNRDATA *dcd) // Optional
|
|---|
| 723 | {
|
|---|
| 724 | HPOINTER hptr;
|
|---|
| 725 | CHAR *p;
|
|---|
| 726 | ULONG flags;
|
|---|
| 727 |
|
|---|
| 728 | // fill in a container record from a FILESTATUS4L structure
|
|---|
| 729 |
|
|---|
| 730 | pci->hwndCnr = hwndCnr;
|
|---|
| 731 | pci->pszFileName = xstrdup(pszFileName, pszSrcFile, __LINE__);
|
|---|
| 732 | //strcpy(pci->pszFileName, pszFileName);
|
|---|
| 733 | flags = driveflags[toupper(*pci->pszFileName) - 'A'];
|
|---|
| 734 | // load the object's Subject, if required
|
|---|
| 735 | //pci->pszSubject = NullStr;
|
|---|
| 736 | if (pfsa4->cbList > 4 &&
|
|---|
| 737 | dcd &&
|
|---|
| 738 | fLoadSubject &&
|
|---|
| 739 | (!isalpha(*pci->pszFileName) ||
|
|---|
| 740 | !(flags & DRIVE_NOLOADSUBJS)))
|
|---|
| 741 | {
|
|---|
| 742 | APIRET rc;
|
|---|
| 743 | EAOP2 eaop;
|
|---|
| 744 | PGEA2LIST pgealist;
|
|---|
| 745 | PFEA2LIST pfealist;
|
|---|
| 746 | PGEA2 pgea;
|
|---|
| 747 | PFEA2 pfea;
|
|---|
| 748 | CHAR *value;
|
|---|
| 749 |
|
|---|
| 750 | pgealist = xmallocz(sizeof(GEA2LIST) + 32, pszSrcFile, __LINE__);
|
|---|
| 751 | if (pgealist) {
|
|---|
| 752 | pgea = &pgealist->list[0];
|
|---|
| 753 | strcpy(pgea->szName, SUBJECT);
|
|---|
| 754 | pgea->cbName = strlen(pgea->szName);
|
|---|
| 755 | pgea->oNextEntryOffset = 0;
|
|---|
| 756 | pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
|
|---|
| 757 | pfealist = xmallocz(1532, pszSrcFile, __LINE__);
|
|---|
| 758 | if (pfealist) {
|
|---|
| 759 | pfealist->cbList = 1024;
|
|---|
| 760 | eaop.fpGEA2List = pgealist;
|
|---|
| 761 | eaop.fpFEA2List = pfealist;
|
|---|
| 762 | eaop.oError = 0;
|
|---|
| 763 | rc = DosQueryPathInfo(pci->pszFileName, FIL_QUERYEASFROMLIST,
|
|---|
| 764 | (PVOID) & eaop, (ULONG) sizeof(EAOP2));
|
|---|
| 765 | if (!rc) {
|
|---|
| 766 | pfea = &eaop.fpFEA2List->list[0];
|
|---|
| 767 | value = pfea->szName + pfea->cbName + 1;
|
|---|
| 768 | value[pfea->cbValue] = 0;
|
|---|
| 769 | if (*(USHORT *) value == EAT_ASCII)
|
|---|
| 770 | pci->pszSubject = xstrdup(value + (sizeof(USHORT) * 2), pszSrcFile, __LINE__);
|
|---|
| 771 | }
|
|---|
| 772 | free(pfealist);
|
|---|
| 773 | }
|
|---|
| 774 | free(pgealist);
|
|---|
| 775 | }
|
|---|
| 776 | }
|
|---|
| 777 | if (!pci->pszSubject)
|
|---|
| 778 | pci->pszSubject = NullStr;
|
|---|
| 779 |
|
|---|
| 780 | pci->pszLongName = NULL;
|
|---|
| 781 | if (fLoadLongnames &&
|
|---|
| 782 | dcd &&
|
|---|
| 783 | pfsa4->cbList > 4L &&
|
|---|
| 784 | isalpha(*pci->pszFileName) &&
|
|---|
| 785 | ~flags & DRIVE_NOLONGNAMES &&
|
|---|
| 786 | ~flags & DRIVE_NOLOADLONGS)
|
|---|
| 787 | {
|
|---|
| 788 | APIRET rc;
|
|---|
| 789 | EAOP2 eaop;
|
|---|
| 790 | PGEA2LIST pgealist;
|
|---|
| 791 | PFEA2LIST pfealist;
|
|---|
| 792 | PGEA2 pgea;
|
|---|
| 793 | PFEA2 pfea;
|
|---|
| 794 | CHAR *value;
|
|---|
| 795 |
|
|---|
| 796 | pgealist = xmallocz(sizeof(GEA2LIST) + 32, pszSrcFile, __LINE__);
|
|---|
| 797 | if (pgealist) {
|
|---|
| 798 | pgea = &pgealist->list[0];
|
|---|
| 799 | strcpy(pgea->szName, LONGNAME);
|
|---|
| 800 | pgea->cbName = strlen(pgea->szName);
|
|---|
| 801 | pgea->oNextEntryOffset = 0;
|
|---|
| 802 | pgealist->cbList = (sizeof(GEA2LIST) + pgea->cbName);
|
|---|
| 803 | pfealist = xmallocz(1532, pszSrcFile, __LINE__);
|
|---|
| 804 | if (pfealist) {
|
|---|
| 805 | pfealist->cbList = 1024;
|
|---|
| 806 | eaop.fpGEA2List = pgealist;
|
|---|
| 807 | eaop.fpFEA2List = pfealist;
|
|---|
| 808 | eaop.oError = 0;
|
|---|
| 809 | rc = DosQueryPathInfo(pci->pszFileName, FIL_QUERYEASFROMLIST,
|
|---|
| 810 | (PVOID) & eaop, (ULONG) sizeof(EAOP2));
|
|---|
| 811 | if (!rc) {
|
|---|
| 812 | pfea = &eaop.fpFEA2List->list[0];
|
|---|
| 813 | value = pfea->szName + pfea->cbName + 1; // Point at EA value
|
|---|
| 814 | value[pfea->cbValue] = 0; // Terminate
|
|---|
| 815 | if (*(USHORT *) value == EAT_ASCII) {
|
|---|
| 816 | p = value + sizeof(USHORT) * 2; // Point at value string
|
|---|
| 817 | pci->pszLongName = xstrdup(p, pszSrcFile, __LINE__);
|
|---|
| 818 | }
|
|---|
| 819 | }
|
|---|
| 820 | free(pfealist);
|
|---|
| 821 | }
|
|---|
| 822 | free(pgealist);
|
|---|
| 823 | }
|
|---|
| 824 | }
|
|---|
| 825 | if (!pci->pszLongName)
|
|---|
| 826 | pci->pszLongName = NullStr;
|
|---|
| 827 |
|
|---|
| 828 | if (fForceUpper)
|
|---|
| 829 | strupr(pci->pszFileName);
|
|---|
| 830 | else if (fForceLower)
|
|---|
| 831 | strlwr(pci->pszFileName);
|
|---|
| 832 |
|
|---|
| 833 | if (pfsa4->attrFile & FILE_DIRECTORY) {
|
|---|
| 834 | if (fNoIconsDirs ||
|
|---|
| 835 | (flags & DRIVE_NOLOADICONS) ||
|
|---|
| 836 | !isalpha(*pci->pszFileName)) {
|
|---|
| 837 | hptr = (HPOINTER) 0;
|
|---|
| 838 | }
|
|---|
| 839 | else
|
|---|
| 840 | hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
|
|---|
| 841 | }
|
|---|
| 842 | else {
|
|---|
| 843 | if (fNoIconsFiles ||
|
|---|
| 844 | (flags & DRIVE_NOLOADICONS) ||
|
|---|
| 845 | !isalpha(*pci->pszFileName)) {
|
|---|
| 846 | hptr = IDFile(pci->pszFileName);
|
|---|
| 847 | }
|
|---|
| 848 | else
|
|---|
| 849 | hptr = WinLoadFileIcon(pci->pszFileName, FALSE);
|
|---|
| 850 | }
|
|---|
| 851 | if (!hptr) {
|
|---|
| 852 | hptr = pfsa4->attrFile & FILE_DIRECTORY ?
|
|---|
| 853 | hptrDir :
|
|---|
| 854 | pfsa4->attrFile & FILE_SYSTEM ?
|
|---|
| 855 | hptrSystem :
|
|---|
| 856 | pfsa4->attrFile & FILE_HIDDEN ?
|
|---|
| 857 | hptrHidden : pfsa4->attrFile & FILE_READONLY ? hptrReadonly : hptrFile;
|
|---|
| 858 | }
|
|---|
| 859 |
|
|---|
| 860 | // Tell container what part of pathname to display
|
|---|
| 861 | if (partial) {
|
|---|
| 862 | p = strrchr(pci->pszFileName, '\\');
|
|---|
| 863 | if (!p) {
|
|---|
| 864 | p = strrchr(pci->pszFileName, ':');
|
|---|
| 865 | if (!p)
|
|---|
| 866 | p = pci->pszFileName;
|
|---|
| 867 | else
|
|---|
| 868 | p++;
|
|---|
| 869 | }
|
|---|
| 870 | else if ((dcd && dcd->type == TREE_FRAME) ||
|
|---|
| 871 | !(pfsa4->attrFile & FILE_DIRECTORY) || !*(p + 1))
|
|---|
| 872 | p++;
|
|---|
| 873 | if (!*p)
|
|---|
| 874 | p = pci->pszFileName;
|
|---|
| 875 | }
|
|---|
| 876 | else
|
|---|
| 877 | p = pci->pszFileName;
|
|---|
| 878 | pci->pszDisplayName = p;
|
|---|
| 879 |
|
|---|
| 880 | //comma format the file size for large file support
|
|---|
| 881 | {
|
|---|
| 882 | CHAR szBuf[30];
|
|---|
| 883 | CommaFmtULL(szBuf, sizeof(szBuf), pfsa4->cbFile, ' ');
|
|---|
| 884 | pci->pszFmtFileSize = xstrdup(szBuf, pszSrcFile, __LINE__);
|
|---|
| 885 | # ifdef FORTIFY
|
|---|
| 886 | {
|
|---|
| 887 | if (dcd && dcd->type == TREE_FRAME) {
|
|---|
| 888 | // Will be freed in TreeCnrWndProc WM_DESTROY
|
|---|
| 889 | // Fortify_SetOwner(pci->pszFmtFileSize, 1);
|
|---|
| 890 | Fortify_SetScope(pci->pszFmtFileSize, 2);
|
|---|
| 891 | }
|
|---|
| 892 | }
|
|---|
| 893 | # endif
|
|---|
| 894 | }
|
|---|
| 895 | pci->date.day = pfsa4->fdateLastWrite.day;
|
|---|
| 896 | pci->date.month = pfsa4->fdateLastWrite.month;
|
|---|
| 897 | pci->date.year = pfsa4->fdateLastWrite.year + 1980;
|
|---|
| 898 | pci->time.seconds = pfsa4->ftimeLastWrite.twosecs * 2;
|
|---|
| 899 | pci->time.minutes = pfsa4->ftimeLastWrite.minutes;
|
|---|
| 900 | pci->time.hours = pfsa4->ftimeLastWrite.hours;
|
|---|
| 901 | pci->ladate.day = pfsa4->fdateLastAccess.day;
|
|---|
| 902 | pci->ladate.month = pfsa4->fdateLastAccess.month;
|
|---|
| 903 | pci->ladate.year = pfsa4->fdateLastAccess.year + 1980;
|
|---|
| 904 | pci->latime.seconds = pfsa4->ftimeLastAccess.twosecs * 2;
|
|---|
| 905 | pci->latime.minutes = pfsa4->ftimeLastAccess.minutes;
|
|---|
| 906 | pci->latime.hours = pfsa4->ftimeLastAccess.hours;
|
|---|
| 907 | pci->crdate.day = pfsa4->fdateCreation.day;
|
|---|
| 908 | pci->crdate.month = pfsa4->fdateCreation.month;
|
|---|
| 909 | pci->crdate.year = pfsa4->fdateCreation.year + 1980;
|
|---|
| 910 | pci->crtime.seconds = pfsa4->ftimeCreation.twosecs * 2;
|
|---|
| 911 | pci->crtime.minutes = pfsa4->ftimeCreation.minutes;
|
|---|
| 912 | pci->crtime.hours = pfsa4->ftimeCreation.hours;
|
|---|
| 913 | pci->easize = CBLIST_TO_EASIZE(pfsa4->cbList);
|
|---|
| 914 | pci->cbFile = pfsa4->cbFile;
|
|---|
| 915 | pci->attrFile = pfsa4->attrFile;
|
|---|
| 916 | pci->pszDispAttr = FileAttrToString(pci->attrFile);
|
|---|
| 917 | pci->rc.pszIcon = pci->pszDisplayName;
|
|---|
| 918 | pci->rc.hptrIcon = hptr;
|
|---|
| 919 |
|
|---|
| 920 | if (dcd &&
|
|---|
| 921 | (*dcd->mask.szMask || dcd->mask.antiattr ||
|
|---|
| 922 | ((dcd->mask.attrFile &
|
|---|
| 923 | (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED)) !=
|
|---|
| 924 | (FILE_HIDDEN | FILE_SYSTEM | FILE_READONLY | FILE_ARCHIVED)))) {
|
|---|
| 925 | if (*dcd->mask.szMask || dcd->mask.antiattr) {
|
|---|
| 926 | if (!Filter((PMINIRECORDCORE) pci, (PVOID) & dcd->mask))
|
|---|
| 927 | pci->rc.flRecordAttr |= CRA_FILTERED;
|
|---|
| 928 | }
|
|---|
| 929 | else if ((!(dcd->mask.attrFile & FILE_HIDDEN) &&
|
|---|
| 930 | (pci->attrFile & FILE_HIDDEN)) ||
|
|---|
| 931 | (!(dcd->mask.attrFile & FILE_SYSTEM) &&
|
|---|
| 932 | (pci->attrFile & FILE_SYSTEM)) ||
|
|---|
| 933 | (!(dcd->mask.attrFile & FILE_READONLY) &&
|
|---|
| 934 | (pci->attrFile & FILE_READONLY)) ||
|
|---|
| 935 | (!(dcd->mask.attrFile & FILE_ARCHIVED) &&
|
|---|
| 936 | (pci->attrFile & FILE_ARCHIVED)))
|
|---|
| 937 | pci->rc.flRecordAttr |= CRA_FILTERED;
|
|---|
| 938 | }
|
|---|
| 939 |
|
|---|
| 940 | return pfsa4->cbFile + pci->easize;
|
|---|
| 941 |
|
|---|
| 942 | } // FillInRecordFromFSA
|
|---|
| 943 |
|
|---|
| 944 | VOID ProcessDirectory(const HWND hwndCnr,
|
|---|
| 945 | const PCNRITEM pciParent,
|
|---|
| 946 | const CHAR *szDirBase,
|
|---|
| 947 | const BOOL filestoo,
|
|---|
| 948 | const BOOL recurse,
|
|---|
| 949 | const BOOL partial,
|
|---|
| 950 | CHAR *stopflag,
|
|---|
| 951 | DIRCNRDATA *dcd, // Optional
|
|---|
| 952 | ULONG *pulTotalFiles, // Optional
|
|---|
| 953 | PULONGLONG pullTotalBytes) // Optional
|
|---|
| 954 | {
|
|---|
| 955 | /* put all the directories (and files if filestoo is TRUE) from a
|
|---|
| 956 | * directory into the container. recurse through subdirectories if
|
|---|
| 957 | * recurse is TRUE.
|
|---|
| 958 | */
|
|---|
| 959 |
|
|---|
| 960 | PSZ pszFileSpec;
|
|---|
| 961 | INT t;
|
|---|
| 962 | PFILEFINDBUF4L paffbFound;
|
|---|
| 963 | PFILEFINDBUF4L *papffbSelected;
|
|---|
| 964 | PFILEFINDBUF4L pffbFile;
|
|---|
| 965 | PFILEFINDBUF4L paffbTotal = NULL;
|
|---|
| 966 | PFILEFINDBUF4L paffbTemp;
|
|---|
| 967 | HDIR hdir = HDIR_CREATE;
|
|---|
| 968 | ULONG ulFindCnt;
|
|---|
| 969 | ULONG ulFindMax;
|
|---|
| 970 | ULONG ulSelCnt;
|
|---|
| 971 | ULONG ulTotal = 0;
|
|---|
| 972 | ULONGLONG ullBytes;
|
|---|
| 973 | ULONGLONG ullTotalBytes;
|
|---|
| 974 | ULONG ulReturnFiles = 0;
|
|---|
| 975 | ULONGLONG ullReturnBytes = 0;
|
|---|
| 976 | PCH pchEndPath;
|
|---|
| 977 | APIRET rc;
|
|---|
| 978 | PCNRITEM pci;
|
|---|
| 979 | PCNRITEM pciFirst;
|
|---|
| 980 | RECORDINSERT ri;
|
|---|
| 981 | BOOL ok = TRUE;
|
|---|
| 982 | ULONG ulBufBytes;
|
|---|
| 983 | ULONG x;
|
|---|
| 984 |
|
|---|
| 985 | if (isalpha(*szDirBase) && szDirBase[1] == ':' && szDirBase[2] == '\\') {
|
|---|
| 986 | if ((driveflags[toupper(*szDirBase) - 'A'] & DRIVE_REMOTE) && fRemoteBug)
|
|---|
| 987 | ulFindMax = 1; // file system gets confused
|
|---|
| 988 | else if (driveflags[toupper(*szDirBase) - 'A'] & DRIVE_ZIPSTREAM)
|
|---|
| 989 | ulFindMax = min(FilesToGet, 225); // anything more is wasted
|
|---|
| 990 | else
|
|---|
| 991 | ulFindMax = FilesToGet; // full-out
|
|---|
| 992 | }
|
|---|
| 993 | else
|
|---|
| 994 | ulFindMax = FilesToGet;
|
|---|
| 995 |
|
|---|
| 996 | if (OS2ver[0] == 20 && OS2ver[1] < 30)
|
|---|
| 997 | ulFindMax = min(ulFindMax, (65535 / sizeof(FILEFINDBUF4L)));
|
|---|
| 998 |
|
|---|
| 999 | ulBufBytes = ulFindMax * sizeof(FILEFINDBUF4L);
|
|---|
| 1000 |
|
|---|
| 1001 | pszFileSpec = xmalloc(CCHMAXPATH + 2, pszSrcFile, __LINE__);
|
|---|
| 1002 | paffbFound = xmalloc(ulBufBytes, pszSrcFile, __LINE__);
|
|---|
| 1003 | papffbSelected = xmalloc(sizeof(PFILEFINDBUF4L) * ulFindMax, pszSrcFile, __LINE__);
|
|---|
| 1004 |
|
|---|
| 1005 | if (paffbFound && papffbSelected && pszFileSpec) {
|
|---|
| 1006 | t = strlen(szDirBase);
|
|---|
| 1007 | memcpy(pszFileSpec, szDirBase, t + 1);
|
|---|
| 1008 | pchEndPath = pszFileSpec + t;
|
|---|
| 1009 | if (*(pchEndPath - 1) != '\\') {
|
|---|
| 1010 | memcpy(pchEndPath, "\\", 2);
|
|---|
| 1011 | pchEndPath++;
|
|---|
| 1012 | }
|
|---|
| 1013 | memcpy(pchEndPath, "*", 2);
|
|---|
| 1014 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 1015 | ulFindCnt = ulFindMax;
|
|---|
| 1016 | rc = xDosFindFirst(pszFileSpec,
|
|---|
| 1017 | &hdir,
|
|---|
| 1018 | FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
|
|---|
| 1019 | FILE_SYSTEM | FILE_HIDDEN |
|
|---|
| 1020 | (filestoo ? FILE_DIRECTORY : MUST_HAVE_DIRECTORY),
|
|---|
| 1021 | paffbFound,
|
|---|
| 1022 | ulBufBytes,
|
|---|
| 1023 | &ulFindCnt,
|
|---|
| 1024 | FIL_QUERYEASIZEL);
|
|---|
| 1025 | priority_normal();
|
|---|
| 1026 | *pchEndPath = 0; // Chop off wildcard
|
|---|
| 1027 | if (!rc) {
|
|---|
| 1028 | do {
|
|---|
| 1029 | /*
|
|---|
| 1030 | * remove . and .. from list if present
|
|---|
| 1031 | * also counter file system bugs that sometimes
|
|---|
| 1032 | * allows normal files to slip through when
|
|---|
| 1033 | * only directories should appear (only a few
|
|---|
| 1034 | * network file systems exhibit such a problem).
|
|---|
| 1035 | */
|
|---|
| 1036 |
|
|---|
| 1037 | if (stopflag && *stopflag)
|
|---|
| 1038 | goto Abort;
|
|---|
| 1039 | pffbFile = paffbFound;
|
|---|
| 1040 | ulSelCnt = 0;
|
|---|
| 1041 | for (;;) {
|
|---|
| 1042 | if (!*pffbFile->achName ||
|
|---|
| 1043 | (!filestoo && ~pffbFile->attrFile & FILE_DIRECTORY) ||
|
|---|
| 1044 | (pffbFile->attrFile & FILE_DIRECTORY &&
|
|---|
| 1045 | pffbFile->achName[0] == '.' &&
|
|---|
| 1046 | (!pffbFile->achName[1] ||
|
|---|
| 1047 | (pffbFile->achName[1] == '.' && !pffbFile->achName[2])))) {
|
|---|
| 1048 | // ulFindCnt--; // Got . or .. or file to be skipped
|
|---|
| 1049 | }
|
|---|
| 1050 | else
|
|---|
| 1051 | papffbSelected[ulSelCnt++] = pffbFile; // Remember selected file
|
|---|
| 1052 | if (!pffbFile->oNextEntryOffset) {
|
|---|
| 1053 | // ulFindCnt = ulSelCnt; // Remember number selected
|
|---|
| 1054 | break;
|
|---|
| 1055 | }
|
|---|
| 1056 | pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + pffbFile->oNextEntryOffset);
|
|---|
| 1057 | } // for
|
|---|
| 1058 | if (ulSelCnt) {
|
|---|
| 1059 | // One or more entries selected
|
|---|
| 1060 | if (stopflag && *stopflag)
|
|---|
| 1061 | goto Abort;
|
|---|
| 1062 | if (fSyncUpdates) {
|
|---|
| 1063 | pciFirst = WinSendMsg(hwndCnr, CM_ALLOCRECORD,
|
|---|
| 1064 | MPFROMLONG(EXTRA_RECORD_BYTES),
|
|---|
| 1065 | MPFROMLONG(ulSelCnt));
|
|---|
| 1066 | if (!pciFirst) {
|
|---|
| 1067 | Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
|
|---|
| 1068 | GetPString(IDS_CMALLOCRECERRTEXT));
|
|---|
| 1069 | ok = FALSE;
|
|---|
| 1070 | ullTotalBytes = 0;
|
|---|
| 1071 | }
|
|---|
| 1072 | else {
|
|---|
| 1073 | // 04 Jan 08 SHL fixme like comp.c to handle less than ulSelCnt records
|
|---|
| 1074 | pci = pciFirst;
|
|---|
| 1075 | ullTotalBytes = 0;
|
|---|
| 1076 | // Insert selected in container
|
|---|
| 1077 | for (x = 0; x < ulSelCnt; x++) {
|
|---|
| 1078 | pffbFile = papffbSelected[x];
|
|---|
| 1079 | ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec,
|
|---|
| 1080 | pffbFile, partial, dcd);
|
|---|
| 1081 | pci = (PCNRITEM) pci->rc.preccNextRecord;
|
|---|
| 1082 | ullTotalBytes += ullBytes;
|
|---|
| 1083 | } // for
|
|---|
| 1084 | memset(&ri, 0, sizeof(RECORDINSERT));
|
|---|
| 1085 | ri.cb = sizeof(RECORDINSERT);
|
|---|
| 1086 | ri.pRecordOrder = (PRECORDCORE) CMA_END;
|
|---|
| 1087 | ri.pRecordParent = (PRECORDCORE) pciParent;
|
|---|
| 1088 | ri.zOrder = (ULONG) CMA_TOP;
|
|---|
| 1089 | ri.cRecordsInsert = ulSelCnt;
|
|---|
| 1090 | ri.fInvalidateRecord = TRUE;
|
|---|
| 1091 | // !fSyncUpdates && dcd && dcd->type == DIR_FRAME ? FALSE : TRUE; //fSyncUpdates always TRUE 12-1-08 GKY
|
|---|
| 1092 | if (!WinSendMsg(hwndCnr,
|
|---|
| 1093 | CM_INSERTRECORD,
|
|---|
| 1094 | MPFROMP(pciFirst), MPFROMP(&ri))) {
|
|---|
| 1095 | DosSleep(10); // Give GUI time to work
|
|---|
| 1096 | WinSetFocus(HWND_DESKTOP, hwndCnr);
|
|---|
| 1097 | if (!WinSendMsg(hwndCnr,
|
|---|
| 1098 | CM_INSERTRECORD,
|
|---|
| 1099 | MPFROMP(pciFirst), MPFROMP(&ri))) {
|
|---|
| 1100 | Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
|
|---|
| 1101 | GetPString(IDS_CMINSERTERRTEXT));
|
|---|
| 1102 | ok = FALSE;
|
|---|
| 1103 | ullTotalBytes = 0;
|
|---|
| 1104 | if (WinIsWindow((HAB) 0, hwndCnr))
|
|---|
| 1105 | FreeCnrItemList(hwndCnr, pciFirst);
|
|---|
| 1106 | }
|
|---|
| 1107 | // }
|
|---|
| 1108 | }
|
|---|
| 1109 | }
|
|---|
| 1110 | if (ok) {
|
|---|
| 1111 | ullReturnBytes += ullTotalBytes;
|
|---|
| 1112 | ulReturnFiles += ulSelCnt;
|
|---|
| 1113 | }
|
|---|
| 1114 | } // if sync updates
|
|---|
| 1115 | else {
|
|---|
| 1116 | // Append newly selected entries to aggregate list
|
|---|
| 1117 | paffbTemp = xrealloc(paffbTotal,
|
|---|
| 1118 | sizeof(FILEFINDBUF4L) * (ulSelCnt + ulTotal),
|
|---|
| 1119 | pszSrcFile, __LINE__);
|
|---|
| 1120 | if (paffbTemp) {
|
|---|
| 1121 | // 13 Aug 07 SHL fixme to optimize copy
|
|---|
| 1122 | paffbTotal = paffbTemp;
|
|---|
| 1123 | for (x = 0; x < ulSelCnt; x++)
|
|---|
| 1124 | paffbTotal[x + ulTotal] = *papffbSelected[x];
|
|---|
| 1125 | ulTotal += ulSelCnt;
|
|---|
| 1126 | }
|
|---|
| 1127 | else {
|
|---|
| 1128 | saymsg(MB_ENTER,
|
|---|
| 1129 | HWND_DESKTOP,
|
|---|
| 1130 | GetPString(IDS_ERRORTEXT), GetPString(IDS_OUTOFMEMORY));
|
|---|
| 1131 | break;
|
|---|
| 1132 | }
|
|---|
| 1133 | }
|
|---|
| 1134 | } // if entries selected
|
|---|
| 1135 | if (stopflag && *stopflag)
|
|---|
| 1136 | goto Abort;
|
|---|
| 1137 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 1138 | ulFindCnt = ulFindMax;
|
|---|
| 1139 | rc = xDosFindNext(hdir, paffbFound, ulBufBytes, &ulFindCnt, FIL_QUERYEASIZEL);
|
|---|
| 1140 | priority_normal();
|
|---|
| 1141 | if (rc)
|
|---|
| 1142 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 1143 | } while (!rc);
|
|---|
| 1144 |
|
|---|
| 1145 | DosFindClose(hdir);
|
|---|
| 1146 | xfree(paffbFound, pszSrcFile, __LINE__);
|
|---|
| 1147 | paffbFound = NULL;
|
|---|
| 1148 | xfree(papffbSelected, pszSrcFile, __LINE__);
|
|---|
| 1149 | papffbSelected = NULL;
|
|---|
| 1150 |
|
|---|
| 1151 | if (ulTotal && paffbTotal) {
|
|---|
| 1152 |
|
|---|
| 1153 | if (stopflag && *stopflag)
|
|---|
| 1154 | goto Abort;
|
|---|
| 1155 |
|
|---|
| 1156 | pciFirst = WinSendMsg(hwndCnr, CM_ALLOCRECORD,
|
|---|
| 1157 | MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(ulTotal));
|
|---|
| 1158 | if (!pciFirst) {
|
|---|
| 1159 | Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
|
|---|
| 1160 | GetPString(IDS_CMALLOCRECERRTEXT));
|
|---|
| 1161 | ok = FALSE;
|
|---|
| 1162 | ullTotalBytes = 0;
|
|---|
| 1163 | }
|
|---|
| 1164 | else {
|
|---|
| 1165 | // 04 Jan 08 SHL fixme like comp.c to handle less than ulSelCnt records
|
|---|
| 1166 | pci = pciFirst;
|
|---|
| 1167 | ullTotalBytes = 0;
|
|---|
| 1168 | pffbFile = paffbTotal;
|
|---|
| 1169 | for (x = 0; x < ulTotal; x++) {
|
|---|
| 1170 | ullBytes = FillInRecordFromFFB(hwndCnr, pci, pszFileSpec,
|
|---|
| 1171 | pffbFile, partial, dcd);
|
|---|
| 1172 | pci = (PCNRITEM) pci->rc.preccNextRecord;
|
|---|
| 1173 | ullTotalBytes += ullBytes;
|
|---|
| 1174 | // Can not use offset since we have merged lists - this should be equivalent
|
|---|
| 1175 | pffbFile = (PFILEFINDBUF4L)((PBYTE)pffbFile + sizeof(FILEFINDBUF4L));
|
|---|
| 1176 | }
|
|---|
| 1177 | if (ulTotal) {
|
|---|
| 1178 | memset(&ri, 0, sizeof(RECORDINSERT));
|
|---|
| 1179 | ri.cb = sizeof(RECORDINSERT);
|
|---|
| 1180 | ri.pRecordOrder = (PRECORDCORE) CMA_END;
|
|---|
| 1181 | ri.pRecordParent = (PRECORDCORE) pciParent;
|
|---|
| 1182 | ri.zOrder = (ULONG) CMA_TOP;
|
|---|
| 1183 | ri.cRecordsInsert = ulTotal;
|
|---|
| 1184 | ri.fInvalidateRecord = (!fSyncUpdates && dcd &&
|
|---|
| 1185 | dcd->type == DIR_FRAME) ? FALSE : TRUE;
|
|---|
| 1186 | if (!WinSendMsg(hwndCnr, CM_INSERTRECORD,
|
|---|
| 1187 | MPFROMP(pciFirst), MPFROMP(&ri))) {
|
|---|
| 1188 | DosSleep(10); // Give GUI time to work
|
|---|
| 1189 | WinSetFocus(HWND_DESKTOP, hwndCnr);
|
|---|
| 1190 | if (!WinSendMsg(hwndCnr, CM_INSERTRECORD,
|
|---|
| 1191 | MPFROMP(pciFirst), MPFROMP(&ri))) {
|
|---|
| 1192 | Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
|
|---|
| 1193 | GetPString(IDS_CMINSERTERRTEXT));
|
|---|
| 1194 | ok = FALSE;
|
|---|
| 1195 | ullTotalBytes = 0;
|
|---|
| 1196 | if (WinIsWindow((HAB) 0, hwndCnr))
|
|---|
| 1197 | FreeCnrItemList(hwndCnr, pciFirst);
|
|---|
| 1198 | }
|
|---|
| 1199 | }
|
|---|
| 1200 | }
|
|---|
| 1201 | }
|
|---|
| 1202 | if (ok) {
|
|---|
| 1203 | ullReturnBytes += ullTotalBytes;
|
|---|
| 1204 | ulReturnFiles += ulFindCnt;
|
|---|
| 1205 | }
|
|---|
| 1206 | }
|
|---|
| 1207 | }
|
|---|
| 1208 |
|
|---|
| 1209 | /**
|
|---|
| 1210 | * DosFind for subdirectories of a read-only directory on a FAT volume
|
|---|
| 1211 | * returns path not found if there are no subdirectories
|
|---|
| 1212 | * FAT FS seems to ignore . and .. in this case
|
|---|
| 1213 | * Map to no more files
|
|---|
| 1214 | * We could verify that directory is marked read-only, it's probably not
|
|---|
| 1215 | * worth the extra code since we do verify 2 out of 3 prerequisites
|
|---|
| 1216 | * 15 Jan 08 SHL
|
|---|
| 1217 | */
|
|---|
| 1218 | if (rc == ERROR_PATH_NOT_FOUND && !filestoo) {
|
|---|
| 1219 | ULONG ulDriveType = 0;
|
|---|
| 1220 | CHAR szFSType[CCHMAXPATH];
|
|---|
| 1221 | INT removable = CheckDrive(*pszFileSpec, szFSType, &ulDriveType);
|
|---|
| 1222 | if (removable != -1 && strcmp(szFSType, "FAT") == 0)
|
|---|
| 1223 | rc = ERROR_NO_MORE_FILES;
|
|---|
| 1224 | }
|
|---|
| 1225 |
|
|---|
| 1226 | if (rc && rc != ERROR_NO_MORE_FILES) {
|
|---|
| 1227 | Dos_Error(MB_ENTER, rc, HWND_DESKTOP, pszSrcFile, __LINE__,
|
|---|
| 1228 | GetPString(IDS_CANTFINDDIRTEXT), pszFileSpec);
|
|---|
| 1229 | }
|
|---|
| 1230 |
|
|---|
| 1231 | if (!fSyncUpdates && dcd && dcd->type == DIR_FRAME)
|
|---|
| 1232 | WinSendMsg(hwndCnr, CM_INVALIDATERECORD, MPVOID,
|
|---|
| 1233 | MPFROM2SHORT(0, CMA_ERASE));
|
|---|
| 1234 | }
|
|---|
| 1235 | Abort:
|
|---|
| 1236 | xfree(paffbTotal, pszSrcFile, __LINE__);
|
|---|
| 1237 | xfree(pszFileSpec, pszSrcFile, __LINE__);
|
|---|
| 1238 | xfree(paffbFound, pszSrcFile, __LINE__);
|
|---|
| 1239 | xfree(papffbSelected, pszSrcFile, __LINE__);
|
|---|
| 1240 |
|
|---|
| 1241 | if (recurse) {
|
|---|
| 1242 | pci = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pciParent),
|
|---|
| 1243 | MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
|
|---|
| 1244 | while (pci && (INT)pci != -1) {
|
|---|
| 1245 | if ((pci->attrFile & FILE_DIRECTORY))
|
|---|
| 1246 | //if (fInitialDriveScan)
|
|---|
| 1247 | Stubby(hwndCnr, pci);
|
|---|
| 1248 | /*else {
|
|---|
| 1249 | while (StubbyScanCount != 0)
|
|---|
| 1250 | DosSleep(50);
|
|---|
| 1251 | Stubby(hwndCnr, pci);
|
|---|
| 1252 | } */
|
|---|
| 1253 | //Stubby(hwndCnr, pci);
|
|---|
| 1254 | pci = WinSendMsg(hwndCnr, CM_QUERYRECORD, MPFROMP(pci),
|
|---|
| 1255 | MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
|
|---|
| 1256 | }
|
|---|
| 1257 | }
|
|---|
| 1258 |
|
|---|
| 1259 | if (pulTotalFiles)
|
|---|
| 1260 | *pulTotalFiles = ulReturnFiles;
|
|---|
| 1261 |
|
|---|
| 1262 | if (pullTotalBytes)
|
|---|
| 1263 | *pullTotalBytes = ullReturnBytes;
|
|---|
| 1264 |
|
|---|
| 1265 | } // ProcessDirectory
|
|---|
| 1266 |
|
|---|
| 1267 | VOID FillDirCnr(HWND hwndCnr,
|
|---|
| 1268 | CHAR * pszDirectory,
|
|---|
| 1269 | DIRCNRDATA * dcd,
|
|---|
| 1270 | PULONGLONG pullTotalBytes)
|
|---|
| 1271 | {
|
|---|
| 1272 | ProcessDirectory(hwndCnr,
|
|---|
| 1273 | (PCNRITEM)NULL,
|
|---|
| 1274 | pszDirectory,
|
|---|
| 1275 | TRUE, // filestoo
|
|---|
| 1276 | FALSE, // recurse
|
|---|
| 1277 | TRUE, // partial
|
|---|
| 1278 | dcd ? &dcd->stopflag : NULL,
|
|---|
| 1279 | dcd,
|
|---|
| 1280 | NULL, // total files
|
|---|
| 1281 | pullTotalBytes);
|
|---|
| 1282 | DosPostEventSem(CompactSem);
|
|---|
| 1283 |
|
|---|
| 1284 | #if 0 // fixme to be gone or to be configurable
|
|---|
| 1285 | {
|
|---|
| 1286 | int state = _heapchk();
|
|---|
| 1287 | if (state != _HEAPOK)
|
|---|
| 1288 | Runtime_Error(pszSrcFile, __LINE__, "heap corrupted %d", state);
|
|---|
| 1289 | else
|
|---|
| 1290 | DbgMsg(pszSrcFile, __LINE__, "_memavl %u", _memavl());
|
|---|
| 1291 | }
|
|---|
| 1292 | #endif
|
|---|
| 1293 |
|
|---|
| 1294 | } // FillDirCnr
|
|---|
| 1295 |
|
|---|
| 1296 | VOID FillTreeCnr(HWND hwndCnr, HWND hwndParent)
|
|---|
| 1297 | {
|
|---|
| 1298 | ULONG ulCurDriveNum, ulDriveMap, numtoinsert = 0;
|
|---|
| 1299 | ULONG ulDriveType;
|
|---|
| 1300 | PCNRITEM pci, pciFirst = NULL, pciNext, pciParent = NULL;
|
|---|
| 1301 | INT x, removable;
|
|---|
| 1302 | CHAR suggest[32];
|
|---|
| 1303 | CHAR szDrive[] = " :\\";
|
|---|
| 1304 | CHAR szFSType[CCHMAXPATH];
|
|---|
| 1305 | FILESTATUS4L fsa4;
|
|---|
| 1306 | APIRET rc;
|
|---|
| 1307 | BOOL drivesbuilt = FALSE;
|
|---|
| 1308 | ULONG startdrive = 3;
|
|---|
| 1309 | static BOOL didonce = FALSE;
|
|---|
| 1310 |
|
|---|
| 1311 | fDummy = TRUE;
|
|---|
| 1312 | *suggest = 0;
|
|---|
| 1313 | for (x = 0; x < 26; x++) {
|
|---|
| 1314 | driveflags[x] &= (DRIVE_IGNORE | DRIVE_NOPRESCAN | DRIVE_NOLOADICONS |
|
|---|
| 1315 | DRIVE_NOLOADSUBJS | DRIVE_NOLOADLONGS |
|
|---|
| 1316 | DRIVE_INCLUDEFILES | DRIVE_SLOW | DRIVE_NOSTATS |
|
|---|
| 1317 | DRIVE_WRITEVERIFYOFF);
|
|---|
| 1318 | }
|
|---|
| 1319 | memset(driveserial, -1, sizeof(driveserial));
|
|---|
| 1320 |
|
|---|
| 1321 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 1322 | if (!DosQuerySysInfo(QSV_BOOT_DRIVE,
|
|---|
| 1323 | QSV_BOOT_DRIVE,
|
|---|
| 1324 | (PVOID) &startdrive,
|
|---|
| 1325 | (ULONG) sizeof(ULONG)) &&
|
|---|
| 1326 | startdrive)
|
|---|
| 1327 | {
|
|---|
| 1328 | driveflags[startdrive - 1] |= DRIVE_BOOT;
|
|---|
| 1329 | }
|
|---|
| 1330 |
|
|---|
| 1331 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 1332 | rc = DosQCurDisk(&ulCurDriveNum, &ulDriveMap);
|
|---|
| 1333 | if (rc) {
|
|---|
| 1334 | Dos_Error(MB_CANCEL,
|
|---|
| 1335 | rc,
|
|---|
| 1336 | HWND_DESKTOP,
|
|---|
| 1337 | pszSrcFile, __LINE__, PCSZ_FILLDIRQCURERRTEXT);
|
|---|
| 1338 | exit(0);
|
|---|
| 1339 | }
|
|---|
| 1340 |
|
|---|
| 1341 | // Calc number of drive items to create
|
|---|
| 1342 | for (x = 0; x < 26; x++) {
|
|---|
| 1343 | if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE))
|
|---|
| 1344 | numtoinsert++;
|
|---|
| 1345 | }
|
|---|
| 1346 |
|
|---|
| 1347 | if (numtoinsert) {
|
|---|
| 1348 | pciFirst = WinSendMsg(hwndCnr,
|
|---|
| 1349 | CM_ALLOCRECORD,
|
|---|
| 1350 | MPFROMLONG(EXTRA_RECORD_BYTES),
|
|---|
| 1351 | MPFROMLONG((ULONG) numtoinsert));
|
|---|
| 1352 | }
|
|---|
| 1353 |
|
|---|
| 1354 | if (!pciFirst) {
|
|---|
| 1355 | Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__, GetPString(IDS_CMALLOCRECERRTEXT));
|
|---|
| 1356 | // 04 Jan 08 SHL fixme not just up and die
|
|---|
| 1357 | exit(0);
|
|---|
| 1358 | }
|
|---|
| 1359 |
|
|---|
| 1360 | // 04 Jan 08 SHL fixme like comp.c to handle less than ulSelCnt records
|
|---|
| 1361 | pci = pciFirst;
|
|---|
| 1362 | for (x = 0; x < 26; x++) {
|
|---|
| 1363 | if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE)) {
|
|---|
| 1364 |
|
|---|
| 1365 | CHAR s[80];
|
|---|
| 1366 | ULONG flags = 0;
|
|---|
| 1367 | ULONG size = sizeof(ULONG);
|
|---|
| 1368 |
|
|---|
| 1369 | *szDrive = (CHAR)x + 'A'; // Build path spec
|
|---|
| 1370 |
|
|---|
| 1371 | sprintf(s, "%c.DriveFlags", toupper(*szDrive));
|
|---|
| 1372 | if (PrfQueryProfileData(fmprof, appname, s, &flags, &size)) {
|
|---|
| 1373 | driveflags[toupper(*szDrive) - 'A'] |= flags;
|
|---|
| 1374 | }
|
|---|
| 1375 |
|
|---|
| 1376 | if (x > 1) {
|
|---|
| 1377 | // Hard drive (2..N)
|
|---|
| 1378 | if (!(driveflags[x] & DRIVE_NOPRESCAN)) {
|
|---|
| 1379 | *szFSType = 0;
|
|---|
| 1380 | ulDriveType = 0;
|
|---|
| 1381 | removable = CheckDrive(*szDrive, szFSType, &ulDriveType);
|
|---|
| 1382 | driveserial[x] = -1;
|
|---|
| 1383 | if (removable != -1) {
|
|---|
| 1384 | struct {
|
|---|
| 1385 | ULONG serial;
|
|---|
| 1386 | CHAR volumelength;
|
|---|
| 1387 | CHAR volumelabel[CCHMAXPATH];
|
|---|
| 1388 | } volser;
|
|---|
| 1389 |
|
|---|
| 1390 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 1391 | if (!DosQueryFSInfo((ULONG) x,
|
|---|
| 1392 | FSIL_VOLSER, &volser, sizeof(volser))) {
|
|---|
| 1393 | driveserial[x] = volser.serial;
|
|---|
| 1394 | }
|
|---|
| 1395 | }
|
|---|
| 1396 | else
|
|---|
| 1397 | driveflags[x] |= DRIVE_INVALID;
|
|---|
| 1398 |
|
|---|
| 1399 | memset(&fsa4, 0, sizeof(FILESTATUS4L));
|
|---|
| 1400 | driveflags[x] |= removable == -1 || removable == 1 ?
|
|---|
| 1401 | DRIVE_REMOVABLE : 0;
|
|---|
| 1402 | if (ulDriveType & DRIVE_REMOTE)
|
|---|
| 1403 | driveflags[x] |= DRIVE_REMOTE;
|
|---|
| 1404 | if (!stricmp(szFSType,RAMFS)) {
|
|---|
| 1405 | driveflags[x] |= DRIVE_RAMDISK;
|
|---|
| 1406 | driveflags[x] &= ~DRIVE_REMOTE;
|
|---|
| 1407 | }
|
|---|
| 1408 | if (!stricmp(szFSType,NDFS32)) {
|
|---|
| 1409 | driveflags[x] |= DRIVE_VIRTUAL;
|
|---|
| 1410 | driveflags[x] &= ~DRIVE_REMOTE;
|
|---|
| 1411 | }
|
|---|
| 1412 | if (!stricmp(szFSType,NTFS))
|
|---|
| 1413 | driveflags[x] |= DRIVE_NOTWRITEABLE;
|
|---|
| 1414 | if (strcmp(szFSType, HPFS) &&
|
|---|
| 1415 | strcmp(szFSType, JFS) &&
|
|---|
| 1416 | strcmp(szFSType, ISOFS) &&
|
|---|
| 1417 | strcmp(szFSType, CDFS) &&
|
|---|
| 1418 | strcmp(szFSType, FAT32) &&
|
|---|
| 1419 | strcmp(szFSType, NDFS32) &&
|
|---|
| 1420 | strcmp(szFSType, RAMFS) &&
|
|---|
| 1421 | strcmp(szFSType, NTFS) &&
|
|---|
| 1422 | strcmp(szFSType, HPFS386)) {
|
|---|
| 1423 | driveflags[x] |= DRIVE_NOLONGNAMES;
|
|---|
| 1424 | }
|
|---|
| 1425 |
|
|---|
| 1426 | if (!strcmp(szFSType, CDFS) || !strcmp(szFSType,ISOFS)) {
|
|---|
| 1427 | removable = 1;
|
|---|
| 1428 | driveflags[x] |= DRIVE_REMOVABLE | DRIVE_NOTWRITEABLE | DRIVE_CDROM;
|
|---|
| 1429 | }
|
|---|
| 1430 | if (!stricmp(szFSType, CBSIFS)) {
|
|---|
| 1431 | driveflags[x] |= DRIVE_ZIPSTREAM;
|
|---|
| 1432 | driveflags[x] &= ~DRIVE_REMOTE;
|
|---|
| 1433 | if (ulDriveType & DRIVE_REMOVABLE)
|
|---|
| 1434 | driveflags[x] |= DRIVE_REMOVABLE;
|
|---|
| 1435 | if (!(ulDriveType & DRIVE_NOLONGNAMES))
|
|---|
| 1436 | driveflags[x] &= ~DRIVE_NOLONGNAMES;
|
|---|
| 1437 | }
|
|---|
| 1438 | if (!fVerifyOffChecked[x]) {
|
|---|
| 1439 | if (driveflags[x] & DRIVE_REMOVABLE)
|
|---|
| 1440 | driveflags[x] |= DRIVE_WRITEVERIFYOFF;
|
|---|
| 1441 | if (!(driveflags[x] & DRIVE_INVALID)) {
|
|---|
| 1442 | CHAR Key[80];
|
|---|
| 1443 |
|
|---|
| 1444 | sprintf(Key, "%c.VerifyOffChecked", (CHAR) (x + 'A'));
|
|---|
| 1445 | fVerifyOffChecked[x] = TRUE;
|
|---|
| 1446 | PrfWriteProfileData(fmprof, appname, Key, &fVerifyOffChecked[x], sizeof(BOOL));
|
|---|
| 1447 | }
|
|---|
| 1448 | }
|
|---|
| 1449 | pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
|
|---|
| 1450 | if ((ULONG)(toupper(*szDrive) - '@') == ulCurDriveNum)
|
|---|
| 1451 | pci->rc.flRecordAttr |= (CRA_CURSORED | CRA_SELECTED);
|
|---|
| 1452 |
|
|---|
| 1453 | if (removable == 0) {
|
|---|
| 1454 | // Fixed volume
|
|---|
| 1455 | pci->attrFile |= FILE_DIRECTORY;
|
|---|
| 1456 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 1457 | rc = DosQueryPathInfo(szDrive,
|
|---|
| 1458 | FIL_QUERYEASIZEL,
|
|---|
| 1459 | &fsa4, (ULONG) sizeof(FILESTATUS4L));
|
|---|
| 1460 | // ERROR_BAD_NET_RSP = 58
|
|---|
| 1461 | if (rc == 58) {
|
|---|
| 1462 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 1463 | rc = DosQueryPathInfo(szDrive,
|
|---|
| 1464 | FIL_STANDARDL,
|
|---|
| 1465 | &fsa4, (ULONG) sizeof(FILESTATUS4L));
|
|---|
| 1466 | fsa4.cbList = 0;
|
|---|
| 1467 | }
|
|---|
| 1468 | if (rc && !didonce) {
|
|---|
| 1469 | // Guess drive letter
|
|---|
| 1470 | if (!*suggest) {
|
|---|
| 1471 | *suggest = '/';
|
|---|
| 1472 | suggest[1] = 0;
|
|---|
| 1473 | }
|
|---|
| 1474 | sprintf(suggest + strlen(suggest), "%c" , toupper(*szDrive));
|
|---|
| 1475 | pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
|
|---|
| 1476 | pci->pszDisplayName = pci->pszFileName;
|
|---|
| 1477 | pci->rc.pszIcon = pci->pszDisplayName;
|
|---|
| 1478 | pci->attrFile = FILE_DIRECTORY;
|
|---|
| 1479 | pci->pszDispAttr = FileAttrToString(pci->attrFile);
|
|---|
| 1480 | driveserial[x] = -1;
|
|---|
| 1481 | }
|
|---|
| 1482 | else
|
|---|
| 1483 | FillInRecordFromFSA(hwndCnr, pci, szDrive, &fsa4, TRUE, NULL);
|
|---|
| 1484 | }
|
|---|
| 1485 | else {
|
|---|
| 1486 | // Removable volume
|
|---|
| 1487 | pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
|
|---|
| 1488 | pci->pszDisplayName = pci->pszFileName;
|
|---|
| 1489 | pci->rc.pszIcon = pci->pszDisplayName;
|
|---|
| 1490 | pci->attrFile = FILE_DIRECTORY;
|
|---|
| 1491 | pci->pszDispAttr = FileAttrToString(pci->attrFile);
|
|---|
| 1492 | }
|
|---|
| 1493 | SelectDriveIcon(pci);
|
|---|
| 1494 | # ifdef FORTIFY
|
|---|
| 1495 | // Will be freed by TreeCnrWndProc WM_DESTROY
|
|---|
| 1496 | Fortify_SetScope(pci->pszFileName, 2);
|
|---|
| 1497 | # endif
|
|---|
| 1498 | }
|
|---|
| 1499 | else {
|
|---|
| 1500 | pci->rc.hptrIcon = hptrDunno;
|
|---|
| 1501 | pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
|
|---|
| 1502 | # ifdef FORTIFY
|
|---|
| 1503 | // Will be freed by TreeCnrWndProc WM_DESTROY
|
|---|
| 1504 | Fortify_SetScope(pci->pszFileName, 2);
|
|---|
| 1505 | # endif
|
|---|
| 1506 | pci->pszDisplayName = pci->pszFileName;
|
|---|
| 1507 | pci->rc.pszIcon = pci->pszFileName;
|
|---|
| 1508 | pci->attrFile = FILE_DIRECTORY;
|
|---|
| 1509 | pci->pszDispAttr = FileAttrToString(pci->attrFile);
|
|---|
| 1510 | driveserial[x] = -1;
|
|---|
| 1511 | }
|
|---|
| 1512 | }
|
|---|
| 1513 | else {
|
|---|
| 1514 | // diskette drive (A or B)
|
|---|
| 1515 | pci->rc.hptrIcon = hptrFloppy;
|
|---|
| 1516 | pci->pszFileName = xstrdup(szDrive, pszSrcFile, __LINE__);
|
|---|
| 1517 | pci->pszDisplayName = pci->pszFileName;
|
|---|
| 1518 | pci->rc.pszIcon = pci->pszDisplayName;
|
|---|
| 1519 | pci->attrFile = FILE_DIRECTORY;
|
|---|
| 1520 | pci->pszDispAttr = FileAttrToString(pci->attrFile);
|
|---|
| 1521 | driveflags[x] |= (DRIVE_REMOVABLE | DRIVE_NOLONGNAMES);
|
|---|
| 1522 | driveserial[x] = -1;
|
|---|
| 1523 | }
|
|---|
| 1524 | pci->rc.flRecordAttr |= CRA_RECORDREADONLY;
|
|---|
| 1525 | pci = (PCNRITEM) pci->rc.preccNextRecord; // next rec
|
|---|
| 1526 | }
|
|---|
| 1527 | else if (!(ulDriveMap & (1L << x)))
|
|---|
| 1528 | driveflags[x] |= DRIVE_INVALID;
|
|---|
| 1529 | } // for drives
|
|---|
| 1530 |
|
|---|
| 1531 | PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
|
|---|
| 1532 | drivesbuilt = TRUE;
|
|---|
| 1533 |
|
|---|
| 1534 | // insert the drives
|
|---|
| 1535 | if (numtoinsert && pciFirst) {
|
|---|
| 1536 | RECORDINSERT ri;
|
|---|
| 1537 |
|
|---|
| 1538 | memset(&ri, 0, sizeof(RECORDINSERT));
|
|---|
| 1539 | ri.cb = sizeof(RECORDINSERT);
|
|---|
| 1540 | ri.pRecordOrder = (PRECORDCORE) CMA_END;
|
|---|
| 1541 | ri.pRecordParent = (PRECORDCORE) NULL;
|
|---|
| 1542 | ri.zOrder = (ULONG) CMA_TOP;
|
|---|
| 1543 | ri.cRecordsInsert = numtoinsert;
|
|---|
| 1544 | ri.fInvalidateRecord = FALSE;
|
|---|
| 1545 | if (!WinSendMsg(hwndCnr,
|
|---|
| 1546 | CM_INSERTRECORD, MPFROMP(pciFirst), MPFROMP(&ri)))
|
|---|
| 1547 | {
|
|---|
| 1548 | Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
|
|---|
| 1549 | GetPString(IDS_CMINSERTERRTEXT));
|
|---|
| 1550 | }
|
|---|
| 1551 | }
|
|---|
| 1552 |
|
|---|
| 1553 | // move cursor onto the default drive rather than the first drive
|
|---|
| 1554 | if (!fSwitchTree) {
|
|---|
| 1555 | pci = (PCNRITEM) WinSendMsg(hwndCnr,
|
|---|
| 1556 | CM_QUERYRECORD,
|
|---|
| 1557 | MPVOID,
|
|---|
| 1558 | MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
|
|---|
| 1559 | while (pci && (INT)pci != -1) {
|
|---|
| 1560 | if ((ULONG) (toupper(*pci->pszFileName) - '@') == ulCurDriveNum) {
|
|---|
| 1561 | WinSendMsg(hwndCnr,
|
|---|
| 1562 | CM_SETRECORDEMPHASIS,
|
|---|
| 1563 | MPFROMP(pci), MPFROM2SHORT(TRUE, CRA_CURSORED));
|
|---|
| 1564 | break;
|
|---|
| 1565 | }
|
|---|
| 1566 | pci = (PCNRITEM) WinSendMsg(hwndCnr,
|
|---|
| 1567 | CM_QUERYRECORD,
|
|---|
| 1568 | MPFROMP(pci),
|
|---|
| 1569 | MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
|
|---|
| 1570 | }
|
|---|
| 1571 | }
|
|---|
| 1572 |
|
|---|
| 1573 | if (hwndParent) {
|
|---|
| 1574 | WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
|
|---|
| 1575 | MAIN_DRIVELIST),
|
|---|
| 1576 | LM_DELETEALL, MPVOID, MPVOID);
|
|---|
| 1577 | }
|
|---|
| 1578 |
|
|---|
| 1579 | if (fShowEnv) {
|
|---|
| 1580 | RECORDINSERT ri;
|
|---|
| 1581 |
|
|---|
| 1582 | pciParent = WinSendMsg(hwndCnr,
|
|---|
| 1583 | CM_ALLOCRECORD,
|
|---|
| 1584 | MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(1));
|
|---|
| 1585 | if (pciParent) {
|
|---|
| 1586 | pciParent->flags |= RECFLAGS_ENV;
|
|---|
| 1587 | pciParent->pszFileName = xstrdup(GetPString(IDS_ENVVARSTEXT), pszSrcFile, __LINE__);
|
|---|
| 1588 | pciParent->pszDisplayName = pciParent->pszFileName; // 03 Aug 07 SHL
|
|---|
| 1589 | pciParent->rc.hptrIcon = hptrEnv;
|
|---|
| 1590 | pciParent->rc.pszIcon = pciParent->pszFileName;
|
|---|
| 1591 | pciParent->pszDispAttr = FileAttrToString(0);
|
|---|
| 1592 | memset(&ri, 0, sizeof(RECORDINSERT));
|
|---|
| 1593 | ri.cb = sizeof(RECORDINSERT);
|
|---|
| 1594 | ri.pRecordOrder = (PRECORDCORE) CMA_END;
|
|---|
| 1595 | ri.pRecordParent = (PRECORDCORE) NULL;
|
|---|
| 1596 | ri.zOrder = (ULONG) CMA_TOP;
|
|---|
| 1597 | ri.cRecordsInsert = 1;
|
|---|
| 1598 | ri.fInvalidateRecord = FALSE;
|
|---|
| 1599 | if (WinSendMsg(hwndCnr,
|
|---|
| 1600 | CM_INSERTRECORD, MPFROMP(pciParent), MPFROMP(&ri))) {
|
|---|
| 1601 |
|
|---|
| 1602 | char *p, *pp;
|
|---|
| 1603 |
|
|---|
| 1604 | p = pszTreeEnvVarList;
|
|---|
| 1605 | while (*p == ';')
|
|---|
| 1606 | p++;
|
|---|
| 1607 | while (*p) {
|
|---|
| 1608 | *szFSType = 0;
|
|---|
| 1609 | pp = szFSType;
|
|---|
| 1610 | while (*p && *p != ';')
|
|---|
| 1611 | *pp++ = *p++;
|
|---|
| 1612 | *pp = 0;
|
|---|
| 1613 | while (*p == ';')
|
|---|
| 1614 | p++;
|
|---|
| 1615 | if (*szFSType &&
|
|---|
| 1616 | (!stricmp(szFSType, PCSZ_LIBPATH) || getenv(szFSType))) {
|
|---|
| 1617 | pci = WinSendMsg(hwndCnr,
|
|---|
| 1618 | CM_ALLOCRECORD,
|
|---|
| 1619 | MPFROMLONG(EXTRA_RECORD_BYTES),
|
|---|
| 1620 | MPFROMLONG(1));
|
|---|
| 1621 | if (pci) {
|
|---|
| 1622 | CHAR fname[CCHMAXPATH];
|
|---|
| 1623 | pci->flags |= RECFLAGS_ENV;
|
|---|
| 1624 | sprintf(fname, "%%%s%%", szFSType);
|
|---|
| 1625 | pci->pszFileName = xstrdup(fname, pszSrcFile, __LINE__);
|
|---|
| 1626 | pci->rc.hptrIcon = hptrEnv;
|
|---|
| 1627 | pci->rc.pszIcon = pci->pszFileName;
|
|---|
| 1628 | pci->pszDispAttr = FileAttrToString(0);
|
|---|
| 1629 | memset(&ri, 0, sizeof(RECORDINSERT));
|
|---|
| 1630 | ri.cb = sizeof(RECORDINSERT);
|
|---|
| 1631 | ri.pRecordOrder = (PRECORDCORE) CMA_END;
|
|---|
| 1632 | ri.pRecordParent = (PRECORDCORE) pciParent;
|
|---|
| 1633 | ri.zOrder = (ULONG) CMA_TOP;
|
|---|
| 1634 | ri.cRecordsInsert = 1;
|
|---|
| 1635 | ri.fInvalidateRecord = FALSE;
|
|---|
| 1636 | if (!WinSendMsg(hwndCnr,
|
|---|
| 1637 | CM_INSERTRECORD,
|
|---|
| 1638 | MPFROMP(pci), MPFROMP(&ri))) {
|
|---|
| 1639 | Win_Error(hwndCnr, HWND_DESKTOP, pszSrcFile, __LINE__,
|
|---|
| 1640 | GetPString(IDS_CMINSERTERRTEXT));
|
|---|
| 1641 | FreeCnrItem(hwndCnr, pci);
|
|---|
| 1642 | }
|
|---|
| 1643 | }
|
|---|
| 1644 | }
|
|---|
| 1645 | }
|
|---|
| 1646 | WinSendMsg(hwndCnr,
|
|---|
| 1647 | CM_INVALIDATERECORD,
|
|---|
| 1648 | MPFROMP(&pciParent),
|
|---|
| 1649 | MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
|
|---|
| 1650 | }
|
|---|
| 1651 | else
|
|---|
| 1652 | FreeCnrItem(hwndCnr, pciParent);
|
|---|
| 1653 | }
|
|---|
| 1654 | } // if show env
|
|---|
| 1655 | {
|
|---|
| 1656 | STUBBYSCAN *stubbyScan;
|
|---|
| 1657 | HWND hwndDrivesList = WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
|
|---|
| 1658 | MAIN_DRIVELIST);
|
|---|
| 1659 |
|
|---|
| 1660 | pci = (PCNRITEM) WinSendMsg(hwndCnr,
|
|---|
| 1661 | CM_QUERYRECORD,
|
|---|
| 1662 | MPVOID,
|
|---|
| 1663 | MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
|
|---|
| 1664 | StubbyScanCount ++;
|
|---|
| 1665 | while (pci && (INT)pci != -1) {
|
|---|
| 1666 | stubbyScan = xmallocz(sizeof(STUBBYSCAN), pszSrcFile, __LINE__);
|
|---|
| 1667 | if (!stubbyScan)
|
|---|
| 1668 | break;
|
|---|
| 1669 | stubbyScan->pci = pci;
|
|---|
| 1670 | stubbyScan->hwndCnr = hwndCnr;
|
|---|
| 1671 | stubbyScan->hwndDrivesList = hwndDrivesList;
|
|---|
| 1672 | stubbyScan->RamDrive = FALSE;
|
|---|
| 1673 | pciNext = (PCNRITEM) WinSendMsg(hwndCnr,
|
|---|
| 1674 | CM_QUERYRECORD,
|
|---|
| 1675 | MPFROMP(pci),
|
|---|
| 1676 | MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
|
|---|
| 1677 | if (~pci->flags & RECFLAGS_ENV) {
|
|---|
| 1678 | ULONG drvNum = toupper(*pci->pszFileName) - 'A'; // 0..25
|
|---|
| 1679 | if (drvNum == ulCurDriveNum || drvNum >= 2) {
|
|---|
| 1680 | ULONG flags = driveflags[drvNum]; // Speed up
|
|---|
| 1681 | if (~flags & DRIVE_INVALID &&
|
|---|
| 1682 | ~flags & DRIVE_NOPRESCAN &&
|
|---|
| 1683 | (!fNoRemovableScan || ~flags & DRIVE_REMOVABLE)) //&& !fDrivetoSkip[drvNum])
|
|---|
| 1684 | {
|
|---|
| 1685 | if (DRIVE_RAMDISK)
|
|---|
| 1686 | stubbyScan->RamDrive = TRUE;
|
|---|
| 1687 | if (xbeginthread(StubbyScanThread,
|
|---|
| 1688 | 65536,
|
|---|
| 1689 | stubbyScan,
|
|---|
| 1690 | pszSrcFile,
|
|---|
| 1691 | __LINE__) == -1)
|
|---|
| 1692 | {
|
|---|
| 1693 | xfree(stubbyScan, pszSrcFile, __LINE__);
|
|---|
| 1694 | }
|
|---|
| 1695 | } // if drive for scanning
|
|---|
| 1696 | else
|
|---|
| 1697 | WinSendMsg(hwndDrivesList,
|
|---|
| 1698 | LM_INSERTITEM,
|
|---|
| 1699 | MPFROM2SHORT(LIT_SORTASCENDING, 0),
|
|---|
| 1700 | MPFROMP(pci->pszFileName));
|
|---|
| 1701 | }
|
|---|
| 1702 | else {
|
|---|
| 1703 | WinSendMsg(hwndCnr,
|
|---|
| 1704 | CM_INVALIDATERECORD,
|
|---|
| 1705 | MPFROMP(&pci),
|
|---|
| 1706 | MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
|
|---|
| 1707 | WinSendMsg(hwndDrivesList,
|
|---|
| 1708 | LM_INSERTITEM,
|
|---|
| 1709 | MPFROM2SHORT(LIT_SORTASCENDING, 0),
|
|---|
| 1710 | MPFROMP(pci->pszFileName));
|
|---|
| 1711 | }
|
|---|
| 1712 | //fDrivetoSkip[drvNum] = FALSE;
|
|---|
| 1713 | }
|
|---|
| 1714 | pci = pciNext;
|
|---|
| 1715 | } // while
|
|---|
| 1716 | StubbyScanCount--;
|
|---|
| 1717 | }
|
|---|
| 1718 | if (hwndParent)
|
|---|
| 1719 | WinSendMsg(WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
|
|---|
| 1720 | MAIN_DRIVELIST), LM_SELECTITEM,
|
|---|
| 1721 | MPFROM2SHORT(0, 0), MPFROMLONG(TRUE));
|
|---|
| 1722 |
|
|---|
| 1723 | pci = (PCNRITEM) WinSendMsg(hwndCnr,
|
|---|
| 1724 | CM_QUERYRECORD,
|
|---|
| 1725 | MPVOID,
|
|---|
| 1726 | MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
|
|---|
| 1727 | while (pci && (INT)pci != -1) {
|
|---|
| 1728 | pciNext = (PCNRITEM) WinSendMsg(hwndCnr,
|
|---|
| 1729 | CM_QUERYRECORD,
|
|---|
| 1730 | MPFROMP(pci),
|
|---|
| 1731 | MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
|
|---|
| 1732 | if (pci->flags & RECFLAGS_ENV) {
|
|---|
| 1733 | pci = (PCNRITEM) WinSendMsg(hwndCnr,
|
|---|
| 1734 | CM_QUERYRECORD,
|
|---|
| 1735 | MPFROMP(pci),
|
|---|
| 1736 | MPFROM2SHORT(CMA_FIRSTCHILD,
|
|---|
| 1737 | CMA_ITEMORDER));
|
|---|
| 1738 | while (pci && (INT)pci != -1) {
|
|---|
| 1739 | if (pci->flags & RECFLAGS_ENV)
|
|---|
| 1740 | FleshEnv(hwndCnr, pci);
|
|---|
| 1741 | pci = (PCNRITEM) WinSendMsg(hwndCnr,
|
|---|
| 1742 | CM_QUERYRECORD,
|
|---|
| 1743 | MPFROMP(pci),
|
|---|
| 1744 | MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
|
|---|
| 1745 | }
|
|---|
| 1746 | break;
|
|---|
| 1747 | }
|
|---|
| 1748 | pci = (PCNRITEM) WinSendMsg(hwndCnr,
|
|---|
| 1749 | CM_QUERYRECORD,
|
|---|
| 1750 | MPFROMP(pci),
|
|---|
| 1751 | MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
|
|---|
| 1752 | }
|
|---|
| 1753 |
|
|---|
| 1754 | if (!drivesbuilt && hwndMain)
|
|---|
| 1755 | PostMsg(hwndMain, UM_BUILDDRIVEBAR, MPVOID, MPVOID);
|
|---|
| 1756 | DosSleep(16); // 05 Aug 07 GKY 33
|
|---|
| 1757 | fDummy = FALSE;
|
|---|
| 1758 | DosPostEventSem(CompactSem);
|
|---|
| 1759 |
|
|---|
| 1760 | {
|
|---|
| 1761 | BYTE info;
|
|---|
| 1762 | BOOL includesyours = FALSE;
|
|---|
| 1763 |
|
|---|
| 1764 | // 10 Jan 08 SHL fixme to understand fFirstTime
|
|---|
| 1765 | if (*suggest || (!(driveflags[1] & DRIVE_IGNORE) && fFirstTime)) {
|
|---|
| 1766 | if (!DosDevConfig(&info, DEVINFO_FLOPPY) && info == 1) {
|
|---|
| 1767 | if (!*suggest) {
|
|---|
| 1768 | *suggest = '/';
|
|---|
| 1769 | suggest[1] = 0;
|
|---|
| 1770 | }
|
|---|
| 1771 | else
|
|---|
| 1772 | memmove(suggest + 2, suggest + 1, strlen(suggest));
|
|---|
| 1773 | suggest[1] = 'B';
|
|---|
| 1774 | }
|
|---|
| 1775 | }
|
|---|
| 1776 | if (*suggest) {
|
|---|
| 1777 | for (x = 2; x < 26; x++) {
|
|---|
| 1778 | if (driveflags[x] & DRIVE_IGNORE) {
|
|---|
| 1779 | includesyours = TRUE;
|
|---|
| 1780 | sprintf(suggest + strlen(suggest), "%c", (char)(x + 'A'));
|
|---|
| 1781 | }
|
|---|
| 1782 | }
|
|---|
| 1783 | strcat(suggest, " %*");
|
|---|
| 1784 | if (saymsg(MB_YESNO | MB_ICONEXCLAMATION,
|
|---|
| 1785 | (hwndParent) ? hwndParent : hwndCnr,
|
|---|
| 1786 | GetPString(IDS_SUGGESTTITLETEXT),
|
|---|
| 1787 | GetPString(IDS_SUGGEST1TEXT),
|
|---|
| 1788 | (includesyours) ? GetPString(IDS_SUGGEST2TEXT) : NullStr,
|
|---|
| 1789 | suggest) == MBID_YES) {
|
|---|
| 1790 | char s[64];
|
|---|
| 1791 |
|
|---|
| 1792 | sprintf(s, "PARAMETERS=%s", suggest);
|
|---|
| 1793 | WinCreateObject(WPProgram, "FM/2", s, FM3Folder, CO_UPDATEIFEXISTS);
|
|---|
| 1794 | WinCreateObject(WPProgram,
|
|---|
| 1795 | "FM/2 Lite", s, FM3Folder, CO_UPDATEIFEXISTS);
|
|---|
| 1796 | WinCreateObject(WPProgram,
|
|---|
| 1797 | "Archive Viewer/2", s, FM3Tools, CO_UPDATEIFEXISTS);
|
|---|
| 1798 | WinCreateObject(WPProgram,
|
|---|
| 1799 | "Dir Sizes", s, FM3Tools, CO_UPDATEIFEXISTS);
|
|---|
| 1800 | WinCreateObject(WPProgram,
|
|---|
| 1801 | "Visual Tree", s, FM3Tools, CO_UPDATEIFEXISTS);
|
|---|
| 1802 | WinCreateObject(WPProgram,
|
|---|
| 1803 | "Visual Directory", s, FM3Tools, CO_UPDATEIFEXISTS);
|
|---|
| 1804 | WinCreateObject(WPProgram,
|
|---|
| 1805 | "Global File Viewer", s, FM3Tools, CO_UPDATEIFEXISTS);
|
|---|
| 1806 | WinCreateObject(WPProgram, "Databar", s, FM3Tools, CO_UPDATEIFEXISTS);
|
|---|
| 1807 | }
|
|---|
| 1808 | }
|
|---|
| 1809 | }
|
|---|
| 1810 | didonce = TRUE;
|
|---|
| 1811 | if (fInitialDriveScan) {
|
|---|
| 1812 | HWND hwndDrivesList = WinWindowFromID(WinQueryWindow(hwndParent, QW_PARENT),
|
|---|
| 1813 | MAIN_DRIVELIST);
|
|---|
| 1814 | while (StubbyScanCount != 0 || ProcessDirCount != 0)
|
|---|
| 1815 | DosSleep(50);
|
|---|
| 1816 | WinShowWindow(hwndCnr, TRUE);
|
|---|
| 1817 | WinShowWindow(hwndDrivesList, TRUE);
|
|---|
| 1818 | fInitialDriveScan = FALSE;
|
|---|
| 1819 | }
|
|---|
| 1820 | } // FillTreeCnr
|
|---|
| 1821 |
|
|---|
| 1822 |
|
|---|
| 1823 | /**
|
|---|
| 1824 | * Empty all records from a container and free associated storage and
|
|---|
| 1825 | * Free up field infos
|
|---|
| 1826 | */
|
|---|
| 1827 |
|
|---|
| 1828 | VOID EmptyCnr(HWND hwnd)
|
|---|
| 1829 | {
|
|---|
| 1830 | PFIELDINFO pfi;
|
|---|
| 1831 |
|
|---|
| 1832 | #if 0 // fixme to be gone or to be configurable
|
|---|
| 1833 | {
|
|---|
| 1834 | int state = _heapchk();
|
|---|
| 1835 | if (state != _HEAPOK)
|
|---|
| 1836 | Runtime_Error(pszSrcFile, __LINE__, "heap corrupted %d", state);
|
|---|
| 1837 | }
|
|---|
| 1838 | #endif
|
|---|
| 1839 |
|
|---|
| 1840 | // Remove all records
|
|---|
| 1841 | RemoveCnrItems(hwnd, NULL, 0, CMA_FREE);
|
|---|
| 1842 |
|
|---|
| 1843 | // Remove field info descriptors
|
|---|
| 1844 | pfi = (PFIELDINFO) WinSendMsg(hwnd, CM_QUERYDETAILFIELDINFO, MPVOID,
|
|---|
| 1845 | MPFROMSHORT(CMA_FIRST));
|
|---|
| 1846 | if (pfi &&
|
|---|
| 1847 | (INT)WinSendMsg(hwnd, CM_REMOVEDETAILFIELDINFO, MPVOID,
|
|---|
| 1848 | MPFROM2SHORT(0, CMA_FREE)) == -1) {
|
|---|
| 1849 | Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_REMOVEDETAILFIELDINFO hwnd %x", hwnd);
|
|---|
| 1850 | }
|
|---|
| 1851 | }
|
|---|
| 1852 |
|
|---|
| 1853 | /**
|
|---|
| 1854 | * Free storage associated with container item
|
|---|
| 1855 | */
|
|---|
| 1856 |
|
|---|
| 1857 | VOID FreeCnrItemData(PCNRITEM pci)
|
|---|
| 1858 | {
|
|---|
| 1859 | if (pci->pszSubject) {
|
|---|
| 1860 | if (pci->pszSubject != NullStr)
|
|---|
| 1861 | free(pci->pszSubject);
|
|---|
| 1862 | pci->pszSubject = NULL; // Catch illegal references
|
|---|
| 1863 | }
|
|---|
| 1864 |
|
|---|
| 1865 | // 08 Sep 08 SHL Remove excess logic
|
|---|
| 1866 | if (pci->pszLongName) {
|
|---|
| 1867 | if (pci->pszLongName != NullStr)
|
|---|
| 1868 | free(pci->pszLongName);
|
|---|
| 1869 | pci->pszLongName = NULL; // Catch illegal references
|
|---|
| 1870 | }
|
|---|
| 1871 |
|
|---|
| 1872 | // Bypass free if pszDisplayName points into pszFileName buffer
|
|---|
| 1873 | // 05 Sep 08 SHL Correct pointer overlap compare logic
|
|---|
| 1874 | if (pci->pszDisplayName) {
|
|---|
| 1875 | if (pci->pszDisplayName != NullStr) {
|
|---|
| 1876 | if (!pci->pszFileName ||
|
|---|
| 1877 | pci->pszDisplayName < pci->pszFileName ||
|
|---|
| 1878 | pci->pszDisplayName >= pci->pszFileName + _msize(pci->pszFileName))
|
|---|
| 1879 | {
|
|---|
| 1880 | free(pci->pszDisplayName);
|
|---|
| 1881 | }
|
|---|
| 1882 | }
|
|---|
| 1883 | pci->pszDisplayName = NULL; // Catch illegal references
|
|---|
| 1884 | }
|
|---|
| 1885 |
|
|---|
| 1886 | if (!pci->pszFileName)
|
|---|
| 1887 | Runtime_Error(pszSrcFile, __LINE__, "FreeCnrItemData attempting free %p data twice", pci);
|
|---|
| 1888 | else {
|
|---|
| 1889 | if (pci->pszFileName != NullStr)
|
|---|
| 1890 | free(pci->pszFileName);
|
|---|
| 1891 | pci->pszFileName = NULL; // Catch illegal references
|
|---|
| 1892 | }
|
|---|
| 1893 |
|
|---|
| 1894 | // 08 Sep 08 SHL Remove excess logic
|
|---|
| 1895 | if (pci->pszLongName) {
|
|---|
| 1896 | if (pci->pszLongName != NullStr)
|
|---|
| 1897 | free(pci->pszLongName);
|
|---|
| 1898 | pci->pszLongName = NULL; // Catch illegal references
|
|---|
| 1899 | }
|
|---|
| 1900 |
|
|---|
| 1901 | if (pci->pszFmtFileSize) {
|
|---|
| 1902 | if (pci->pszFmtFileSize != NullStr)
|
|---|
| 1903 | free(pci->pszFmtFileSize);
|
|---|
| 1904 | pci->pszFmtFileSize = NULL; // Catch illegal references
|
|---|
| 1905 | }
|
|---|
| 1906 | }
|
|---|
| 1907 |
|
|---|
| 1908 | /**
|
|---|
| 1909 | * Free single container item and associated storage
|
|---|
| 1910 | */
|
|---|
| 1911 |
|
|---|
| 1912 | VOID FreeCnrItem(HWND hwnd, PCNRITEM pci)
|
|---|
| 1913 | {
|
|---|
| 1914 | // DbgMsg(pszSrcFile, __LINE__, "FreeCnrItem hwnd %x pci %p", hwnd, pci);
|
|---|
| 1915 |
|
|---|
| 1916 | FreeCnrItemData(pci);
|
|---|
| 1917 |
|
|---|
| 1918 | if (!WinSendMsg(hwnd, CM_FREERECORD, MPFROMP(&pci), MPFROMSHORT(1))) {
|
|---|
| 1919 | Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,
|
|---|
| 1920 | "CM_FREERECORD hwnd %x pci %p file %s",
|
|---|
| 1921 | hwnd, pci,
|
|---|
| 1922 | pci && pci->pszFileName ? pci->pszFileName : "n/a");
|
|---|
| 1923 | }
|
|---|
| 1924 | }
|
|---|
| 1925 |
|
|---|
| 1926 | /**
|
|---|
| 1927 | * Free container item list and associated storage
|
|---|
| 1928 | */
|
|---|
| 1929 |
|
|---|
| 1930 | VOID FreeCnrItemList(HWND hwnd, PCNRITEM pciFirst)
|
|---|
| 1931 | {
|
|---|
| 1932 | PCNRITEM pci = pciFirst;
|
|---|
| 1933 | PCNRITEM pciNext;
|
|---|
| 1934 | USHORT usCount;
|
|---|
| 1935 |
|
|---|
| 1936 | for (usCount = 0; pci; usCount++) {
|
|---|
| 1937 | pciNext = (PCNRITEM) pci->rc.preccNextRecord;
|
|---|
| 1938 | FreeCnrItemData(pci);
|
|---|
| 1939 | pci = pciNext;
|
|---|
| 1940 | }
|
|---|
| 1941 |
|
|---|
| 1942 | if (usCount) {
|
|---|
| 1943 | if (!WinSendMsg(hwnd, CM_FREERECORD, MPFROMP(&pci), MPFROMSHORT(usCount))) {
|
|---|
| 1944 | Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_FREERECORD hwnd %x pci %p cnt %u", hwnd, pci, usCount);
|
|---|
| 1945 | }
|
|---|
| 1946 | }
|
|---|
| 1947 | }
|
|---|
| 1948 |
|
|---|
| 1949 | /**
|
|---|
| 1950 | * Remove item(s) from container and free associated storage if requested
|
|---|
| 1951 | * @param pciFirst points to first item to remove or NULL to remove all
|
|---|
| 1952 | * @param usCnt is remove count or 0 to remove all
|
|---|
| 1953 | * @returns count of items remaining in container or -1 if error
|
|---|
| 1954 | */
|
|---|
| 1955 |
|
|---|
| 1956 | INT RemoveCnrItems(HWND hwnd, PCNRITEM pciFirst, USHORT usCnt, USHORT usFlags)
|
|---|
| 1957 | {
|
|---|
| 1958 | INT remaining = usCnt;
|
|---|
| 1959 | PCNRITEM pci;
|
|---|
| 1960 |
|
|---|
| 1961 | if ((usCnt && !pciFirst) || (!usCnt && pciFirst)) {
|
|---|
| 1962 | Runtime_Error(pszSrcFile, __LINE__, "pciFirst %p usCnt %u mismatch", pciFirst, usCnt);
|
|---|
| 1963 | remaining = -1;
|
|---|
| 1964 | }
|
|---|
| 1965 | else {
|
|---|
| 1966 | // Free our buffers if free requested
|
|---|
| 1967 | if (usFlags & CMA_FREE) {
|
|---|
| 1968 | if (pciFirst)
|
|---|
| 1969 | pci = pciFirst;
|
|---|
| 1970 | else {
|
|---|
| 1971 | pci = (PCNRITEM)WinSendMsg(hwnd, CM_QUERYRECORD, MPVOID,
|
|---|
| 1972 | MPFROM2SHORT(CMA_FIRST, CMA_ITEMORDER));
|
|---|
| 1973 | if ((INT)pci == -1) {
|
|---|
| 1974 | Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_QUERYRECORD");
|
|---|
| 1975 | remaining = -1;
|
|---|
| 1976 | pci = NULL;
|
|---|
| 1977 | }
|
|---|
| 1978 | }
|
|---|
| 1979 | while (pci) {
|
|---|
| 1980 | // 12 Sep 07 SHL dwg drivebar crash testing - ticket# ???
|
|---|
| 1981 | static PCNRITEM pciLast; // 12 Sep 07 SHL
|
|---|
| 1982 | ULONG ulSize = sizeof(*pci);
|
|---|
| 1983 | ULONG ulAttr;
|
|---|
| 1984 | APIRET apiret = DosQueryMem((PVOID)pci, &ulSize, &ulAttr);
|
|---|
| 1985 | if (apiret)
|
|---|
| 1986 | Dos_Error(MB_ENTER, apiret, HWND_DESKTOP, pszSrcFile, __LINE__,
|
|---|
| 1987 | "DosQueryMem failed pci %p pciLast %p", pci, pciLast);
|
|---|
| 1988 | FreeCnrItemData(pci);
|
|---|
| 1989 | pciLast = pci;
|
|---|
| 1990 | pci = (PCNRITEM)pci->rc.preccNextRecord;
|
|---|
| 1991 | if (remaining && --remaining == 0)
|
|---|
| 1992 | break;
|
|---|
| 1993 | }
|
|---|
| 1994 | }
|
|---|
| 1995 | }
|
|---|
| 1996 |
|
|---|
| 1997 | // DbgMsg(pszSrcFile, __LINE__, "RemoveCnrItems %p %u %s", pci, usCnt, pci->pszFileName);
|
|---|
| 1998 |
|
|---|
| 1999 | if (remaining != - 1) {
|
|---|
| 2000 | remaining = (INT)WinSendMsg(hwnd, CM_REMOVERECORD, MPFROMP(&pciFirst), MPFROM2SHORT(usCnt, usFlags));
|
|---|
| 2001 | if (remaining == -1) {
|
|---|
| 2002 | Win_Error(hwnd, HWND_DESKTOP, pszSrcFile, __LINE__,"CM_REMOVERECORD hwnd %x pci %p cnt %u", hwnd, pciFirst, usCnt);
|
|---|
| 2003 | }
|
|---|
| 2004 | }
|
|---|
| 2005 |
|
|---|
| 2006 | return remaining;
|
|---|
| 2007 | }
|
|---|
| 2008 |
|
|---|
| 2009 | #pragma alloc_text(FILLDIR,FillInRecordFromFFB,FillInRecordFromFSA,IDFile)
|
|---|
| 2010 | #pragma alloc_text(FILLDIR1,ProcessDirectory,FillDirCnr,FillTreeCnr,FileAttrToString,StubbyScanThread)
|
|---|
| 2011 | #pragma alloc_text(EMPTYCNR,EmptyCnr,FreeCnrItemData,FreeCnrItem,FreeCnrItemList,RemoveCnrItems)
|
|---|
| 2012 |
|
|---|