1 /*
2 * FREE.C - internal command.
3 *
4 *
5 * History:
6 *
7 * 01-Sep-1999 (Eric Kohl)
8 * Started.
9 *
10 * 28-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
11 * Remove all hardcoded strings in En.rc
12 */
13
14 #include "precomp.h"
15
16 #ifdef INCLUDE_CMD_FREE
17
18 static VOID
PrintDiskInfo(LPTSTR szDisk)19 PrintDiskInfo (LPTSTR szDisk)
20 {
21 TCHAR szMsg[RC_STRING_MAX_SIZE];
22 TCHAR szRootPath[4] = _T("A:\\");
23 TCHAR szDrive[2] = _T("A");
24 TCHAR szVolume[64];
25 TCHAR szSerial[10];
26 TCHAR szTotal[40];
27 TCHAR szUsed[40];
28 TCHAR szFree[40];
29 DWORD dwSerial;
30 ULONGLONG uliSize;
31 DWORD dwSecPerCl;
32 DWORD dwBytPerSec;
33 DWORD dwFreeCl;
34 DWORD dwTotCl;
35
36 if (_tcslen (szDisk) < 2 || szDisk[1] != _T(':'))
37 {
38 ConErrResPrintf(STRING_FREE_ERROR1);
39 return;
40 }
41
42 szRootPath[0] = szDisk[0];
43 szDrive[0] = _totupper (szRootPath[0]);
44
45 if (!GetVolumeInformation (szRootPath, szVolume, 64, &dwSerial,
46 NULL, NULL, NULL, 0))
47 {
48 LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, ARRAYSIZE(szMsg));
49 ConErrPrintf(_T("%s %s:\n"), szMsg, szDrive);
50 return;
51 }
52
53 if (szVolume[0] == _T('\0'))
54 {
55
56 LoadString(CMD_ModuleHandle, STRING_FREE_ERROR2, szMsg, ARRAYSIZE(szMsg));
57 _tcscpy (szVolume, szMsg);
58 }
59
60 _stprintf (szSerial,
61 _T("%04X-%04X"),
62 HIWORD(dwSerial),
63 LOWORD(dwSerial));
64
65 if (!GetDiskFreeSpace (szRootPath, &dwSecPerCl,
66 &dwBytPerSec, &dwFreeCl, &dwTotCl))
67 {
68 LoadString(CMD_ModuleHandle, STRING_FREE_ERROR1, szMsg, ARRAYSIZE(szMsg));
69 ConErrPrintf(_T("%s %s:\n"), szMsg, szDrive);
70 return;
71 }
72
73 uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)dwTotCl;
74 ConvertULargeInteger(uliSize, szTotal, 40, TRUE);
75
76 uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)(dwTotCl - dwFreeCl);
77 ConvertULargeInteger(uliSize, szUsed, 40, TRUE);
78
79 uliSize = dwSecPerCl * dwBytPerSec * (ULONGLONG)dwFreeCl;
80 ConvertULargeInteger(uliSize, szFree, 40, TRUE);
81
82 ConOutResPrintf(STRING_FREE_HELP1, szDrive, szVolume, szSerial, szTotal, szUsed, szFree);
83 }
84
85
CommandFree(LPTSTR param)86 INT CommandFree (LPTSTR param)
87 {
88 LPTSTR szParam;
89 TCHAR szDefPath[MAX_PATH];
90 INT argc, i;
91 LPTSTR *arg;
92
93 if (!_tcsncmp (param, _T("/?"), 2))
94 {
95 ConOutResPaging(TRUE,STRING_FREE_HELP2);
96 return 0;
97 }
98
99 if (!param || *param == _T('\0'))
100 {
101 GetCurrentDirectory (MAX_PATH, szDefPath);
102 szDefPath[2] = _T('\0');
103 szParam = szDefPath;
104 }
105 else
106 szParam = param;
107
108 arg = split (szParam, &argc, FALSE, FALSE);
109
110 for (i = 0; i < argc; i++)
111 PrintDiskInfo (arg[i]);
112
113 freep (arg);
114
115 return 0;
116 }
117
118 #endif /* INCLUDE_CMD_FREE */
119
120 /* EOF */
121