| 1 |
|
|---|
| 2 | /***********************************************************************
|
|---|
| 3 |
|
|---|
| 4 | $Id: dirsize.c 552 2007-03-01 06:24:47Z 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 if (type & DRIVE_VIRTUAL)
|
|---|
| 104 | WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Virtual drive");
|
|---|
| 105 | else if (type & DRIVE_RAMDISK)
|
|---|
| 106 | WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Ramdisk");
|
|---|
| 107 | else {
|
|---|
| 108 | sprintf(s, "Local drive%s", (removable) ? " (removable)" : "");
|
|---|
| 109 | WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, s);
|
|---|
| 110 | }
|
|---|
| 111 | sprintf(s, "IFS: %s", FileSystem);
|
|---|
| 112 | WinSetDlgItemText(hwnd, DIRSIZE_IFS, s);
|
|---|
| 113 | memset(&volser, 0, sizeof(volser));
|
|---|
| 114 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 115 | if (!DosQueryFSInfo(toupper(*curdir) - '@', FSIL_VOLSER,
|
|---|
| 116 | &volser, (ULONG) sizeof(volser))) {
|
|---|
| 117 | sprintf(s, "Label: %s", volser.volumelabel);
|
|---|
| 118 | WinSetDlgItemText(hwnd, DIRSIZE_LABEL, s);
|
|---|
| 119 | }
|
|---|
| 120 | if (!DosQueryFSInfo(toupper(*curdir) - '@',
|
|---|
| 121 | FSIL_ALLOC, &fsa, sizeof(FSALLOCATE))) {
|
|---|
| 122 | percentfree = fsa.cUnit ? (fsa.cUnitAvail * 100) / fsa.cUnit : 0;
|
|---|
| 123 | if (!percentfree && fsa.cUnitAvail)
|
|---|
| 124 | percentfree = 1;
|
|---|
| 125 | percentused = 100 - percentfree;
|
|---|
| 126 | sprintf(s, "Units free: %lu", fsa.cUnitAvail);
|
|---|
| 127 | WinSetDlgItemText(hwnd, DIRSIZE_UNITSFREE, s);
|
|---|
| 128 | sprintf(s, "Unit size: %lu x %u = %lu",
|
|---|
| 129 | fsa.cSectorUnit,
|
|---|
| 130 | fsa.cbSector, fsa.cSectorUnit * fsa.cbSector);
|
|---|
| 131 | WinSetDlgItemText(hwnd, DIRSIZE_UNITSIZE, s);
|
|---|
| 132 | sprintf(s, "Units used: %lu", fsa.cUnit - fsa.cUnitAvail);
|
|---|
| 133 | WinSetDlgItemText(hwnd, DIRSIZE_UNITSUSED, s);
|
|---|
| 134 | sprintf(s, "Bytes free: %.0f",
|
|---|
| 135 | (float)fsa.cUnitAvail * (fsa.cSectorUnit * fsa.cbSector));
|
|---|
| 136 | WinSetDlgItemText(hwnd, DIRSIZE_BYTESFREE, s);
|
|---|
| 137 | sprintf(s, "Bytes used: %.0f",
|
|---|
| 138 | (float)(fsa.cUnit - fsa.cUnitAvail) *
|
|---|
| 139 | (fsa.cSectorUnit * fsa.cbSector));
|
|---|
| 140 | WinSetDlgItemText(hwnd, DIRSIZE_BYTESUSED, s);
|
|---|
| 141 | sprintf(s, "Percent used: %u%%", percentused);
|
|---|
| 142 | WinSetDlgItemText(hwnd, DIRSIZE_PERCENT, s);
|
|---|
| 143 | WinSendDlgItemMsg(hwnd, DIRSIZE_SLIDER, SLM_SETSLIDERINFO,
|
|---|
| 144 | MPFROM2SHORT(SMA_SLIDERARMPOSITION,
|
|---|
| 145 | SMA_INCREMENTVALUE),
|
|---|
| 146 | MPFROMSHORT(percentused));
|
|---|
| 147 | WinShowWindow(WinWindowFromID(hwnd, DIRSIZE_SLIDER), TRUE);
|
|---|
| 148 | }
|
|---|
| 149 | }
|
|---|
| 150 | else {
|
|---|
| 151 | WinSetDlgItemText(hwnd, DIRSIZE_LOCAL, "Drive not ready.");
|
|---|
| 152 | WinShowWindow(WinWindowFromID(hwnd, DIRSIZE_SLIDER), FALSE);
|
|---|
| 153 | }
|
|---|
| 154 | }
|
|---|
| 155 | return 0;
|
|---|
| 156 |
|
|---|
| 157 | case WM_CONTROL:
|
|---|
| 158 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 159 | case DIRSIZE_LISTBOX:
|
|---|
| 160 | switch (SHORT2FROMMP(mp1)) {
|
|---|
| 161 | case LN_ENTER:
|
|---|
| 162 | WinPostMsg(hwnd, WM_COMMAND, MPFROM2SHORT(DID_OK, 0), MPVOID);
|
|---|
| 163 | break;
|
|---|
| 164 | case LN_SELECT:
|
|---|
| 165 | {
|
|---|
| 166 | SHORT x;
|
|---|
| 167 |
|
|---|
| 168 | x = (SHORT) WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX,
|
|---|
| 169 | LM_QUERYSELECTION,
|
|---|
| 170 | MPFROMSHORT(LIT_FIRST), MPVOID);
|
|---|
| 171 | if (x >= 0) {
|
|---|
| 172 | WinSendDlgItemMsg(hwnd, DIRSIZE_LISTBOX,
|
|---|
| 173 | LM_QUERYITEMTEXT,
|
|---|
| 174 | MPFROM2SHORT(x, sizeof(curdir)),
|
|---|
| 175 | MPFROMP(curdir));
|
|---|
| 176 | WinPostMsg(hwnd, UM_RESCAN, MPVOID, MPVOID);
|
|---|
| 177 | }
|
|---|
| 178 | }
|
|---|
| 179 | break;
|
|---|
| 180 | }
|
|---|
| 181 | break;
|
|---|
| 182 | }
|
|---|
| 183 | return 0;
|
|---|
| 184 |
|
|---|
| 185 | case WM_COMMAND:
|
|---|
| 186 | switch (SHORT1FROMMP(mp1)) {
|
|---|
| 187 | case DID_CANCEL:
|
|---|
| 188 | WinDismissDlg(hwnd, 0);
|
|---|
| 189 | break;
|
|---|
| 190 |
|
|---|
| 191 | case DID_OK:
|
|---|
| 192 | if (*curdir) {
|
|---|
| 193 | WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_HIDE);
|
|---|
| 194 | WinDlgBox(HWND_DESKTOP, hwnd,
|
|---|
| 195 | DirSizeProc, FM3ModHandle, DSZ_FRAME, curdir);
|
|---|
| 196 | WinSetWindowPos(hwnd, HWND_TOP, 0, 0, 0, 0, SWP_SHOW);
|
|---|
| 197 | }
|
|---|
| 198 | else
|
|---|
| 199 | DosBeep(50, 100);
|
|---|
| 200 | break;
|
|---|
| 201 | }
|
|---|
| 202 | return 0;
|
|---|
| 203 | } // switch
|
|---|
| 204 | return WinDefDlgProc(hwnd, msg, mp1, mp2);
|
|---|
| 205 | }
|
|---|
| 206 |
|
|---|
| 207 | #ifdef NEVER
|
|---|
| 208 |
|
|---|
| 209 | VOID APIENTRY deinit(ULONG why)
|
|---|
| 210 | {
|
|---|
| 211 | if (fmprof)
|
|---|
| 212 | PrfCloseProfile(fmprof);
|
|---|
| 213 | fmprof = (HINI) 0;
|
|---|
| 214 |
|
|---|
| 215 | flushall();
|
|---|
| 216 |
|
|---|
| 217 | DosExitList(EXLST_REMOVE, deinit);
|
|---|
| 218 | }
|
|---|
| 219 |
|
|---|
| 220 | #endif
|
|---|
| 221 |
|
|---|
| 222 | int main(int argc, char *argv[])
|
|---|
| 223 | {
|
|---|
| 224 | HAB hab;
|
|---|
| 225 | HMQ hmq;
|
|---|
| 226 | static CHAR fullname[CCHMAXPATH];
|
|---|
| 227 | INT x;
|
|---|
| 228 | ULONG rcl;
|
|---|
| 229 |
|
|---|
| 230 | DosError(FERR_DISABLEHARDERR);
|
|---|
| 231 | *fullname = 0;
|
|---|
| 232 | for (x = 1; x < argc; x++) {
|
|---|
| 233 | if (!strchr("/;,`\'", *argv[x]) &&
|
|---|
| 234 | !*fullname && (IsRoot(argv[x]) || IsFile(argv[x]) == 0)) {
|
|---|
| 235 | if (IsRoot(argv[x]))
|
|---|
| 236 | strcpy(fullname, argv[x]);
|
|---|
| 237 | else if (DosQueryPathInfo(argv[x],
|
|---|
| 238 | FIL_QUERYFULLNAME,
|
|---|
| 239 | fullname, sizeof(fullname)))
|
|---|
| 240 | *fullname = 0;
|
|---|
| 241 | }
|
|---|
| 242 | }
|
|---|
| 243 |
|
|---|
| 244 | # ifdef NEVER
|
|---|
| 245 | DosExitList(EXLST_ADD, deinit);
|
|---|
| 246 | # endif
|
|---|
| 247 |
|
|---|
| 248 | hab = WinInitialize(0);
|
|---|
| 249 | if (hab) {
|
|---|
| 250 | hmq = WinCreateMsgQueue(hab, 384);
|
|---|
| 251 | if (hmq) {
|
|---|
| 252 | if (InitFM3DLL(hab, argc, argv)) {
|
|---|
| 253 | if (!*fullname)
|
|---|
| 254 | rcl = WinDlgBox(HWND_DESKTOP,
|
|---|
| 255 | HWND_DESKTOP, DirMainProc, 0, DIRSIZE_FRAME, NULL);
|
|---|
| 256 | else
|
|---|
| 257 | rcl = WinDlgBox(HWND_DESKTOP,
|
|---|
| 258 | HWND_DESKTOP,
|
|---|
| 259 | DirSizeProc, FM3ModHandle, DSZ_FRAME, fullname);
|
|---|
| 260 | if (rcl == DID_ERROR)
|
|---|
| 261 | rcl = WinGetLastError(hab);
|
|---|
| 262 | }
|
|---|
| 263 | WinDestroyMsgQueue(hmq);
|
|---|
| 264 | }
|
|---|
| 265 | WinTerminate(hab);
|
|---|
| 266 | }
|
|---|
| 267 | return 0;
|
|---|
| 268 |
|
|---|
| 269 | } // main
|
|---|