GPL sync + delete value implemented
[reactos.git] / rosapps / sysutils / regexpl / ShellCommandDeleteValue.cpp
1 /* $Id: ShellCommandDeleteValue.cpp,v 1.2 2000/10/24 20:17:41 narnaoud Exp $
2 *
3 * regexpl - Console Registry Explorer
4 *
5 * Copyright (C) 2000 Nedko Arnaoudov <nedkohome@atia.com>
6 *
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.
11 *
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.
16 *
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.
21 */
22
23 // ShellCommandDeleteValue.cpp: implementation of the CShellCommandDeleteValue class.
24 //
25 //////////////////////////////////////////////////////////////////////
26
27 #include "ph.h"
28 #include "ShellCommandDeleteValue.h"
29 #include "RegistryExplorer.h"
30
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")
34
35 //////////////////////////////////////////////////////////////////////
36 // Construction/Destruction
37 //////////////////////////////////////////////////////////////////////
38
39 CShellCommandDeleteValue::CShellCommandDeleteValue(CRegistryTree& rTree):m_rTree(rTree)
40 {
41 }
42
43 CShellCommandDeleteValue::~CShellCommandDeleteValue()
44 {
45 }
46
47 BOOL CShellCommandDeleteValue::Match(const TCHAR *pchCommand)
48 {
49 return _tcsicmp(pchCommand,DV_CMD) == 0;
50 }
51
52 int CShellCommandDeleteValue::Execute(CConsole &rConsole, CArgumentParser& rArguments)
53 {
54 rArguments.ResetArgumentIteration();
55 TCHAR *pchCommandItself = rArguments.GetNextArgument();
56
57 TCHAR *pchParameter;
58 TCHAR *pchValueFull = NULL;
59 BOOL blnHelp = FALSE;
60 // DWORD dwError;
61
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))
64 {
65 pchValueFull = pchCommandItself + DV_CMD_LENGTH;
66 }
67 else if (_tcsnicmp(pchCommandItself,DV_CMD _T("/"),DV_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
68 {
69 pchParameter = pchCommandItself + DV_CMD_LENGTH;
70 goto CheckValueArgument;
71 }
72
73 while((pchParameter = rArguments.GetNextArgument()) != NULL)
74 {
75 CheckValueArgument:
76 if ((_tcsicmp(pchParameter,_T("/?")) == 0)
77 ||(_tcsicmp(pchParameter,_T("-?")) == 0))
78 {
79 blnHelp = TRUE;
80 break;
81 }
82 else if (!pchValueFull)
83 {
84 pchValueFull = pchParameter;
85 }
86 else
87 {
88 rConsole.Write(_T("Bad parameter: "));
89 rConsole.Write(pchParameter);
90 rConsole.Write(_T("\n"));
91 }
92 }
93
94 CRegistryTree *pTree = NULL;
95 CRegistryKey *pKey = NULL;
96 TCHAR *pchValueName;
97 TCHAR *pchPath;
98
99 if (blnHelp)
100 {
101 rConsole.Write(GetHelpString());
102 return 0;
103 }
104
105 if (pchValueFull)
106 {
107 if (_tcscmp(pchValueFull,_T("\\")) == 0)
108 goto CommandNAonRoot;
109
110 TCHAR *pchSep = _tcsrchr(pchValueFull,_T('\\'));
111 pchValueName = pchSep?(pchSep+1):(pchValueFull);
112 pchPath = pchSep?pchValueFull:NULL;
113
114 //if (_tcsrchr(pchValueName,_T('.')))
115 //{
116 // pchValueName = _T("");
117 // pchPath = pchValueFull;
118 //}
119 //else
120 if (pchSep)
121 *pchSep = 0;
122 }
123 else
124 {
125 pchValueName = _T("");
126 pchPath = NULL;
127 }
128
129 if (pchPath)
130 {
131 pTree = new CRegistryTree(m_rTree);
132 if ((_tcscmp(pTree->GetCurrentPath(),m_rTree.GetCurrentPath()) != 0)
133 ||(!pTree->ChangeCurrentKey(pchPath)))
134 {
135 rConsole.Write(_T("Cannot open key "));
136 rConsole.Write(pchPath);
137 rConsole.Write(_T("\n"));
138 goto SkipCommand;
139 }
140 else
141 {
142 pKey = pTree->GetCurrentKey();
143 }
144 }
145 else
146 {
147 pKey = m_rTree.GetCurrentKey();
148 }
149
150 if (pKey)
151 { // not root key ???
152 if (pKey->DeleteValue(pchValueName) != ERROR_SUCCESS)
153 rConsole.Write(_T("Cannot set value\n"));
154 } // if (pKey)
155 else
156 {
157 CommandNAonRoot:
158 rConsole.Write(DV_CMD COMMAND_NA_ON_ROOT);
159 }
160
161 SkipCommand:
162 if (pTree)
163 delete pTree;
164 return 0;
165 }
166
167 const TCHAR * CShellCommandDeleteValue::GetHelpString()
168 {
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");
174 }
175
176 const TCHAR * CShellCommandDeleteValue::GetHelpShortDescriptionString()
177 {
178 return DV_CMD_SHORT_DESC;
179 }