ReactOS 0.4.16-dev-2613-g9533ad7
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
22#include <windef.h>
23#include <winbase.h>
24#include <wincon.h>
25#include <winnls.h>
26
27#include <conutils.h>
28
29#include "resource.h"
30
31#define MAX_LABEL_LENGTH 32
32#define MAX_DRIVE_LENGTH 2
33
34static
35VOID
37{
38 va_list arg_ptr;
39
40 va_start(arg_ptr, MessageId);
43 NULL,
44 MessageId,
46 &arg_ptr);
47 va_end(arg_ptr);
48}
49
50static
51VOID
53{
54 DWORD dwOldMode;
55 DWORD dwRead = 0;
57 LPWSTR p;
58 PCHAR pBuf;
59
61
63 GetConsoleMode(hFile, &dwOldMode);
64
66
67 ReadFile(hFile, (PVOID)pBuf, dwLength - 1, &dwRead, NULL);
68
69 MultiByteToWideChar(GetConsoleCP(), 0, pBuf, dwRead, lpInput, dwLength - 1);
70 HeapFree(GetProcessHeap(), 0, pBuf);
71
72 for (p = lpInput; *p; p++)
73 {
74 if (*p == L'\x0d')
75 {
76 *p = UNICODE_NULL;
77 break;
78 }
79 }
80
81 SetConsoleMode(hFile, dwOldMode);
82}
83
84static
85BOOL
87{
88 WCHAR szOldPath[MAX_PATH];
89 BOOL bResult;
90
92 bResult = SetCurrentDirectoryW(pszPath);
93
94 SetCurrentDirectoryW(szOldPath);
95
96 return bResult;
97}
98
99static
100BOOL
102{
103 WCHAR szOptions[4];
104 WCHAR szInput[16];
105 BOOL bResult = FALSE;
106
107 LoadStringW(NULL, STRING_LABEL_OPTIONS, szOptions, ARRAYSIZE(szOptions));
108
109 for (;;)
110 {
111 ConPuts(StdOut, L"\n");
113
114 ConInString(szInput, ARRAYSIZE(szInput));
115
116 if (towupper(szInput[0]) == szOptions[0])
117 {
118 bResult = TRUE;
119 break;
120 }
121 else if (towupper(szInput[0]) == szOptions[1])
122 {
123 bResult = FALSE;
124 break;
125 }
126
127 ConPuts(StdOut, L"\n");
128 }
129
130 ConPuts(StdOut, L"\n");
131
132 return bResult;
133}
134
135int wmain(int argc, WCHAR *argv[])
136{
137 WCHAR szRootPath[] = L" :\\";
138 WCHAR szBuffer[80] = L"";
139 WCHAR szLabel[80] = L"";
140 WCHAR szOldLabel[80];
141 DWORD dwSerialNr;
142 INT i;
143
144 /* Initialize the Console Standard Streams */
146
147 /* print help */
148 if (argc > 1 && wcscmp(argv[1], L"/?") == 0)
149 {
151 return 0;
152 }
153
154 if (argc > 1)
155 {
156 size_t len = 0;
157 for (i = 1; i < argc; i++)
158 {
159 if (i > 1)
160 len++;
161 len += wcslen(argv[i]);
162 }
163
165 {
167 return 1;
168 }
169
170 for (i = 1; i < argc; i++)
171 {
172 if (i > 1)
173 wcscat(szBuffer, L" ");
174 wcscat(szBuffer, argv[i]);
175 }
176 }
177
178 if (wcslen(szBuffer) > 0)
179 {
180 if (szBuffer[1] == L':')
181 {
182 szRootPath[0] = towupper(szBuffer[0]);
183 wcscpy(szLabel, &szBuffer[2]);
184 }
185 else
186 {
187 wcscpy(szLabel, szBuffer);
188 }
189 }
190
191 if (wcslen(szLabel) > MAX_LABEL_LENGTH)
192 {
194 return 1;
195 }
196
197 if (szRootPath[0] == L' ')
198 {
199 /* get label of current drive */
200 WCHAR szCurPath[MAX_PATH];
201 GetCurrentDirectoryW(MAX_PATH, szCurPath);
202 szRootPath[0] = szCurPath[0];
203 }
204
205 /* check root path */
206 if (!IsValidPathName(szRootPath))
207 {
209 return 1;
210 }
211
212 if (wcslen(szLabel) == 0)
213 {
214 GetVolumeInformationW(szRootPath, szOldLabel, ARRAYSIZE(szOldLabel), &dwSerialNr,
215 NULL, NULL, NULL, 0);
216
217 /* print drive info */
218 if (szOldLabel[0] != UNICODE_NULL)
219 {
220 ConResPrintf(StdOut, STRING_LABEL_TEXT1, towupper(szRootPath[0]), szOldLabel);
221 }
222 else
223 {
225 }
226
227 /* print the volume serial number */
228 ConResPrintf(StdOut, STRING_LABEL_TEXT3, HIWORD(dwSerialNr), LOWORD(dwSerialNr));
229
231
232 ConInString(szLabel, ARRAYSIZE(szLabel));
233 ConPuts(StdOut, L"\n");
234
235 if (wcslen(szLabel) == 0)
236 {
237 if (PromptYesNo() == FALSE)
238 return 0;
239 }
240 }
241
242 if (!SetVolumeLabelW(szRootPath, szLabel))
243 {
245 return 1;
246 }
247
248 return 0;
249}
250
251/* EOF */
#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
void ConPuts(FILE *fp, LPCWSTR psz)
Definition: conutils_noros.h:8
#define ConInitStdStreams()
Definition: conutils_noros.h:5
#define StdOut
Definition: conutils_noros.h:6
void ConResPrintf(FILE *fp, UINT nID,...)
#define StdErr
Definition: conutils_noros.h:7
void ConResPuts(FILE *fp, UINT nID)
#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:1571
BOOL WINAPI DECLSPEC_HOTPATCH SetConsoleMode(HANDLE hConsoleHandle, DWORD dwMode)
Definition: console.c:1608
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:2168
UINT WINAPI DECLSPEC_HOTPATCH GetConsoleCP(void)
Definition: console.c:821
MonoAssembly int argc
Definition: metahost.c:107
_ACRTIMP size_t __cdecl wcslen(const wchar_t *)
Definition: wcs.c:2983
_ACRTIMP int __cdecl wcscmp(const wchar_t *, const wchar_t *)
Definition: wcs.c:1972
#define va_end(v)
Definition: stdarg.h:28
#define va_start(v, l)
Definition: stdarg.h:26
char * va_list
Definition: vadefs.h:50
#define L(x)
Definition: resources.c:13
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
static VOID ConFormatMessage(PCON_STREAM Stream, DWORD MessageId,...)
Definition: label.c:36
static VOID ConInString(LPWSTR lpInput, DWORD dwLength)
Definition: label.c:52
#define MAX_LABEL_LENGTH
Definition: label.c:31
static BOOL IsValidPathName(LPCWSTR pszPath)
Definition: label.c:86
static BOOL PromptYesNo(VOID)
Definition: label.c:101
#define MAX_DRIVE_LENGTH
Definition: label.c:32
#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
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:1028
#define LOWORD(l)
Definition: pedump.c:82
short WCHAR
Definition: pedump.c:58
int wmain()
wcscat
wcscpy
#define LoadStringW
Definition: utils.h:64
#define towupper(c)
Definition: wctype.h:99
#define LANG_USER_DEFAULT
Definition: tnerror.cpp:50
const uint16_t * LPCWSTR
Definition: typedefs.h:57
uint16_t * LPWSTR
Definition: typedefs.h:56
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:291
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define FORMAT_MESSAGE_FROM_SYSTEM
Definition: winbase.h:400
#define ENABLE_ECHO_INPUT
Definition: wincon.h:109
#define ENABLE_LINE_INPUT
Definition: wincon.h:108