From add5e2d89fc541cd6a6f63737596d7bb0f8fb971 Mon Sep 17 00:00:00 2001 From: Nedko Arnaudov Date: Mon, 16 Apr 2001 05:11:54 +0000 Subject: [PATCH] Added base support for user settings. svn path=/trunk/; revision=1804 --- rosapps/sysutils/regexpl/Makefile | 4 +- rosapps/sysutils/regexpl/RegistryExplorer.cpp | 64 ++++++++++++++++--- rosapps/sysutils/regexpl/RegistryExplorer.h | 7 +- 3 files changed, 64 insertions(+), 11 deletions(-) diff --git a/rosapps/sysutils/regexpl/Makefile b/rosapps/sysutils/regexpl/Makefile index 7f726cfc3ef..ba8b93d1cb9 100644 --- a/rosapps/sysutils/regexpl/Makefile +++ b/rosapps/sysutils/regexpl/Makefile @@ -1,4 +1,4 @@ -# $Id: Makefile,v 1.4 2001/01/10 01:25:29 narnaoud Exp $ +# $Id: Makefile,v 1.5 2001/04/16 05:11:54 narnaoud Exp $ # # ReactOS makefile for RegExpl # @@ -52,6 +52,8 @@ OBJECTS = \ TextHistory.o \ Completion.o \ Pattern.o \ + Settings.o \ + Prompt.o \ $(TARGET_NAME).coff CLEAN_FILES = \ diff --git a/rosapps/sysutils/regexpl/RegistryExplorer.cpp b/rosapps/sysutils/regexpl/RegistryExplorer.cpp index 584033a956f..2d9711cfe4b 100644 --- a/rosapps/sysutils/regexpl/RegistryExplorer.cpp +++ b/rosapps/sysutils/regexpl/RegistryExplorer.cpp @@ -1,4 +1,4 @@ -/* $Id: RegistryExplorer.cpp,v 1.5 2001/04/15 22:17:50 narnaoud Exp $ +/* $Id: RegistryExplorer.cpp,v 1.6 2001/04/16 05:11:54 narnaoud Exp $ * * regexpl - Console Registry Explorer * @@ -20,7 +20,7 @@ * Boston, MA 02111-1307, USA. */ -// Registry Explorer.cpp : Defines the entry point for the console application. +// RegistryExplorer.cpp : Defines the entry point for the Regiistry Explorer. // #include "ph.h" @@ -46,6 +46,8 @@ #include "ShellCommandDeleteKey.h" #include "ShellCommandSetValue.h" #include "ShellCommandDeleteValue.h" +#include "Prompt.h" +#include "Settings.h" TCHAR pchCurrentKey[PROMPT_BUFFER_SIZE]; @@ -134,6 +136,38 @@ int main () int nRetCode = 0; + HRESULT hr; + + CSettings *pSettings = NULL; + CPrompt *pPrompt = NULL; + + pSettings = new CSettings(); + if (!pSettings) + { + _ftprintf(stderr,_T("Cannot initialize settings. Out of memory.\n")); + goto Abort; + } + + hr = pSettings->Load(SETTINGS_REGISTRY_KEY); + if (FAILED(hr)) + { + _ftprintf(stderr,_T("Cannot load settings. Error is 0x%X.\n"),(unsigned int)hr); + goto Abort; + } + + pPrompt = new CPrompt(Tree,hr); + if (!pPrompt) + { + _ftprintf(stderr,_T("Cannot initialize prompt. Out of memory.\n")); + goto Abort; + } + + if (FAILED(hr)) + { + _ftprintf(stderr,_T("Cannot initialize prompt. Error is 0x%X.\n"),(unsigned int)hr); + goto Abort; + } + // input buffer size in chars #define INPUT_BUFFER_SIZE 1024 //#define INPUT_BUFFER_SIZE 128 @@ -154,7 +188,7 @@ int main () if (!Console.GetTextAttribute(wOldConsoleAttribute)) goto Abort; Console.SetTitle(_T("Registry Explorer")); - Console.SetTextAttribute(FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED/*|FOREGROUND_INTENSITY*/); + Console.SetTextAttribute(pSettings->GetNormalTextAttributes()); VERIFY(SetConsoleCtrlHandler((PHANDLER_ROUTINE)HandlerRoutine,TRUE)); @@ -164,25 +198,29 @@ int main () //Tree.SetDesiredOpenKeyAccess(KEY_READ); - const TCHAR *pszCurrentPath; + hr = pPrompt->SetPrompt(pSettings->GetPrompt()); + if (FAILED(hr)) + { + _ftprintf(stderr,_T("Cannot initialize prompt. Error is 0x%X.\n"),(unsigned int)hr); + goto Abort; + } + GetCommand: // prompt // TODO: make prompt user-customizable Console.EnableWrite(); - pszCurrentPath = Tree.GetCurrentPath(); - Console.Write(pszCurrentPath?pszCurrentPath:_T("NULL (Internal Error)")); - Console.Write(_T("\n# ")); + pPrompt->ShowPrompt(Console); Console.FlushInputBuffer(); blnCommandExecutionInProgress = FALSE; // Set command line color -// Console.SetTextAttribute(/*FOREGROUND_BLUE|*/FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY); + Console.SetTextAttribute(pSettings->GetPromptTextAttributes()); if (!Console.ReadLine()) goto Abort; // Set normal color -// Console.SetTextAttribute(FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED|FOREGROUND_INTENSITY); + Console.SetTextAttribute(pSettings->GetNormalTextAttributes()); Console.BeginScrollingOperation(); blnCommandExecutionInProgress = TRUE; @@ -222,6 +260,14 @@ GetCommand: Abort: _ftprintf(stderr,_T("Abnormal program termination.\nPlease report bugs to ") EMAIL _T("\n")); nRetCode = 1; + Exit: + + if (pSettings) + delete pSettings; + + if (pPrompt) + delete pPrompt; + return nRetCode; } diff --git a/rosapps/sysutils/regexpl/RegistryExplorer.h b/rosapps/sysutils/regexpl/RegistryExplorer.h index e8671f2ddca..a5df34aa7af 100644 --- a/rosapps/sysutils/regexpl/RegistryExplorer.h +++ b/rosapps/sysutils/regexpl/RegistryExplorer.h @@ -1,4 +1,4 @@ -/* $Id: RegistryExplorer.h,v 1.5 2001/01/13 23:53:23 narnaoud Exp $ */ +/* $Id: RegistryExplorer.h,v 1.6 2001/04/16 05:11:54 narnaoud Exp $ */ #ifndef _REGISTRY_EXPLORER_H__INCLUDED #define _REGISTRY_EXPLORER_H__INCLUDED @@ -49,4 +49,9 @@ #define COMMAND_NA_ON_ROOT _T(" is not applicable to root key.\n") +#define SETTINGS_REGISTRY_KEY _T("SOFTWARE\\Registry Explorer") +#define NORMAL_TEXT_ATTRIBUTES_VALUE_NAME _T("Normal Text Color") +#define PROMPT_TEXT_ATTRIBUTES_VALUE_NAME _T("Prompt Text Color") +#define PROMPT_VALUE_NAME _T("Prompt") + #endif //#ifndef _REGISTRY_EXPLORER_H__INCLUDED