GPL sync + delete value implemented
[reactos.git] / rosapps / sysutils / regexpl / ShellCommandChangeKey.cpp
1 /* $Id: ShellCommandChangeKey.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 // ShellCommandChangeKey.cpp: implementation of the CShellCommandChangeKey class.
24 //
25 //////////////////////////////////////////////////////////////////////
26
27 #include "ph.h"
28 #include "RegistryExplorer.h"
29 #include "ShellCommandChangeKey.h"
30
31 #define CD_CMD _T("CD")
32 #define CD_CMD_LENGTH COMMAND_LENGTH(CD_CMD)
33 #define CD_CMD_SHORT_DESC CD_CMD _T(" command changes current key.\n")
34 //////////////////////////////////////////////////////////////////////
35 // Construction/Destruction
36 //////////////////////////////////////////////////////////////////////
37
38 CShellCommandChangeKey::CShellCommandChangeKey(CRegistryTree& rTree):m_rTree(rTree)
39 {
40
41 }
42
43 CShellCommandChangeKey::~CShellCommandChangeKey()
44 {
45
46 }
47
48 BOOL CShellCommandChangeKey::Match(const TCHAR *pchCommand)
49 {
50 if (_tcsicmp(pchCommand,CD_CMD) == 0)
51 return TRUE;
52 if (_tcsnicmp(pchCommand,CD_CMD _T(".."),CD_CMD_LENGTH+1*sizeof(TCHAR)) == 0)
53 return TRUE;
54 if (_tcsnicmp(pchCommand,CD_CMD _T("\\"),CD_CMD_LENGTH+2*sizeof(TCHAR)) == 0)
55 return TRUE;
56 return FALSE;
57 }
58
59 int CShellCommandChangeKey::Execute(CConsole &rConsole, CArgumentParser& rArguments)
60 {
61 BOOL blnHelp = FALSE;
62
63 rArguments.ResetArgumentIteration();
64 const TCHAR *pchCommandItself = rArguments.GetNextArgument();
65 const TCHAR *pchPath = rArguments.GetNextArgument();
66
67 if ((_tcsnicmp(pchCommandItself,CD_CMD _T(".."),CD_CMD_LENGTH+2*sizeof(TCHAR)) == 0)||
68 (_tcsnicmp(pchCommandItself,CD_CMD _T("\\"),CD_CMD_LENGTH+1*sizeof(TCHAR)) == 0))
69 {
70 if (!pchPath) pchPath = pchCommandItself + CD_CMD_LENGTH;
71 else blnHelp = TRUE;
72 }
73
74 if ((!blnHelp)&&(pchPath != NULL)&&(!rArguments.GetNextArgument()))
75 {
76 ASSERT(_tcslen(pchPath) <= PROMPT_BUFFER_SIZE);
77 if (!m_rTree.ChangeCurrentKey(pchPath))
78 {
79 rConsole.Write(m_rTree.GetLastErrorDescription());
80 rConsole.Write(_T("\n"));
81 }
82 }
83 else
84 {
85 rConsole.Write(GetHelpString());
86 }
87
88 return 0;
89 }
90
91 const TCHAR * CShellCommandChangeKey::GetHelpString()
92 {
93 return CD_CMD_SHORT_DESC
94 _T("Syntax: ") CD_CMD _T(" <KEY>\n\n")
95 _T(" <KEY> - Relative path of desired key.\n\n")
96 _T("Without parameters, command displays this help.\n");
97
98 }
99
100 const TCHAR * CShellCommandChangeKey::GetHelpShortDescriptionString()
101 {
102 return CD_CMD_SHORT_DESC;
103 }
104