1 /* $Id: RegistryExplorer.cpp,v 1.6 2001/04/16 05:11:54 narnaoud Exp $
3 * regexpl - Console Registry Explorer
5 * Copyright (C) 2000,2001 Nedko Arnaoudov <nedkohome@atia.com>
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[]*/)
88 CShellCommandsLinkedList
CommandsList(Console
);
90 CShellCommandExit ExitCommand
;
91 CommandsList
.AddCommand(&ExitCommand
);
93 CShellCommandVersion VersionCommand
;
94 CommandsList
.AddCommand(&VersionCommand
);
96 CShellCommandHelp
HelpCommand(CommandsList
);
97 CommandsList
.AddCommand(&HelpCommand
);
99 CShellCommandDir
DirCommand(Tree
);
100 CommandsList
.AddCommand(&DirCommand
);
102 CShellCommandChangeKey
ChangeKeyCommand(Tree
);
103 CommandsList
.AddCommand(&ChangeKeyCommand
);
105 CShellCommandValue
ValueCommand(Tree
);
106 CommandsList
.AddCommand(&ValueCommand
);
108 CShellCommandOwner
OwnerCommand(Tree
);
109 CommandsList
.AddCommand(&OwnerCommand
);
111 CShellCommandDACL
DACLCommand(Tree
);
112 CommandsList
.AddCommand(&DACLCommand
);
114 CShellCommandSACL
SACLCommand(Tree
);
115 CommandsList
.AddCommand(&SACLCommand
);
117 //CShellCommandDOKA DOKACommand(Tree);
118 //CommandsList.AddCommand(&DOKACommand);
120 CShellCommandConnect
ConnectCommand(Tree
);
121 CommandsList
.AddCommand(&ConnectCommand
);
123 CShellCommandNewKey
NewKeyCommand(Tree
);
124 CommandsList
.AddCommand(&NewKeyCommand
);
126 CShellCommandDeleteKey
DeleteKeyCommand(Tree
);
127 CommandsList
.AddCommand(&DeleteKeyCommand
);
129 CShellCommandSetValue
SetValueCommand(Tree
);
130 CommandsList
.AddCommand(&SetValueCommand
);
132 CShellCommandDeleteValue
DeleteValueCommand(Tree
);
133 CommandsList
.AddCommand(&DeleteValueCommand
);
135 CArgumentParser Parser
;
141 CSettings
*pSettings
= NULL
;
142 CPrompt
*pPrompt
= NULL
;
144 pSettings
= new CSettings();
147 _ftprintf(stderr
,_T("Cannot initialize settings. Out of memory.\n"));
151 hr
= pSettings
->Load(SETTINGS_REGISTRY_KEY
);
154 _ftprintf(stderr
,_T("Cannot load settings. Error is 0x%X.\n"),(unsigned int)hr
);
158 pPrompt
= new CPrompt(Tree
,hr
);
161 _ftprintf(stderr
,_T("Cannot initialize prompt. Out of memory.\n"));
167 _ftprintf(stderr
,_T("Cannot initialize prompt. Error is 0x%X.\n"),(unsigned int)hr
);
171 // input buffer size in chars
172 #define INPUT_BUFFER_SIZE 1024
173 //#define INPUT_BUFFER_SIZE 128
174 //#define INPUT_BUFFER_SIZE 10
178 pchCommand
= Console
.Init(INPUT_BUFFER_SIZE
,10);
179 if (pchCommand
== NULL
)
181 _ftprintf(stderr
,_T("Cannot initialize console.\n"));
185 Console
.SetReplaceCompletionCallback(CompletionCallback
);
187 WORD wOldConsoleAttribute
;
188 if (!Console
.GetTextAttribute(wOldConsoleAttribute
)) goto Abort
;
190 Console
.SetTitle(_T("Registry Explorer"));
191 Console
.SetTextAttribute(pSettings
->GetNormalTextAttributes());
193 VERIFY(SetConsoleCtrlHandler((PHANDLER_ROUTINE
)HandlerRoutine
,TRUE
));
195 if (!Console
.Write(HELLO_MSG
196 //(_L(__TIMESTAMP__))
199 //Tree.SetDesiredOpenKeyAccess(KEY_READ);
201 hr
= pPrompt
->SetPrompt(pSettings
->GetPrompt());
204 _ftprintf(stderr
,_T("Cannot initialize prompt. Error is 0x%X.\n"),(unsigned int)hr
);
210 // TODO: make prompt user-customizable
211 Console
.EnableWrite();
212 pPrompt
->ShowPrompt(Console
);
213 Console
.FlushInputBuffer();
215 blnCommandExecutionInProgress
= FALSE
;
217 // Set command line color
218 Console
.SetTextAttribute(pSettings
->GetPromptTextAttributes());
219 if (!Console
.ReadLine())
223 Console
.SetTextAttribute(pSettings
->GetNormalTextAttributes());
225 Console
.BeginScrollingOperation();
226 blnCommandExecutionInProgress
= TRUE
;
228 // Parse command line (1st step - convert to multi sz)
229 Parser
.SetArgumentList(pchCommand
);
231 int nCommandReturnValue
;
232 switch(CommandsList
.Execute(Parser
,nCommandReturnValue
))
234 case -1: // not recognized command
236 Parser
.ResetArgumentIteration();
237 TCHAR
*pchCommandItself
= Parser
.GetNextArgument();
238 size_t cmdlen
= _tcslen(pchCommandItself
);
240 (pchCommandItself
[cmdlen
-1] != _T('\\'))||
241 (Parser
.GetNextArgument())||
242 (!Tree
.ChangeCurrentKey(pchCommandItself
)))
244 Console
.Write(_T("Unknown command \""));
245 Console
.Write(pchCommandItself
);
246 Console
.Write(_T("\"\n"));
249 case -2: // empty line
251 case 0: // exit command
253 Console
.SetTextAttribute(wOldConsoleAttribute
);
256 Console
.Write(_T("\n"));
261 _ftprintf(stderr
,_T("Abnormal program termination.\nPlease report bugs to ") EMAIL
_T("\n"));