bf224b5f99a4104b95baca06c10a1c801e314f9f
[reactos.git] / rosapps / sysutils / regexpl / ShellCommandNewKey.cpp
1 /* $Id: ShellCommandNewKey.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 // ShellCommandNewKey.cpp: implementation of the CShellCommandNewKey class.
12 //
13 //////////////////////////////////////////////////////////////////////
14
15 #include "ph.h"
16 #include "ShellCommandNewKey.h"
17 #include "RegistryExplorer.h"
18
19 #define NK_CMD _T("NK")
20 #define NK_CMD_SHORT_DESC NK_CMD _T(" command is used to create new key.\n")
21
22 //////////////////////////////////////////////////////////////////////
23 // Construction/Destruction
24 //////////////////////////////////////////////////////////////////////
25
26 CShellCommandNewKey::CShellCommandNewKey(CRegistryTree& rTree):m_rTree(rTree)
27 {
28 }
29
30 CShellCommandNewKey::~CShellCommandNewKey()
31 {
32 }
33
34 BOOL CShellCommandNewKey::Match(const TCHAR *pchCommand)
35 {
36 return _tcsicmp(pchCommand,NK_CMD) == 0;
37 }
38
39 int CShellCommandNewKey::Execute(CConsole &rConsole, CArgumentParser& rArguments)
40 {
41 const TCHAR *pchNewKey = NULL, *pchArg;
42
43 BOOL blnHelp = FALSE;
44 BOOL blnExitAfterHelp = FALSE;
45 BOOL blnVolatile = 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("/v")) == 0)
55 ||(_tcsicmp(pchArg,_T("-v")) == 0))
56 {
57 blnVolatile = TRUE;
58 }
59 else
60 {
61 if (pchNewKey)
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 pchNewKey = pchArg;
71 }
72 }
73 }
74
75 if ((!blnHelp) && (!pchNewKey))
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.IsCurrentRoot())
91 { // root key
92 rConsole.Write(NK_CMD COMMAND_NA_ON_ROOT);
93 return 0;
94 }
95
96 if (!m_rTree.NewKey(pchNewKey,blnVolatile))
97 {
98 rConsole.Write(_T("Cannot create key.\n"));
99 rConsole.Write(m_rTree.GetLastErrorDescription());
100 }
101 return 0;
102 }
103
104 const TCHAR * CShellCommandNewKey::GetHelpString()
105 {
106 return NK_CMD_SHORT_DESC
107 _T("Syntax: ") NK_CMD _T(" [/v] [/?] Key_Name\n\n")
108 _T(" /? - This help.\n\n")
109 _T(" /v - Create volatile key. The information is stored in memory and is not\n")
110 _T(" preserved when the corresponding registry hive is unloaded.\n");
111 }
112
113 const TCHAR * CShellCommandNewKey::GetHelpShortDescriptionString()
114 {
115 return NK_CMD_SHORT_DESC;
116 }