3 * regexpl - Console Registry Explorer
5 * Copyright (C) 2000-2005 Nedko Arnaudov <nedko@users.sourceforge.net>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; see the file COPYING. If not, write to
19 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 * Boston, MA 02111-1307, USA.
23 // ShellCommandDeleteValue.cpp: implementation of the CShellCommandDeleteValue class.
25 //////////////////////////////////////////////////////////////////////
28 #include "ShellCommandDeleteValue.h"
29 #include "RegistryExplorer.h"
32 #define DV_CMD _T("DV")
33 #define DV_CMD_LENGTH COMMAND_LENGTH(DV_CMD)
34 #define DV_CMD_SHORT_DESC DV_CMD _T(" command is used to delete value.\n")
36 //////////////////////////////////////////////////////////////////////
37 // Construction/Destruction
38 //////////////////////////////////////////////////////////////////////
40 CShellCommandDeleteValue::CShellCommandDeleteValue(CRegistryTree
& rTree
):m_rTree(rTree
)
44 CShellCommandDeleteValue::~CShellCommandDeleteValue()
48 BOOL
CShellCommandDeleteValue::Match(const TCHAR
*pszCommand
)
50 return _tcsicmp(pszCommand
,DV_CMD
) == 0;
53 int CShellCommandDeleteValue::Execute(CConsole
&rConsole
, CArgumentParser
& rArguments
)
55 rArguments
.ResetArgumentIteration();
56 TCHAR
*pszCommandItself
= rArguments
.GetNextArgument();
59 TCHAR
*pszValueFull
= NULL
;
62 if ((_tcsnicmp(pszCommandItself
,DV_CMD
_T(".."),DV_CMD_LENGTH
+2*sizeof(TCHAR
)) == 0)||
63 (_tcsnicmp(pszCommandItself
,DV_CMD
_T("\\"),DV_CMD_LENGTH
+1*sizeof(TCHAR
)) == 0))
65 pszValueFull
= pszCommandItself
+ DV_CMD_LENGTH
;
67 else if (_tcsnicmp(pszCommandItself
,DV_CMD
_T("/"),DV_CMD_LENGTH
+1*sizeof(TCHAR
)) == 0)
69 pszParameter
= pszCommandItself
+ DV_CMD_LENGTH
;
70 goto CheckValueArgument
;
73 while((pszParameter
= rArguments
.GetNextArgument()) != NULL
)
76 if ((_tcsicmp(pszParameter
,_T("/?")) == 0)
77 ||(_tcsicmp(pszParameter
,_T("-?")) == 0))
82 else if (!pszValueFull
)
84 pszValueFull
= pszParameter
;
88 rConsole
.Write(_T("Bad parameter: "));
89 rConsole
.Write(pszParameter
);
90 rConsole
.Write(_T("\n"));
95 TCHAR
*pszValueNamePattern
;
96 const TCHAR
*pszEmpty
= _T("");
101 rConsole
.Write(GetHelpString());
107 if (_tcscmp(pszValueFull
,_T("\\")) == 0)
108 goto CommandNAonRoot
;
110 TCHAR
*pchSep
= _tcsrchr(pszValueFull
,_T('\\'));
111 pszValueNamePattern
= pchSep
?(pchSep
+1):(pszValueFull
);
112 pszPath
= pchSep
?pszValueFull
:_T(".");
119 pszValueNamePattern
= (TCHAR
*)pszEmpty
;
124 size_t s
= _tcslen(pszValueNamePattern
);
125 if (s
&& (pszValueNamePattern
[0] == _T('\"'))&&(pszValueNamePattern
[s
-1] == _T('\"')))
127 pszValueNamePattern
[s
-1] = 0;
128 pszValueNamePattern
++;
132 if (!m_rTree
.GetKey(pszPath
,KEY_QUERY_VALUE
|KEY_SET_VALUE
,Key
))
134 rConsole
.Write(m_rTree
.GetLastErrorDescription());
139 { // not root key ???
141 DWORD dwMaxValueNameLength
;
142 LONG nError
= Key
.GetMaxValueNameLength(dwMaxValueNameLength
);
143 if (nError
!= ERROR_SUCCESS
)
145 _stprintf(Buffer
,_T("Cannot query info about %s key. Error is %u\n"),Key
.GetKeyName(),(unsigned int)nError
);
146 rConsole
.Write(Buffer
);
150 TCHAR
*pszValueName
= new TCHAR
[dwMaxValueNameLength
];
153 rConsole
.Write("Out of memory.");
157 Key
.InitValueEnumeration(pszValueName
,dwMaxValueNameLength
,NULL
,0,NULL
);
159 while ((nError
= Key
.GetNextValue()) == ERROR_SUCCESS
)
161 if (PatternMatch(pszValueNamePattern
,pszValueName
))
163 nError
= Key
.DeleteValue(pszValueName
);
164 if (nError
!= ERROR_SUCCESS
)
166 _stprintf(Buffer
,_T("Cannot delete value. Error is %u\n"),(unsigned int)nError
);
167 rConsole
.Write(Buffer
);
171 InvalidateCompletion();
173 Key
.InitValueEnumeration(pszValueName
,dwMaxValueNameLength
,NULL
,0,NULL
); // reset iteration
180 rConsole
.Write(DV_CMD COMMAND_NA_ON_ROOT
);
186 const TCHAR
* CShellCommandDeleteValue::GetHelpString()
188 return DV_CMD_SHORT_DESC
189 _T("Syntax: ") DV_CMD
_T(" [<PATH>][<VALUE_NAME>] [/?]\n\n")
190 _T(" <PATH> - Optional relative path of key which value will be delete.\n")
191 _T(" <VALUE_NAME> - Name pattern of key's value. Default is key's default value.\n")
192 _T(" /? - This help.\n\n");
195 const TCHAR
* CShellCommandDeleteValue::GetHelpShortDescriptionString()
197 return DV_CMD_SHORT_DESC
;