1 /* $Id: ShellCommandDeleteValue.cpp,v 1.2 2000/10/24 20:17:41 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
*pchCommand
)
49 return _tcsicmp(pchCommand
,DV_CMD
) == 0;
52 int CShellCommandDeleteValue::Execute(CConsole
&rConsole
, CArgumentParser
& rArguments
)
54 rArguments
.ResetArgumentIteration();
55 TCHAR
*pchCommandItself
= rArguments
.GetNextArgument();
58 TCHAR
*pchValueFull
= NULL
;
62 if ((_tcsnicmp(pchCommandItself
,DV_CMD
_T(".."),DV_CMD_LENGTH
+2*sizeof(TCHAR
)) == 0)||
63 (_tcsnicmp(pchCommandItself
,DV_CMD
_T("\\"),DV_CMD_LENGTH
+1*sizeof(TCHAR
)) == 0))
65 pchValueFull
= pchCommandItself
+ DV_CMD_LENGTH
;
67 else if (_tcsnicmp(pchCommandItself
,DV_CMD
_T("/"),DV_CMD_LENGTH
+1*sizeof(TCHAR
)) == 0)
69 pchParameter
= pchCommandItself
+ DV_CMD_LENGTH
;
70 goto CheckValueArgument
;
73 while((pchParameter
= rArguments
.GetNextArgument()) != NULL
)
76 if ((_tcsicmp(pchParameter
,_T("/?")) == 0)
77 ||(_tcsicmp(pchParameter
,_T("-?")) == 0))
82 else if (!pchValueFull
)
84 pchValueFull
= pchParameter
;
88 rConsole
.Write(_T("Bad parameter: "));
89 rConsole
.Write(pchParameter
);
90 rConsole
.Write(_T("\n"));
94 CRegistryTree
*pTree
= NULL
;
95 CRegistryKey
*pKey
= NULL
;
101 rConsole
.Write(GetHelpString());
107 if (_tcscmp(pchValueFull
,_T("\\")) == 0)
108 goto CommandNAonRoot
;
110 TCHAR
*pchSep
= _tcsrchr(pchValueFull
,_T('\\'));
111 pchValueName
= pchSep
?(pchSep
+1):(pchValueFull
);
112 pchPath
= pchSep
?pchValueFull
:NULL
;
114 //if (_tcsrchr(pchValueName,_T('.')))
116 // pchValueName = _T("");
117 // pchPath = pchValueFull;
125 pchValueName
= _T("");
131 pTree
= new CRegistryTree(m_rTree
);
132 if ((_tcscmp(pTree
->GetCurrentPath(),m_rTree
.GetCurrentPath()) != 0)
133 ||(!pTree
->ChangeCurrentKey(pchPath
)))
135 rConsole
.Write(_T("Cannot open key "));
136 rConsole
.Write(pchPath
);
137 rConsole
.Write(_T("\n"));
142 pKey
= pTree
->GetCurrentKey();
147 pKey
= m_rTree
.GetCurrentKey();
151 { // not root key ???
152 if (pKey
->DeleteValue(pchValueName
) != ERROR_SUCCESS
)
153 rConsole
.Write(_T("Cannot set value\n"));
158 rConsole
.Write(DV_CMD COMMAND_NA_ON_ROOT
);
167 const TCHAR
* CShellCommandDeleteValue::GetHelpString()
169 return DV_CMD_SHORT_DESC
170 _T("Syntax: ") DV_CMD
_T(" [<PATH>][<VALUE_NAME>] [/?]\n\n")
171 _T(" <PATH> - Optional relative path of key which value will be delete.\n")
172 _T(" <VALUE_NAME> - Name of key's value. Default is key's default value.\n")
173 _T(" /? - This help.\n\n");
176 const TCHAR
* CShellCommandDeleteValue::GetHelpShortDescriptionString()
178 return DV_CMD_SHORT_DESC
;