[SETUPLIB] Improve the bootloader 'validity' checks -- Addendum to f06734e5 (r74512).
[reactos.git] / base / shell / cmd / label.c
1 /*
2 * LABEL.C - label internal command.
3 *
4 *
5 * History:
6 *
7 * 10-Dec-1998 (Eric Kohl)
8 * Started.
9 *
10 * 11-Dec-1998 (Eric Kohl)
11 * Finished.
12 *
13 * 19-Jan-1998 (Eric Kohl)
14 * Unicode ready!
15 *
16 * 28-Apr-2005 (Magnus Olsen <magnus@greatlord.com>)
17 * Remove all hardcoded strings in En.rc
18 */
19
20 #include "precomp.h"
21
22 #ifdef INCLUDE_CMD_LABEL
23
24
25 INT cmd_label (LPTSTR param)
26 {
27 TCHAR szRootPath[] = _T("A:\\");
28 TCHAR szLabel[80];
29 TCHAR szOldLabel[80];
30 DWORD dwSerialNr;
31
32 /* set empty label string */
33 szLabel[0] = _T('\0');
34
35 nErrorLevel = 0;
36
37 /* print help */
38 if (!_tcsncmp (param, _T("/?"), 2))
39 {
40 ConOutResPaging(TRUE,STRING_LABEL_HELP1);
41 return 0;
42 }
43
44 /* get parameters */
45 if (param[0] != _T('\0') && param[1] == _T(':'))
46 {
47 szRootPath[0] = toupper(*param);
48 param += 2;
49 while (_istspace(*param))
50 param++;
51 }
52 else
53 {
54 /* get label of current drive */
55 TCHAR szCurPath[MAX_PATH];
56 GetCurrentDirectory (MAX_PATH, szCurPath);
57 szRootPath[0] = szCurPath[0];
58 }
59
60 _tcsncat(szLabel, param, 79);
61
62 /* check root path */
63 if (!IsValidPathName (szRootPath))
64 {
65 error_invalid_drive ();
66 nErrorLevel = 1;
67 return 1;
68 }
69
70 if (szLabel[0] == _T('\0'))
71 {
72 GetVolumeInformation(szRootPath, szOldLabel, 80, &dwSerialNr,
73 NULL, NULL, NULL, 0);
74
75 /* print drive info */
76 if (szOldLabel[0] != _T('\0'))
77 {
78 ConOutResPrintf(STRING_LABEL_HELP2, _totupper(szRootPath[0]), szOldLabel);
79 }
80 else
81 {
82 ConOutResPrintf(STRING_LABEL_HELP3, _totupper(szRootPath[0]));
83 }
84
85 /* print the volume serial number */
86 ConOutResPrintf(STRING_LABEL_HELP4, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
87
88 ConOutResPuts(STRING_LABEL_HELP5);
89
90 ConInString(szLabel, 80);
91 }
92
93 if (!SetVolumeLabel(szRootPath, szLabel))
94 {
95 ConOutFormatMessage(GetLastError());
96 nErrorLevel = 1;
97 return 1;
98 }
99
100 return 0;
101 }
102
103 #endif /* INCLUDE_CMD_LABEL */
104
105 /* EOF */