Reactos
1/*
2 * regexpl - Console Registry Explorer
3 *
4 * Copyright (C) 2000-2005 Nedko Arnaudov <nedko@users.sourceforge.net>
5 *
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.
10 *
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.
15 *
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.
20 */
21
22// Settings.cpp : implemetation of CSettings class - user customizable settings for Registry Explorer
23
24#include "ph.h"
25#include "RegistryExplorer.h"
26#include "Settings.h"
27#include "Prompt.h"
28
29#define DEFAULT_NORMAL_TEXT_ATTRIBUTES FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED
30#define DEFAULT_COMMAND_TEXT_ATTRIBUTES FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED
31
32CSettings::CSettings()
33{
34 m_pszPrompt = NULL;
35
36 m_wNormalTextAttributes = DEFAULT_NORMAL_TEXT_ATTRIBUTES;
37 m_wCommandTextAttributes = DEFAULT_COMMAND_TEXT_ATTRIBUTES;
38}
39
40CSettings::~CSettings()
41{
42 VERIFY(SUCCEEDED(Clean()));
43}
44
45HRESULT CSettings::Clean()
46{
47 if (m_pszPrompt)
48 {
49 delete[] m_pszPrompt;
50 m_pszPrompt = NULL;
51 }
52
53 return S_OK;
54}
55
56HRESULT CSettings::Load(LPCTSTR pszLoadKey)
57{
58 HKEY hKey = NULL;
59 HRESULT hr;
60 DWORD dwType;
61 DWORD dwSize;
62 DWORD w;
63
64 hr = Clean();
65 if (FAILED(hr))
66 return hr;
67
68 hr = S_OK;
69
70 LONG nError = RegOpenKeyEx(HKEY_CURRENT_USER,pszLoadKey,0,KEY_QUERY_VALUE,&hKey);
71 if (nError != ERROR_SUCCESS)
72 return S_FALSE;
73
74 nError = RegQueryValueEx(hKey,PROMPT_VALUE_NAME,NULL,&dwType,NULL,&dwSize);
75 if (nError == ERROR_SUCCESS && dwType == REG_SZ)
76 {
77 m_pszPrompt = (TCHAR *) new (std::nothrow) BYTE[dwSize];
78 if (!m_pszPrompt)
79 {
80 hr = E_OUTOFMEMORY;
81 goto Exit;
82 }
83
84 nError = RegQueryValueEx(hKey,PROMPT_VALUE_NAME,NULL,&dwType,(BYTE *)m_pszPrompt,&dwSize);
85 if (nError != ERROR_SUCCESS || dwType != REG_SZ)
86 {
87 delete m_pszPrompt;
88 m_pszPrompt = NULL;
89 hr = S_FALSE;
90 }
91 }
92 else
93 {
94 hr = S_FALSE;
95 }
96
97 dwSize = sizeof(DWORD);
98 nError = RegQueryValueEx(hKey,NORMAL_TEXT_ATTRIBUTES_VALUE_NAME,NULL,&dwType,(BYTE *)&w,&dwSize);
99 if (nError != ERROR_SUCCESS || dwType != REG_DWORD)
100 {
101 hr = S_FALSE;
102 }
103 else
104 {
105 m_wNormalTextAttributes = (WORD)w;
106 }
107
108 dwSize = sizeof(DWORD);
109 nError = RegQueryValueEx(hKey,COMMAND_TEXT_ATTRIBUTES_VALUE_NAME,NULL,&dwType,(BYTE *)&w,&dwSize);
110 if (nError != ERROR_SUCCESS || dwType != REG_DWORD)
111 {
112 hr = S_FALSE;
113 }
114 else
115 {
116 m_wCommandTextAttributes = (WORD)w;
117 }
118
119Exit:
120
121 if (hKey)
122 VERIFY(RegCloseKey(hKey) == ERROR_SUCCESS);
123
124 return hr;
125}
126
127HRESULT CSettings::Store(LPCTSTR pszLoadKey)
128{
129 return S_OK;
130}
131
132LPCTSTR CSettings::GetPrompt()
133{
134 return m_pszPrompt?m_pszPrompt:CPrompt::GetDefaultPrompt();
135}
136
137WORD CSettings::GetNormalTextAttributes()
138{
139 return m_wNormalTextAttributes;
140}
141
142WORD CSettings::GetCommandTextAttributes()
143{
144 return m_wCommandTextAttributes;
145}