- Remove hard-coded reference to cmdstart.bat and load it from registry (Software...
[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 szMsg[RC_STRING_MAX_SIZE];
28 TCHAR szRootPath[] = _T("A:\\");
29 TCHAR szLabel[80];
30 TCHAR szOldLabel[80];
31 DWORD dwSerialNr;
32 LPTSTR *arg;
33 INT args;
34
35 /* set empty label string */
36 szLabel[0] = _T('\0');
37
38 /* print help */
39 if (!_tcsncmp (param, _T("/?"), 2))
40 {
41 ConOutResPaging(TRUE,STRING_LABEL_HELP1);
42 return 0;
43 }
44
45 nErrorLevel = 0;
46
47 /* get parameters */
48 arg = split (param, &args, FALSE);
49
50 if (args > 2)
51 {
52 /* too many parameters */
53 error_too_many_parameters (arg[args - 1]);
54 freep (arg);
55 nErrorLevel = 1;
56 return 1;
57 }
58
59 if (args == 0)
60 {
61 /* get label of current drive */
62 TCHAR szCurPath[MAX_PATH];
63 GetCurrentDirectory (MAX_PATH, szCurPath);
64 szRootPath[0] = szCurPath[0];
65 }
66 else
67 {
68 if ((_tcslen (arg[0]) >= 2) && (arg[0][1] == _T(':')))
69 {
70 szRootPath[0] = toupper (*arg[0]);
71 if (args == 2)
72 _tcsncpy (szLabel, arg[1], 12);
73 }
74 else
75 {
76 TCHAR szCurPath[MAX_PATH];
77 GetCurrentDirectory (MAX_PATH, szCurPath);
78 szRootPath[0] = szCurPath[0];
79 _tcsncpy (szLabel, arg[0], 12);
80 }
81 }
82
83 /* check root path */
84 if (!IsValidPathName (szRootPath))
85 {
86 error_invalid_drive ();
87 freep (arg);
88 nErrorLevel = 1;
89 return 1;
90 }
91
92 GetVolumeInformation(szRootPath, szOldLabel, 80, &dwSerialNr,
93 NULL, NULL, NULL, 0);
94
95 /* print drive info */
96 if (szOldLabel[0] != _T('\0'))
97 {
98 LoadString(CMD_ModuleHandle, STRING_LABEL_HELP2, szMsg, RC_STRING_MAX_SIZE);
99 ConOutPrintf(szMsg, _totupper(szRootPath[0]), szOldLabel);
100 }
101 else
102 {
103 LoadString(CMD_ModuleHandle, STRING_LABEL_HELP3, szMsg, RC_STRING_MAX_SIZE);
104 ConOutPrintf(szMsg, _totupper(szRootPath[0]));
105 }
106
107 /* print the volume serial number */
108 LoadString(CMD_ModuleHandle, STRING_LABEL_HELP4, szMsg, RC_STRING_MAX_SIZE);
109 ConOutPrintf(szMsg, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
110
111 if (szLabel[0] == _T('\0'))
112 {
113 LoadString(CMD_ModuleHandle, STRING_LABEL_HELP5, szMsg, RC_STRING_MAX_SIZE);
114 ConOutResPuts(STRING_LABEL_HELP5);
115
116 ConInString(szLabel, 80);
117 }
118
119 SetVolumeLabel(szRootPath, szLabel);
120
121 freep(arg);
122
123 return 0;
124 }
125
126 #endif /* INCLUDE_CMD_LABEL */
127
128 /* EOF */