source: trunk/dirsize.c@ 1220

Last change on this file since 1220 was 1220, checked in by John Small, 17 years ago

Ticket 187: Moved typedef's and some #define's from fm3dll.h

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