fdc28eed8db170f57c477f0041e555905fefd21e
[reactos.git] / rosapps / sysutils / regexpl / ShellCommandDeleteValue.cpp
1 /* $Id: ShellCommandDeleteValue.cpp,v 1.3 2001/01/10 01:25:29 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 *pszCommand)
48 {
49 return _tcsicmp(pszCommand,DV_CMD) == 0;
50 }
51
52 int CShellCommandDeleteValue::Execute(CConsole &rConsole, CArgumentParser& rArguments)
53 {
54 rArguments.ResetArgumentIteration();
55 TCHAR *pszCommandItself = rArguments.GetNextArgument();
56
57 TCHAR *pszParameter;
58 TCHAR *pszValueFull = NULL;
59 BOOL blnHelp = FALSE;
60 // DWORD dwError;
61
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))
64 {
65 pszValueFull = pszCommandItself + DV_CMD_LENGTH;
66 }
67 else if (_tcsnicmp(pszCommandItself,DV_CMD _T("/"),DV_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
68 {
69 pszParameter = pszCommandItself + DV_CMD_LENGTH;
70 goto CheckValueArgument;
71 }
72
73 while((pszParameter = rArguments.GetNextArgument()) != NULL)
74 {
75 CheckValueArgument:
76 if ((_tcsicmp(pszParameter,_T("/?")) == 0)
77 ||(_tcsicmp(pszParameter,_T("-?")) == 0))
78 {
79 blnHelp = TRUE;
80 break;
81 }
82 else if (!pszValueFull)
83 {
84 pszValueFull = pszParameter;
85 }
86 else
87 {
88 rConsole.Write(_T("Bad parameter: "));
89 rConsole.Write(pszParameter);
90 rConsole.Write(_T("\n"));
91 }
92 }
93
94 CRegistryKey Key;
95 TCHAR *pszValueName;
96 const TCHAR *pszPath;
97
98 if (blnHelp)
99 {
100 rConsole.Write(GetHelpString());
101 return 0;
102 }
103
104 if (pszValueFull)
105 {
106 if (_tcscmp(pszValueFull,_T("\\")) == 0)
107 goto CommandNAonRoot;
108
109 TCHAR *pchSep = _tcsrchr(pszValueFull,_T('\\'));
110 pszValueName = pchSep?(pchSep+1):(pszValueFull);
111 pszPath = pchSep?pszValueFull:_T(".");
112
113 //if (_tcsrchr(pszValueName,_T('.')))
114 //{
115 // pszValueName = _T("");
116 // pszPath = pszValueFull;
117 //}
118 //else
119 if (pchSep)
120 *pchSep = 0;
121 }
122 else
123 {
124 pszValueName = _T("");
125 pszPath = _T(".");
126 }
127
128 {
129 size_t s = _tcslen(pszValueName);
130 if (s && (pszValueName[0] == _T('\"'))&&(pszValueName[s-1] == _T('\"')))
131 {
132 pszValueName[s-1] = 0;
133 pszValueName++;
134 }
135 }
136
137 if (!m_rTree.GetKey(pszPath,KEY_SET_VALUE,Key))
138 {
139 rConsole.Write(m_rTree.GetLastErrorDescription());
140 goto SkipCommand;
141 }
142
143 if (!Key.IsRoot())
144 { // not root key ???
145 LONG nError = Key.DeleteValue(pszValueName);
146 if (nError != ERROR_SUCCESS)
147 {
148 char Buffer[254];
149 _stprintf(Buffer,_T("Cannot delete value. Error is %u\n"),(unsigned int)nError);
150 rConsole.Write(Buffer);
151 }
152 else
153 {
154 InvalidateCompletion();
155 }
156 } // if (pKey)
157 else
158 {
159 CommandNAonRoot:
160 rConsole.Write(DV_CMD COMMAND_NA_ON_ROOT);
161 }
162
163 SkipCommand:
164 // if (pTree)
165 // delete pTree;
166 return 0;
167 }
168
169 const TCHAR * CShellCommandDeleteValue::GetHelpString()
170 {
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");
176 }
177
178 const TCHAR * CShellCommandDeleteValue::GetHelpShortDescriptionString()
179 {
180 return DV_CMD_SHORT_DESC;
181 }