Registry Explorer (console tool) by Nedko Arnaoudov added to the system utilities...
[reactos.git] / rosapps / sysutils / regexpl / ShellCommandDeleteKey.cpp
1 /* $Id: ShellCommandDeleteKey.cpp,v 1.1 2000/10/04 21:04:31 ea Exp $
2 *
3 * regexpl - Console Registry Explorer
4 *
5 * Copyright (c) 1999-2000 Nedko Arnaoudov <nedkohome@atia.com>
6 *
7 * License: GNU GPL
8 *
9 */
10
11 // ShellCommandDeleteKey.cpp: implementation of the CShellCommandDeleteKey class.
12 //
13 //////////////////////////////////////////////////////////////////////
14
15 #include "ph.h"
16 #include "ShellCommandDeleteKey.h"
17 #include "RegistryExplorer.h"
18
19 #define DK_CMD _T("DK")
20 #define DK_CMD_SHORT_DESC DK_CMD _T(" command is used to delete key(s).\n")
21
22 //////////////////////////////////////////////////////////////////////
23 // Construction/Destruction
24 //////////////////////////////////////////////////////////////////////
25
26 CShellCommandDeleteKey::CShellCommandDeleteKey(CRegistryTree& rTree):m_rTree(rTree)
27 {
28 }
29
30 CShellCommandDeleteKey::~CShellCommandDeleteKey()
31 {
32 }
33
34 BOOL CShellCommandDeleteKey::Match(const TCHAR *pchCommand)
35 {
36 return _tcsicmp(pchCommand,DK_CMD) == 0;
37 }
38
39 int CShellCommandDeleteKey::Execute(CConsole &rConsole, CArgumentParser& rArguments)
40 {
41 const TCHAR *pchKey = NULL, *pchArg;
42
43 BOOL blnHelp = FALSE;
44 BOOL blnExitAfterHelp = FALSE;
45 BOOL blnRecursive = FALSE;
46
47 while((pchArg = rArguments.GetNextArgument()) != NULL)
48 {
49 if ((_tcsicmp(pchArg,_T("/?")) == 0)
50 ||(_tcsicmp(pchArg,_T("-?")) == 0))
51 {
52 blnHelp = TRUE;
53 }
54 else if ((_tcsicmp(pchArg,_T("/s")) == 0)
55 ||(_tcsicmp(pchArg,_T("-s")) == 0))
56 {
57 blnRecursive = TRUE;
58 }
59 else
60 {
61 if (pchKey)
62 {
63 rConsole.Write(_T("Wrong parameter : \""));
64 rConsole.Write(pchArg);
65 rConsole.Write(_T("\"\n\n"));
66 blnHelp = TRUE;
67 }
68 else
69 {
70 pchKey = pchArg;
71 }
72 }
73 }
74
75 if ((!blnHelp) && (!pchKey))
76 {
77 rConsole.Write(_T("Key name not specified !\n\n"));
78 blnExitAfterHelp = TRUE;
79 }
80
81 if (blnHelp)
82 {
83 rConsole.Write(GetHelpString());
84 if (blnExitAfterHelp)
85 return 0;
86 else
87 rConsole.Write(_T("\n"));
88 }
89
90 if (!m_rTree.DeleteKey(pchKey,blnRecursive))
91 {
92 rConsole.Write(_T("Cannot delete key.\n"));
93 rConsole.Write(m_rTree.GetLastErrorDescription());
94 }
95 return 0;
96 }
97
98 const TCHAR * CShellCommandDeleteKey::GetHelpString()
99 {
100 return DK_CMD_SHORT_DESC
101 _T("Syntax: ") DK_CMD _T(" [/s] [/?] Key_Name\n\n")
102 _T(" /? - This help.\n\n")
103 _T(" /s - Delete key and all subkeys.\n");
104 }
105
106 const TCHAR * CShellCommandDeleteKey::GetHelpShortDescriptionString()
107 {
108 return DK_CMD_SHORT_DESC;
109 }