source: trunk/dll/flesh.c@ 858

Last change on this file since 858 was 847, checked in by Gregg Young, 18 years ago

Removed large file APIs from code where hey are not needed.

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