source: trunk/dirsize.c@ 1036

Last change on this file since 1036 was 907, checked in by Steven Levine, 18 years ago

Avoid out of memory traps in Compare Directories
Rework Compare Directories progress display for 2 second update rate
Start refactoring to reduce dependence on fm3dll.h
Add timer services (IsITimerExpired etc.)

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.9 KB
Line 
1
2/***********************************************************************
3
4 $Id: dirsize.c 907 2008-01-06 07:26:17Z stevenhl $
5
6 Directory sizes applet
7
8 Copyright (c) 1993-98 M. Kimes
9 Copyright (c) 2004 Steven H.Levine
10
11 11 Jun 02 SHL Baseline
12 06 Jan 04 SHL Total drives >4GB better
13
14***********************************************************************/
15
16#include <string.h>
17#include <ctype.h>
18
19#define INCL_DOS
20#define INCL_WIN
21
22#include "dll\fm3dlg.h"
23#include "dirsize.h"
24#include "dll\fm3dll.h"
25
26MRESULT EXPENTRY DirMainProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
27{
28 static CHAR curdir[4];
29
30 switch (msg) {
31 case WM_INITDLG:
32 *curdir = 0;
33 WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
34 break;
35
36 case UM_UNDO:
37 {
38 ULONG x;
39 ULONG ulDriveMap;
40 ULONG ulDriveNum;
41 CHAR dirname[] = " :\\";
42 BOOL first = TRUE;
43
44 WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
45
46 DosError(FERR_DISABLEHARDERR);
47 DosQCurDisk(&ulDriveNum, &ulDriveMap);
48
49 for (x = 2; x < 26; x++) {
50 if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE)) {
51 *dirname = (CHAR) x + 'A';
52 WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX, LM_INSERTITEM,
53 MPFROM2SHORT(LIT_END, 0), MPFROMP(dirname));
54 if (first) {
55 WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX, LM_SELECTITEM,
56 MPFROMSHORT(0), MPFROMSHORT(TRUE));
57 first = FALSE;
58 }
59 }
60 }
61 }
62 return 0;
63
64 case UM_RESCAN:
65 {
66 CHAR FileSystem[CCHMAXPATH];
67 CHAR s[CCHMAXPATH * 2];
68 FSALLOCATE fsa;
69 ULONG type;
70 USHORT percentused;
71 USHORT percentfree;
72 struct
73 {
74 ULONG serial;
75 CHAR volumelength;
76 CHAR volumelabel[CCHMAXPATH];
77 }
78 volser;
79 INT removable;
80
81 WinSetDlgItemText(hwnd, DIRSIZE_LABEL, "");
82 WinSetDlgItemText(hwnd, DIRSIZE_UNITSFREE, "");
83 WinSetDlgItemText(hwnd, DIRSIZE_UNITSUSED, "");
84 WinSetDlgItemText(hwnd, DIRSIZE_UNITSIZE, "");
85 WinSetDlgItemText(hwnd, DIRSIZE_PERCENT, "");
86 WinSetDlgItemText(hwnd, DIRSIZE_BYTESUSED, "");
87 WinSetDlgItemText(hwnd, DIRSIZE_BYTESFREE, "");
88 WinSetDlgItemText(hwnd, DIRSIZE_IFS, "");
89 WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "");
90 WinSendDlgItemMsg(hwnd, DIRSIZE_SLIDER, SLM_SETSLIDERINFO,
91 MPFROM2SHORT(SMA_SLIDERARMPOSITION,
92 SMA_INCREMENTVALUE), MPFROMSHORT(0));
93 removable = CheckDrive(toupper(*curdir), FileSystem, &type);
94 if (removable != -1) {
95 if (type & DRIVE_ZIPSTREAM)
96 WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Zipstream drive");
97 else if (type & DRIVE_REMOTE)
98 WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Remote drive");
99 else if (type & DRIVE_VIRTUAL)
100 WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Virtual drive");
101 else if (type & DRIVE_RAMDISK)
102 WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Ramdisk");
103 else {
104 sprintf(s, "Local drive%s", (removable) ? " (removable)" : "");
105 WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, s);
106 }
107 sprintf(s, "IFS: %s", FileSystem);
108 WinSetDlgItemText(hwnd, DIRSIZE_IFS, s);
109 memset(&volser, 0, sizeof(volser));
110 DosError(FERR_DISABLEHARDERR);
111 if (!DosQueryFSInfo(toupper(*curdir) - '@', FSIL_VOLSER,
112 &volser, (ULONG) sizeof(volser))) {
113 sprintf(s, "Label: %s", volser.volumelabel);
114 WinSetDlgItemText(hwnd, DIRSIZE_LABEL, s);
115 }
116 if (!DosQueryFSInfo(toupper(*curdir) - '@',
117 FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) {
118 percentfree = fsa.cUnit ? (fsa.cUnitAvail * 100) / fsa.cUnit : 0;
119 if (!percentfree && fsa.cUnitAvail)
120 percentfree = 1;
121 percentused = 100 - percentfree;
122 sprintf(s, "Units free: %lu", fsa.cUnitAvail);
123 WinSetDlgItemText(hwnd, DIRSIZE_UNITSFREE, s);
124 sprintf(s, "Unit size: %lu x %u = %lu",
125 fsa.cSectorUnit,
126 fsa.cbSector, fsa.cSectorUnit * fsa.cbSector);
127 WinSetDlgItemText(hwnd, DIRSIZE_UNITSIZE, s);
128 sprintf(s, "Units used: %lu", fsa.cUnit - fsa.cUnitAvail);
129 WinSetDlgItemText(hwnd, DIRSIZE_UNITSUSED, s);
130 sprintf(s, "Bytes free: %.0f",
131 (float)fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector));
132 WinSetDlgItemText(hwnd, DIRSIZE_BYTESFREE, s);
133 sprintf(s, "Bytes used: %.0f",
134 (float)(fsa.cUnit - fsa.cUnitAvail) *
135 (fsa.cSectorUnit * fsa.cbSector));
136 WinSetDlgItemText(hwnd, DIRSIZE_BYTESUSED, s);
137 sprintf(s, "Percent used: %u%%", percentused);
138 WinSetDlgItemText(hwnd, DIRSIZE_PERCENT, s);
139 WinSendDlgItemMsg(hwnd, DIRSIZE_SLIDER, SLM_SETSLIDERINFO,
140 MPFROM2SHORT(SMA_SLIDERARMPOSITION,
141 SMA_INCREMENTVALUE),
142 MPFROMSHORT(percentused));
143 WinShowWindow(WinWindowFromID(hwnd, DIRSIZE_SLIDER), TRUE);
144 }
145 }
146 else {
147 WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Drive not ready.");
148 WinShowWindow(WinWindowFromID(hwnd, DIRSIZE_SLIDER), FALSE);
149 }
150 }
151 return 0;
152
153 case WM_CONTROL:
154 switch (SHORT1FROMMP(mp1)) {
155 case DIRSIZE_LISTBOX:
156 switch (SHORT2FROMMP(mp1)) {
157 case LN_ENTER:
158 WinPostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
159 break;
160 case LN_SELECT:
161 {
162 SHORT x;
163
164 x = (SHORT) WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX,
165 LM_QUERYSELECTION,
166 MPFROMSHORT(LIT_FIRST), MPVOID);
167 if (x >= 0) {
168 WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX,
169 LM_QUERYITEMTEXT,
170 MPFROM2SHORT(x, sizeof(curdir)),
171 MPFROMP(curdir));
172 WinPostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
173 }
174 }
175 break;
176 }
177 break;
178 }
179 return 0;
180
181 case WM_COMMAND:
182 switch (SHORT1FROMMP(mp1)) {
183 case DID_CANCEL:
184 WinDismissDlg(hwnd, 0);
185 break;
186
187 case DID_OK:
188 if (*curdir) {
189 WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_HIDE);
190 WinDlgBox(HWND_DESKTOP, hwnd,
191 DirSizeProc, FM3ModHandle, DSZ_FRAME, curdir);
192 WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOW);
193 }
194 else
195 DosBeep(50, 100);
196 break;
197 }
198 return 0;
199 } // switch
200 return WinDefDlgProc(hwnd, msg, mp1, mp2);
201}
202
203#ifdef NEVER // 05 Jan 08 SHL fixme to be gone?
204
205VOID APIENTRY deinit(ULONG why)
206{
207 if (fmprof)
208 PrfCloseProfile(fmprof);
209 fmprof = (HINI) 0;
210
211 flushall();
212
213 DosExitList(EXLST_REMOVE, deinit);
214}
215
216#endif
217
218int main(int argc, char *argv[])
219{
220 HAB hab;
221 HMQ hmq;
222 static CHAR fullname[CCHMAXPATH];
223 INT x;
224 ULONG rcl;
225
226 DosError(FERR_DISABLEHARDERR);
227 *fullname = 0;
228 for (x = 1; x < argc; x++) {
229 if (!strchr("/;,`\'", *argv[x]) &&
230 !*fullname && (IsRoot(argv[x]) || IsFile(argv[x]) == 0)) {
231 if (IsRoot(argv[x]))
232 strcpy(fullname, argv[x]);
233 else if (DosQueryPathInfo(argv[x],
234 FIL_QUERYFULLNAME,
235 fullname, sizeof(fullname)))
236 *fullname = 0;
237 }
238 }
239
240# ifdef NEVER
241 DosExitList(EXLST_ADD, deinit);
242# endif
243
244 hab = WinInitialize(0);
245 if (hab) {
246 hmq = WinCreateMsgQueue(hab, 384);
247 if (hmq) {
248 if (InitFM3DLL(hab, argc, argv)) {
249 if (!*fullname)
250 rcl = WinDlgBox(HWND_DESKTOP,
251 HWND_DESKTOP, DirMainProc, 0, DIRSIZE_FRAME, NULL);
252 else
253 rcl = WinDlgBox(HWND_DESKTOP,
254 HWND_DESKTOP,
255 DirSizeProc, FM3ModHandle, DSZ_FRAME, fullname);
256 if (rcl == DID_ERROR)
257 rcl = WinGetLastError(hab);
258 }
259 WinDestroyMsgQueue(hmq);
260 }
261 WinTerminate(hab);
262 }
263 return 0;
264
265} // main
Note: See TracBrowser for help on using the repository browser.