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