sync with trunk head (34904)
[reactos.git] / reactos / 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 hardcode string to En.rc
18 */
19
20 #include <precomp.h>
21
22 #ifdef INCLUDE_CMD_LABEL
23
24
25 INT cmd_label (LPTSTR cmd, 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 _tcsncpy (szLabel, param, 12);
61
62 /* check root path */
63 if (!IsValidPathName (szRootPath))
64 {
65 error_invalid_drive ();
66 nErrorLevel = 1;
67 return 1;
68 }
69
70 GetVolumeInformation(szRootPath, szOldLabel, 80, &dwSerialNr,
71 NULL, NULL, NULL, 0);
72
73 /* print drive info */
74 if (szOldLabel[0] != _T('\0'))
75 {
76 ConOutResPrintf(STRING_LABEL_HELP2, _totupper(szRootPath[0]), szOldLabel);
77 }
78 else
79 {
80 ConOutResPrintf(STRING_LABEL_HELP3, _totupper(szRootPath[0]));
81 }
82
83 /* print the volume serial number */
84 ConOutResPrintf(STRING_LABEL_HELP4, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
85
86 if (szLabel[0] == _T('\0'))
87 {
88 ConOutResPuts(STRING_LABEL_HELP5);
89
90 ConInString(szLabel, 80);
91 }
92
93 SetVolumeLabel(szRootPath, szLabel);
94
95 return 0;
96 }
97
98 #endif /* INCLUDE_CMD_LABEL */
99
100 /* EOF */