ReactOS 0.4.16-dev-125-g798ea90
CShellCommandSetValue Class Reference

#include <ShellCommandSetValue.h>

Inheritance diagram for CShellCommandSetValue:
Collaboration diagram for CShellCommandSetValue:

Public Member Functions

 CShellCommandSetValue (CRegistryTree &rTree)
 
virtual ~CShellCommandSetValue ()
 
virtual BOOL Match (const TCHAR *pchCommand)
 
virtual int Execute (CConsole &rConsole, CArgumentParser &rArguments)
 
virtual const TCHARGetHelpString ()
 
virtual const TCHARGetHelpShortDescriptionString ()
 
- Public Member Functions inherited from CShellCommand
 CShellCommand ()
 
virtual ~CShellCommand ()
 
virtual BOOL Match (const TCHAR *pchCommand)=0
 
virtual int Execute (CConsole &rConsole, CArgumentParser &rArguments)=0
 
virtual const TCHARGetHelpString ()=0
 
virtual const TCHARGetHelpShortDescriptionString ()=0
 

Private Attributes

CRegistryTreem_rTree
 

Detailed Description

Definition at line 12 of file ShellCommandSetValue.h.

Constructor & Destructor Documentation

◆ CShellCommandSetValue()

CShellCommandSetValue::CShellCommandSetValue ( CRegistryTree rTree)

Definition at line 98 of file ShellCommandSetValue.cpp.

98 :m_rTree(rTree)
99{
100}

◆ ~CShellCommandSetValue()

CShellCommandSetValue::~CShellCommandSetValue ( )
virtual

Definition at line 102 of file ShellCommandSetValue.cpp.

103{
104}

Member Function Documentation

◆ Execute()

int CShellCommandSetValue::Execute ( CConsole rConsole,
CArgumentParser rArguments 
)
virtual

Implements CShellCommand.

Definition at line 119 of file ShellCommandSetValue.cpp.

