2 * regexpl - Console Registry Explorer
4 * Copyright (C) 2000-2005 Nedko Arnaudov <nedko@users.sourceforge.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 // ShellCommandDeleteKey.cpp: implementation of the CShellCommandDeleteKey class.
24 //////////////////////////////////////////////////////////////////////
27 #include "ShellCommandDeleteKey.h"
28 #include "RegistryExplorer.h"
30 #define DK_CMD _T("DK")
31 #define DK_CMD_SHORT_DESC DK_CMD _T(" command is used to delete key(s).\n")
33 //////////////////////////////////////////////////////////////////////
34 // Construction/Destruction
35 //////////////////////////////////////////////////////////////////////
37 CShellCommandDeleteKey::CShellCommandDeleteKey(CRegistryTree
& rTree
):m_rTree(rTree
)
41 CShellCommandDeleteKey::~CShellCommandDeleteKey()
45 BOOL
CShellCommandDeleteKey::Match(const TCHAR
*pchCommand
)
47 return _tcsicmp(pchCommand
,DK_CMD
) == 0;
50 int CShellCommandDeleteKey::Execute(CConsole
&rConsole
, CArgumentParser
& rArguments
)
52 TCHAR
*pchKey
= NULL
, *pchArg
;
55 BOOL blnExitAfterHelp
= FALSE
;
56 BOOL blnRecursive
= FALSE
;
58 while((pchArg
= rArguments
.GetNextArgument()) != NULL
)
60 if ((_tcsicmp(pchArg
,_T("/?")) == 0)
61 ||(_tcsicmp(pchArg
,_T("-?")) == 0))
65 else if ((_tcsicmp(pchArg
,_T("/s")) == 0)
66 ||(_tcsicmp(pchArg
,_T("-s")) == 0))
74 rConsole
.Write(_T("Wrong parameter : \""));
75 rConsole
.Write(pchArg
);
76 rConsole
.Write(_T("\"\n\n"));
86 if ((!blnHelp
) && (!pchKey
))
88 rConsole
.Write(_T("Key name not specified !\n\n"));
89 blnExitAfterHelp
= TRUE
;
94 rConsole
.Write(GetHelpString());
98 rConsole
.Write(_T("\n"));
101 // search for last key name token
109 while(*pch
== _T('\\'))
112 while((pch
> pchKey
)&&(*pch
!= _T('\\')))
115 ASSERT(pch
>= pchKey
);
117 const TCHAR
*pszPath
;
118 TCHAR
*pszPattern
= pch
;
119 if (*pch
== _T('\\'))
130 rConsole
.Write(DK_CMD COMMAND_NA_ON_ROOT
);
141 size_t s
= _tcslen(pszPattern
);
142 if (s
&& (pszPattern
[0] == _T('\"'))&&(pszPattern
[s
-1] == _T('\"')))
149 if (!m_rTree
.DeleteSubkeys(pszPattern
,pszPath
,blnRecursive
))
151 rConsole
.Write(_T("Cannot delete key(s).\n"));
152 rConsole
.Write(m_rTree
.GetLastErrorDescription());
156 InvalidateCompletion();
162 const TCHAR
* CShellCommandDeleteKey::GetHelpString()
164 return DK_CMD_SHORT_DESC
165 _T("Syntax: ") DK_CMD
_T(" [/s] [/?] [PATH]KEY_NAME\n\n")
166 _T(" PATH - optional path to key which subkey(s) will be deleted. Default is current key.")
167 _T(" KEY_NAME - name of key to be deleted. Wildcards can be used.")
168 _T(" /? - This help.\n\n")
169 _T(" /s - Delete key and all subkeys.\n");
172 const TCHAR
* CShellCommandDeleteKey::GetHelpShortDescriptionString()
174 return DK_CMD_SHORT_DESC
;