3 * regexpl - Console Registry Explorer
5 * Copyright (C) 2000-2005 Nedko Arnaudov <nedko@users.sourceforge.net>
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.
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.
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.
23 // RegistryExplorer.cpp : Defines the entry point for the Regiistry Explorer.
27 #include "RegistryExplorer.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"
52 TCHAR pchCurrentKey
[PROMPT_BUFFER_SIZE
];
57 BOOL blnCommandExecutionInProgress
= FALSE
;
59 BOOL WINAPI
HandlerRoutine(DWORD dwCtrlType
)
64 case CTRL_BREAK_EVENT
:
65 if (blnCommandExecutionInProgress
)
76 Console
.Write(_T("\n"));
77 Console
.DisableWrite();
85 //int _tmain(/*int argc, TCHAR* argv[], TCHAR* envp[]*/)
92 CSettings
*pSettings
= NULL
;
93 CPrompt
*pPrompt
= NULL
;
95 CShellCommandsLinkedList
CommandsList(Console
);
97 CShellCommandExit ExitCommand
;
98 CommandsList
.AddCommand(&ExitCommand
);
100 CShellCommandVersion VersionCommand
;
101 CommandsList
.AddCommand(&VersionCommand
);
103 CShellCommandHelp
HelpCommand(CommandsList
);
104 CommandsList
.AddCommand(&HelpCommand
);
106 CShellCommandDir
DirCommand(Tree
);
107 CommandsList
.AddCommand(&DirCommand
);
109 CShellCommandChangeKey
ChangeKeyCommand(Tree
);
110 CommandsList
.AddCommand(&ChangeKeyCommand
);
112 CShellCommandValue
ValueCommand(Tree
);
113 CommandsList
.AddCommand(&ValueCommand
);
115 CShellCommandOwner
OwnerCommand(Tree
);
116 CommandsList
.AddCommand(&OwnerCommand
);
118 CShellCommandDACL
DACLCommand(Tree
);
119 CommandsList
.AddCommand(&DACLCommand
);
121 CShellCommandSACL
SACLCommand(Tree
);
122 CommandsList
.AddCommand(&SACLCommand
);
124 CShellCommandConnect
ConnectCommand(Tree
);
125 CommandsList
.AddCommand(&ConnectCommand
);
127 CShellCommandNewKey
NewKeyCommand(Tree
);
128 CommandsList
.AddCommand(&NewKeyCommand
);
130 CShellCommandDeleteKey
DeleteKeyCommand(Tree
);
131 CommandsList
.AddCommand(&DeleteKeyCommand
);
133 CShellCommandSetValue
SetValueCommand(Tree
);
134 CommandsList
.AddCommand(&SetValueCommand
);
136 CShellCommandDeleteValue
DeleteValueCommand(Tree
);
137 CommandsList
.AddCommand(&DeleteValueCommand
);
139 CArgumentParser Parser
;
141 pSettings
= new CSettings();
144 _ftprintf(stderr
,_T("Cannot initialize settings. Out of memory.\n"));
148 hr
= pSettings
->Load(SETTINGS_REGISTRY_KEY
);
151 _ftprintf(stderr
,_T("Cannot load settings. Error is 0x%X.\n"),(unsigned int)hr
);
155 pPrompt
= new CPrompt(Tree
,hr
);
158 _ftprintf(stderr
,_T("Cannot initialize prompt. Out of memory.\n"));
164 _ftprintf(stderr
,_T("Cannot initialize prompt. Error is 0x%X.\n"),(unsigned int)hr
);
168 // input buffer size in chars
169 #define INPUT_BUFFER_SIZE 1024
170 //#define INPUT_BUFFER_SIZE 128
171 //#define INPUT_BUFFER_SIZE 10
175 pchCommand
= Console
.Init(INPUT_BUFFER_SIZE
,10);
176 if (pchCommand
== NULL
)
178 _ftprintf(stderr
,_T("Cannot initialize console.\n"));
183 Console
.SetReplaceCompletionCallback(CompletionCallback
);
185 WORD wOldConsoleAttribute
;
186 if (!Console
.GetTextAttribute(wOldConsoleAttribute
)) goto Abort
;
188 Console
.SetTitle(_T("Registry Explorer"));
189 Console
.SetTextAttribute(pSettings
->GetNormalTextAttributes());
191 VERIFY(SetConsoleCtrlHandler((PHANDLER_ROUTINE
)HandlerRoutine
,TRUE
));
193 if (!Console
.Write(HELLO_MSG
194 //(_L(__TIMESTAMP__))
197 //Tree.SetDesiredOpenKeyAccess(KEY_READ);
199 hr
= pPrompt
->SetPrompt(pSettings
->GetPrompt());
202 _ftprintf(stderr
,_T("Cannot initialize prompt. Error is 0x%X.\n"),(unsigned int)hr
);
208 // TODO: make prompt user-customizable
209 Console
.EnableWrite();
210 pPrompt
->ShowPrompt(Console
);
211 Console
.FlushInputBuffer();
213 blnCommandExecutionInProgress
= FALSE
;
215 // Set command line color
216 Console
.SetTextAttribute(pSettings
->GetCommandTextAttributes());
217 if (!Console
.ReadLine())
221 Console
.SetTextAttribute(pSettings
->GetNormalTextAttributes());
223 Console
.BeginScrollingOperation();
224 blnCommandExecutionInProgress
= TRUE
;
226 // Parse command line (1st step - convert to multi sz)
227 Parser
.SetArgumentList(pchCommand
);
229 int nCommandReturnValue
;
230 switch(CommandsList
.Execute(Parser
,nCommandReturnValue
))
232 case -1: // not recognized command
234 Parser
.ResetArgumentIteration();
235 TCHAR
*pchCommandItself
= Parser
.GetNextArgument();
236 size_t cmdlen
= _tcslen(pchCommandItself
);
238 (pchCommandItself
[cmdlen
-1] != _T('\\'))||
239 (Parser
.GetNextArgument())||
240 (!Tree
.ChangeCurrentKey(pchCommandItself
)))
242 Console
.Write(_T("Unknown command \""));
243 Console
.Write(pchCommandItself
);
244 Console
.Write(_T("\"\n"));
247 case -2: // empty line
249 case 0: // exit command
251 Console
.SetTextAttribute(wOldConsoleAttribute
);
254 Console
.Write(_T("\n"));
259 _ftprintf(stderr
,_T("Abnormal program termination.\nPlease report bugs to ") EMAIL
_T("\n"));