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