2 * regexpl - Console Registry Explorer
4 * Copyright (C) 2000-2005 Nedko Arnaudov <nedko@users.sourceforge.net>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; see the file COPYING. If not, write to
18 * the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
22 // RegistryExplorer.cpp : Defines the entry point for the Regiistry Explorer.
26 #include "RegistryExplorer.h"
28 #include "RegistryKey.h"
29 #include "RegistryTree.h"
30 #include "SecurityDescriptor.h"
31 #include "ArgumentParser.h"
32 #include "ShellCommandsLinkedList.h"
33 #include "ShellCommandExit.h"
34 #include "ShellCommandVersion.h"
35 #include "ShellCommandHelp.h"
36 #include "ShellCommandDir.h"
37 #include "ShellCommandChangeKey.h"
38 #include "ShellCommandValue.h"
39 #include "ShellCommandOwner.h"
40 #include "ShellCommandDACL.h"
41 #include "ShellCommandSACL.h"
42 //#include "ShellCommandDOKA.h"
43 #include "ShellCommandConnect.h"
44 #include "ShellCommandNewKey.h"
45 #include "ShellCommandDeleteKey.h"
46 #include "ShellCommandSetValue.h"
47 #include "ShellCommandDeleteValue.h"
51 TCHAR pchCurrentKey
[PROMPT_BUFFER_SIZE
];
56 BOOL blnCommandExecutionInProgress
= FALSE
;
58 BOOL WINAPI
HandlerRoutine(DWORD dwCtrlType
)
63 case CTRL_BREAK_EVENT
:
64 if (blnCommandExecutionInProgress
)
75 Console
.Write(_T("\n"));
76 Console
.DisableWrite();
84 //int _tmain(/*int argc, TCHAR* argv[], TCHAR* envp[]*/)
91 CSettings
*pSettings
= NULL
;
92 CPrompt
*pPrompt
= NULL
;
94 CShellCommandsLinkedList
CommandsList(Console
);
96 CShellCommandExit ExitCommand
;
97 CommandsList
.AddCommand(&ExitCommand
);
99 CShellCommandVersion VersionCommand
;
100 CommandsList
.AddCommand(&VersionCommand
);
102 CShellCommandHelp
HelpCommand(CommandsList
);
103 CommandsList
.AddCommand(&HelpCommand
);
105 CShellCommandDir
DirCommand(Tree
);
106 CommandsList
.AddCommand(&DirCommand
);
108 CShellCommandChangeKey
ChangeKeyCommand(Tree
);
109 CommandsList
.AddCommand(&ChangeKeyCommand
);
111 CShellCommandValue
ValueCommand(Tree
);
112 CommandsList
.AddCommand(&ValueCommand
);
114 CShellCommandOwner
OwnerCommand(Tree
);
115 CommandsList
.AddCommand(&OwnerCommand
);
117 CShellCommandDACL
DACLCommand(Tree
);
118 CommandsList
.AddCommand(&DACLCommand
);
120 CShellCommandSACL
SACLCommand(Tree
);
121 CommandsList
.AddCommand(&SACLCommand
);
123 CShellCommandConnect
ConnectCommand(Tree
);
124 CommandsList
.AddCommand(&ConnectCommand
);
126 CShellCommandNewKey
NewKeyCommand(Tree
);
127 CommandsList
.AddCommand(&NewKeyCommand
);
129 CShellCommandDeleteKey
DeleteKeyCommand(Tree
);
130 CommandsList
.AddCommand(&DeleteKeyCommand
);
132 CShellCommandSetValue
SetValueCommand(Tree
);
133 CommandsList
.AddCommand(&SetValueCommand
);
135 CShellCommandDeleteValue
DeleteValueCommand(Tree
);
136 CommandsList
.AddCommand(&DeleteValueCommand
);
138 CArgumentParser Parser
;
140 pSettings
= new (std::nothrow
) CSettings();
143 _ftprintf(stderr
,_T("Cannot initialize settings. Out of memory.\n"));
147 hr
= pSettings
->Load(SETTINGS_REGISTRY_KEY
);
150 _ftprintf(stderr
,_T("Cannot load settings. Error is 0x%X.\n"),(unsigned int)hr
);
154 pPrompt
= new (std::nothrow
) CPrompt(Tree
,hr
);
157 _ftprintf(stderr
,_T("Cannot initialize prompt. Out of memory.\n"));
163 _ftprintf(stderr
,_T("Cannot initialize prompt. Error is 0x%X.\n"),(unsigned int)hr
);
167 // input buffer size in chars
168 #define INPUT_BUFFER_SIZE 1024
169 //#define INPUT_BUFFER_SIZE 128
170 //#define INPUT_BUFFER_SIZE 10
174 pchCommand
= Console
.Init(INPUT_BUFFER_SIZE
,10);
175 if (pchCommand
== NULL
)
177 _ftprintf(stderr
,_T("Cannot initialize console.\n"));
182 Console
.SetReplaceCompletionCallback(CompletionCallback
);
184 WORD wOldConsoleAttribute
;
185 if (!Console
.GetTextAttribute(wOldConsoleAttribute
)) goto Abort
;
187 Console
.SetTitle(_T("Registry Explorer"));
188 Console
.SetTextAttribute(pSettings
->GetNormalTextAttributes());
190 VERIFY(SetConsoleCtrlHandler((PHANDLER_ROUTINE
)HandlerRoutine
,TRUE
));
192 if (!Console
.Write(HELLO_MSG
193 //(_L(__TIMESTAMP__))
196 //Tree.SetDesiredOpenKeyAccess(KEY_READ);
198 hr
= pPrompt
->SetPrompt(pSettings
->GetPrompt());
201 _ftprintf(stderr
,_T("Cannot initialize prompt. Error is 0x%X.\n"),(unsigned int)hr
);
207 // TODO: make prompt user-customizable
208 Console
.EnableWrite();
209 pPrompt
->ShowPrompt(Console
);
210 Console
.FlushInputBuffer();
212 blnCommandExecutionInProgress
= FALSE
;
214 // Set command line color
215 Console
.SetTextAttribute(pSettings
->GetCommandTextAttributes());
216 if (!Console
.ReadLine())
220 Console
.SetTextAttribute(pSettings
->GetNormalTextAttributes());
222 Console
.BeginScrollingOperation();
223 blnCommandExecutionInProgress
= TRUE
;
225 // Parse command line (1st step - convert to multi sz)
226 Parser
.SetArgumentList(pchCommand
);
228 int nCommandReturnValue
;
229 switch(CommandsList
.Execute(Parser
,nCommandReturnValue
))
231 case -1: // not recognized command
233 Parser
.ResetArgumentIteration();
234 TCHAR
*pchCommandItself
= Parser
.GetNextArgument();
235 size_t cmdlen
= _tcslen(pchCommandItself
);
237 (pchCommandItself
[cmdlen
-1] != _T('\\'))||
238 (Parser
.GetNextArgument())||
239 (!Tree
.ChangeCurrentKey(pchCommandItself
)))
241 Console
.Write(_T("Unknown command \""));
242 Console
.Write(pchCommandItself
);
243 Console
.Write(_T("\"\n"));
246 case -2: // empty line
248 case 0: // exit command
250 Console
.SetTextAttribute(wOldConsoleAttribute
);
253 Console
.Write(_T("\n"));
258 _ftprintf(stderr
,_T("Abnormal program termination.\nPlease report bugs to ") EMAIL
_T("\n"));