32#define SET_VALUE_CMD _T("SV")
33#define SET_VALUE_CMD_LENGTH COMMAND_LENGTH(SET_VALUE_CMD)
34#define SET_VALUE_CMD_SHORT_DESC SET_VALUE_CMD _T(" command is used to set value.\n")
38 const TCHAR *pszDigits;
39 const TCHAR *pszOctalNumbers =
_T(
"01234567");
40 const TCHAR *pszDecimalNumbers =
_T(
"0123456789");
41 const TCHAR *pszHexNumbers =
_T(
"0123456789ABCDEF");
42 const TCHAR *pszNumbers;
43 unsigned int nBase = 0;
44 if (*pszIn ==
_T(
'0'))
46 if ((*(pszIn+1) ==
_T(
'x'))||((*(pszIn+1) ==
_T(
'X'))))
50 pszNumbers = pszHexNumbers;
56 pszNumbers = pszOctalNumbers;
63 pszNumbers = pszDecimalNumbers;
66 const TCHAR *pszDigit = pszDigits;
72 const TCHAR *pszNumber;
73 while (pszDigit > pszDigits)
76 pszNumber =
_tcschr(pszNumbers,*pszDigit);
80 dwAdd = (pszNumber-pszNumbers)*nMul;
82 if (rdwOut + dwAdd < rdwOut)
86 if (nMul * nBase < nMul)
131 DWORD dwValueSize = 0;
143 goto CheckValueArgument;
149 blnBadParameter =
FALSE;
150 if (((*pszParameter ==
_T(
'/'))||(*pszParameter ==
_T(
'-')))
151 &&(*(pszParameter+1) ==
_T(
'?')))
161 else if (
_tcsicmp(pszParameter,
_T(
"dw")) == 0)
165 else if (
_tcsicmp(pszParameter,
_T(
"dwle")) == 0)
169 else if (
_tcsicmp(pszParameter,
_T(
"dwbe")) == 0)
173 else if (
_tcsicmp(pszParameter,
_T(
"sz")) == 0)
177 else if (
_tcsicmp(pszParameter,
_T(
"esz")) == 0)
183 blnBadParameter =
TRUE;
186 else if (pszValueData ==
NULL)
188 pszValueData = pszParameter;
190 else if (!pszValueFull)
192 pszValueFull = pszParameter;
196 blnBadParameter =
TRUE;
200 rConsole.
Write(
_T(
"Bad parameter: "));
201 rConsole.
Write(pszParameter);
211 const TCHAR *pszEmpty =
_T(
"");
212 const TCHAR *pszPath;
227 goto CommandNAonRoot;
230 pszValueName = pchSep?(pchSep+1):(pszValueFull);
231 pszPath = pchSep?pszValueFull:
_T(
".");
244 pszValueName = (
TCHAR*)pszEmpty;
255 goto CommandNAonRoot;
266 rConsole.
Write(
_T(
"Cannot open file "));
267 rConsole.
Write(pszValueData);
272 if (dwValueSize == (
DWORD)-1)
276 rConsole.
Write(
_T(
"Cannot get size of file "));
277 rConsole.
Write(pszValueData);
282 pDataBuffer =
new BYTE [dwValueSize];
285 rConsole.
Write(
_T(
"Cannot load file into memory. Out of memory.\n"));
291 rConsole.
Write(
_T(
"Cannot load file into memory. Error reading file.\n"));
297 ASSERT(dwBytesReaded == dwValueSize);
303 pDataBuffer = (
BYTE *)
new BYTE [dwValueSize];
306 rConsole.
Write(
_T(
"Cannot convert "));
307 rConsole.
Write(pszValueData);
308 rConsole.
Write(
_T(
" to DWORD \n"));
314 nByte = *pDataBuffer;
315 *pDataBuffer = *(pDataBuffer+3);
316 *(pDataBuffer+3) = nByte;
317 nByte = *(pDataBuffer+1);
318 *(pDataBuffer+1) = *(pDataBuffer+2);
319 *(pDataBuffer+2) = nByte;
324 dwValueSize =
_tcslen(pszValueData)+1;
325 if (*pszValueData ==
_T(
'\"'))
328 *(pszValueData+dwValueSize) = 0;
331 dwValueSize *=
sizeof(
TCHAR);
332 pDataBuffer = (
BYTE *)
new BYTE [dwValueSize];
335 const TCHAR *pchSrc = pszValueData;
339 if (pchSrc[0] ==
_T(
'^'))
341 if (pchSrc[1] ==
_T(
'a'))
343 else if (pchSrc[1] ==
_T(
'b'))
345 else if (pchSrc[1] ==
_T(
'f'))
347 else if (pchSrc[1] ==
_T(
'n'))
349 else if (pchSrc[1] ==
_T(
'r'))
351 else if (pchSrc[1] ==
_T(
't'))
354 *pchDest = pchSrc[1];
376 if (
s && (pszValueName[0] ==
_T(
'\"'))&&(pszValueName[
s-1] ==
_T(
'\"')))
378 pszValueName[
s-1] = 0;
383 nError =
Key.SetValue(pszValueName,dwType,pDataBuffer,dwValueSize);
397 delete[] pDataBuffer;
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")
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")
422 _T(
" dwle - number with syntax: [0 [{ x | X }]] [digits]\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");
void InvalidateCompletion()
#define COMMAND_NA_ON_ROOT
#define SET_VALUE_CMD_SHORT_DESC
BOOL StringToDWORD(DWORD &rdwOut, const TCHAR *pszIn)
#define SET_VALUE_CMD_LENGTH
void ResetArgumentIteration()
TCHAR * GetNextArgument()
BOOL Write(const TCHAR *p, DWORD dwChars=0)
BOOL GetKey(const TCHAR *pchRelativePath, REGSAM DesiredAccess, CRegistryKey &rKey)
const TCHAR * GetLastErrorDescription()
virtual int Execute(CConsole &rConsole, CArgumentParser &rArguments)
virtual const TCHAR * GetHelpShortDescriptionString()
virtual const TCHAR * GetHelpString()
virtual ~CShellCommandSetValue()
virtual BOOL Match(const TCHAR *pchCommand)
CShellCommandSetValue(CRegistryTree &rTree)
#define ReadFile(a, b, c, d, e)
#define INVALID_HANDLE_VALUE
DWORD WINAPI GetFileSize(HANDLE hFile, LPDWORD lpFileSizeHigh)
#define REG_DWORD_LITTLE_ENDIAN
#define REG_DWORD_BIG_ENDIAN