ReactOS 0.4.16-dev-340-g0540c21
label.c
Go to the documentation of this file.
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 <stdio.h>
21#include <stdlib.h>
22
23#include <windef.h>
24#include <winbase.h>
25#include <wincon.h>
26#include <winnls.h>
27#include <winuser.h>
28
29#include <conutils.h>
30
31#include "resource.h"
32
33#define MAX_LABEL_LENGTH 32
34#define MAX_DRIVE_LENGTH 2
35
36
37static
38VOID
40{
41 va_list arg_ptr;
42
43 va_start(arg_ptr, MessageId);
46 NULL,
47 MessageId,
49 &arg_ptr);
50 va_end(arg_ptr);
51}
52
53
54static
55VOID
57{
58 DWORD dwOldMode;
59 DWORD dwRead = 0;
61 LPWSTR p;
62 PCHAR pBuf;
63
65
67 GetConsoleMode(hFile, &dwOldMode);
68
70
71 ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
72
73 MultiByteToWideChar(GetConsoleCP(), 0, pBuf, dwRead, lpInput, dwLength - 1);
74 HeapFree(GetProcessHeap(), 0, pBuf);
75
76 for (p = lpInput; *p; p++)
77 {
78 if (*p == L'\x0d')
79 {
80 *p = UNICODE_NULL;
81 break;
82 }
83 }
84
85 SetConsoleMode(hFile, dwOldMode);
86}
87
88
89static
90BOOL
92{
93 WCHAR szOldPath[MAX_PATH];
94 BOOL bResult;
95
97 bResult = SetCurrentDirectoryW(pszPath);
98
99 SetCurrentDirectoryW(szOldPath);
100
101 return bResult;
102}
103
104
105static
106BOOL
108{
109 WCHAR szOptions[4];
110 WCHAR szInput[16];
111 BOOL bResult = FALSE;
112
114
115 for (;;)
116 {
117 ConPuts(StdOut, L"\n");
119
120 ConInString(szInput, ARRAYSIZE(szInput));
121
122 if (towupper(szInput[0]) == szOptions[0])
123 {
124 bResult = TRUE;
125 break;
126 }
127 else if (towupper(szInput[0]) == szOptions[1])
128 {
129 bResult = FALSE;
130 break;
131 }
132
133 ConPuts(StdOut, L"\n");
134 }
135
136 ConPuts(StdOut, L"\n");
137
138 return bResult;
139}
140
141
142int wmain(int argc, WCHAR *argv[])
143{
144 WCHAR szRootPath[] = L" :\\";
145 WCHAR szBuffer[80] = L"";
146 WCHAR szLabel[80] = L"";
147 WCHAR szOldLabel[80];
148 DWORD dwSerialNr;
149 INT len, i;
150
151 /* Initialize the Console Standard Streams */
153
154 /* print help */
155 if (argc > 1 && wcscmp(argv[1], L"/?") == 0)
156 {
158 return 0;
159 }
160
161 if (argc > 1)
162 {
163 len = 0;
164 for (i = 1; i < argc; i++)
165 {
166 if (i > 1)
167 len++;
168 len += wcslen(argv[i]);
169 }
170
172 {
174 return 1;
175 }
176
177 for (i = 1; i < argc; i++)
178 {
179 if (i > 1)
180 wcscat(szBuffer, L" ");
181 wcscat(szBuffer, argv[i]);
182 }
183 }
184
185 if (wcslen(szBuffer) > 0)
186 {
187 if (szBuffer[1] == L':')
188 {
189 szRootPath[0] = towupper(szBuffer[0]);
190 wcscpy(szLabel, &szBuffer[2]);
191 }
192 else
193 {
194 wcscpy(szLabel, szBuffer);
195 }
196 }
197
198 if (wcslen(szLabel) > MAX_LABEL_LENGTH)
199 {
201 return 1;
202 }
203
204 if (szRootPath[0] == L' ')
205 {
206 /* get label of current drive */
207 WCHAR szCurPath[MAX_PATH];
208 GetCurrentDirectoryW(MAX_PATH, szCurPath);
209 szRootPath[0] = szCurPath[0];
210 }
211
212 /* check root path */
213 if (!IsValidPathName(szRootPath))
214 {
216 return 1;
217 }
218
219 if (wcslen(szLabel) == 0)
220 {
221 GetVolumeInformationW(szRootPath, szOldLabel, ARRAYSIZE(szOldLabel), &dwSerialNr,
222 NULL, NULL, NULL, 0);
223
224 /* print drive info */
225 if (szOldLabel[0] != UNICODE_NULL)
226 {
227 ConResPrintf(StdOut, STRING_LABEL_TEXT1, towupper(szRootPath[0]), szOldLabel);
228 }
229 else
230 {
232 }
233
234 /* print the volume serial number */
235 ConResPrintf(StdOut, STRING_LABEL_TEXT3, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
236
238
239 ConInString(szLabel, ARRAYSIZE(szLabel));
240 ConPuts(StdOut, L"\n");
241
242 if (wcslen(szLabel) == 0)
243 {
244 if (PromptYesNo() == FALSE)
245 return 0;
246 }
247 }
248
249 if (!SetVolumeLabelW(szRootPath, szLabel))
250 {
252 return 1;
253 }
254
255 return 0;
256}
257
258/* EOF */
static int argc
Definition: ServiceArgs.c:12
char * va_list
Definition: acmsvcex.h:78
#define va_end(ap)
Definition: acmsvcex.h:90
#define va_start(ap, A)
Definition: acmsvcex.h:91
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: fc.c:16
#define ConInitStdStreams()
Definition: fc.c:13
#define StdOut
Definition: fc.c:14
void ConResPrintf(FILE *fp, UINT nID,...)
Definition: fc.c:33
#define StdErr
Definition: fc.c:15
void ConResPuts(FILE *fp, UINT nID)
Definition: fc.c:27
#define STRING_LABEL_TEXT4
Definition: resource.h:9
#define STRING_LABEL_HELP
Definition: resource.h:5
#define STRING_ERROR_INVALID_LABEL
Definition: resource.h:14
#define STRING_ERROR_INVALID_DRIVE
Definition: resource.h:13
#define STRING_LABEL_PROMPT
Definition: resource.h:10
#define STRING_LABEL_TEXT3
Definition: resource.h:8
#define STRING_LABEL_TEXT1
Definition: resource.h:6
#define STRING_LABEL_TEXT2
Definition: resource.h:7
#define STRING_LABEL_OPTIONS
Definition: resource.h:11
HANDLE WINAPI GetStdHandle(IN DWORD nStdHandle)
Definition: console.c:203
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define ARRAYSIZE(array)
Definition: filtermapper.c:47
#define GetProcessHeap()
Definition: compat.h:736
#define GetCurrentDirectoryW(x, y)
Definition: compat.h:756
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define MultiByteToWideChar
Definition: compat.h:110
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
static DWORD DWORD * dwLength
Definition: fusion.c:86
BOOL WINAPI GetConsoleMode(HANDLE hConsoleHandle, LPDWORD lpMode)
Definition: console.c:1569
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1606
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleCP(VOID)
Definition: console.c:2391
BOOL WINAPI GetVolumeInformationW(IN LPCWSTR lpRootPathName, IN LPWSTR lpVolumeNameBuffer, IN DWORD nVolumeNameSize, OUT LPDWORD lpVolumeSerialNumber OPTIONAL, OUT LPDWORD lpMaximumComponentLength OPTIONAL, OUT LPDWORD lpFileSystemFlags OPTIONAL, OUT LPWSTR lpFileSystemNameBuffer OPTIONAL, IN DWORD nFileSystemNameSize)
Definition: volume.c:226
BOOL WINAPI SetVolumeLabelW(IN LPCWSTR lpRootPathName, IN LPCWSTR lpVolumeName OPTIONAL)
Definition: volume.c:503
BOOL WINAPI SetCurrentDirectoryW(IN LPCWSTR lpPathName)
Definition: path.c:2249
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLfloat GLfloat p
Definition: glext.h:8902
GLenum GLsizei len
Definition: glext.h:6722
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
static VOID ConFormatMessage(PCON_STREAM Stream, DWORD MessageId,...)
Definition: label.c:39
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:56
#define MAX_LABEL_LENGTH
Definition: label.c:33
static BOOL IsValidPathName(LPCWSTR pszPath)
Definition: label.c:91
static BOOL PromptYesNo(VOID)
Definition: label.c:107
#define MAX_DRIVE_LENGTH
Definition: label.c:34
#define PCHAR
Definition: match.c:90
static IStream Stream
Definition: htmldoc.c:1115
#define argv
Definition: mplay32.c:18
_In_ HANDLE hFile
Definition: mswsock.h:90
#define UNICODE_NULL
#define L(x)
Definition: ntvdm.h:50
INT ConMsgPrintfV(IN PCON_STREAM Stream, IN DWORD dwFlags, IN LPCVOID lpSource OPTIONAL, IN DWORD dwMessageId, IN DWORD dwLanguageId, IN va_list *Arguments OPTIONAL)
Definition: outstream.c:1030
#define LOWORD(l)
Definition: pedump.c:82
int wmain()
_CRTIMP wchar_t *__cdecl wcscpy(_Out_writes_z_(_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
_Check_return_ _CRTIMP int __cdecl wcscmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
_CRTIMP wchar_t *__cdecl wcscat(_Inout_updates_z_(_String_length_(_Dest)+_String_length_(_Source)+1) wchar_t *_Dest, _In_z_ const wchar_t *_Source)
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
#define towupper(c)
Definition: wctype.h:99
int32_t INT
Definition: typedefs.h:58
#define HIWORD(l)
Definition: typedefs.h:247
char * PCHAR
Definition: typedefs.h:51
#define STD_INPUT_HANDLE
Definition: winbase.h:293
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define GetModuleHandle
Definition: winbase.h:3852
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:449
#define ENABLE_ECHO_INPUT
Definition: wincon.h:80
#define ENABLE_LINE_INPUT
Definition: wincon.h:79
#define LoadString
Definition: winuser.h:5831
__wchar_t WCHAR
Definition: xmlstorage.h:180
WCHAR * LPWSTR
Definition: xmlstorage.h:184
const WCHAR * LPCWSTR
Definition: xmlstorage.h:185