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