1 |
|
---|
2 | /***********************************************************************
|
---|
3 |
|
---|
4 | $Id: dirsize.c 551 2007-02-28 01:33:51Z gyoung $
|
---|
5 |
|
---|
6 | Directory sizes applet
|
---|
7 |
|
---|
8 | Copyright (c) 1993-98 M. Kimes
|
---|
9 | Copyright (c) 2004 Steven H.Levine
|
---|
10 |
|
---|
11 | Revisions 11 Jun 02 SHL - Baseline
|
---|
12 | 06 Jan 04 SHL - Total drives >4GB better
|
---|
13 |
|
---|
14 | ***********************************************************************/
|
---|
15 |
|
---|
16 | #define INCL_DOS
|
---|
17 | #define INCL_WIN
|
---|
18 |
|
---|
19 | #include <os2.h>
|
---|
20 | #include <stdarg.h>
|
---|
21 | #include <stdio.h>
|
---|
22 | #include <stdlib.h>
|
---|
23 | #include <string.h>
|
---|
24 | #include <ctype.h>
|
---|
25 |
|
---|
26 | #include "dll\fm3dll.h"
|
---|
27 | #include "dll\fm3dlg.h"
|
---|
28 | #include "dirsize.h"
|
---|
29 |
|
---|
30 | MRESULT EXPENTRY DirMainProc(HWND hwnd, ULONG msg, MPARAM mp1, MPARAM mp2)
|
---|
31 | {
|
---|
32 | static CHAR curdir[4];
|
---|
33 |
|
---|
34 | switch (msg) {
|
---|
35 | case WM_INITDLG:
|
---|
36 | *curdir = 0;
|
---|
37 | WinSendMsg(hwnd, UM_UNDO, MPVOID, MPVOID);
|
---|
38 | break;
|
---|
39 |
|
---|
40 | case UM_UNDO:
|
---|
41 | {
|
---|
42 | ULONG x;
|
---|
43 | ULONG ulDriveMap;
|
---|
44 | ULONG ulDriveNum;
|
---|
45 | CHAR dirname[] = " :\\";
|
---|
46 | BOOL first = TRUE;
|
---|
47 |
|
---|
48 | WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX, LM_DELETEALL, MPVOID, MPVOID);
|
---|
49 |
|
---|
50 | DosError(FERR_DISABLEHARDERR);
|
---|
51 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
52 |
|
---|
53 | for (x = 2; x < 26; x++) {
|
---|
54 | if ((ulDriveMap & (1L << x)) && !(driveflags[x] & DRIVE_IGNORE)) {
|
---|
55 | *dirname = (CHAR) x + 'A';
|
---|
56 | WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX, LM_INSERTITEM,
|
---|
57 | MPFROM2SHORT(LIT_END, 0), MPFROMP(dirname));
|
---|
58 | if (first) {
|
---|
59 | WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX, LM_SELECTITEM,
|
---|
60 | MPFROMSHORT(0), MPFROMSHORT(TRUE));
|
---|
61 | first = FALSE;
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|
65 | }
|
---|
66 | return 0;
|
---|
67 |
|
---|
68 | case UM_RESCAN:
|
---|
69 | {
|
---|
70 | CHAR FileSystem[CCHMAXPATH];
|
---|
71 | CHAR s[CCHMAXPATH * 2];
|
---|
72 | FSALLOCATE fsa;
|
---|
73 | ULONG type;
|
---|
74 | USHORT percentused;
|
---|
75 | USHORT percentfree;
|
---|
76 | struct
|
---|
77 | {
|
---|
78 | ULONG serial;
|
---|
79 | CHAR volumelength;
|
---|
80 | CHAR volumelabel[CCHMAXPATH];
|
---|
81 | }
|
---|
82 | volser;
|
---|
83 | INT removable;
|
---|
84 |
|
---|
85 | WinSetDlgItemText(hwnd, DIRSIZE_LABEL, "");
|
---|
86 | WinSetDlgItemText(hwnd, DIRSIZE_UNITSFREE, "");
|
---|
87 | WinSetDlgItemText(hwnd, DIRSIZE_UNITSUSED, "");
|
---|
88 | WinSetDlgItemText(hwnd, DIRSIZE_UNITSIZE, "");
|
---|
89 | WinSetDlgItemText(hwnd, DIRSIZE_PERCENT, "");
|
---|
90 | WinSetDlgItemText(hwnd, DIRSIZE_BYTESUSED, "");
|
---|
91 | WinSetDlgItemText(hwnd, DIRSIZE_BYTESFREE, "");
|
---|
92 | WinSetDlgItemText(hwnd, DIRSIZE_IFS, "");
|
---|
93 | WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "");
|
---|
94 | WinSendDlgItemMsg(hwnd, DIRSIZE_SLIDER, SLM_SETSLIDERINFO,
|
---|
95 | MPFROM2SHORT(SMA_SLIDERARMPOSITION,
|
---|
96 | SMA_INCREMENTVALUE), MPFROMSHORT(0));
|
---|
97 | removable = CheckDrive(toupper(*curdir), FileSystem, &type);
|
---|
98 | if (removable != -1) {
|
---|
99 | if (type & DRIVE_ZIPSTREAM)
|
---|
100 | WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Zipstream drive");
|
---|
101 | else if (type & DRIVE_REMOTE)
|
---|
102 | WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Remote drive");
|
---|
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
|
---|
204 |
|
---|
205 | VOID 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 |
|
---|
218 | int 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
|
---|