source: trunk/dll/flesh.c@ 1651

Last change on this file since 1651 was 1651, checked in by Gregg Young, 14 years ago

Reverted part of the changes as they caused dbl entries

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 14.2 KB
Line 
1
2/***********************************************************************
3
4 $Id: flesh.c 1651 2011-11-19 22:15:55Z gyoung $
5
6 Flesh
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2005, 2010 Steven H. Levine
10
11 24 May 05 SHL Rework Win_Error usage
12 25 May 05 SHL Rework for ProcessDirectory
13 28 May 05 SHL Clean while reading code
14 24 Oct 05 SHL Delete obsolete code
15 22 Jul 06 SHL Check more run time errors
16 19 Oct 06 SHL Stubby - correct . and .. detect
17 22 Mar 07 GKY Use QWL_USER
18 01 Aug 07 SHL Sync with CNRITEM mods
19 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
20 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
21 29 Feb 08 GKY Use xfree where appropriate
22 24 Nov 08 GKY remove redundant code and minor speed up of Stubby
23 25 Dec 08 GKY Add ProcessDirectoryThread to allow optional recursive drive scan at startup.
24 25 Dec 08 GKY Add DRIVE_RSCANNED flag to monitor for the first recursive drive scan per session
25 to prevent duplicate directory names in tree following a copy before initial scan.
26 08 Mar 09 GKY Additional strings move to PCSZs in init.c
27 13 Dec 09 GKY Fixed separate paramenters. Please note that appname should be used in
28 profile calls for user settings that work and are setable in more than one
29 miniapp; FM3Str should be used for setting only relavent to FM/2 or that
30 aren't user settable; realappname should be used for setting applicable to
31 one or more miniapp but not to FM/2
32 17 JAN 10 GKY Changes to get working with Watcom 1.9 Beta (1/16/10). Mostly cast CHAR CONSTANT * as CHAR *.
33
34***********************************************************************/
35
36#include <stdlib.h>
37#include <string.h>
38#include <ctype.h>
39
40#define INCL_DOS
41#define INCL_DOSERRORS
42#define INCL_WIN
43#define INCL_LONGLONG // dircnrs.h
44
45#include "fm3dll.h"
46#include "draglist.h" // Data declaration(s)
47#include "notebook.h" // Data declaration(s)
48#include "info.h" // Data declaration(s)
49#include "init.h" // Data declaration(s)
50#include "mainwnd.h" // Data declaration(s)
51#include "fm3str.h"
52#include "filldir.h" // FileAttrToString...
53#include "errutil.h" // Dos_Error...
54#include "strutil.h" // GetPString
55#include "flesh.h"
56#include "valid.h" // IsValidDir
57#include "misc.h" // LoadLibPath
58#include "findrec.h" // FindCnrRecord
59#include "notify.h" // Notify
60#include "wrappers.h" // xfree
61#include "excputil.h" // xbeginthread
62
63// Data definitions
64#pragma data_seg(DATA1)
65
66static PSZ pszSrcFile = __FILE__;
67
68#pragma data_seg(GLOBAL1)
69ULONG NoBrokenNotify;
70BOOL fFilesInTree;
71
72BOOL FleshEnv(HWND hwndCnr, PCNRITEM pciParent)
73{
74 PCNRITEM pciL;
75 DIRCNRDATA *dcd;
76 CHAR path[CCHMAXPATH + 12],
77 fullpath[CCHMAXPATH + 12], *env, *p, *pp, *var = NULL;
78
79 if (!pciParent || (INT) pciParent == -1 || !hwndCnr)
80 return FALSE;
81 dcd = (DIRCNRDATA *) WinQueryWindowPtr(hwndCnr, QWL_USER);
82 if (!dcd)
83 return FALSE;
84
85 strcpy(path, pciParent->pszFileName + 1);
86 if (stricmp(path, GetPString(IDS_ENVVARSTEXT) + 1))
87 UnFlesh(hwndCnr, pciParent);
88 if (*path) {
89 path[strlen(path) - 1] = 0;
90 if (!stricmp(path, PCSZ_LIBPATH)) {
91 var = xmalloc(65536, pszSrcFile, __LINE__);
92 if (var)
93 LoadLibPath(var, 65536);
94 env = var;
95 }
96 else
97 env = getenv(path);
98 if (env && *env) {
99 p = env;
100 while (*p) {
101 pp = path;
102 while (*p == ';')
103 p++;
104 while (*p && *p != ';') {
105 *pp = *p;
106 p++;
107 pp++;
108 }
109 *pp = 0;
110 if (*path &&
111 strcmp(path, ".") &&
112 strcmp(path, ".\\") &&
113 strcmp(path, "..") &&
114 strcmp(path, "..\\") &&
115 strncmp(path, ".\\", 2) && strncmp(path, "..\\", 3)) {
116 if (!DosQueryPathInfo(path,
117 FIL_QUERYFULLNAME,
118 fullpath,
119 sizeof(fullpath)) && IsValidDir(fullpath)) {
120 pciL = FindCnrRecord(hwndCnr,
121 fullpath, pciParent, FALSE, FALSE, FALSE);
122 if (pciL) {
123 while (pciL && pciL != (PCNRITEM) - 1 && pciL != pciParent)
124 pciL = WinSendMsg(hwndCnr,
125 CM_QUERYRECORD,
126 MPFROMP(pciL),
127 MPFROM2SHORT(CMA_PARENT, CMA_ITEMORDER));
128 }
129 if (!pciL) {
130
131 RECORDINSERT ri;
132
133 pciL = WinSendMsg(hwndCnr,
134 CM_ALLOCRECORD,
135 MPFROMLONG(EXTRA_RECORD_BYTES),
136 MPFROMLONG(1));
137 if (pciL) {
138 pciL->pszFileName = xstrdup(fullpath, pszSrcFile, __LINE__);
139 pciL->rc.pszIcon = pciL->pszFileName;
140 if (!fNoIconsDirs &&
141 (!isalpha(*fullpath) ||
142 !(driveflags[toupper(*fullpath) - 'A'] &
143 DRIVE_NOLOADICONS)))
144 pciL->rc.hptrIcon = WinLoadFileIcon(fullpath, FALSE);
145 if (!pciL->rc.hptrIcon)
146 pciL->rc.hptrIcon = hptrDir;
147 pciL->attrFile = FILE_DIRECTORY;
148 pciL->pszDispAttr = FileAttrToString(pciL->attrFile);
149 memset(&ri, 0, sizeof(ri));
150 ri.cb = sizeof(ri);
151 ri.pRecordOrder = (PRECORDCORE) CMA_END;
152 ri.pRecordParent = (PRECORDCORE) pciParent;
153 ri.zOrder = (ULONG) CMA_TOP;
154 ri.cRecordsInsert = 1;
155 ri.fInvalidateRecord = FALSE;
156 if (!WinSendMsg(hwndCnr,
157 CM_INSERTRECORD, MPFROMP(pciL), MPFROMP(&ri)))
158 FreeCnrItem(hwndCnr, pciL);
159 }
160 }
161 }
162 }
163 }
164 }
165 xfree(var, pszSrcFile, __LINE__);
166 pciL = (PCNRITEM) WinSendMsg(hwndCnr,
167 CM_QUERYRECORD,
168 MPFROMP(pciParent),
169 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
170 while (pciL && (INT) pciL != -1) {
171 pciL->flags |= (RECFLAGS_NODRAG | RECFLAGS_UNDERENV);
172 WinSendMsg(hwndCnr,
173 CM_INVALIDATERECORD, MPFROMP(&pciL), MPFROM2SHORT(1, 0));
174 pciL = WinSendMsg(hwndCnr,
175 CM_QUERYRECORD,
176 MPFROMP(pciL), MPFROM2SHORT(CMA_NEXT, CMA_ITEMORDER));
177 }
178 }
179 return TRUE;
180}
181
182BOOL Flesh(HWND hwndCnr, PCNRITEM pciParent)
183{
184 PCNRITEM pciL;
185 DIRCNRDATA *dcd;
186 BOOL includefiles = fFilesInTree;
187
188 if (!pciParent || (INT) pciParent == -1 || !hwndCnr)
189 return FALSE;
190 pciL = (PCNRITEM) WinSendMsg(hwndCnr,
191 CM_QUERYRECORD,
192 MPFROMP(pciParent),
193 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
194 if (!pciL || !*pciL->pszFileName) {
195 if (pciL && (INT) pciL != -1)
196 RemoveCnrItems(hwndCnr, pciL, 1, CMA_FREE);
197 dcd = INSTDATA(hwndCnr);
198 if (dcd && dcd->size != sizeof(DIRCNRDATA))
199 dcd = NULL;
200 if (driveflags[toupper(*pciParent->pszFileName) - 'A'] &
201 DRIVE_INCLUDEFILES)
202 includefiles = TRUE;
203 ProcessDirectory(hwndCnr,
204 pciParent,
205 pciParent->pszFileName,
206 includefiles, // filestoo
207 TRUE, // recurse
208 TRUE, // partial
209 NULL, // stop flag
210 dcd,
211 NULL, // total files
212 NULL); // total bytes
213 //}
214 }
215 driveflags[*pciParent->pszFileName - 'A'] |= DRIVE_RSCANNED;
216 return TRUE;
217}
218
219BOOL UnFlesh(HWND hwndCnr, PCNRITEM pciParent)
220{
221 BOOL ret = FALSE;
222 PCNRITEM pciL;
223
224 if (!pciParent || !hwndCnr)
225 return FALSE;
226 for (;;) {
227 pciL = (PCNRITEM) WinSendMsg(hwndCnr,
228 CM_QUERYRECORD,
229 MPFROMP(pciParent),
230 MPFROM2SHORT(CMA_FIRSTCHILD, CMA_ITEMORDER));
231 if (pciL && (INT) pciL != -1) {
232 ret = TRUE;
233 RemoveCnrItems(hwndCnr, pciL, 1, CMA_FREE);
234 }
235 else
236 break;
237 }
238 if (ret) {
239 WinSendMsg(hwndCnr,
240 CM_INVALIDATERECORD,
241 MPFROMP(&pciParent),
242 MPFROM2SHORT(1, CMA_ERASE | CMA_REPOSITION));
243 }
244 return ret;
245}
246
247#define DDEPTH 64
248
249/**
250 * Fill in drive tree subtree
251 * @return TRUE if OK, else FALSE
252 * This only scans the root directory and adds the first level directories
253 * Flesh does a recursive scan and should be used on fast hardware.
254 */
255
256BOOL Stubby(HWND hwndCnr, PCNRITEM pciParent)
257{
258 /**
259 * this code is full of workarounds for screwed up LANs.
260 * let's hope all the current LAN programmers fall into
261 * a black hole and make way for people who can get it right...
262 */
263
264 BOOL ok = FALSE;
265 FILEFINDBUF3 ffb[DDEPTH];
266 PFILEFINDBUF3 pffb;
267 HDIR hDir = HDIR_CREATE;
268 ULONG nm, ulM = 1, total = 0, fl = MUST_HAVE_DIRECTORY;
269 CHAR str[CCHMAXPATH];
270 register INT len;
271 APIRET rc, prc;
272 BOOL isadir = FALSE, isremote = FALSE, includefiles = fFilesInTree;
273 ULONG ddepth = DDEPTH;
274 ULONG drvNum;
275 ULONG flags;
276 static BOOL brokenlan = FALSE, isbroken = FALSE;
277
278 if (!pciParent || !*pciParent->pszFileName || !hwndCnr)
279 return FALSE;
280
281 len = strlen(pciParent->pszFileName);
282 memcpy(str, pciParent->pszFileName, len + 1);
283 if (str[len - 1] != '\\')
284 str[len++] = '\\';
285 str[len++] = '*';
286 str[len] = 0;
287
288 if (!isalpha(*str) || str[1] != ':' || str[2] != '\\')
289 MakeFullName(str);
290
291 drvNum = toupper(*pciParent->pszFileName) - 'A';
292 flags = driveflags[drvNum];
293 if (!isalpha(*str) ||
294 str[1] != ':' ||
295 str[2] != '\\' || ((flags & DRIVE_IGNORE)))
296 return FALSE; // Not a directory
297
298 if (flags & DRIVE_INCLUDEFILES)
299 includefiles = TRUE;
300
301 if (flags & DRIVE_REMOTE)
302 isremote = TRUE;
303
304 if (isremote) {
305 if (fRemoteBug) {
306 if (brokenlan) {
307 ddepth = (ULONG) - 1;
308 ddepth--;
309 }
310 ulM = 1;
311 }
312 }
313 else if (isbroken)
314 ddepth = 14;
315
316 if (!fRemoteBug)
317 ulM = (ddepth <= DDEPTH) ? ddepth : 1;
318
319 nm = ulM;
320
321 DosError(FERR_DISABLEHARDERR);
322 if (includefiles)
323 fl = FILE_DIRECTORY;
324 rc = DosFindFirst(str,
325 &hDir,
326 FILE_NORMAL | fl |
327 FILE_READONLY | FILE_ARCHIVED |
328 FILE_SYSTEM | FILE_HIDDEN,
329 &ffb, ulM * sizeof(FILEFINDBUF3), &nm, FIL_STANDARD);
330 if (ulM == 1 && !rc) {
331 do {
332 pffb = &ffb[0];
333 if (!includefiles && !(pffb->attrFile & FILE_DIRECTORY) && !brokenlan) {
334 brokenlan = TRUE;
335 ddepth = (ULONG) - 1;
336 ddepth--;
337 if (!NoBrokenNotify) {
338 prc = saymsg(MB_YESNO | MB_ICONEXCLAMATION,
339 HWND_DESKTOP,
340 GetPString(IDS_LANERRORTITLETEXT),
341 GetPString(IDS_LANERRORTEXT));
342 if (prc == MBID_NO) {
343 saymsg(MB_ENTER,
344 HWND_DESKTOP,
345 GetPString(IDS_LANERROR2TITLETEXT),
346 GetPString(IDS_LANERROR2TEXT));
347 NoBrokenNotify = 255;
348 PrfWriteProfileData(fmprof, FM3Str, "NoBrokenNotify",
349 &NoBrokenNotify, sizeof(ULONG));
350 }
351 }
352 else {
353 NoBrokenNotify--;
354 PrfWriteProfileData(fmprof, FM3Str, "NoBrokenNotify",
355 &NoBrokenNotify, sizeof(ULONG));
356 }
357 }
358 if (*pffb->achName &&
359 (includefiles || (pffb->attrFile & FILE_DIRECTORY)) &&
360 // Skip . and ..
361 (pffb->achName[0] != '.' ||
362 (pffb->achName[1] &&
363 (pffb->achName[1] != '.' || pffb->achName[2])))) {
364 DosFindClose(hDir);
365 isadir = TRUE;
366 goto Interruptus;
367 }
368 nm = 1;
369 DosError(FERR_DISABLEHARDERR);
370 }
371 while (++total < ddepth && !(rc = (DosFindNext(hDir,
372 &ffb,
373 sizeof(FILEFINDBUF3),
374 &nm))));
375 DosFindClose(hDir);
376 // If drive B:
377 if (toupper(*pciParent->pszFileName) > 'B' &&
378 (*(pciParent->pszFileName + 1)) == ':' &&
379 (*(pciParent->pszFileName + 2)) == '\\' && !(*(pciParent->pszFileName + 3))) {
380
381 CHAR s[132];
382 sprintf(s,
383 GetPString(IDS_NOSUBDIRSTEXT),
384 total, toupper(*pciParent->pszFileName));
385 if (rc && rc != ERROR_NO_MORE_FILES)
386 sprintf(&s[strlen(s)], GetPString(IDS_SEARCHERRORTEXT), rc, str);
387 else if (ddepth < 16)
388 brokenlan = TRUE;
389 Notify(s);
390 }
391 goto None;
392 }
393
394 if (!rc) {
395 DosFindClose(hDir);
396 if (nm) {
397 PBYTE fb = (PBYTE)&ffb[0];
398 for (len = 0; len < nm; len++) {
399 pffb = (PFILEFINDBUF3) fb;
400 if (!includefiles && !(pffb->attrFile & FILE_DIRECTORY)) {
401 if (!isbroken) {
402 isbroken = TRUE;
403 if (!NoBrokenNotify) {
404 prc = saymsg(MB_YESNO | MB_ICONEXCLAMATION,
405 HWND_DESKTOP,
406 GetPString(IDS_FSDERRORTITLETEXT),
407 GetPString(IDS_FSDERRORTEXT),
408 isremote ? GetPString(IDS_REMOTETEXT) :
409 GetPString(IDS_LOCALTEXT),
410 *str);
411 if (prc == MBID_NO) {
412 saymsg(MB_ENTER,
413 HWND_DESKTOP,
414 GetPString(IDS_FSDERROR2TITLETEXT),
415 GetPString(IDS_FSDERROR2TEXT));
416 NoBrokenNotify = 255;
417 PrfWriteProfileData(fmprof, FM3Str, "NoBrokenNotify",
418 &NoBrokenNotify, sizeof(ULONG));
419 }
420 }
421 else {
422 NoBrokenNotify--;
423 PrfWriteProfileData(fmprof, FM3Str, "NoBrokenNotify",
424 &NoBrokenNotify, sizeof(ULONG));
425 }
426 }
427 }
428 if (*pffb->achName &&
429 (includefiles || (pffb->attrFile & FILE_DIRECTORY)) &&
430 // Skip . and ..
431 (pffb->achName[0] != '.' || (pffb->achName[1]
432 && (pffb->achName[1] != '.'
433 || pffb->achName[2])))) {
434 isadir = TRUE;
435 break;
436 }
437 fb += pffb->oNextEntryOffset;
438 } // for
439
440 Interruptus:
441
442 if (isadir) {
443
444 PCNRITEM pci;
445
446 if (WinIsWindow((HAB)0, hwndCnr)) {
447 pci = WinSendMsg(hwndCnr,
448 CM_ALLOCRECORD,
449 MPFROMLONG(EXTRA_RECORD_BYTES), MPFROMLONG(1));
450 if (!pci) {
451 Win_Error(hwndCnr, HWND_DESKTOP, __FILE__, __LINE__,
452 GetPString(IDS_RECORDALLOCFAILEDTEXT));
453 }
454 else {
455 RECORDINSERT ri;
456 pci->pszFileName = NullStr;
457 pci->pszDisplayName = pci->pszFileName;
458 pci->rc.pszIcon = pci->pszDisplayName;
459 memset(&ri, 0, sizeof(RECORDINSERT));
460 ri.cb = sizeof(RECORDINSERT);
461 ri.pRecordOrder = (PRECORDCORE) CMA_END;
462 ri.pRecordParent = (PRECORDCORE) pciParent;
463 ri.zOrder = (ULONG) CMA_TOP;
464 ri.cRecordsInsert = 1;
465 ri.fInvalidateRecord = TRUE;
466 //DbgMsg(pszSrcFile, __LINE__, "Stubby %p CM_INSERTRECORD \"%s\" %.255s", hwndCnr, pci->pszFileName, pffb->achName); // 18 Dec 08 SHL fixme debug
467 if (!WinSendMsg(hwndCnr,
468 CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
469 DosSleep(50); //05 Aug 07 GKY 100
470 WinSetFocus(HWND_DESKTOP, hwndCnr);
471 if (WinIsWindow((HAB)0, hwndCnr)) {
472 //DbgMsg(pszSrcFile, __LINE__, "Stubby %p CM_INSERTRECORD %s", hwndCnr, pci->pszFileName); // 18 Dec 08 SHL fixme debug
473 if (!WinSendMsg(hwndCnr,
474 CM_INSERTRECORD, MPFROMP(pci), MPFROMP(&ri))) {
475 Win_Error(hwndCnr, HWND_DESKTOP, __FILE__, __LINE__,
476 GetPString(IDS_RECORDINSERTFAILEDTEXT));
477 FreeCnrItem(hwndCnr, pci);
478 }
479 else
480 ok = TRUE;
481 }
482 }
483 else
484 ok = TRUE;
485 }
486 }
487 }
488 else if (toupper(*str) > 'B' && str[1] == ':' && str[2] == '\\' &&
489 !str[3]) {
490
491 CHAR s[162];
492
493 sprintf(s,
494 GetPString(IDS_NOSUBDIRS2TEXT),
495 nm,
496 toupper(*pciParent->pszFileName),
497 (isremote) ? GetPString(IDS_NOSUBDIRS3TEXT) : NullStr);
498 Notify(s);
499 }
500 }
501 }
502 else if (toupper(*str) > 'B' && rc != ERROR_NO_MORE_FILES) {
503 CHAR s[CCHMAXPATH + 80];
504 sprintf(s, GetPString(IDS_SEARCHERRORTEXT), rc, str);
505 Notify(s);
506 }
507
508None:
509
510 DosError(FERR_DISABLEHARDERR);
511 return ok;
512}
513
514#pragma alloc_text(FLESH,Flesh,FleshEnv,UnFlesh,Stubby)
Note: See TracBrowser for help on using the repository browser.