source: trunk/dll/flesh.c@ 166

Last change on this file since 166 was 166, checked in by root, 20 years ago

Rework for ProcessDirectory

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 15.7 KB
Line 
1
2/***********************************************************************
3
4 $Id: flesh.c 166 2005-05-26 02:43:17Z root $
5
6 Flesh
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2005 Steven H. Levine
10
11 24 May 05 SHL Rework Win_Error usage
12 25 May 05 SHL Rework for ProcessDirectory
13
14***********************************************************************/
15
16#define INCL_DOS
17#define INCL_DOSERRORS
18#define INCL_WIN
19
20#include <os2.h>
21#include <stdarg.h>
22#include <stdio.h>
23#include <stdlib.h>
24#include <string.h>
25#include <ctype.h>
26
27#include "fm3dll.h"
28#include "fm3str.h"
29
30#pragma data_seg(DATA1)
31#pragma alloc_text(FLESH,Flesh,FleshEnv,Unflesh,Stubby)
32
33
34BOOL FleshEnv (HWND hwndCnr,PCNRITEM pciParent) {
35
36 PCNRITEM pciL;
37 DIRCNRDATA *dcd;
38 CHAR path[CCHMAXPATH + 12],
39 fullpath[CCHMAXPATH + 12],
40 *env,
41 *p,
42 *pp,
43 *var = NULL;
44
45 if(!pciParent ||
46 (INT)pciParent == -1 ||
47 !hwndCnr)
48 return FALSE;
49 dcd = (DIRCNRDATA *)WinQueryWindowPtr(hwndCnr,0);
50 if(!dcd)
51 return FALSE;
52
53 strcpy(path,
54 pciParent->szFileName + 1);
55 if(stricmp(path,GetPString(IDS_ENVVARSTEXT) + 1))
56 UnFlesh(hwndCnr,pciParent);
57 if(*path) {
58 path[strlen(path) - 1] = 0;
59 if(!stricmp(path,"LIBPATH")) {
60 var = malloc(65536);
61 if(var)
62 LoadLibPath(var,65536);
63 env = var;
64 }
65 else
66 env = getenv(path);
67 if(env && *env) {
68 p = env;
69 while(*p) {
70 pp = path;
71 while(*p == ';')
72 p++;
73 while(*p && *p != ';') {
74 *pp = *p;
75 p++;
76 pp++;
77 }
78 *pp = 0;
79 if(*path &&
80 strcmp(path,".") &&
81 strcmp(path,".\\") &&
82 strcmp(path,"..") &&
83 strcmp(path,"..\\") &&
84 strncmp(path,".\\",2) &&
85 strncmp(path,"..\\",3)) {
86 if(!DosQueryPathInfo(path,
87 FIL_QUERYFULLNAME,
88 fullpath,
89 sizeof(fullpath)) &&
90 IsValidDir(fullpath)) {
91 pciL = FindCnrRecord(hwndCnr,
92 fullpath,
93 pciParent,
94 FALSE,
95 FALSE,
96 FALSE);
97 if(pciL) {
98 while(pciL && pciL != (PCNRITEM)-1 && pciL != pciParent)
99 pciL = WinSendMsg(hwndCnr,
100 CM_QUERYRECORD,
101 MPFROMP(pciL),
102 MPFROM2SHORT(CMA_PARENT,CMA_ITEMORDER));
103 }
104 if(!pciL) {
105
106 RECORDINSERT ri;
107
108 pciL = WinSendMsg(hwndCnr,
109 CM_ALLOCRECORD,
110 MPFROMLONG(EXTRA_RECORD_BYTES2),
111 MPFROMLONG(1));
112 if(pciL) {
113 strcpy(pciL->szFileName,fullpath);
114 pciL->pszFileName = pciL->szFileName;
115 pciL->rc.pszIcon = pciL->pszFileName;
116 if(!fNoIconsDirs &&
117 (!isalpha(*fullpath) ||
118 !(driveflags[toupper(*fullpath) - 'A'] & DRIVE_NOLOADICONS)))
119 pciL->rc.hptrIcon = WinLoadFileIcon(fullpath,FALSE);
120 if(!pciL->rc.hptrIcon)
121 pciL->rc.hptrIcon = hptrDir;
122 pciL->attrFile = FILE_DIRECTORY;
123 strcpy(pciL->szDispAttr,"----D-");
124 pciL->pszDispAttr = pciL->szDispAttr;
125 memset(&ri,0,sizeof(ri));
126 ri.cb = sizeof(ri);
127 ri.pRecordOrder = (PRECORDCORE)CMA_END;
128 ri.pRecordParent = (PRECORDCORE)pciParent;
129 ri.zOrder = (ULONG)CMA_TOP;
130 ri.cRecordsInsert = 1;
131 ri.fInvalidateRecord = FALSE;
132 if(!WinSendMsg(hwndCnr,
133 CM_INSERTRECORD,
134 MPFROMP(pciL),
135 MPFROMP(&ri)))
136 WinSendMsg(hwndCnr,
137 CM_FREERECORD,
138 MPFROMP(&pciL),
139 MPFROMSHORT(1));
140 }
141 }
142 }
143 }
144 }
145 }
146 if(var)
147 free(var);
148 pciL = (PCNRITEM)WinSendMsg(hwndCnr,
149 CM_QUERYRECORD,
150 MPFROMP(pciParent),
151 MPFROM2SHORT(CMA_FIRSTCHILD,
152 CMA_ITEMORDER));
153 while(pciL && (INT)pciL != -1) {
154 pciL->flags |= (RECFLAGS_NODRAG | RECFLAGS_UNDERENV);
155 WinSendMsg(hwndCnr,
156 CM_INVALIDATERECORD,
157 MPFROMP(&pciL),
158 MPFROM2SHORT(1,0));
159 pciL = WinSendMsg(hwndCnr,
160 CM_QUERYRECORD,
161 MPFROMP(pciL),
162 MPFROM2SHORT(CMA_NEXT,
163 CMA_ITEMORDER));
164 }
165 }
166 return TRUE;
167}
168
169
170BOOL Flesh(HWND hwndCnr,PCNRITEM pciParent)
171{
172
173 PCNRITEM pciL;
174 DIRCNRDATA *dcd;
175 BOOL includefiles = fFilesInTree;
176
177 if(!pciParent || (INT)pciParent == -1 || !hwndCnr)
178 return FALSE;
179 pciL = (PCNRITEM)WinSendMsg(hwndCnr,
180 CM_QUERYRECORD,
181 MPFROMP(pciParent),
182 MPFROM2SHORT(CMA_FIRSTCHILD,
183 CMA_ITEMORDER));
184 if (!pciL || !*pciL->szFileName)
185 {
186 if (pciL && (INT)pciL != -1)
187 {
188 WinSendMsg(hwndCnr,
189 CM_REMOVERECORD,
190 MPFROMP(&pciL),
191 MPFROM2SHORT(1,CMA_FREE));
192 }
193 dcd = INSTDATA(hwndCnr);
194 if (dcd && dcd->size != sizeof(DIRCNRDATA))
195 dcd = NULL;
196 if (driveflags[toupper(*pciParent->szFileName) - 'A'] & DRIVE_INCLUDEFILES)
197 includefiles = TRUE;
198 ProcessDirectory(hwndCnr,
199 pciParent,
200 pciParent->szFileName,
201 includefiles,
202 TRUE,
203 TRUE,
204 NULL,
205 dcd,
206 NULL,
207 NULL);
208 }
209 return TRUE;
210}
211
212
213BOOL UnFlesh (HWND hwndCnr,PCNRITEM pciParent) {
214
215 BOOL ret = FALSE;
216 PCNRITEM pciL;
217
218 if(!pciParent || !hwndCnr)
219 return FALSE;
220 for(;;) {
221 pciL = (PCNRITEM)WinSendMsg(hwndCnr,
222 CM_QUERYRECORD,
223 MPFROMP(pciParent),
224 MPFROM2SHORT(CMA_FIRSTCHILD,
225 CMA_ITEMORDER));
226 if(pciL && (INT)pciL != -1) {
227 ret = TRUE;
228 WinSendMsg(hwndCnr,
229 CM_REMOVERECORD,
230 MPFROMP(&pciL),
231 MPFROM2SHORT(1,CMA_FREE));
232 }
233 else
234 break;
235 }
236 if(ret)
237 WinSendMsg(hwndCnr,
238 CM_INVALIDATERECORD,
239 MPFROMP(&pciParent),
240 MPFROM2SHORT(1,
241 CMA_ERASE | CMA_REPOSITION));
242 return ret;
243}
244
245#define DDEPTH 16
246
247BOOL Stubby (HWND hwndCnr,PCNRITEM pciParent) {
248
249 /*
250 * this code is full of workarounds for screwed up LANs.
251 * let's hope all the current LAN programmers fall into
252 * a black hole and make way for people who can get it right...
253 */
254
255 BOOL ret = FALSE;
256 FILEFINDBUF3 ffb[DDEPTH];
257 PFILEFINDBUF3 pffb;
258 HDIR hDir = HDIR_CREATE;
259 ULONG nm,ulM = 1L,total = 0L,fl = MUST_HAVE_DIRECTORY;
260 CHAR str[CCHMAXPATH];
261 register INT len;
262 APIRET rc,prc;
263 BOOL isadir = FALSE,isremote = FALSE,includefiles = fFilesInTree;
264 ULONG ddepth = 3L;
265 static BOOL brokenlan = FALSE,isbroken = FALSE;
266
267 if(!pciParent || !*pciParent->szFileName || !hwndCnr)
268 return FALSE;
269
270 len = strlen(pciParent->szFileName);
271 memcpy(str,pciParent->szFileName,len + 1);
272 if(str[len - 1] != '\\')
273 str[len++] = '\\';
274 str[len++] = '*';
275 str[len] = 0;
276
277 if(!isalpha(*str) ||
278 str[1] != ':' ||
279 str[2] != '\\')
280 MakeFullName(str);
281
282 if(!isalpha(*str) ||
283 str[1] != ':' ||
284 str[2] != '\\' ||
285 ((driveflags[toupper(*str) - 'A'] & DRIVE_IGNORE)))
286 return FALSE;
287
288 if(isalpha(*str) &&
289 driveflags[toupper(*str) - 'A'] & DRIVE_INCLUDEFILES)
290 includefiles = TRUE;
291
292 if(!isalpha(*str) ||
293 str[1] != ':' ||
294 str[2] != '\\' ||
295 ((driveflags[toupper(*str) - 'A'] & DRIVE_REMOTE)))
296 isremote = TRUE;
297
298 if(isremote) {
299 ddepth = 14;
300 if(fRemoteBug) {
301 if(brokenlan) {
302 ddepth = (ULONG)-1;
303 ddepth--;
304 }
305 ulM = 1L;
306 }
307 }
308 else if(isbroken)
309 ddepth = 14;
310
311 if(!isremote || !fRemoteBug)
312 ulM = (ddepth < 16L) ? ddepth : 1L;
313
314 nm = ulM;
315
316// WinSetWindowText(hwndStatus,str);
317
318 DosError(FERR_DISABLEHARDERR);
319 if(includefiles)
320 fl = FILE_DIRECTORY;
321 rc = DosFindFirst(str,
322 &hDir,
323 FILE_NORMAL | fl |
324 FILE_READONLY | FILE_ARCHIVED |
325 FILE_SYSTEM | FILE_HIDDEN,
326 &ffb,
327 ulM * sizeof(FILEFINDBUF3),
328 &nm,
329 FIL_STANDARD);
330 if(ulM == 1L && !rc) {
331 do {
332 pffb = &ffb[0];
333 if(!includefiles && !(pffb->attrFile & FILE_DIRECTORY) && !brokenlan) {
334 brokenlan = TRUE;
335 ddepth = (ULONG)-1L;
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 = 255L;
348 PrfWriteProfileData(fmprof,
349 FM3Str,
350 "NoBrokenNotify",
351 &NoBrokenNotify,
352 sizeof(ULONG));
353 }
354 }
355 else {
356 NoBrokenNotify--;
357 PrfWriteProfileData(fmprof,
358 FM3Str,
359 "NoBrokenNotify",
360 &NoBrokenNotify,
361 sizeof(ULONG));
362 }
363 }
364 if(*pffb->achName &&
365 (includefiles || (pffb->attrFile & FILE_DIRECTORY)) &&
366 (*pffb->achName != '.' || (pffb->achName[1] &&
367 pffb->achName[1] != '.'))) {
368 DosFindClose(hDir);
369 isadir = TRUE;
370 goto Interruptus;
371 }
372 nm = 1L;
373 DosError(FERR_DISABLEHARDERR);
374 } while(++total < ddepth && !(rc = (DosFindNext(hDir,
375 &ffb,
376 sizeof(FILEFINDBUF3),
377 &nm))));
378 DosFindClose(hDir);
379 if(toupper(*pciParent->szFileName) > 'B' &&
380 pciParent->szFileName[1] == ':' &&
381 pciParent->szFileName[2] == '\\' &&
382 !pciParent->szFileName[3]) {
383
384 CHAR s[132];
385
386 sprintf(s,
387 GetPString(IDS_NOSUBDIRSTEXT),
388 total,
389 toupper(*pciParent->szFileName));
390 if(rc && rc != ERROR_NO_MORE_FILES)
391 sprintf(&s[strlen(s)],
392 GetPString(IDS_SEARCHERRORTEXT),
393 rc,
394 str);
395 else if(ddepth < 16L)
396 brokenlan = TRUE;
397 Notify(s);
398 }
399 goto None;
400 }
401
402 if(!rc) {
403 DosFindClose(hDir);
404 if(nm) {
405
406 register PBYTE fb = (PBYTE)&ffb[0];
407
408 for(len = 0;len < nm;len++) {
409 pffb = (PFILEFINDBUF3)fb;
410 if(!includefiles && !(pffb->attrFile & FILE_DIRECTORY)) {
411 if(!isbroken) {
412 isbroken = TRUE;
413 if(!NoBrokenNotify) {
414 prc = saymsg(MB_YESNO | MB_ICONEXCLAMATION,
415 HWND_DESKTOP,
416 GetPString(IDS_FSDERRORTITLETEXT),
417 GetPString(IDS_FSDERRORTEXT),
418 (isremote) ?
419 GetPString(IDS_REMOTETEXT) :
420 GetPString(IDS_LOCALTEXT),
421 *str);
422 if(prc == MBID_NO) {
423 saymsg(MB_ENTER,
424 HWND_DESKTOP,
425 GetPString(IDS_FSDERROR2TITLETEXT),
426 GetPString(IDS_FSDERROR2TEXT));
427 NoBrokenNotify = 255L;
428 PrfWriteProfileData(fmprof,
429 FM3Str,
430 "NoBrokenNotify",
431 &NoBrokenNotify,
432 sizeof(ULONG));
433 }
434 }
435 else {
436 NoBrokenNotify--;
437 PrfWriteProfileData(fmprof,
438 FM3Str,
439 "NoBrokenNotify",
440 &NoBrokenNotify,
441 sizeof(ULONG));
442 }
443 }
444 }
445 if(*pffb->achName &&
446 (includefiles || (pffb->attrFile & FILE_DIRECTORY)) &&
447 (*pffb->achName != '.' || (pffb->achName[1] &&
448 pffb->achName[1] != '.'))) {
449 isadir = TRUE;
450 break;
451 }
452 fb += pffb->oNextEntryOffset;
453 }
454
455Interruptus:
456
457 if(isadir) {
458
459 PCNRITEM pci;
460
461// WinSetWindowText(hwndStatus2,"Found a dir");
462
463 pci = WinSendMsg(hwndCnr,
464 CM_ALLOCRECORD,
465 MPFROMLONG(EXTRA_RECORD_BYTES2),
466 MPFROMLONG(1L));
467 if(pci) {
468
469 RECORDINSERT ri;
470
471 *pci->szFileName = 0;
472 pci->pszFileName = pci->szFileName;
473 pci->rc.pszIcon = pci->pszFileName;
474 memset(&ri,0,sizeof(RECORDINSERT));
475 ri.cb = sizeof(RECORDINSERT);
476 ri.pRecordOrder = (PRECORDCORE)CMA_END;
477 ri.pRecordParent = (PRECORDCORE)pciParent;
478 ri.zOrder = (ULONG)CMA_TOP;
479 ri.cRecordsInsert = 1L;
480 ri.fInvalidateRecord = TRUE;
481 if(!WinSendMsg(hwndCnr,
482 CM_INSERTRECORD,
483 MPFROMP(pci),
484 MPFROMP(&ri))) {
485 DosSleep(100L);
486 WinSetFocus(HWND_DESKTOP,hwndCnr);
487 if(WinIsWindow((HAB)0,hwndCnr)) {
488 if(WinSendMsg(hwndCnr,
489 CM_INSERTRECORD,
490 MPFROMP(pci),
491 MPFROMP(&ri)))
492 ret = TRUE;
493 else {
494 Win_Error(hwndCnr,HWND_DESKTOP,__FILE__,__LINE__,
495 GetPString(IDS_RECORDINSERTFAILEDTEXT));
496 WinSendMsg(hwndCnr,
497 CM_FREERECORD,
498 MPFROMP(&pci),
499 MPFROMSHORT(1));
500 }
501 }
502 }
503 else
504 ret = TRUE;
505// WinSetWindowText(hwndStatus2,NullStr);
506 }
507 else
508 Win_Error(hwndCnr,HWND_DESKTOP,__FILE__,__LINE__,
509 GetPString(IDS_RECORDALLOCFAILEDTEXT));
510 }
511 else if(toupper(*str) > 'B' && str[1] == ':' && str[2] == '\\' &&
512 !str[3]) {
513
514 CHAR s[162];
515
516 sprintf(s,
517 GetPString(IDS_NOSUBDIRS2TEXT),
518 nm,
519 toupper(*pciParent->szFileName),
520 (isremote) ? GetPString(IDS_NOSUBDIRS3TEXT) : NullStr);
521 Notify(s);
522 }
523 }
524 }
525 else if(toupper(*str) > 'B' &&
526 rc != ERROR_NO_MORE_FILES) {
527
528 CHAR s[CCHMAXPATH + 80];
529
530 sprintf(s,
531 GetPString(IDS_SEARCHERRORTEXT),
532 rc,
533 str);
534 Notify(s);
535 }
536
537None:
538
539 DosError(FERR_DISABLEHARDERR);
540 return ret;
541}
542
Note: See TracBrowser for help on using the repository browser.