2
* PROGRAM: Windows NT registry installation program
4
* DESCRIPTION: Registry update routines
6
* The contents of this file are subject to the Interbase Public
7
* License Version 1.0 (the "License"); you may not use this file
8
* except in compliance with the License. You may obtain a copy
9
* of the License at http://www.Inprise.com/IPL.html
11
* Software distributed under the License is distributed on an
12
* "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, either express
13
* or implied. See the License for the specific language governing
14
* rights and limitations under the License.
16
* The Original Code was created by Inprise Corporation
17
* and its predecessors. Portions created by Inprise Corporation are
18
* Copyright (C) Inprise Corporation.
20
* All Rights Reserved.
21
* Contributor(s): ______________________________________.
23
* 01-Feb-2002 Paul Reeves: Removed hard-coded registry path
28
#include "../jrd/common.h"
32
//#include "../jrd/license.h"
33
#include "../utilities/install/install_nt.h"
34
#include "../utilities/install/regis_proto.h"
35
#include "../utilities/install/registry.h"
37
static void cleanup_key(HKEY, const char*);
38
#ifdef THIS_CODE_IS_TEMPORARILY_NOT_USED_ANYMORE
39
static USHORT remove_subkeys(HKEY, bool, pfnRegError);
42
USHORT REGISTRY_install(HKEY hkey_rootnode,
43
const TEXT* directory,
44
pfnRegError err_handler)
46
/**************************************
48
* R E G I S T R Y _ i n s t a l l
50
**************************************
52
* Functional description
53
* Install Firebird in the registry.
55
**************************************/
58
SLONG status = RegCreateKeyEx(hkey_rootnode,
59
REG_KEY_ROOT_INSTANCES,
62
REG_OPTION_NON_VOLATILE,
64
NULL, &hkey_instances, &disp);
65
if (status != ERROR_SUCCESS) {
66
return (*err_handler) (status, "RegCreateKeyEx", NULL);
69
TEXT path_name[MAXPATHLEN];
71
USHORT len = GetFullPathName(directory, sizeof(path_name), path_name, &p);
72
if (len && path_name[len - 1] != '/' && path_name[len - 1] != '\\') {
73
path_name[len++] = '\\';
77
if ((status = RegSetValueEx(hkey_instances, FB_DEFAULT_INSTANCE, 0,
78
REG_SZ, reinterpret_cast<const BYTE*>(path_name),
79
(DWORD) (len + 1))) != ERROR_SUCCESS)
81
(*err_handler) (status, "RegSetValueEx", hkey_instances);
83
// Removes the "Instances" key if we just created it.
84
// Else, keep it, because we don't want to trash other instances.
85
if (disp == REG_CREATED_NEW_KEY)
87
RegDeleteKey(hkey_rootnode, REG_KEY_ROOT_INSTANCES);
88
cleanup_key(hkey_rootnode, REG_KEY_ROOT_PRODUCT);
89
cleanup_key(hkey_rootnode, REG_KEY_ROOT_COMPANY);
95
RegCloseKey(hkey_instances);
99
USHORT REGISTRY_remove(HKEY hkey_rootnode,
101
pfnRegError err_handler)
103
/**************************************
105
* R E G I S T R Y _ r e m o v e
107
**************************************
109
* Functional description
110
* Remove Firebird from the registry.
112
**************************************/
115
SLONG status = RegOpenKeyEx(hkey_rootnode, REG_KEY_ROOT_INSTANCES, 0,
116
KEY_READ | KEY_WRITE, &hkey_instances);
117
if (status != ERROR_SUCCESS)
121
return (*err_handler) (status, "RegOpenKeyEx", NULL);
124
// Remove the FB_DEFAULT_INSTANCE value
125
if ((status = RegDeleteValue(hkey_instances, FB_DEFAULT_INSTANCE))
128
RegCloseKey(hkey_instances);
131
return (*err_handler) (status, "RegDeleteValue", NULL);
134
RegCloseKey(hkey_instances);
135
cleanup_key(hkey_rootnode, REG_KEY_ROOT_INSTANCES);
136
cleanup_key(hkey_rootnode, REG_KEY_ROOT_PRODUCT);
137
cleanup_key(hkey_rootnode, REG_KEY_ROOT_COMPANY);
142
static void cleanup_key(HKEY hkey_rootnode, const char* key)
144
/**************************************
146
* c l e a n u p _ k e y
148
**************************************
150
* Functional description
151
* Remove a key, if found unused (no subkeys and no values).
152
* This function is silent.
154
**************************************/
158
if (RegOpenKeyEx(hkey_rootnode, key, 0,
159
KEY_READ | KEY_WRITE, &hkey) == ERROR_SUCCESS)
161
DWORD subkeys_count, values_count;
162
if (RegQueryInfoKey(hkey, NULL, 0, 0,
163
&subkeys_count, NULL, NULL,
164
&values_count, 0, 0, NULL, NULL) == ERROR_SUCCESS &&
165
subkeys_count == 0 && values_count == 0)
168
RegDeleteKey(hkey_rootnode, key);
176
#ifdef THIS_CODE_IS_TEMPORARILY_NOT_USED_ANYMORE
177
// I keep it here for possible re-use after FB 1.5 release. OM, sept 30, 2003.
178
static USHORT remove_subkeys(
181
pfnRegError err_handler)
183
/**************************************
185
* r e m o v e _ s u b k e y s
187
**************************************
189
* Functional description
190
* Remove all sub-keys of an Firebird key from the registry.
192
**************************************/
193
TEXT buffer[MAXPATHLEN];
194
DWORD n_sub_keys, max_sub_key;
195
FILETIME last_write_time;
197
DWORD buf_len = sizeof(buffer);
198
DWORD status = RegQueryInfoKey(hkey,
203
&i, &i, &i, &i, &i, &last_write_time);
204
if (status != ERROR_SUCCESS && status != ERROR_MORE_DATA) {
207
return (*err_handler) (status, "RegQueryInfoKey", NULL);
210
TEXT* sub_key = (++max_sub_key > sizeof(buffer)) ?
211
(TEXT*) malloc((SLONG) max_sub_key) : buffer;
213
const TEXT* p = NULL;
214
for (DWORD i = 0; i < n_sub_keys; i++) {
215
DWORD sub_key_len = max_sub_key;
216
if ((status = RegEnumKeyEx(hkey, i, sub_key, &sub_key_len,
218
&last_write_time)) != ERROR_SUCCESS)
225
if ((status = RegOpenKeyEx(hkey, sub_key,
227
KEY_ENUMERATE_SUB_KEYS | KEY_QUERY_VALUE |
228
KEY_WRITE, &hkey_sub)) != ERROR_SUCCESS)
233
const USHORT ret = remove_subkeys(hkey_sub, silent_flag, err_handler);
234
RegCloseKey(hkey_sub);
235
if (ret == FB_FAILURE)
237
if ((status = RegDeleteKey(hkey, sub_key)) != ERROR_SUCCESS) {
243
if (buffer != sub_key)
249
return (*err_handler) (status, p, NULL);