1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: dirsize.c 54 2003-04-18 03:03:24Z root $
|
---|
5 |
|
---|
6 | Directory size
|
---|
7 |
|
---|
8 | Copyright (c) 1993-98 M. Kimes
|
---|
9 | Copyright (c) 2001, 2002 Steven H.Levine
|
---|
10 |
|
---|
11 | Revisions 16 Oct 02 SHL - Handle large partitions
|
---|
12 | 12 Feb 03 SHL - Use CBLIST_TO_EASIZE
|
---|
13 |
|
---|
14 | ***********************************************************************/
|
---|
15 |
|
---|
16 | #define INCL_DOS
|
---|
17 | #define INCL_WIN
|
---|
18 | #define INCL_GPI
|
---|
19 |
|
---|
20 | #include <os2.h>
|
---|
21 | #include <stdio.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <ctype.h>
|
---|
25 | #include "fm3dll.h"
|
---|
26 | #include "fm3dlg.h"
|
---|
27 | #include "fm3str.h"
|
---|
28 |
|
---|
29 | #pragma alloc_text(DIRSIZE,ProcessDir,FillCnrs,DirSizeProc)
|
---|
30 | #pragma alloc_text(DIRSIZE2,PrintToFile,FillInRecSizes,SortSizeCnr)
|
---|
31 |
|
---|
32 | typedef struct {
|
---|
33 | CHAR *filename;
|
---|
34 | HWND hwndCnr;
|
---|
35 | CHAR *stopflag;
|
---|
36 | DIRCNRDATA *dcd;
|
---|
37 | } DIRSIZE;
|
---|
38 |
|
---|
39 | typedef struct {
|
---|
40 | CHAR dirname[CCHMAXPATH];
|
---|
41 | CHAR stopflag;
|
---|
42 | BOOL dying;
|
---|
43 | BOOL working;
|
---|
44 | HPOINTER hptr;
|
---|
45 | } TEMP;
|
---|
46 |
|
---|
47 |
|
---|
48 | SHORT APIENTRY SortSizeCnr (PMINIRECORDCORE p1,PMINIRECORDCORE p2,
|
---|
49 | PVOID SortFlags) {
|
---|
50 |
|
---|
51 | ULONG size1,size2;
|
---|
52 |
|
---|
53 | size1 = ((PCNRITEM)p1)->cbFile + ((PCNRITEM)p1)->easize;
|
---|
54 | size2 = ((PCNRITEM)p2)->cbFile + ((PCNRITEM)p2)->easize;
|
---|
55 | return (size1 < size2) ? 1 : (size1 == size2) ? 0 : -1;
|
---|
56 | }
|
---|
57 |
|
---|
58 |
|
---|
59 | static ULONG ProcessDir (HWND hwndCnr,CHAR *filename,PCNRITEM pciParent,
|
---|
60 | CHAR *stopflag,BOOL top)
|
---|
61 | {
|
---|
62 | CHAR maskstr[CCHMAXPATH],*pEndMask;
|
---|
63 | register char *p,*sp,*pp;
|
---|
64 | ULONG nm,totalbytes = 0L,subbytes = 0L,temp;
|
---|
65 | HDIR hdir;
|
---|
66 | FILEFINDBUF4 *ffb;
|
---|
67 | APIRET rc;
|
---|
68 | RECORDINSERT ri;
|
---|
69 | PCNRITEM pciP;
|
---|
70 |
|
---|
71 | ffb = malloc(sizeof(FILEFINDBUF4) /* * FilesToGet */);
|
---|
72 | if(!ffb)
|
---|
73 | return -1L;
|
---|
74 | strcpy(maskstr,filename);
|
---|
75 | if(maskstr[strlen(maskstr) - 1] != '\\')
|
---|
76 | strcat(maskstr,"\\");
|
---|
77 | pEndMask = &maskstr[strlen(maskstr)]; // Point after last \
|
---|
78 | strcat(maskstr,"*");
|
---|
79 | //printf("%s\n",maskstr);
|
---|
80 | hdir = HDIR_CREATE;
|
---|
81 | nm = 1L;
|
---|
82 | memset(ffb,0,sizeof(ffb));
|
---|
83 | DosError(FERR_DISABLEHARDERR);
|
---|
84 | //printf("FIND1\n");
|
---|
85 | rc = DosFindFirst(filename, &hdir,
|
---|
86 | FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
|
---|
87 | FILE_SYSTEM | FILE_HIDDEN | MUST_HAVE_DIRECTORY,
|
---|
88 | ffb, sizeof(FILEFINDBUF4),&nm, FIL_QUERYEASIZE);
|
---|
89 | if(!rc)
|
---|
90 | DosFindClose(hdir);
|
---|
91 |
|
---|
92 | /*
|
---|
93 | * the "|| strlen(filename) < 4 below works around an OS/2 bug
|
---|
94 | * that prevents FAT root directories from being found when
|
---|
95 | * requesting EASIZE. sheesh.
|
---|
96 | */
|
---|
97 | if((!rc && (ffb->attrFile & FILE_DIRECTORY)) || strlen(filename) < 4)
|
---|
98 | {
|
---|
99 | if(*stopflag) {
|
---|
100 | free(ffb);
|
---|
101 | return -1L;
|
---|
102 | }
|
---|
103 | //printf("CM_ALLOCRECORD\n");
|
---|
104 | pciP = WinSendMsg(hwndCnr,CM_ALLOCRECORD,MPFROMLONG(EXTRA_RECORD_BYTES2),
|
---|
105 | MPFROMLONG(1L));
|
---|
106 | if(!pciP) {
|
---|
107 | free(ffb);
|
---|
108 | return -1L;
|
---|
109 | }
|
---|
110 | if(!rc)
|
---|
111 | totalbytes = ffb->cbFile + CBLIST_TO_EASIZE(ffb->cbList);
|
---|
112 | else
|
---|
113 | DosError(FERR_DISABLEHARDERR);
|
---|
114 | pciP->pszLongname = pciP->szFileName;
|
---|
115 | pciP->rc.hptrIcon = hptrDir;
|
---|
116 | *pciP->szDispAttr = *pciP->Longname = *pciP->subject = 0;
|
---|
117 | pciP->attrFile = 0L;
|
---|
118 | }
|
---|
119 | else
|
---|
120 | {
|
---|
121 | free(ffb);
|
---|
122 | Dos_Error(MB_ENTER,
|
---|
123 | rc,
|
---|
124 | HWND_DESKTOP,
|
---|
125 | __FILE__,
|
---|
126 | __LINE__,
|
---|
127 | GetPString(IDS_CANTFINDDIRTEXT),
|
---|
128 | filename);
|
---|
129 | return -1L;
|
---|
130 | }
|
---|
131 |
|
---|
132 | if(strlen(filename) < 4 || top)
|
---|
133 | strcpy(pciP->szFileName,filename);
|
---|
134 | else {
|
---|
135 | p = strrchr(filename,'\\');
|
---|
136 | if(!p)
|
---|
137 | p = filename;
|
---|
138 | else
|
---|
139 | p++;
|
---|
140 | sp = (strchr(filename,' ') != NULL) ? "\"" : NullStr;
|
---|
141 | pp = pciP->szFileName;
|
---|
142 | if(*sp) {
|
---|
143 | *pp = *sp;
|
---|
144 | pp++;
|
---|
145 | *pp = 0;
|
---|
146 | }
|
---|
147 | strcpy(pp,p);
|
---|
148 | if(*sp)
|
---|
149 | strcat(pp,sp);
|
---|
150 | }
|
---|
151 | pciP->pszFileName = pciP->szFileName + strlen(pciP->szFileName);
|
---|
152 | pciP->rc.pszIcon = pciP->pszLongname;
|
---|
153 | pciP->rc.flRecordAttr |= CRA_RECORDREADONLY;
|
---|
154 | if(fForceUpper)
|
---|
155 | strupr(pciP->szFileName);
|
---|
156 | else if(fForceLower)
|
---|
157 | strlwr(pciP->szFileName);
|
---|
158 | memset(&ri,0,sizeof(RECORDINSERT));
|
---|
159 | ri.cb = sizeof(RECORDINSERT);
|
---|
160 | ri.pRecordOrder = (PRECORDCORE)CMA_END;
|
---|
161 | ri.pRecordParent = (PRECORDCORE)pciParent;
|
---|
162 | ri.zOrder = (USHORT)CMA_TOP;
|
---|
163 | ri.cRecordsInsert = 1L;
|
---|
164 | ri.fInvalidateRecord = TRUE;
|
---|
165 | //printf("CM_INSERTRECORD\n");
|
---|
166 | if(!WinSendMsg(hwndCnr,CM_INSERTRECORD,MPFROMP(pciP),MPFROMP(&ri))) {
|
---|
167 | //printf("Insert failed\n");
|
---|
168 | free(ffb);
|
---|
169 | return -1L;
|
---|
170 | }
|
---|
171 | hdir = HDIR_CREATE;
|
---|
172 | nm = 1L;
|
---|
173 | //printf("FIND2\n");
|
---|
174 | rc = DosFindFirst(maskstr,&hdir,
|
---|
175 | FILE_NORMAL | FILE_READONLY | FILE_ARCHIVED |
|
---|
176 | FILE_SYSTEM | FILE_HIDDEN | FILE_DIRECTORY,
|
---|
177 | ffb,
|
---|
178 | sizeof(FILEFINDBUF4),
|
---|
179 | &nm,
|
---|
180 | FIL_QUERYEASIZE);
|
---|
181 | if(!rc)
|
---|
182 | {
|
---|
183 | register PBYTE fb = (PBYTE)ffb;
|
---|
184 | FILEFINDBUF4 *pffbFile;
|
---|
185 | ULONG x;
|
---|
186 |
|
---|
187 | while(!rc)
|
---|
188 | {
|
---|
189 | priority_normal();
|
---|
190 | //printf("Found %lu\n",nm);
|
---|
191 | for(x = 0L;x < nm;x++)
|
---|
192 | {
|
---|
193 | pffbFile = (FILEFINDBUF4 *)fb;
|
---|
194 | //printf("%s\n",pffbFile->achName);
|
---|
195 | //fflush(stdout);
|
---|
196 | // Total size skipping . and ..
|
---|
197 | if((*pffbFile->achName != '.' ||
|
---|
198 | (pffbFile->achName[1] && pffbFile->achName[1] != '.')) ||
|
---|
199 | !(pffbFile->attrFile & FILE_DIRECTORY))
|
---|
200 | {
|
---|
201 | totalbytes += pffbFile->cbFile +
|
---|
202 | CBLIST_TO_EASIZE(pffbFile->cbList);
|
---|
203 | if(!(pffbFile->attrFile & FILE_DIRECTORY))
|
---|
204 | pciP->attrFile++; // Bump file count
|
---|
205 | if(*stopflag)
|
---|
206 | break;
|
---|
207 | if(pffbFile->attrFile & FILE_DIRECTORY) {
|
---|
208 | // Recurse into subdir
|
---|
209 | strcpy(pEndMask,pffbFile->achName); // Append dirname to base dirname
|
---|
210 | if(!*stopflag)
|
---|
211 | {
|
---|
212 | temp = ProcessDir(hwndCnr,maskstr,pciP,stopflag,FALSE);
|
---|
213 | if(temp != (ULONG)-1L)
|
---|
214 | subbytes += temp;
|
---|
215 | }
|
---|
216 | }
|
---|
217 | }
|
---|
218 | if(!pffbFile->oNextEntryOffset)
|
---|
219 | break;
|
---|
220 | fb += pffbFile->oNextEntryOffset;
|
---|
221 | } // for matches
|
---|
222 | if(*stopflag)
|
---|
223 | break;
|
---|
224 | DosSleep(0L);
|
---|
225 | nm = 1L; /* FilesToGet */
|
---|
226 | rc = DosFindNext(hdir,ffb,sizeof(FILEFINDBUF4) ,&nm);
|
---|
227 | } // while more found
|
---|
228 | DosFindClose(hdir);
|
---|
229 | priority_normal();
|
---|
230 | }
|
---|
231 | pciP->cbFile = totalbytes;
|
---|
232 | pciP->easize = subbytes;
|
---|
233 | WinSendMsg(hwndCnr,CM_INVALIDATERECORD,MPFROMP(&pciP),
|
---|
234 | MPFROM2SHORT(1,CMA_ERASE | CMA_TEXTCHANGED));
|
---|
235 | free(ffb);
|
---|
236 | return totalbytes + subbytes;
|
---|
237 | }
|
---|
238 |
|
---|
239 |
|
---|
240 | VOID FillInRecSizes (HWND hwndCnr,PCNRITEM pciParent,ULONG totalbytes,
|
---|
241 | CHAR *stopflag,BOOL isroot)
|
---|
242 | {
|
---|
243 | PCNRITEM pci = pciParent;
|
---|
244 | SHORT attrib = CMA_FIRSTCHILD;
|
---|
245 |
|
---|
246 | if(pci) {
|
---|
247 |
|
---|
248 | CHAR tf[80],tb[80],tt[80],br[80];
|
---|
249 | register CHAR *p;
|
---|
250 | register ULONG cntr,x;
|
---|
251 | float cntra = 0.0;
|
---|
252 |
|
---|
253 | commafmt(tf,sizeof(tf),(pci->cbFile > 0L && pci->cbFile < 1024L) ? 1L :
|
---|
254 | pci->cbFile / 1024L);
|
---|
255 | *br = 0;
|
---|
256 | if(totalbytes) {
|
---|
257 | if(isroot) {
|
---|
258 |
|
---|
259 | FSALLOCATE fsa;
|
---|
260 | APIRET rc;
|
---|
261 |
|
---|
262 | memset(&fsa,0,sizeof(fsa));
|
---|
263 | rc = DosQueryFSInfo(toupper(*pci->szFileName) - '@',FSIL_ALLOC,&fsa,
|
---|
264 | sizeof(FSALLOCATE));
|
---|
265 | if(!rc)
|
---|
266 | cntra = (totalbytes * 100.0) /
|
---|
267 | ((float)fsa.cUnit * (fsa.cSectorUnit * fsa.cbSector));
|
---|
268 | pci->Longname[1] = 1;
|
---|
269 | }
|
---|
270 | else
|
---|
271 | cntra = (((float)pci->cbFile + pci->easize) * 100.0) / totalbytes;
|
---|
272 | cntr = (ULONG)cntra / 2;
|
---|
273 | p = br;
|
---|
274 | for(x = 0;x < cntr;x++) {
|
---|
275 | *p = '#';
|
---|
276 | p++;
|
---|
277 | }
|
---|
278 | if(cntr * 2 != (ULONG)cntra) {
|
---|
279 | *p = '=';
|
---|
280 | p++;
|
---|
281 | x++;
|
---|
282 | }
|
---|
283 | for(;x < 50;x++) {
|
---|
284 | *p = ' ';
|
---|
285 | p++;
|
---|
286 | }
|
---|
287 | *p = 0;
|
---|
288 | }
|
---|
289 | pci->flags = (ULONG)cntra;
|
---|
290 | commafmt(tb,sizeof(tb),(pci->easize > 0L && pci->easize < 1024L) ? 1L :
|
---|
291 | pci->easize / 1024L);
|
---|
292 | commafmt(tt,sizeof(tt),(pci->cbFile + pci->easize > 0L &&
|
---|
293 | pci->cbFile + pci->easize < 1024L) ? 1L :
|
---|
294 | (pci->cbFile + pci->easize) / 1024L);
|
---|
295 | sprintf(&pci->szFileName[strlen(pci->szFileName)],
|
---|
296 | " %sk + %sk = %sk (%.02lf%%%s)\r%s",
|
---|
297 | tf,
|
---|
298 | tb,
|
---|
299 | tt,
|
---|
300 | cntra,
|
---|
301 | (isroot) ? GetPString(IDS_OFDRIVETEXT) : NullStr,
|
---|
302 | br);
|
---|
303 | WinSendMsg(hwndCnr,
|
---|
304 | CM_INVALIDATERECORD,
|
---|
305 | MPFROMP(&pci),
|
---|
306 | MPFROM2SHORT(1,0));
|
---|
307 | isroot = FALSE;
|
---|
308 | }
|
---|
309 | else
|
---|
310 | attrib = CMA_FIRST;
|
---|
311 | pci = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pci),
|
---|
312 | MPFROM2SHORT(attrib,CMA_ITEMORDER));
|
---|
313 | while(pci && (INT)pci != -1) {
|
---|
314 | if(*stopflag)
|
---|
315 | break;
|
---|
316 | FillInRecSizes(hwndCnr,pci,totalbytes,stopflag,isroot);
|
---|
317 | isroot = FALSE;
|
---|
318 | pci = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pci),
|
---|
319 | MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER));
|
---|
320 | }
|
---|
321 | }
|
---|
322 |
|
---|
323 |
|
---|
324 | static VOID PrintToFile (HWND hwndCnr,ULONG indent,PCNRITEM pciParent,
|
---|
325 | FILE *fp) {
|
---|
326 |
|
---|
327 | PCNRITEM pci;
|
---|
328 | register CHAR *p;
|
---|
329 |
|
---|
330 | if(!pciParent) {
|
---|
331 | pciParent = WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(NULL),
|
---|
332 | MPFROM2SHORT(CMA_FIRST,CMA_ITEMORDER));
|
---|
333 | indent = 0;
|
---|
334 | }
|
---|
335 | if(pciParent) {
|
---|
336 | p = strchr(pciParent->szFileName,'\r');
|
---|
337 | if(p)
|
---|
338 | *p = 0;
|
---|
339 | fprintf(fp,"%*.*s%s %lu %s%s\n",
|
---|
340 | indent * 2,indent * 2," ",
|
---|
341 | pciParent->szFileName,
|
---|
342 | pciParent->attrFile,
|
---|
343 | GetPString(IDS_FILETEXT),
|
---|
344 | &"s"[pciParent->attrFile == 1]);
|
---|
345 | if(p)
|
---|
346 | *p = '\r';
|
---|
347 | if(pciParent->rc.flRecordAttr & CRA_EXPANDED) {
|
---|
348 | pci = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pciParent),
|
---|
349 | MPFROM2SHORT(CMA_FIRSTCHILD,CMA_ITEMORDER));
|
---|
350 | while(pci && (INT)pci != -1) {
|
---|
351 | DosSleep(0L);
|
---|
352 | PrintToFile(hwndCnr,indent + 1,pci,fp);
|
---|
353 | pci = (PCNRITEM)WinSendMsg(hwndCnr,CM_QUERYRECORD,MPFROMP(pci),
|
---|
354 | MPFROM2SHORT(CMA_NEXT,CMA_ITEMORDER));
|
---|
355 | }
|
---|
356 | }
|
---|
357 | }
|
---|
358 | }
|
---|
359 |
|
---|
360 |
|
---|
361 | static VOID FillCnrs (VOID *args)
|
---|
362 | {
|
---|
363 | HAB hab;
|
---|
364 | HMQ hmq;
|
---|
365 | DIRSIZE *dirsize = (DIRSIZE *)args;
|
---|
366 | HWND hwndCnr;
|
---|
367 | ULONG totalbytes;
|
---|
368 |
|
---|
369 | if(!dirsize)
|
---|
370 | return;
|
---|
371 | hwndCnr = dirsize->hwndCnr;
|
---|
372 |
|
---|
373 | DosError(FERR_DISABLEHARDERR);
|
---|
374 |
|
---|
375 | // priority_normal();
|
---|
376 | hab = WinInitialize(0);
|
---|
377 | if(hab) {
|
---|
378 | hmq = WinCreateMsgQueue(hab,0);
|
---|
379 | if(hmq) {
|
---|
380 | WinCancelShutdown(hmq,TRUE);
|
---|
381 | totalbytes = ProcessDir(hwndCnr,dirsize->filename,
|
---|
382 | (PCNRITEM)NULL,dirsize->stopflag,TRUE);
|
---|
383 | DosPostEventSem(CompactSem);
|
---|
384 | WinEnableWindowUpdate(hwndCnr,FALSE);
|
---|
385 | FillInRecSizes(hwndCnr,NULL,totalbytes,dirsize->stopflag,TRUE);
|
---|
386 | WinEnableWindowUpdate(hwndCnr,TRUE);
|
---|
387 | WinSendMsg(hwndCnr,CM_INVALIDATERECORD,MPVOID,
|
---|
388 | MPFROM2SHORT(0,CMA_ERASE | CMA_TEXTCHANGED));
|
---|
389 | WinDestroyMsgQueue(hmq);
|
---|
390 | }
|
---|
391 | WinTerminate(hab);
|
---|
392 | }
|
---|
393 | PostMsg(WinQueryWindow(hwndCnr,QW_PARENT),
|
---|
394 | UM_CONTAINER_FILLED,
|
---|
395 | MPVOID,MPVOID);
|
---|
396 | free(dirsize);
|
---|
397 | }
|
---|
398 |
|
---|
399 |
|
---|
400 | MRESULT EXPENTRY DirSizeProc (HWND hwnd,ULONG msg,MPARAM mp1,MPARAM mp2)
|
---|
401 | {
|
---|
402 | TEMP *data;
|
---|
403 |
|
---|
404 | switch(msg) {
|
---|
405 | case WM_INITDLG:
|
---|
406 | if(!mp2) {
|
---|
407 | WinDismissDlg(hwnd,0);
|
---|
408 | break;
|
---|
409 | }
|
---|
410 | data = malloc(sizeof(TEMP));
|
---|
411 | if(!data) {
|
---|
412 | WinDismissDlg(hwnd,0);
|
---|
413 | break;
|
---|
414 | }
|
---|
415 | memset(data,0,sizeof(TEMP));
|
---|
416 | strcpy(data->dirname,(CHAR *)mp2);
|
---|
417 | WinSetWindowPtr(hwnd,0,(PVOID)data);
|
---|
418 | data->hptr = WinLoadPointer(HWND_DESKTOP,FM3ModHandle,DIRSIZE_ICON);
|
---|
419 | WinDefDlgProc(hwnd,WM_SETICON,MPFROMLONG(data->hptr),MPVOID);
|
---|
420 | {
|
---|
421 | CHAR s[CCHMAXPATH + 81];
|
---|
422 |
|
---|
423 | sprintf(s,
|
---|
424 | GetPString(IDS_DIRSIZETITLETEXT),
|
---|
425 | data->dirname);
|
---|
426 | WinSetWindowText(hwnd,s);
|
---|
427 | }
|
---|
428 | {
|
---|
429 | DIRSIZE *dirsize;
|
---|
430 |
|
---|
431 | dirsize = malloc(sizeof(DIRSIZE));
|
---|
432 | if(!dirsize) {
|
---|
433 | WinDismissDlg(hwnd,0);
|
---|
434 | break;
|
---|
435 | }
|
---|
436 | dirsize->stopflag = (CHAR *)&data->stopflag;
|
---|
437 | dirsize->filename = data->dirname;
|
---|
438 | dirsize->hwndCnr = WinWindowFromID(hwnd,DSZ_CNR);
|
---|
439 | if(_beginthread(FillCnrs,NULL,122880L * 5L,(PVOID)dirsize) == -1) {
|
---|
440 | free(dirsize);
|
---|
441 | WinDismissDlg(hwnd,0);
|
---|
442 | break;
|
---|
443 | }
|
---|
444 | data->working = TRUE;
|
---|
445 | }
|
---|
446 | PostMsg(hwnd,UM_SETUP,MPVOID,MPVOID);
|
---|
447 | break;
|
---|
448 |
|
---|
449 | case UM_SETUP:
|
---|
450 | {
|
---|
451 | CNRINFO cnri;
|
---|
452 | FSALLOCATE fsa;
|
---|
453 | APIRET rc;
|
---|
454 |
|
---|
455 | memset(&cnri,0,sizeof(CNRINFO));
|
---|
456 | cnri.cb = sizeof(CNRINFO);
|
---|
457 | WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_QUERYCNRINFO,
|
---|
458 | MPFROMP(&cnri),MPFROMLONG(sizeof(CNRINFO)));
|
---|
459 | cnri.cyLineSpacing = 0;
|
---|
460 | cnri.cxTreeIndent = 12L;
|
---|
461 | cnri.flWindowAttr = CV_TREE | CV_FLOW | CA_TREELINE | CA_OWNERDRAW;
|
---|
462 | WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_SETCNRINFO,MPFROMP(&cnri),
|
---|
463 | MPFROMLONG(CMA_FLWINDOWATTR | CMA_TREEICON |
|
---|
464 | CMA_LINESPACING | CMA_CXTREEINDENT));
|
---|
465 | data = INSTDATA(hwnd);
|
---|
466 | if(data && isalpha(*data->dirname)) {
|
---|
467 | memset(&fsa,0,sizeof(fsa));
|
---|
468 | rc = DosQueryFSInfo(toupper(*data->dirname) - '@',FSIL_ALLOC,&fsa,
|
---|
469 | sizeof(FSALLOCATE));
|
---|
470 | if(!rc) {
|
---|
471 |
|
---|
472 | CHAR s[132],tf[80],tb[80],tu[80];
|
---|
473 |
|
---|
474 | commafmt(tf,sizeof(tf),
|
---|
475 | (ULONG)(((float)fsa.cUnitAvail *
|
---|
476 | (fsa.cSectorUnit * fsa.cbSector)) / 1024L));
|
---|
477 | commafmt(tb,sizeof(tb),
|
---|
478 | (ULONG)(((float)fsa.cUnit *
|
---|
479 | (fsa.cSectorUnit * fsa.cbSector)) / 1024L));
|
---|
480 | commafmt(tu,sizeof(tu),
|
---|
481 | (ULONG)(((float)(fsa.cUnit - fsa.cUnitAvail) *
|
---|
482 | (fsa.cSectorUnit * fsa.cbSector)) / 1024L));
|
---|
483 | sprintf(s,
|
---|
484 | GetPString(IDS_FREESPACETEXT),
|
---|
485 | tf,
|
---|
486 | tb,
|
---|
487 | tu);
|
---|
488 | WinSetDlgItemText(hwnd,
|
---|
489 | DSZ_FREESPACE,
|
---|
490 | s);
|
---|
491 | }
|
---|
492 | else
|
---|
493 | WinSetDlgItemText(hwnd,
|
---|
494 | DSZ_FREESPACE,
|
---|
495 | GetPString(IDS_FREESPACEUTEXT));
|
---|
496 | }
|
---|
497 | }
|
---|
498 | return 0;
|
---|
499 |
|
---|
500 | case UM_CONTAINER_FILLED:
|
---|
501 | data = INSTDATA(hwnd);
|
---|
502 | if(!data || data->dying) {
|
---|
503 | data->working = FALSE;
|
---|
504 | WinDismissDlg(hwnd,0);
|
---|
505 | return 0;
|
---|
506 | }
|
---|
507 | data->working = FALSE;
|
---|
508 | {
|
---|
509 | CHAR tb[44],s[66];
|
---|
510 | PCNRITEM pci;
|
---|
511 |
|
---|
512 | pci = WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_QUERYRECORD,MPVOID,
|
---|
513 | MPFROM2SHORT(CMA_FIRST,CMA_ITEMORDER));
|
---|
514 | if(pci && (INT)pci != -1)
|
---|
515 | WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_EXPANDTREE,MPFROMP(pci),MPVOID);
|
---|
516 | *s = 0;
|
---|
517 | pci = WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_QUERYRECORDEMPHASIS,
|
---|
518 | MPFROMLONG(CMA_FIRST),
|
---|
519 | MPFROMSHORT(CRA_CURSORED));
|
---|
520 | if(pci && (INT)pci != -1) {
|
---|
521 | commafmt(tb,sizeof(tb),pci->attrFile);
|
---|
522 | sprintf(s,
|
---|
523 | "%s %s%s",
|
---|
524 | tb,
|
---|
525 | GetPString(IDS_FILETEXT),
|
---|
526 | &"s"[pci->attrFile == 1]);
|
---|
527 | }
|
---|
528 | WinSetDlgItemText(hwnd,DSZ_NUMFILES,s);
|
---|
529 | }
|
---|
530 | WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_SORTRECORD,MPFROMP(SortSizeCnr),
|
---|
531 | MPVOID);
|
---|
532 | DosBeep(500,25);
|
---|
533 | return 0;
|
---|
534 |
|
---|
535 | case WM_ADJUSTWINDOWPOS:
|
---|
536 | PostMsg(hwnd,UM_STRETCH,MPVOID,MPVOID);
|
---|
537 | break;
|
---|
538 |
|
---|
539 | case UM_STRETCH:
|
---|
540 | {
|
---|
541 | SWP swpC,swp;
|
---|
542 |
|
---|
543 | WinQueryWindowPos(hwnd,&swp);
|
---|
544 | if(!(swp.fl & (SWP_HIDE | SWP_MINIMIZE))) {
|
---|
545 | WinQueryWindowPos(WinWindowFromID(hwnd,DSZ_CNR),&swpC);
|
---|
546 | WinSetWindowPos(WinWindowFromID(hwnd,DSZ_CNR),HWND_TOP,
|
---|
547 | SysVal(SV_CXSIZEBORDER),
|
---|
548 | swpC.y,
|
---|
549 | swp.cx - (SysVal(SV_CXSIZEBORDER) * 2),
|
---|
550 | (swp.cy - swpC.y) - (SysVal(SV_CYTITLEBAR) +
|
---|
551 | SysVal(SV_CYSIZEBORDER)),
|
---|
552 | SWP_MOVE | SWP_SIZE);
|
---|
553 | }
|
---|
554 | }
|
---|
555 | return 0;
|
---|
556 |
|
---|
557 | case WM_DRAWITEM:
|
---|
558 | if(mp2) {
|
---|
559 |
|
---|
560 | OWNERITEM *oi = mp2;
|
---|
561 | CNRDRAWITEMINFO *cnd;
|
---|
562 | PCNRITEM pci;
|
---|
563 |
|
---|
564 | if(oi->idItem == CMA_TEXT) {
|
---|
565 | cnd = (CNRDRAWITEMINFO *)oi->hItem;
|
---|
566 | if(cnd) {
|
---|
567 | pci = (PCNRITEM)cnd->pRecord;
|
---|
568 | if(pci) {
|
---|
569 |
|
---|
570 | POINTL aptl[TXTBOX_COUNT],ptl;
|
---|
571 | CHAR *p;
|
---|
572 | LONG clr,x;
|
---|
573 |
|
---|
574 | p = strchr(pci->szFileName,'\r');
|
---|
575 | if(p) {
|
---|
576 | /* draw text */
|
---|
577 | if(!pci->cbFile) /* no size */
|
---|
578 | GpiSetColor(oi->hps,CLR_DARKGRAY);
|
---|
579 | else if(!pci->easize) /* no size below */
|
---|
580 | GpiSetColor(oi->hps,CLR_DARKBLUE);
|
---|
581 | else
|
---|
582 | GpiSetColor(oi->hps,CLR_BLACK);
|
---|
583 | GpiSetBackMix(oi->hps,BM_LEAVEALONE);
|
---|
584 | GpiSetMix(oi->hps,FM_OVERPAINT);
|
---|
585 | *p = 0;
|
---|
586 | GpiQueryTextBox(oi->hps,strlen(pci->szFileName),
|
---|
587 | pci->szFileName,TXTBOX_COUNT,aptl);
|
---|
588 | ptl.x = oi->rclItem.xLeft;
|
---|
589 | ptl.y = (oi->rclItem.yTop - aptl[TXTBOX_TOPRIGHT].y);
|
---|
590 | GpiMove(oi->hps,&ptl);
|
---|
591 | GpiCharString(oi->hps,strlen(pci->szFileName),
|
---|
592 | pci->szFileName);
|
---|
593 | *p = '\r';
|
---|
594 |
|
---|
595 | /* draw the graph box */
|
---|
596 | GpiQueryTextBox(oi->hps,1,"#",TXTBOX_COUNT,aptl);
|
---|
597 | /* draw black outline */
|
---|
598 | GpiSetColor(oi->hps,CLR_BLACK);
|
---|
599 | ptl.x = oi->rclItem.xLeft;
|
---|
600 | ptl.y = oi->rclItem.yBottom + 2;
|
---|
601 | GpiMove(oi->hps,&ptl);
|
---|
602 | ptl.x = oi->rclItem.xLeft + 101;
|
---|
603 | ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y);
|
---|
604 | GpiBox(oi->hps,DRO_OUTLINE,&ptl,0,0);
|
---|
605 | /* fill with gray */
|
---|
606 | GpiSetColor(oi->hps,CLR_PALEGRAY);
|
---|
607 | ptl.x = oi->rclItem.xLeft + 1;
|
---|
608 | ptl.y = oi->rclItem.yBottom + 3;
|
---|
609 | GpiMove(oi->hps,&ptl);
|
---|
610 | ptl.x = oi->rclItem.xLeft + 100;
|
---|
611 | ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 1;
|
---|
612 | GpiBox(oi->hps,DRO_OUTLINEFILL,&ptl,0,0);
|
---|
613 |
|
---|
614 | /* draw shadow at bottom & right sides */
|
---|
615 | GpiSetColor(oi->hps,CLR_DARKGRAY);
|
---|
616 | ptl.x = oi->rclItem.xLeft + 1;
|
---|
617 | ptl.y = oi->rclItem.yBottom + 3;
|
---|
618 | GpiMove(oi->hps,&ptl);
|
---|
619 | ptl.x = oi->rclItem.xLeft + 100;
|
---|
620 | GpiLine(oi->hps,&ptl);
|
---|
621 | ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 1;
|
---|
622 | GpiLine(oi->hps,&ptl);
|
---|
623 |
|
---|
624 | /* draw highlight at top and left sides */
|
---|
625 | GpiSetColor(oi->hps,CLR_WHITE);
|
---|
626 | ptl.x = oi->rclItem.xLeft + 1;
|
---|
627 | GpiLine(oi->hps,&ptl);
|
---|
628 | ptl.y = oi->rclItem.yBottom + 3;
|
---|
629 | GpiLine(oi->hps,&ptl);
|
---|
630 |
|
---|
631 | /* draw shadow of box */
|
---|
632 | GpiSetColor(oi->hps,CLR_DARKGRAY);
|
---|
633 | ptl.x = oi->rclItem.xLeft + 2;
|
---|
634 | ptl.y = oi->rclItem.yBottom;
|
---|
635 | GpiMove(oi->hps,&ptl);
|
---|
636 | ptl.x = oi->rclItem.xLeft + 103;
|
---|
637 | GpiLine(oi->hps,&ptl);
|
---|
638 | ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 2;
|
---|
639 | GpiLine(oi->hps,&ptl);
|
---|
640 | ptl.x--;
|
---|
641 | GpiMove(oi->hps,&ptl);
|
---|
642 | ptl.y = oi->rclItem.yBottom + 1;
|
---|
643 | GpiLine(oi->hps,&ptl);
|
---|
644 | ptl.x = oi->rclItem.xLeft + 2;
|
---|
645 | GpiLine(oi->hps,&ptl);
|
---|
646 |
|
---|
647 | /* fill box with graph bar */
|
---|
648 | if(pci->flags) {
|
---|
649 | if(pci->Longname[1] == 1) /* is root record */
|
---|
650 | GpiSetColor(oi->hps,CLR_DARKGREEN);
|
---|
651 | else
|
---|
652 | GpiSetColor(oi->hps,CLR_RED);
|
---|
653 | ptl.x = oi->rclItem.xLeft + 1;
|
---|
654 | ptl.y = oi->rclItem.yBottom + 3;
|
---|
655 | GpiMove(oi->hps,&ptl);
|
---|
656 | ptl.x = oi->rclItem.xLeft + pci->flags;
|
---|
657 | ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 1;
|
---|
658 | GpiBox(oi->hps,DRO_OUTLINEFILL,&ptl,0,0);
|
---|
659 |
|
---|
660 | /* draw highlights and shadows on graph */
|
---|
661 | if(pci->Longname[1] == 1)
|
---|
662 | GpiSetColor(oi->hps,CLR_GREEN);
|
---|
663 | else
|
---|
664 | GpiSetColor(oi->hps,CLR_PALEGRAY);
|
---|
665 | if(pci->flags > 5) {
|
---|
666 | ptl.x = oi->rclItem.xLeft + 1;
|
---|
667 | ptl.y = oi->rclItem.yBottom + 3;
|
---|
668 | GpiMove(oi->hps,&ptl);
|
---|
669 | ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 1;
|
---|
670 | GpiLine(oi->hps,&ptl);
|
---|
671 | }
|
---|
672 | else {
|
---|
673 | ptl.y = (oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y) - 1;
|
---|
674 | GpiMove(oi->hps,&ptl);
|
---|
675 | }
|
---|
676 | ptl.x = oi->rclItem.xLeft + pci->flags;
|
---|
677 | GpiLine(oi->hps,&ptl);
|
---|
678 | if(pci->Longname[1] != 1) {
|
---|
679 | GpiSetColor(oi->hps,CLR_DARKRED);
|
---|
680 | ptl.x = oi->rclItem.xLeft + 2;
|
---|
681 | ptl.y = oi->rclItem.yBottom + 3;
|
---|
682 | GpiMove(oi->hps,&ptl);
|
---|
683 | ptl.x = oi->rclItem.xLeft + pci->flags;
|
---|
684 | GpiLine(oi->hps,&ptl);
|
---|
685 | }
|
---|
686 | }
|
---|
687 |
|
---|
688 | /* draw hash marks in box */
|
---|
689 | GpiSetColor(oi->hps,CLR_WHITE);
|
---|
690 | clr = CLR_WHITE;
|
---|
691 | for(x = 1;x < 10;x++) {
|
---|
692 | if(clr == CLR_WHITE && x * 10 > pci->flags) {
|
---|
693 | clr = CLR_BLACK;
|
---|
694 | GpiSetColor(oi->hps,CLR_BLACK);
|
---|
695 | }
|
---|
696 | ptl.x = (oi->rclItem.xLeft + 1) + (x * 10);
|
---|
697 | ptl.y = oi->rclItem.yBottom + aptl[TXTBOX_TOPRIGHT].y - 1;
|
---|
698 | GpiMove(oi->hps,&ptl);
|
---|
699 | switch(x) {
|
---|
700 | case 1:
|
---|
701 | case 3:
|
---|
702 | case 7:
|
---|
703 | case 9:
|
---|
704 | ptl.y -= 1;
|
---|
705 | break;
|
---|
706 | case 5:
|
---|
707 | ptl.y -= 4;
|
---|
708 | break;
|
---|
709 | case 2:
|
---|
710 | case 4:
|
---|
711 | case 6:
|
---|
712 | case 8:
|
---|
713 | ptl.y -= 2;
|
---|
714 | break;
|
---|
715 | }
|
---|
716 | GpiLine(oi->hps,&ptl);
|
---|
717 | }
|
---|
718 | return MRFROMLONG(TRUE);
|
---|
719 | }
|
---|
720 | }
|
---|
721 | }
|
---|
722 | }
|
---|
723 | }
|
---|
724 | return FALSE;
|
---|
725 |
|
---|
726 | case WM_CONTROL:
|
---|
727 | switch(SHORT2FROMMP(mp1)) {
|
---|
728 | case CN_ENTER:
|
---|
729 | if(mp2) {
|
---|
730 |
|
---|
731 | PCNRITEM pci = (PCNRITEM)((PNOTIFYRECORDENTER)mp2)->pRecord;
|
---|
732 | CHAR filename[CCHMAXPATH],temp[CCHMAXPATH];
|
---|
733 |
|
---|
734 | if(pci) {
|
---|
735 | *filename = 0;
|
---|
736 | while(pci && (INT)pci != -1) {
|
---|
737 | memset(temp,0,sizeof(temp));
|
---|
738 | strncpy(temp,pci->szFileName,
|
---|
739 | pci->pszFileName - pci->szFileName);
|
---|
740 | strrev(temp);
|
---|
741 | if(*filename && *temp != '\\')
|
---|
742 | strcat(filename,"\\");
|
---|
743 | strcat(filename,temp);
|
---|
744 | pci = WinSendDlgItemMsg(hwnd,DSZ_CNR,CM_QUERYRECORD,
|
---|
745 | MPFROMP(pci),
|
---|
746 | MPFROM2SHORT(CMA_PARENT,
|
---|
747 | CMA_ITEMORDER));
|
---|
748 | }
|
---|
749 | strrev(filename);
|
---|
750 | if(!fVTreeOpensWPS)
|
---|
751 | OpenDirCnr((HWND)0,
|
---|
752 | (hwndMain) ? hwndMain : HWND_DESKTOP,
|
---|
753 | hwnd,
|
---|
754 | FALSE,
|
---|
755 | filename);
|
---|
756 | else {
|
---|
757 |
|
---|
758 | ULONG size = sizeof(ULONG),flWindowAttr = CV_ICON;
|
---|
759 | CHAR s[33];
|
---|
760 |
|
---|
761 | strcpy(s,"ICON");
|
---|
762 | PrfQueryProfileData(fmprof,appname,"DirflWindowAttr",
|
---|
763 | (PVOID)&flWindowAttr,&size);
|
---|
764 | if(flWindowAttr & CV_DETAIL) {
|
---|
765 | if(IsRoot(filename))
|
---|
766 | strcpy(s,"TREE");
|
---|
767 | else
|
---|
768 | strcpy(s,"DETAILS");
|
---|
769 | }
|
---|
770 | OpenObject(filename,s,hwnd);
|
---|
771 | }
|
---|
772 | }
|
---|
773 | }
|
---|
774 | break;
|
---|
775 | case CN_EMPHASIS:
|
---|
776 | data = INSTDATA(hwnd);
|
---|
777 | if(data && !data->working && mp2) {
|
---|
778 |
|
---|
779 | PNOTIFYRECORDEMPHASIS pre = mp2;
|
---|
780 | PCNRITEM pci;
|
---|
781 | CHAR tb[44],s[66];
|
---|
782 |
|
---|
783 | pci = (PCNRITEM)((pre) ? pre->pRecord : NULL);
|
---|
784 | if(pci && (pre->fEmphasisMask & CRA_SELECTED) &&
|
---|
785 | (pci->rc.flRecordAttr & CRA_SELECTED)) {
|
---|
786 | commafmt(tb,sizeof(tb),pci->attrFile);
|
---|
787 | sprintf(s,
|
---|
788 | "%s %s%s",
|
---|
789 | tb,
|
---|
790 | GetPString(IDS_FILETEXT),
|
---|
791 | &"s"[pci->attrFile == 1]);
|
---|
792 | WinSetDlgItemText(hwnd,
|
---|
793 | DSZ_NUMFILES,
|
---|
794 | s);
|
---|
795 | }
|
---|
796 | }
|
---|
797 | break;
|
---|
798 | }
|
---|
799 | return 0;
|
---|
800 |
|
---|
801 | case WM_COMMAND:
|
---|
802 | switch(SHORT1FROMMP(mp1)) {
|
---|
803 | case IDM_HELP:
|
---|
804 | if(hwndHelp)
|
---|
805 | WinSendMsg(hwndHelp,HM_DISPLAY_HELP,
|
---|
806 | MPFROM2SHORT(HELP_DIRSIZE,0),
|
---|
807 | MPFROMSHORT(HM_RESOURCEID));
|
---|
808 | break;
|
---|
809 |
|
---|
810 | case DSZ_PRINT:
|
---|
811 | data = INSTDATA(hwnd);
|
---|
812 | if(data && !data->working) {
|
---|
813 |
|
---|
814 | CHAR filename[CCHMAXPATH];
|
---|
815 | FILE *fp;
|
---|
816 |
|
---|
817 | save_dir2(filename);
|
---|
818 | sprintf(&filename[strlen(filename)],"\\%csizes.Rpt",
|
---|
819 | (data) ? toupper(*data->dirname) : '+');
|
---|
820 | if(export_filename(hwnd,filename,FALSE) && *filename) {
|
---|
821 | if(stricmp(filename,"PRN") &&
|
---|
822 | strnicmp(filename,"\\DEV\\LPT",8) &&
|
---|
823 | !strchr(filename,'.'))
|
---|
824 | strcat(filename,".RPT");
|
---|
825 | fp = fopen(filename,"a+");
|
---|
826 | if(fp) {
|
---|
827 | WinSetPointer(HWND_DESKTOP,hptrBusy);
|
---|
828 | PrintToFile(WinWindowFromID(hwnd,DSZ_CNR),0,NULL,fp);
|
---|
829 | fclose(fp);
|
---|
830 | WinSetPointer(HWND_DESKTOP,hptrArrow);
|
---|
831 | }
|
---|
832 | else
|
---|
833 | saymsg(MB_CANCEL,
|
---|
834 | hwnd,
|
---|
835 | GetPString(IDS_ERRORTEXT),
|
---|
836 | GetPString(IDS_COMPCANTOPENTEXT),
|
---|
837 | filename);
|
---|
838 | }
|
---|
839 | }
|
---|
840 | else
|
---|
841 | DosBeep(50,100);
|
---|
842 | break;
|
---|
843 |
|
---|
844 | case DSZ_EXPAND:
|
---|
845 | case DSZ_COLLAPSE:
|
---|
846 | {
|
---|
847 | PCNRITEM pci;
|
---|
848 |
|
---|
849 | pci = (PCNRITEM)WinSendDlgItemMsg(hwnd,DSZ_CNR,
|
---|
850 | CM_QUERYRECORDEMPHASIS,
|
---|
851 | MPFROMLONG(CMA_FIRST),
|
---|
852 | MPFROMSHORT(CRA_CURSORED));
|
---|
853 | if(pci)
|
---|
854 | ExpandAll(WinWindowFromID(hwnd,DSZ_CNR),
|
---|
855 | (SHORT1FROMMP(mp1) == DSZ_EXPAND),pci);
|
---|
856 | }
|
---|
857 | break;
|
---|
858 |
|
---|
859 | case DID_OK:
|
---|
860 | case DID_CANCEL:
|
---|
861 | data = INSTDATA(hwnd);
|
---|
862 | if(data) {
|
---|
863 | if(data->working) {
|
---|
864 | data->dying = TRUE;
|
---|
865 | data->stopflag = 0xff;
|
---|
866 | DosBeep(1000,100);
|
---|
867 | }
|
---|
868 | else
|
---|
869 | WinDismissDlg(hwnd,0);
|
---|
870 | }
|
---|
871 | break;
|
---|
872 | }
|
---|
873 | return 0;
|
---|
874 |
|
---|
875 | case WM_CLOSE:
|
---|
876 | data = INSTDATA(hwnd);
|
---|
877 | if(data)
|
---|
878 | data->stopflag = 0xff;
|
---|
879 | DosSleep(1L);
|
---|
880 | break;
|
---|
881 |
|
---|
882 | case WM_DESTROY:
|
---|
883 | data = INSTDATA(hwnd);
|
---|
884 | if(data) {
|
---|
885 | data->stopflag = 0xff;
|
---|
886 | if(data->hptr)
|
---|
887 | WinDestroyPointer(data->hptr);
|
---|
888 | DosSleep(33L);
|
---|
889 | free(data);
|
---|
890 | }
|
---|
891 | DosPostEventSem(CompactSem);
|
---|
892 | break;
|
---|
893 | }
|
---|
894 | return WinDefDlgProc(hwnd,msg,mp1,mp2);
|
---|
895 | }
|
---|