source: trunk/dll/flesh.c@ 433

Last change on this file since 433 was 340, checked in by root, 19 years ago

Check more run time errors

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