Added support for escape sequences when setting string value.
[reactos.git] / rosapps / sysutils / regexpl / RegistryExplorer.cpp
1 /* $Id: RegistryExplorer.cpp,v 1.5 2001/04/15 22:17:50 narnaoud Exp $
2 *
3 * regexpl - Console Registry Explorer
4 *
5 * Copyright (C) 2000,2001 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 // Registry Explorer.cpp : Defines the entry point for the console application.
24 //
25
26 #include "ph.h"
27 #include "RegistryExplorer.h"
28 #include "Console.h"
29 #include "RegistryKey.h"
30 #include "RegistryTree.h"
31 #include "SecurityDescriptor.h"
32 #include "ArgumentParser.h"
33 #include "ShellCommandsLinkedList.h"
34 #include "ShellCommandExit.h"
35 #include "ShellCommandVersion.h"
36 #include "ShellCommandHelp.h"
37 #include "ShellCommandDir.h"
38 #include "ShellCommandChangeKey.h"
39 #include "ShellCommandValue.h"
40 #include "ShellCommandOwner.h"
41 #include "ShellCommandDACL.h"
42 #include "ShellCommandSACL.h"
43 //#include "ShellCommandDOKA.h"
44 #include "ShellCommandConnect.h"
45 #include "ShellCommandNewKey.h"
46 #include "ShellCommandDeleteKey.h"
47 #include "ShellCommandSetValue.h"
48 #include "ShellCommandDeleteValue.h"
49
50 TCHAR pchCurrentKey[PROMPT_BUFFER_SIZE];
51
52 CRegistryTree Tree;
53 CConsole Console;
54
55 BOOL blnCommandExecutionInProgress = FALSE;
56
57 BOOL WINAPI HandlerRoutine(DWORD dwCtrlType)
58 {
59 switch(dwCtrlType)
60 {
61 case CTRL_C_EVENT:
62 case CTRL_BREAK_EVENT:
63 if (blnCommandExecutionInProgress)
64 {
65 /* Beep(1000,100);
66 Beep(2000,100);
67 Beep(3000,100);
68 Beep(4000,100);
69 Beep(5000,100);
70 Beep(4000,100);
71 Beep(3000,100);
72 Beep(2000,100);
73 Beep(1000,100);*/
74 Console.Write(_T("\n"));
75 Console.DisableWrite();
76 }
77 return TRUE;
78 default:
79 return FALSE;
80 }
81 }
82
83 //int _tmain(/*int argc, TCHAR* argv[], TCHAR* envp[]*/)
84 int main ()
85 {
86 CShellCommandsLinkedList CommandsList(Console);
87
88 CShellCommandExit ExitCommand;
89 CommandsList.AddCommand(&ExitCommand);
90
91 CShellCommandVersion VersionCommand;
92 CommandsList.AddCommand(&VersionCommand);
93
94 CShellCommandHelp HelpCommand(CommandsList);
95 CommandsList.AddCommand(&HelpCommand);
96
97 CShellCommandDir DirCommand(Tree);
98 CommandsList.AddCommand(&DirCommand);
99
100 CShellCommandChangeKey ChangeKeyCommand(Tree);
101 CommandsList.AddCommand(&ChangeKeyCommand);
102
103 CShellCommandValue ValueCommand(Tree);
104 CommandsList.AddCommand(&ValueCommand);
105
106 CShellCommandOwner OwnerCommand(Tree);
107 CommandsList.AddCommand(&OwnerCommand);
108
109 CShellCommandDACL DACLCommand(Tree);
110 CommandsList.AddCommand(&DACLCommand);
111
112 CShellCommandSACL SACLCommand(Tree);
113 CommandsList.AddCommand(&SACLCommand);
114
115 //CShellCommandDOKA DOKACommand(Tree);
116 //CommandsList.AddCommand(&DOKACommand);
117
118 CShellCommandConnect ConnectCommand(Tree);
119 CommandsList.AddCommand(&ConnectCommand);
120
121 CShellCommandNewKey NewKeyCommand(Tree);
122 CommandsList.AddCommand(&NewKeyCommand);
123
124 CShellCommandDeleteKey DeleteKeyCommand(Tree);
125 CommandsList.AddCommand(&DeleteKeyCommand);
126
127 CShellCommandSetValue SetValueCommand(Tree);
128 CommandsList.AddCommand(&SetValueCommand);
129
130 CShellCommandDeleteValue DeleteValueCommand(Tree);
131 CommandsList.AddCommand(&DeleteValueCommand);
132
133 CArgumentParser Parser;
134
135 int nRetCode = 0;
136
137 // input buffer size in chars
138 #define INPUT_BUFFER_SIZE 1024
139 //#define INPUT_BUFFER_SIZE 128
140 //#define INPUT_BUFFER_SIZE 10
141
142 TCHAR *pchCommand;
143
144 pchCommand = Console.Init(INPUT_BUFFER_SIZE,10);
145 if (pchCommand == NULL)
146 {
147 _ftprintf(stderr,_T("Cannot initialize console.\n"));
148 goto Abort;
149 }
150
151 Console.SetReplaceCompletionCallback(CompletionCallback);
152
153 WORD wOldConsoleAttribute;
154 if (!Console.GetTextAttribute(wOldConsoleAttribute)) goto Abort;
155
156 Console.SetTitle(_T("Registry Explorer"));
157 Console.SetTextAttribute(FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED/*|FOREGROUND_INTENSITY*/);
158
159 VERIFY(SetConsoleCtrlHandler((PHANDLER_ROUTINE)HandlerRoutine,TRUE));
160
161 if (!Console.Write(HELLO_MSG
162 //(_L(__TIMESTAMP__))
163 )) goto Abort;
164
165 //Tree.SetDesiredOpenKeyAccess(KEY_READ);
166
167 const TCHAR *pszCurrentPath;
168 GetCommand:
169 // prompt
170 // TODO: make prompt user-customizable
171 Console.EnableWrite();
172 pszCurrentPath = Tree.GetCurrentPath();
173 Console.Write(pszCurrentPath?pszCurrentPath:_T("NULL (Internal Error)"));
174 Console.Write(_T("\n# "));
175 Console.FlushInputBuffer();
176
177 blnCommandExecutionInProgress = FALSE;
178
179 // Set command line color
180 // Console.SetTextAttribute(/*FOREGROUND_BLUE|*/FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
181 if (!Console.ReadLine())
182 goto Abort;
183
184 // Set normal color
185 // Console.SetTextAttribute(FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY);
186
187 Console.BeginScrollingOperation();
188 blnCommandExecutionInProgress = TRUE;
189
190 // Parse command line (1st step - convert to multi sz)
191 Parser.SetArgumentList(pchCommand);
192
193 int nCommandReturnValue;
194 switch(CommandsList.Execute(Parser,nCommandReturnValue))
195 {
196 case -1: // not recognized command
197 {
198 Parser.ResetArgumentIteration();
199 TCHAR *pchCommandItself = Parser.GetNextArgument();
200 size_t cmdlen = _tcslen(pchCommandItself);
201 if ((!cmdlen)||
202 (pchCommandItself[cmdlen-1] != _T('\\'))||
203 (Parser.GetNextArgument())||
204 (!Tree.ChangeCurrentKey(pchCommandItself)))
205 {
206 Console.Write(_T("Unknown command \""));
207 Console.Write(pchCommandItself);
208 Console.Write(_T("\"\n"));
209 }
210 }
211 case -2: // empty line
212 goto GetCommand;
213 case 0: // exit command
214 nRetCode = 0;
215 Console.SetTextAttribute(wOldConsoleAttribute);
216 goto Exit;
217 default:
218 Console.Write(_T("\n"));
219 goto GetCommand;
220 }
221
222 Abort:
223 _ftprintf(stderr,_T("Abnormal program termination.\nPlease report bugs to ") EMAIL _T("\n"));
224 nRetCode = 1;
225 Exit:
226 return nRetCode;
227 }