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