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