source: trunk/dirsize.c@ 1055

Last change on this file since 1055 was 1055, checked in by Steven Levine, 17 years ago

Avoid WARNALL warning

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