120{
121 LONG nError;
122
123 rArguments.ResetArgumentIteration();
124 TCHAR *pszCommandItself = rArguments.GetNextArgument();
125
126 TCHAR *pszParameter;
127 TCHAR *pszValueFull = NULL;
128 TCHAR *pszValueData = NULL;
129 BOOL blnBadParameter = FALSE;
130 BOOL blnHelp = FALSE;
131 DWORD dwValueSize = 0;
132 DWORD dwType = REG_NONE;
133 BYTE *pDataBuffer = NULL;
134
135 if ((_tcsnicmp(pszCommandItself,SET_VALUE_CMD _T(".."),SET_VALUE_CMD_LENGTH+2*sizeof(TCHAR)) == 0)||
136 (_tcsnicmp(pszCommandItself,SET_VALUE_CMD _T("\\"),SET_VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0))
137 {
138 pszValueFull = pszCommandItself + SET_VALUE_CMD_LENGTH;
139 }
140 else if (_tcsnicmp(pszCommandItself,SET_VALUE_CMD _T("/"),SET_VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
141 {
142 pszParameter = pszCommandItself + SET_VALUE_CMD_LENGTH;
143 goto CheckValueArgument;
144 }
145
146 while((pszParameter = rArguments.GetNextArgument()) != NULL)
147 {
148CheckValueArgument:
149 blnBadParameter = FALSE;
150 if (((*pszParameter == _T('/'))||(*pszParameter == _T('-')))
151 &&(*(pszParameter+1) == _T('?')))
152 {
153 blnHelp = TRUE;
154 }
155 else if (dwType == REG_NONE)
156 {
157 if (_tcsicmp(pszParameter,_T("b")) == 0)
158 {
159 dwType = REG_BINARY;
160 }
161 else if (_tcsicmp(pszParameter,_T("dw")) == 0)
162 {
163 dwType = REG_DWORD;
164 }
165 else if (_tcsicmp(pszParameter,_T("dwle")) == 0)
166 {
168 }
169 else if (_tcsicmp(pszParameter,_T("dwbe")) == 0)
170 {
171 dwType = REG_DWORD_BIG_ENDIAN;
172 }
173 else if (_tcsicmp(pszParameter,_T("sz")) == 0)
174 {
175 dwType = REG_SZ;
176 }
177 else if (_tcsicmp(pszParameter,_T("esz")) == 0)
178 {
179 dwType = REG_EXPAND_SZ;
180 }
181 else
182 {
183 blnBadParameter = TRUE;
184 }
185 }
186 else if (pszValueData == NULL)
187 {
188 pszValueData = pszParameter;
189 }
190 else if (!pszValueFull)
191 {
192 pszValueFull = pszParameter;
193 }
194 else
195 {
196 blnBadParameter = TRUE;
197 }
198 if (blnBadParameter)
199 {
200 rConsole.Write(_T("Bad parameter: "));
201 rConsole.Write(pszParameter);
202 rConsole.Write(_T("\n"));
203 }
204 }
205
206 if (!pszValueData)
207 blnHelp = TRUE;
208
210 TCHAR *pszValueName;
211 const TCHAR *pszEmpty = _T("");
212 const TCHAR *pszPath;
213
214 if (blnHelp)
215 {
216 rConsole.Write(GetHelpString());
217
218 if (pDataBuffer)
219 delete pDataBuffer;
220
221 return 0;
222 }
223
224 if (pszValueFull)
225 {
226 if (_tcscmp(pszValueFull,_T("\\")) == 0)
227 goto CommandNAonRoot;
228
229 TCHAR *pchSep = _tcsrchr(pszValueFull,_T('\\'));
230 pszValueName = pchSep?(pchSep+1):(pszValueFull);
231 pszPath = pchSep?pszValueFull:_T(".");
232
233 //if (_tcsrchr(pszValueName,_T('.')))
234 //{
235 // pszValueName = _T("");
236 // pszPath = pszValueFull;
237 //}
238 //else
239 if (pchSep)
240 *pchSep = 0;
241 }
242 else
243 {
244 pszValueName = (TCHAR*)pszEmpty;
245 pszPath = _T(".");
246 }
247
248 if (!m_rTree.GetKey(pszPath,KEY_SET_VALUE,Key))
249 {
251 goto SkipCommand;
252 }
253
254 if (Key.IsRoot())
255 goto CommandNAonRoot;
256
257 switch (dwType)
258 {
259 case REG_BINARY:
260 {
262 DWORD dwBytesReaded;
265 {
266 rConsole.Write(_T("Cannot open file "));
267 rConsole.Write(pszValueData);
268 rConsole.Write(_T("\n"));
269 goto SkipCommand;
270 }
271 dwValueSize = GetFileSize(hFile,NULL);
272 if (dwValueSize == (DWORD)-1) // ok, that's right, we compare signed with unsigned here.
273 // GetFileSize is documented and declared to return DWORD.
274 // Error is indicated by checking if return is -1. Design->documentation bug ???
275 {
276 rConsole.Write(_T("Cannot get size of file "));
277 rConsole.Write(pszValueData);
278 rConsole.Write(_T("\n"));
280 goto SkipCommand;
281 }
282 pDataBuffer = new BYTE [dwValueSize];
283 if (!pDataBuffer)
284 {
285 rConsole.Write(_T("Cannot load file into memory. Out of memory.\n"));
287 goto SkipCommand;
288 }
289 if (!ReadFile(hFile,pDataBuffer,dwValueSize,&dwBytesReaded,NULL))
290 {
291 rConsole.Write(_T("Cannot load file into memory. Error reading file.\n"));
293 goto SkipCommand;
294 }
295
297 ASSERT(dwBytesReaded == dwValueSize);
298 }
299 break;
302 dwValueSize = 4;
303 pDataBuffer = (BYTE *) new BYTE [dwValueSize];
304 if (!StringToDWORD(*(DWORD *)pDataBuffer,pszValueData))
305 {
306 rConsole.Write(_T("Cannot convert "));
307 rConsole.Write(pszValueData);
308 rConsole.Write(_T(" to DWORD \n"));
309 goto SkipCommand;
310 }
311 if (dwType == REG_DWORD_BIG_ENDIAN)
312 {
313 unsigned char nByte;
314 nByte = *pDataBuffer;
315 *pDataBuffer = *(pDataBuffer+3);
316 *(pDataBuffer+3) = nByte;
317 nByte = *(pDataBuffer+1);
318 *(pDataBuffer+1) = *(pDataBuffer+2);
319 *(pDataBuffer+2) = nByte;
320 }
321 break;
322 case REG_SZ:
323 case REG_EXPAND_SZ:
324 dwValueSize = _tcslen(pszValueData)+1;
325 if (*pszValueData == _T('\"'))
326 {
327 dwValueSize -= 2;
328 *(pszValueData+dwValueSize) = 0;
329 pszValueData++;
330 }
331 dwValueSize *= sizeof(TCHAR);
332 pDataBuffer = (BYTE *) new BYTE [dwValueSize];
333
334 {
335 const TCHAR *pchSrc = pszValueData;
336 TCHAR *pchDest = (TCHAR *)pDataBuffer;
337 while(*pchSrc)
338 {
339 if (pchSrc[0] == _T('^'))
340 {
341 if (pchSrc[1] == _T('a'))
342 *pchDest = _T('\a');
343 else if (pchSrc[1] == _T('b'))
344 *pchDest = _T('\b');
345 else if (pchSrc[1] == _T('f'))
346 *pchDest = _T('\f');
347 else if (pchSrc[1] == _T('n'))
348 *pchDest = _T('\n');
349 else if (pchSrc[1] == _T('r'))
350 *pchDest = _T('\r');
351 else if (pchSrc[1] == _T('t'))
352 *pchDest = _T('\t');
353 else
354 *pchDest = pchSrc[1];
355
356 pchSrc +=2;
357 pchDest++;
358 dwValueSize--;
359 }
360 else
361 {
362 *pchDest = *pchSrc;
363 pchSrc++;
364 pchDest++;
365 }
366 }
367 *pchDest = _T('\0');
368 }
369 break;
370 default:
371 ASSERT(FALSE);
372 }
373
374 {
375 size_t s = _tcslen(pszValueName);
376 if (s && (pszValueName[0] == _T('\"'))&&(pszValueName[s-1] == _T('\"')))
377 {
378 pszValueName[s-1] = 0;
379 pszValueName++;
380 }
381 }
382
383 nError = Key.SetValue(pszValueName,dwType,pDataBuffer,dwValueSize);
384 if (nError != ERROR_SUCCESS)
385 {
386 char Buffer[254];
387 _stprintf(Buffer,_T("Cannot set value. Error is %u\n"),(unsigned int)nError);
388 rConsole.Write(Buffer);
389 }
390 else
391 {
393 }
394
395SkipCommand:
396 if (pDataBuffer)
397 delete[] pDataBuffer;
398 return 0;
399
400CommandNAonRoot:
402 return 0;
403}
void InvalidateCompletion()
Definition: Completion.cpp:511
#define COMMAND_NA_ON_ROOT
BOOL StringToDWORD(DWORD &rdwOut, const TCHAR *pszIn)
#define SET_VALUE_CMD_LENGTH
#define SET_VALUE_CMD
Definition: bufpool.h:45
void ResetArgumentIteration()
TCHAR * GetNextArgument()
BOOL Write(const TCHAR *p, DWORD dwChars=0)
Definition: Console.cpp:90
BOOL GetKey(const TCHAR *pchRelativePath, REGSAM DesiredAccess, CRegistryKey &rKey)
const TCHAR * GetLastErrorDescription()
virtual const TCHAR * GetHelpString()
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define CloseHandle
Definition: compat.h:739
#define OPEN_EXISTING
Definition: compat.h:775
#define ReadFile(a, b, c, d, e)
Definition: compat.h:742
#define INVALID_HANDLE_VALUE
Definition: compat.h:731
#define GENERIC_READ
Definition: compat.h:135
#define FILE_SHARE_READ
Definition: compat.h:136
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
Definition: fileinfo.c:331
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
GLdouble s
Definition: gl.h:2039
#define _tcscmp
Definition: tchar.h:1424
#define REG_SZ
Definition: layer.c:22
#define ASSERT(a)
Definition: mode.c:44
#define _stprintf
Definition: utility.h:124
#define _tcsrchr
Definition: utility.h:116
_In_ HANDLE hFile
Definition: mswsock.h:90
#define REG_BINARY
Definition: nt_native.h:1496
#define REG_DWORD_LITTLE_ENDIAN
Definition: nt_native.h:1498
#define REG_DWORD_BIG_ENDIAN
Definition: nt_native.h:1499
#define REG_NONE
Definition: nt_native.h:1492
#define REG_EXPAND_SZ
Definition: nt_native.h:1494
#define KEY_SET_VALUE
Definition: nt_native.h:1017
long LONG
Definition: pedump.c:60
#define REG_DWORD
Definition: sdbapi.c:596
#define VERIFY(e)
Definition: ph.h:34
#define _T(x)
Definition: vfdio.h:22
#define CreateFile
Definition: winbase.h:3749
char TCHAR
Definition: xmlstorage.h:189
#define _tcsnicmp
Definition: xmlstorage.h:207
#define _tcslen
Definition: xmlstorage.h:198
#define _tcsicmp
Definition: xmlstorage.h:205
unsigned char BYTE
Definition: xxhash.c:193

◆ GetHelpShortDescriptionString()

const TCHAR * CShellCommandSetValue::GetHelpShortDescriptionString ( )
virtual

Implements CShellCommand.

Definition at line 431 of file ShellCommandSetValue.cpp.

432{
434}
#define SET_VALUE_CMD_SHORT_DESC

◆ GetHelpString()

const TCHAR * CShellCommandSetValue::GetHelpString ( )
virtual

Implements CShellCommand.

Definition at line 405 of file ShellCommandSetValue.cpp.

406{
408 _T("Syntax: ") SET_VALUE_CMD _T(" <TYPE> <VALUE> [<PATH>][<VALUE_NAME>] [/?]\n\n")
409 _T(" <TYPE> - Type of value to be set. Must be one of following:\n")
410 _T(" b - binary value.\n")
411 _T(" dw - A 32-bit number.\n")
412 _T(" dwle - A 32-bit number in little-endian format.\n")
413 _T(" dwbe - A 32-bit number in big-endian format.\n")
414 _T(" sz - A null-terminated string.\n")
415 _T(" esz - A null-terminated string that contains unexpanded\n")
416 _T(" references to environment variables.\n")
417// _T(" msz - An array of null-terminated strings,\n")
418// _T(" terminated by two null characters.\n")
419 _T(" <VALUE> - The data to be set. According to <TYPE>, <VALUE> means:\n")
420 _T(" b - name of file from which to read binary data.\n")
421 _T(" dw \\\n")
422 _T(" dwle - number with syntax: [0 [{ x | X }]] [digits]\n")
423 _T(" dwbe /\n")
424 _T(" sz \\\n")
425 _T(" esz - <VALUE> string is interpreted as string\n")
426 _T(" <PATH> - Optional relative path of key which value will be processed. ^ is the escape char\n")
427 _T(" <VALUE_NAME> - Name of key's value. Default is key's default value.\n")
428 _T(" /? - This help.\n");
429}
Type
Definition: Type.h:7
#define read
Definition: acwin.h:96
int help
Definition: sort.c:20
int null(void)
Definition: ftp.c:1794
Definition: ehthrow.cxx:93
Definition: _set.h:50
TYPE
Definition: eventcreate.c:652
GLint GLint GLint GLint GLint x
Definition: gl.h:1548
GLint GLenum GLsizei GLsizei GLsizei GLint GLsizei const GLvoid * data
Definition: gl.h:1950
GLdouble n
Definition: glext.h:7729
GLboolean GLboolean GLboolean b
Definition: glext.h:6204
GLuint in
Definition: glext.h:9616
const GLuint GLenum const GLvoid * binary
Definition: glext.h:7538
REFIID LPVOID DWORD_PTR dw
Definition: atlbase.h:40
@ VALUE_NAME
Definition: inffile.c:76
static const int digits[]
Definition: decode.c:71
static unsigned int number
Definition: dsound.c:1479
static WCHAR escape[]
Definition: url.c:36
int one
Definition: sehframes.cpp:28
CardRegion * from
Definition: spigame.cpp:19
Definition: path.h:35
Definition: fci.c:127
Definition: format.c:58
Definition: copy.c:22
Definition: name.c:39
static int processed(const type_t *type)
Definition: typegen.c:2254
Definition: pdh_main.c:94
static GLenum which
Definition: wgl_font.c:159

Referenced by Execute().

◆ Match()

BOOL CShellCommandSetValue::Match ( const TCHAR pchCommand)
virtual

Implements CShellCommand.

Definition at line 106 of file ShellCommandSetValue.cpp.

107{
108 if (_tcsicmp(pszCommand,SET_VALUE_CMD) == 0)
109 return TRUE;
110 if (_tcsnicmp(pszCommand,SET_VALUE_CMD _T(".."),SET_VALUE_CMD_LENGTH+2*sizeof(TCHAR)) == 0)
111 return TRUE;
112 if (_tcsnicmp(pszCommand,SET_VALUE_CMD _T("/"),SET_VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
113 return TRUE;
114 if (_tcsnicmp(pszCommand,SET_VALUE_CMD _T("\\"),SET_VALUE_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
115 return TRUE;
116 return FALSE;
117}

Member Data Documentation

◆ m_rTree

CRegistryTree& CShellCommandSetValue::m_rTree
private

Definition at line 22 of file ShellCommandSetValue.h.

Referenced by Execute().


The documentation for this class was generated from the following files: