1 /* $Id: ShellCommandDeleteValue.cpp,v 1.3 2001/01/10 01:25:29 narnaoud Exp $
3 * regexpl - Console Registry Explorer
5 * Copyright (C) 2000 Nedko Arnaoudov <nedkohome@atia.com>
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"
31 #define DV_CMD _T("DV")
32 #define DV_CMD_LENGTH COMMAND_LENGTH(DV_CMD)
33 #define DV_CMD_SHORT_DESC DV_CMD _T(" command is used to delete value.\n")
35 //////////////////////////////////////////////////////////////////////
36 // Construction/Destruction
37 //////////////////////////////////////////////////////////////////////
39 CShellCommandDeleteValue::CShellCommandDeleteValue(CRegistryTree
& rTree
):m_rTree(rTree
)
43 CShellCommandDeleteValue::~CShellCommandDeleteValue()
47 BOOL
CShellCommandDeleteValue::Match(const TCHAR
*pszCommand
)
49 return _tcsicmp(pszCommand
,DV_CMD
) == 0;
52 int CShellCommandDeleteValue::Execute(CConsole
&rConsole
, CArgumentParser
& rArguments
)
54 rArguments
.ResetArgumentIteration();
55 TCHAR
*pszCommandItself
= rArguments
.GetNextArgument();
58 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"));
100 rConsole
.Write(GetHelpString());
106 if (_tcscmp(pszValueFull
,_T("\\")) == 0)
107 goto CommandNAonRoot
;
109 TCHAR
*pchSep
= _tcsrchr(pszValueFull
,_T('\\'));
110 pszValueName
= pchSep
?(pchSep
+1):(pszValueFull
);
111 pszPath
= pchSep
?pszValueFull
:_T(".");
113 //if (_tcsrchr(pszValueName,_T('.')))
115 // pszValueName = _T("");
116 // pszPath = pszValueFull;
124 pszValueName
= _T("");
129 size_t s
= _tcslen(pszValueName
);
130 if (s
&& (pszValueName
[0] == _T('\"'))&&(pszValueName
[s
-1] == _T('\"')))
132 pszValueName
[s
-1] = 0;
137 if (!m_rTree
.GetKey(pszPath
,KEY_SET_VALUE
,Key
))
139 rConsole
.Write(m_rTree
.GetLastErrorDescription());
144 { // not root key ???
145 LONG nError
= Key
.DeleteValue(pszValueName
);
146 if (nError
!= ERROR_SUCCESS
)
149 _stprintf(Buffer
,_T("Cannot delete value. Error is %u\n"),(unsigned int)nError
);
150 rConsole
.Write(Buffer
);
154 InvalidateCompletion();
160 rConsole
.Write(DV_CMD COMMAND_NA_ON_ROOT
);
169 const TCHAR
* CShellCommandDeleteValue::GetHelpString()
171 return DV_CMD_SHORT_DESC
172 _T("Syntax: ") DV_CMD
_T(" [<PATH>][<VALUE_NAME>] [/?]\n\n")
173 _T(" <PATH> - Optional relative path of key which value will be delete.\n")
174 _T(" <VALUE_NAME> - Name of key's value. Default is key's default value.\n")
175 _T(" /? - This help.\n\n");
178 const TCHAR
* CShellCommandDeleteValue::GetHelpShortDescriptionString()
180 return DV_CMD_SHORT_DESC
;