1 |
/* wptRegistry.cpp - W32 Registry access |
/* wptRegistry.cpp - Windows Registry access |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
6 |
* WinPT is free software; you can redistribute it and/or |
* WinPT is free software; you can redistribute it and/or |
7 |
* modify it under the terms of the GNU General Public License |
* modify it under the terms of the GNU General Public License |
8 |
* as published by the Free Software Foundation; either version 2 |
* as published by the Free Software Foundation; either version 2 |
9 |
* of the License, or (at your option) any later version. |
* of the License, or (at your option) any later version. |
10 |
* |
* |
11 |
* WinPT is distributed in the hope that it will be useful, |
* WinPT is distributed in the hope that it will be useful, |
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
* General Public License for more details. |
* General Public License for more details. |
15 |
* |
* |
16 |
* You should have received a copy of the GNU General Public License |
* You should have received a copy of the GNU General Public License |
17 |
* along with WinPT; if not, write to the Free Software Foundation, |
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
*/ |
*/ |
20 |
|
#ifdef HAVE_CONFIG_H |
21 |
#include <windows.h> |
#include <config.h> |
22 |
#include <stdio.h> |
#endif |
23 |
|
|
24 |
#include "wptErrors.h" |
/* For the case WinPT will be compiled in mobile mode, we use a wrapper |
25 |
#include "wptW32API.h" |
to avoid registry access (read, write) and thus this file will not |
26 |
#include "wptGPG.h" |
be used. */ |
27 |
#include "wptRegistry.h" |
#ifndef WINPT_MOBILE |
28 |
#include "wptKeyserver.h" |
#include <windows.h> |
29 |
#include "wptTypes.h" |
#include <stdio.h> |
30 |
#include "wptNLS.h" |
|
31 |
#include "wptVersion.h" |
#include "wptErrors.h" |
32 |
|
#include "wptW32API.h" |
33 |
#define rc_ok(rc) ((rc) == ERROR_SUCCESS) |
#include "wptGPG.h" |
34 |
|
#include "wptRegistry.h" |
35 |
struct reg_hotkey_s reg_hotkeys[] = { |
#include "wptKeyserver.h" |
36 |
{"ClipEncrypt", NULL, 0}, |
#include "wptTypes.h" |
37 |
{"ClipDecrypt", NULL, 0}, |
#include "wptNLS.h" |
38 |
{"ClipSign", NULL, 0}, |
#include "wptVersion.h" |
39 |
{"ClipSignEnc", NULL, 0}, |
#include "wptHotkey.h" |
40 |
{"CwsEncrypt", NULL, 0}, |
|
41 |
{"CwsDecrypt", NULL, 0}, |
#define rc_ok(rc) ((rc) == ERROR_SUCCESS) |
42 |
{"CwsSign", NULL, 0}, |
|
43 |
{"CwsSignEnc", NULL, 0}, |
/* WinPT registry path. */ |
44 |
{0} |
#define WINPT_REG "Software\\WinPT" |
45 |
}; |
|
46 |
|
/* GPG registry path. */ |
47 |
winpt_reg_prefs_s reg_prefs; |
#define GPG_REG "Software\\GNU\\GnuPG" |
48 |
|
|
49 |
#define WINPT_REG "Software\\WinPT" |
#define GPG_MO_REG "Control Panel\\MingW32\\NLS" |
50 |
|
|
51 |
|
/* GPG file association context. */ |
52 |
void |
struct gpg_filetype_s { |
53 |
free_reg_prefs (void) |
const char *descr; /* description. */ |
54 |
{ |
const char *ext; /* extension. */ |
55 |
free_if_alloc (reg_prefs.backup.path); |
int nicon; /* number of the image icon. */ |
56 |
free_if_alloc (reg_prefs.kserv_conf); |
}; |
57 |
memset (®_prefs, 0, sizeof reg_prefs); |
typedef struct gpg_filetype_s *gpg_filetype_t; |
58 |
} /* free_reg_prefs */ |
|
59 |
|
/* Global WinPT registry prefereneces. */ |
60 |
|
struct winpt_prefs_s reg_prefs; |
61 |
/* |
|
62 |
* Register the given WinPT filetype. |
|
63 |
*/ |
/* Return != 0 if GPG4win is installed. */ |
64 |
static int |
int |
65 |
regist_single_filetype (gpg_filetype *gfile) |
is_gpg4win_installed (void) |
66 |
{ |
{ |
67 |
char icon[256], prog[256]; |
char *p; |
68 |
|
|
69 |
memset (&icon, 0, sizeof (icon)); |
p = get_reg_entry_gpg4win (NULL); |
70 |
GetModuleFileName (glob_hinst, prog, sizeof (prog)-1); |
if (!p) |
71 |
_snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon); |
return 0; |
72 |
return create_file_type (prog, gfile->ext, gfile->descr, icon); |
if (dir_exist_check (p)) { |
73 |
} /* regist_single_filetype */ |
free_if_alloc (p); |
74 |
|
return 0; |
75 |
|
} |
76 |
/* |
free_if_alloc (p); |
77 |
* Install the GPG related into the W32 resgistry, if the entry already |
return -1; |
78 |
* exists< the function returns immediately. |
} |
79 |
*/ |
|
80 |
int |
|
81 |
regist_inst_gnupg( int create_mokey ) |
/* Return != 0 if GPGee is installed. */ |
82 |
{ |
static int |
83 |
int rc; |
is_gpgee_installed (void) |
84 |
HKEY reg; |
{ |
85 |
|
HKEY hk; |
86 |
rc = RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", 0, KEY_READ, ® ); |
LONG ec; |
87 |
if( rc_ok( rc ) ) { |
|
88 |
RegCloseKey( reg ); |
ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\GPGee", 0, KEY_READ, &hk); |
89 |
return 0; |
if (ec == ERROR_SUCCESS) { |
90 |
} |
RegCloseKey (hk); |
91 |
rc = RegCreateKey( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", ® ); |
return -1; |
92 |
if( !rc_ok( rc ) ) |
} |
93 |
return WPTERR_REGISTRY; |
|
94 |
RegCloseKey( reg ); |
return 0; |
95 |
if( create_mokey ) { |
} |
96 |
rc = RegOpenKeyEx( HKEY_CURRENT_USER, "Control Panel\\MingW32\\NLS", 0, KEY_READ, ® ); |
|
97 |
if( rc_ok( rc ) ) { |
|
98 |
RegCloseKey( reg ); |
/* Free all members in the registry preference struct. */ |
99 |
return 0; |
void |
100 |
} |
free_reg_prefs (void) |
101 |
rc = RegCreateKey( HKEY_CURRENT_USER, "Control Panel\\MingW32\\NLS", ® ); |
{ |
102 |
if( !rc_ok( rc ) ) |
free_if_alloc (reg_prefs.backup.path); |
103 |
return WPTERR_REGISTRY; |
free_if_alloc (reg_prefs.kserv_conf); |
104 |
RegCloseKey( reg ); |
free_if_alloc (reg_prefs.homedir); |
105 |
} |
memset (®_prefs, 0, sizeof reg_prefs); |
106 |
|
} |
107 |
return 0; |
|
108 |
} /* regist_inst_gpg */ |
|
109 |
|
|
110 |
|
/* Install the GPG related into the W32 resgistry, if the entry already |
111 |
/* |
exists the function returns immediately. */ |
112 |
* Install WinPT into the W32 registry, if the entry already |
int |
113 |
* exists the function returns immediately. |
regist_inst_gnupg (int create_mokey) |
114 |
*/ |
{ |
115 |
int |
int rc; |
116 |
regist_inst_winpt( int with_ext, int * created ) |
HKEY reg; |
117 |
{ |
|
118 |
HKEY reg; |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, GPG_REG, 0, KEY_READ, ®); |
119 |
char * p = NULL; |
if (rc == ERROR_SUCCESS) { |
120 |
int rc, i, id, n = 0; |
RegCloseKey (reg); |
121 |
|
return 0; |
122 |
if( created ) |
} |
123 |
*created = 0; |
rc = RegCreateKey (HKEY_CURRENT_USER, GPG_REG, ®); |
124 |
|
if (rc != ERROR_SUCCESS) |
125 |
p = get_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions" ); |
return WPTERR_REGISTRY; |
126 |
if( p && *p == '1' ) |
RegCloseKey (reg); |
127 |
with_ext = 0; |
|
128 |
free_if_alloc( p ); |
if (!create_mokey) |
129 |
|
return 0; |
130 |
if( with_ext ) { |
|
131 |
id = msg_box( NULL, _("WinPT can register some GPG file types for you so they can " |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, GPG_MO_REG, 0, KEY_READ, ®); |
132 |
"be processed with a double click in the explorer.\n" |
if (rc == ERROR_SUCCESS) { |
133 |
"Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO ); |
RegCloseKey (reg); |
134 |
if( id == IDNO ) { |
return 0; |
135 |
set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" ); |
} |
136 |
goto start; |
rc = RegCreateKey (HKEY_CURRENT_USER, GPG_MO_REG, ®); |
137 |
} |
if (rc != ERROR_SUCCESS) |
138 |
for( i = 0; gpg_filetypes[i].ext; i++ ) { |
return WPTERR_REGISTRY; |
139 |
rc = RegOpenKeyEx( HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, ® ); |
|
140 |
if( rc_ok( rc ) ) { |
RegCloseKey (reg); |
141 |
RegCloseKey( reg ); |
return 0; |
142 |
id = log_box( _("WinPT WARNING"), MB_YESNO|MB_INFO, |
} |
143 |
_("It seems there was already a '%s' file type registered by another application.\n" |
|
144 |
"Do you want to overwrite it?"), gpg_filetypes[i].ext ); |
|
145 |
if( id == IDNO ) |
/* Create a new filetype in the W32 registry. |
146 |
continue; |
We should really care of errors! Otherwise we can damage the registry! */ |
147 |
} |
static int |
148 |
regist_single_filetype( &gpg_filetypes[i] ); |
create_file_type (const char *exefile, const char *ext, |
149 |
n++; |
const char *extname, char *iconfile) |
150 |
} |
{ |
151 |
} |
HKEY reg = NULL; |
152 |
|
char deficon[MAX_PATH+1]; |
153 |
start: |
char defexec[MAX_PATH+1]; |
154 |
rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, ® ); |
char p_exefile[MAX_PATH+1]; |
155 |
if( rc_ok( rc ) ) { |
int rc; |
156 |
RegCloseKey( reg ); |
|
157 |
rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, ® ); |
rc = RegCreateKey (HKEY_CLASSES_ROOT, ext, ®); |
158 |
if( !rc_ok( rc ) ) { |
if( rc_ok( rc ) ) |
159 |
RegCreateKey( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", ® ); |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)extname, strlen( extname ) ); |
160 |
RegCloseKey( reg ); |
if( rc_ok( rc ) ) |
161 |
} |
rc = RegCloseKey( reg ); |
162 |
p = get_reg_entry_keyserver ("Default"); |
if( rc_ok( rc ) ) |
163 |
if (!p) { |
rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, ® ); |
164 |
char buf[16]; |
if( rc_ok( rc ) ) |
165 |
sprintf (buf, "%d", HKP_PORT); |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *) extname, strlen( extname ) ); |
166 |
set_reg_entry_keyserver ("Default_Port", buf); |
if( rc_ok( rc ) ) |
167 |
set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER); |
rc = RegCloseKey( reg ); |
168 |
} |
if( !rc_ok( rc ) ) { |
169 |
free_if_alloc( p ); |
rc = WPTERR_REGISTRY; |
170 |
if( n ) |
goto leave; |
171 |
set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" ); |
} |
172 |
return 0; |
|
173 |
} |
memset( &deficon, 0, sizeof deficon ); |
174 |
rc = RegCreateKey( HKEY_CURRENT_USER, WINPT_REG, ® ); |
_snprintf( deficon, sizeof deficon - 1, "%s\\DefaultIcon", extname ); |
175 |
if( !rc_ok( rc ) ) |
memset( &defexec, 0, sizeof defexec ); |
176 |
return WPTERR_REGISTRY; |
_snprintf( defexec, sizeof defexec - 1, "%s\\shell\\open\\command", extname ); |
177 |
if( created ) |
memset( &p_exefile, 0, sizeof p_exefile ); |
178 |
*created = 1; |
_snprintf( p_exefile, sizeof p_exefile - 1, "%s %%1", exefile ); |
179 |
RegCloseKey( reg ); |
|
180 |
if( n ) |
rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, ® ); |
181 |
set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" ); |
if( rc_ok( rc ) ) |
182 |
return 0; |
rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (BYTE *)iconfile, strlen( iconfile ) ); |
183 |
} /* regist_inst_winpt */ |
if( rc_ok( rc ) ) |
184 |
|
rc = RegCloseKey( reg ); |
185 |
|
if( rc_ok( rc ) ) |
186 |
/* |
rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, ® ); |
187 |
* Create a new filetype in the W32 registry. |
if( rc_ok( rc ) ) |
188 |
* We should really care of errors! Otherwise we can damage the registry! |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)p_exefile, strlen( exefile ) ); |
189 |
*/ |
if( rc_ok( rc ) ) |
190 |
int |
rc = RegCloseKey( reg ); |
191 |
create_file_type( const char *exefile, const char *ext, const char *extname, char *iconfile ) |
if( !rc_ok( rc ) ) { |
192 |
{ |
rc = WPTERR_REGISTRY; |
193 |
int rc; |
goto leave; |
194 |
HKEY reg = NULL; |
} |
195 |
char deficon[256], defexec[256], p_exefile[256]; |
|
196 |
|
leave: |
197 |
|
if (reg) |
198 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, ext, ® ); |
RegCloseKey (reg); |
199 |
if( rc_ok( rc ) ) |
return rc; |
200 |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)extname, strlen( extname ) ); |
} |
201 |
if( rc_ok( rc ) ) |
|
202 |
rc = RegCloseKey( reg ); |
|
203 |
if( rc_ok( rc ) ) |
/* Register the given WinPT filetype. */ |
204 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, ® ); |
static int |
205 |
if( rc_ok( rc ) ) |
regist_single_filetype (gpg_filetype_t gfile) |
206 |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *) extname, strlen( extname ) ); |
{ |
207 |
if( rc_ok( rc ) ) |
char icon[MAX_PATH+1] = {0}; |
208 |
rc = RegCloseKey( reg ); |
char prog[MAX_PATH+1] = {0}; |
209 |
if( !rc_ok( rc ) ) { |
|
210 |
rc = WPTERR_REGISTRY; |
if (!GetModuleFileName (glob_hinst, prog, sizeof (prog)-1)) |
211 |
goto leave; |
return WPTERR_REGISTRY; |
212 |
} |
_snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon); |
213 |
|
return create_file_type (prog, gfile->ext, gfile->descr, icon); |
214 |
memset( &deficon, 0, sizeof deficon ); |
} |
215 |
_snprintf( deficon, sizeof deficon - 1, "%s\\DefaultIcon", extname ); |
|
216 |
memset( &defexec, 0, sizeof defexec ); |
/* Install WinPT into the W32 registry, if the entry already |
217 |
_snprintf( defexec, sizeof defexec - 1, "%s\\shell\\open\\command", extname ); |
exists the function returns immediately. @with_ext can be |
218 |
memset( &p_exefile, 0, sizeof p_exefile ); |
used to register some file types (if 1). @created contains |
219 |
_snprintf( p_exefile, sizeof p_exefile - 1, "%s %%1", exefile ); |
1 if the registry key was created. |
220 |
|
Return value: 0 on success. */ |
221 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, ® ); |
int |
222 |
if( rc_ok( rc ) ) |
regist_inst_winpt (int with_ext, int *created) |
223 |
rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (byte *)iconfile, strlen( iconfile ) ); |
{ |
224 |
if( rc_ok( rc ) ) |
struct gpg_filetype_s gpg_filetypes[] = { |
225 |
rc = RegCloseKey( reg ); |
{_("GPG Detached Signature"), ".sig", 1}, |
226 |
if( rc_ok( rc ) ) |
{_("GPG Encrypted Data"), ".gpg", 2}, |
227 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, ® ); |
{_("GPG Armored Data"), ".asc", 2}, |
228 |
if( rc_ok( rc ) ) |
{0} |
229 |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)p_exefile, strlen( exefile ) ); |
}; |
230 |
if( rc_ok( rc ) ) |
HKEY reg; |
231 |
rc = RegCloseKey( reg ); |
char *p = NULL; |
232 |
if( !rc_ok( rc ) ) { |
char modpath[MAX_PATH+1]; |
233 |
rc = WPTERR_REGISTRY; |
int rc, i, id, n; |
234 |
goto leave; |
|
235 |
} |
if (created) |
236 |
|
*created = 0; |
237 |
leave: |
|
238 |
if( reg ) |
/* If GPGee is already installed deactivate file extension registering |
239 |
RegCloseKey( reg ); |
because it is very likely this would overwrite the GPGee settings. */ |
240 |
return rc; |
if (is_gpgee_installed ()) |
241 |
} /* create_file_type */ |
with_ext = 0; |
242 |
|
|
243 |
|
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, ®); |
244 |
static char * |
if (rc == ERROR_SUCCESS) { |
245 |
expand_path( const char *path ) |
RegCloseKey (reg); |
246 |
{ |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, ®); |
247 |
DWORD len; |
if (rc != ERROR_SUCCESS) { |
248 |
char *p; |
rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", ®); |
249 |
|
if (rc == ERROR_SUCCESS) |
250 |
len = ExpandEnvironmentStrings( path, NULL, 0 ); |
RegCloseKey (reg); |
251 |
if( !len ) |
} |
252 |
return NULL; |
else |
253 |
len += 1; |
RegCloseKey (reg); |
254 |
p = new char[len]; |
p = get_reg_entry_keyserver ("Default"); |
255 |
if( !p ) |
if (!p) { |
256 |
return NULL; |
char buf[16]; |
257 |
len = ExpandEnvironmentStrings( path, p, len ); |
|
258 |
if( !len ) { |
_snprintf (buf, DIM (buf)-1, "%d", HKP_PORT); |
259 |
free_if_alloc( p ); |
set_reg_entry_keyserver ("Default_Port", buf); |
260 |
return NULL; |
set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER); |
261 |
} |
} |
262 |
return p; |
free_if_alloc (p); |
263 |
} /* expand_path */ |
return 0; |
264 |
|
} |
265 |
|
rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, ®); |
266 |
char * |
if (rc != ERROR_SUCCESS) |
267 |
get_reg_entry( HKEY root_key, const char * dir, const char * key ) |
return WPTERR_REGISTRY; |
268 |
{ |
if (created) |
269 |
int rc; |
*created = 1; |
270 |
char text[384] = {0}; |
RegCloseKey (reg); |
271 |
DWORD nbytes, type, n1 = 0; |
if (with_ext) { |
272 |
HKEY reg_key = NULL; |
id = msg_box (NULL, _("WinPT can register some GPG file types for you so they can " |
273 |
char * p = NULL, * tmp = NULL; |
"be processed with a double click in the explorer.\n" |
274 |
|
"Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO); |
275 |
rc = RegOpenKeyEx( root_key, dir, 0, KEY_QUERY_VALUE, ®_key ); |
if (id == IDYES) { |
276 |
if( !rc_ok( rc ) ) |
for (i = 0; gpg_filetypes[i].ext; i++) { |
277 |
goto leave; |
rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, ®); |
278 |
nbytes = sizeof text - 1; |
if (rc == ERROR_SUCCESS) { |
279 |
type = REG_SZ; |
RegCloseKey (reg); |
280 |
|
id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO, |
281 |
rc = RegQueryValueEx (reg_key, key, 0, &type, (BYTE *)&text, &nbytes); |
_("It seems there was already a '%s' file type registered by another application.\n" |
282 |
if (!rc_ok (rc) || !nbytes) |
"Do you want to overwrite it?"), gpg_filetypes[i].ext); |
283 |
goto leave; |
if (id == IDNO) |
284 |
|
continue; |
285 |
if (type == REG_EXPAND_SZ && strchr (text, '%')) |
} |
286 |
p = expand_path (text); |
regist_single_filetype (&gpg_filetypes[i]); |
287 |
else { |
} |
288 |
p = new char[nbytes + 1]; |
} |
289 |
if (!p) |
} |
290 |
BUG (0); |
/* Store the install directory for later use. */ |
291 |
memcpy (p, text, nbytes); |
if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) { |
292 |
p[nbytes] = '\0'; |
while (n-- > 0) { |
293 |
} |
if (modpath[n] == '\\') { |
294 |
|
modpath[n] = 0; |
295 |
leave: |
break; |
296 |
if (reg_key) |
} |
297 |
RegCloseKey (reg_key); |
} |
298 |
return p; |
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath); |
299 |
} /* get_reg_entry */ |
} |
300 |
|
return 0; |
301 |
|
} |
302 |
int |
|
303 |
set_reg_entry( HKEY root_key, const char * dir, const char * key, |
|
304 |
const char * value ) |
/* Expand a string with %foo% entries so that %foo% will |
305 |
{ |
be replaced with its actual value. */ |
306 |
int rc = 0; |
static char* |
307 |
HKEY reg_key; |
expand_path (const char *path) |
308 |
|
{ |
309 |
rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, ®_key ); |
DWORD len; |
310 |
if( !rc_ok( rc ) ) |
char *p; |
311 |
return WPTERR_REGISTRY; |
|
312 |
rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) ); |
len = ExpandEnvironmentStrings (path, NULL, 0); |
313 |
if( !rc_ok( rc ) ) |
if (!len) |
314 |
rc = WPTERR_REGISTRY; |
return NULL; |
315 |
RegCloseKey( reg_key ); |
len += 1; |
316 |
return rc; |
p = new char[len+1]; |
317 |
} /* set_reg_entry */ |
if (!p) |
318 |
|
return NULL; |
319 |
|
len = ExpandEnvironmentStrings (path, p, len); |
320 |
int |
if (!len) { |
321 |
set_reg_key( HKEY root_key, const char * dir, const char * key, |
free_if_alloc (p); |
322 |
const char * value ) |
return NULL; |
323 |
{ |
} |
324 |
int rc = 0; |
return p; |
325 |
HKEY reg_key; |
} |
326 |
|
|
327 |
rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, ®_key ); |
|
328 |
if( !rc_ok( rc ) ) |
/* Retrieve a registry entry with the directory given in @dir |
329 |
return WPTERR_REGISTRY; |
and the key given in @key. |
330 |
|
Return value is the value or NULL otherwise. */ |
331 |
rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) ); |
char* |
332 |
if( !rc_ok( rc ) ) { |
get_reg_entry (HKEY root_key, const char *dir, const char *key) |
333 |
if ( RegCreateKey( root_key, key, ®_key ) != ERROR_SUCCESS ) { |
{ |
334 |
rc = WPTERR_REGISTRY; |
HKEY reg_key = NULL; |
335 |
goto leave; |
char *p = NULL, *pp; |
336 |
} |
DWORD type = REG_SZ, nbytes = 0; |
337 |
rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) ); |
int rc; |
338 |
if ( !rc_ok( rc ) ) |
|
339 |
rc = WPTERR_REGISTRY; |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
340 |
} |
if (rc != ERROR_SUCCESS) |
341 |
|
goto leave; |
342 |
leave: |
rc = RegQueryValueEx (reg_key, key, NULL, &type, NULL, &nbytes); |
343 |
RegCloseKey( reg_key ); |
if (rc != ERROR_SUCCESS) |
344 |
return rc; |
goto leave; |
345 |
} /* set_reg_key */ |
if (!nbytes) |
346 |
|
goto leave; /* empty */ |
347 |
|
p = new char[nbytes+1]; |
348 |
int |
if (!p) |
349 |
set_reg_entry_gpg( const char * key, const char * value ) |
BUG (0); |
350 |
{ |
rc = RegQueryValueEx (reg_key, key, NULL, &type, (BYTE*)p, &nbytes); |
351 |
return set_reg_entry( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key, value ); |
if (rc != ERROR_SUCCESS) |
352 |
} /* set_reg_entry_gpg */ |
goto leave; |
353 |
|
if (type == REG_EXPAND_SZ && strchr (p, '%')) { |
354 |
|
pp = p; |
355 |
int |
p = expand_path (pp); |
356 |
set_reg_entry_mo( const char * value ) |
free_if_alloc (pp); |
357 |
{ |
} |
358 |
return set_reg_entry( HKEY_CURRENT_USER, "Control Panel\\Mingw32\\NLS", "MODir", value ); |
|
359 |
} /* set_reg_entry_mo */ |
leave: |
360 |
|
if (reg_key != NULL) |
361 |
|
RegCloseKey (reg_key); |
362 |
char * |
return p; |
363 |
get_reg_entry_gpg( const char *key ) |
} |
364 |
{ |
|
365 |
return get_reg_entry( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key ); |
|
366 |
} /* get_reg_entry_gpg */ |
/* XXX: use REG_EXPAND_SZ to support multi user environments. |
367 |
|
keep this type and do not overwrite it with REG_SZ. */ |
368 |
|
|
369 |
char * |
/* Set a registry entry. */ |
370 |
get_reg_entry_mo( void ) |
int |
371 |
{ |
set_reg_entry (HKEY root_key, const char *dir, const char *key, |
372 |
return get_reg_entry( HKEY_CURRENT_USER, "Control Panel\\Mingw32\\NLS", "MODir" ); |
const char *value) |
373 |
} /* get_reg_entry_mo */ |
{ |
374 |
|
HKEY reg_key; |
375 |
|
int rc; |
376 |
static const char * cfg [] = { |
|
377 |
NULL, |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_WRITE, ®_key); |
378 |
"CacheTime", |
if (rc != ERROR_SUCCESS) |
379 |
"WordWrap", |
return WPTERR_REGISTRY; |
380 |
"FastMode", |
rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value)); |
381 |
"Viewer", |
if (rc != ERROR_SUCCESS) |
382 |
"KeylistMode", |
rc = WPTERR_REGISTRY; |
383 |
"WipeMode", |
RegCloseKey (reg_key); |
384 |
"AlwaysTrust", |
return rc; |
385 |
"AutoBackup", |
} |
386 |
"BackupMode", |
|
387 |
"DisableHotkeys", |
|
388 |
"NoCompressMultiMedia", |
int |
389 |
"Expert", |
set_reg_key (HKEY root_key, const char *dir, const char *key, |
390 |
}; |
const char *value) |
391 |
|
{ |
392 |
|
HKEY reg_key; |
393 |
int |
int rc; |
394 |
set_reg_winpt_single (int id, int val) |
|
395 |
{ |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_WRITE, ®_key); |
396 |
char buf[64]; |
if (rc != ERROR_SUCCESS) |
397 |
int rc; |
return WPTERR_REGISTRY; |
398 |
|
|
399 |
sprintf (buf, "%d", val); |
rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value)); |
400 |
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id], buf); |
if (rc != ERROR_SUCCESS) { |
401 |
return rc; |
if (RegCreateKey (root_key, key, ®_key) != ERROR_SUCCESS) { |
402 |
} |
rc = WPTERR_REGISTRY; |
403 |
|
goto leave; |
404 |
|
} |
405 |
int |
rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value)); |
406 |
get_reg_winpt_single (int id) |
if (rc != ERROR_SUCCESS) |
407 |
{ |
rc = WPTERR_REGISTRY; |
408 |
char * buf = NULL; |
} |
409 |
int val = 0; |
|
410 |
|
leave: |
411 |
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]); |
RegCloseKey (reg_key); |
412 |
if (buf && *buf != ' ') |
return rc; |
413 |
val = 1; |
} |
414 |
else if (!buf) |
|
415 |
val = -1; |
|
416 |
free_if_alloc (buf); |
int |
417 |
return val; |
set_reg_entry_gpg (const char *key, const char *value) |
418 |
} |
{ |
419 |
|
return set_reg_entry (HKEY_CURRENT_USER, GPG_REG, key, value); |
420 |
|
} |
421 |
int |
|
422 |
set_reg_winpt_prefs (winpt_reg_prefs_s * opt) |
|
423 |
{ |
int |
424 |
char buf[128]; |
set_reg_entry_mo (const char *value) |
425 |
int rc = 0, i; |
{ |
426 |
|
return set_reg_entry (HKEY_CURRENT_USER, GPG_MO_REG, "MODir", value); |
427 |
for (i=1; i < DIM (cfg); i++) { |
} |
428 |
switch (i) { |
|
429 |
case CFG_CACHETIME: |
|
430 |
sprintf (buf, "%d", opt->cache_time); |
char* |
431 |
break; |
get_reg_entry_gpg (const char *key) |
432 |
case CFG_WORDWRAP: |
{ |
433 |
sprintf (buf, "%d", opt->word_wrap); |
char *p; |
434 |
break; |
|
435 |
case CFG_WIPEMODE: |
p = get_reg_entry (HKEY_CURRENT_USER, GPG_REG, key); |
436 |
sprintf (buf, "%d", opt->wipe_mode); |
if (!p || strlen (p) == 0) { |
437 |
break; |
free_if_alloc (p); |
438 |
case CFG_FASTMODE: |
return NULL; |
439 |
sprintf (buf, "%d", opt->use_tmpfiles); |
} |
440 |
break; |
return p; |
441 |
case CFG_NOZIP_MMEDIA: |
} |
442 |
sprintf (buf, "%d", opt->no_zip_mmedia); |
|
443 |
break; |
|
444 |
case CFG_VIEWER: |
/* Return if possible the GPG4Win installation directory concatenated |
445 |
sprintf (buf, "%d", opt->use_viewer); |
with the string in @path if given. */ |
446 |
break; |
char* |
447 |
case CFG_KEYLISTMODE: |
get_reg_entry_gpg4win (const char *path) |
448 |
sprintf (buf, "%d", opt->keylist_mode); |
{ |
449 |
break; |
const char *fmt; |
450 |
case CFG_ALWAYSTRUST: |
char *p, *pp; |
451 |
sprintf (buf, "%d", opt->always_trust); |
|
452 |
break; |
p = get_reg_entry (HKEY_LOCAL_MACHINE, GPG_REG, "Install Directory"); |
453 |
case CFG_AUTOBACKUP: |
if (!p) |
454 |
sprintf (buf, "%d", opt->auto_backup); |
return NULL; |
455 |
break; |
if (!path) |
456 |
case CFG_AUTOBAKMODE: |
return p; |
457 |
sprintf (buf, "%d", opt->backup.mode); |
fmt = "%s\\%s"; |
458 |
break; |
pp = new char[strlen (p) + strlen (path) + strlen (fmt) + 1]; |
459 |
case CFG_DISHOTKEYS: |
if (!pp) |
460 |
sprintf (buf, "%d", opt->no_hotkeys); |
BUG (NULL); |
461 |
break; |
sprintf (pp, fmt, p, path); |
462 |
case CFG_EXPERT: |
free_if_alloc (p); |
463 |
sprintf (buf, "%d", opt->expert); |
return pp; |
464 |
break; |
} |
465 |
} |
|
466 |
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf); |
|
467 |
if (rc) |
char* |
468 |
goto leave; |
get_reg_entry_mo (void) |
469 |
} |
{ |
470 |
|
char *p, *pp; |
471 |
if (opt->backup.path) { |
const char *fmt; |
472 |
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "BackupPath", |
const char *lang; |
473 |
opt->backup.path); |
|
474 |
if (rc) |
p = get_reg_entry (HKEY_CURRENT_USER, GPG_MO_REG, "MODir"); |
475 |
goto leave; |
if (p) |
476 |
} |
return p; |
477 |
if (opt->kserv_conf) { |
|
478 |
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig", |
lang = get_gettext_langid (); |
479 |
opt->kserv_conf); |
if (!lang) |
480 |
if (rc) |
return NULL; |
481 |
goto leave; |
fmt = "share\\locale\\%s\\LC_MESSAGES"; |
482 |
} |
pp = new char[strlen (fmt) + strlen (lang) + 4 + 1]; |
483 |
|
if (!pp) |
484 |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
BUG (NULL); |
485 |
strcpy (buf, " "); |
sprintf (pp, fmt, lang); |
486 |
if (reg_hotkeys[i].enabled) |
p = get_reg_entry_gpg4win (pp); |
487 |
strcpy (buf, reg_hotkeys[i].key); |
free_if_alloc (pp); |
488 |
rc = set_reg_key (HKEY_CURRENT_USER, WINPT_REG, |
return p; |
489 |
reg_hotkeys[i].reg_entry, buf); |
} |
490 |
if (rc) |
|
491 |
break; |
|
492 |
} |
int |
493 |
|
set_reg_winpt_single (int id, int val) |
494 |
leave: |
{ |
495 |
if (rc) { |
char buf[64]; |
496 |
msg_box (NULL, _("Could not write to Registry."), _("Preferences"), MB_ERR); |
int rc; |
497 |
return rc; |
|
498 |
} |
_snprintf (buf, DIM (buf)-1, "%d", val); |
499 |
return 0; |
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id], buf); |
500 |
} /* set_reg_winpt_prefs */ |
return rc; |
501 |
|
} |
502 |
|
|
503 |
int |
|
504 |
set_reg_winpt_flag (const char * name, int val) |
int |
505 |
{ |
get_reg_winpt_single (int id) |
506 |
return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name, val? "1" : "0"); |
{ |
507 |
} /* set_reg_winpt_flag */ |
char *buf; |
508 |
|
int val = 0; |
509 |
|
|
510 |
int |
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]); |
511 |
get_reg_winpt_flag (const char * name) |
if (buf && *buf != ' ') |
512 |
{ |
val = 1; |
513 |
char * buf; |
else if (!buf) |
514 |
int flag = 0; |
val = -1; |
515 |
|
free_if_alloc (buf); |
516 |
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name); |
return val; |
517 |
if (buf && buf[0] == '1') |
} |
518 |
flag = 1; |
|
519 |
else if (!buf || buf && buf[0] != '0') |
|
520 |
flag = -1; |
/* Saves the winpt preferences in the registry. */ |
521 |
free_if_alloc (buf); |
int |
522 |
return flag; |
set_reg_winpt_prefs (winpt_prefs_t opt) |
523 |
} /* get_reg_winpt_flag */ |
{ |
524 |
|
char buf[128]; |
525 |
|
size_t i; |
526 |
int |
int rc = 0; |
527 |
get_reg_winpt_prefs (winpt_reg_prefs_s * opt) |
|
528 |
{ |
for (i=1; i < DIM (cfg); i++) { |
529 |
char * val = NULL; |
switch (i) { |
530 |
int i; |
case CFG_CACHETIME: |
531 |
|
sprintf (buf, "%d", opt->cache_time); |
532 |
for (i=1; i < DIM (cfg); i++) { |
break; |
533 |
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]); |
case CFG_WORDWRAP: |
534 |
if (!val || *val == ' ') { |
sprintf (buf, "%d", opt->word_wrap); |
535 |
free_if_alloc (val); |
break; |
536 |
continue; |
case CFG_WIPEMODE: |
537 |
} |
sprintf (buf, "%d", opt->wipe_mode); |
538 |
switch (i) { |
break; |
539 |
case CFG_CACHETIME: |
case CFG_FILEEXT: |
540 |
opt->cache_time = atol (val); |
sprintf (buf, "%d", opt->default_ext); |
541 |
/* We do NOT support passphrase caching for more than an hour. |
break; |
542 |
* Perhaps we should allow it, but for now we silently drop this. |
case CFG_NOZIP_MMEDIA: |
543 |
*/ |
sprintf (buf, "%d", opt->no_zip_mmedia); |
544 |
if (opt->cache_time > 3600) |
break; |
545 |
opt->cache_time = 3600; |
case CFG_VIEWER: |
546 |
break; |
sprintf (buf, "%d", opt->use_viewer); |
547 |
case CFG_WORDWRAP: |
break; |
548 |
opt->word_wrap = atol (val); |
case CFG_ALWAYSTRUST: |
549 |
break; |
sprintf (buf, "%d", opt->always_trust); |
550 |
case CFG_FASTMODE: |
break; |
551 |
opt->use_tmpfiles = atol (val); |
case CFG_AUTOBACKUP: |
552 |
break; |
sprintf (buf, "%d", opt->auto_backup); |
553 |
case CFG_NOZIP_MMEDIA: |
break; |
554 |
opt->no_zip_mmedia = atol (val); |
case CFG_AUTOBAKMODE: |
555 |
break; |
sprintf (buf, "%d", opt->backup.mode); |
556 |
case CFG_VIEWER: |
break; |
557 |
opt->use_viewer = atol (val); |
case CFG_DISHOTKEYS: |
558 |
break; |
sprintf (buf, "%d", opt->no_hotkeys); |
559 |
case CFG_KEYLISTMODE: |
break; |
560 |
opt->keylist_mode = atol (val); |
case CFG_EXPERT: |
561 |
break; |
sprintf (buf, "%d", opt->expert); |
562 |
case CFG_WIPEMODE: |
break; |
563 |
opt->wipe_mode = atol (val); |
|
564 |
break; |
case CFG_FM_PROGRESS: |
565 |
case CFG_DISHOTKEYS: |
sprintf (buf, "%d", opt->fm.progress); |
566 |
opt->no_hotkeys = atol (val); |
break; |
567 |
break; |
|
568 |
case CFG_ALWAYSTRUST: |
case CFG_BACKUP_INC_SKR: |
569 |
opt->always_trust = atol (val); |
sprintf (buf, "%d", opt->backup.include_secr); |
570 |
break; |
break; |
571 |
case CFG_AUTOBACKUP: |
} |
572 |
opt->auto_backup = atol (val); |
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf); |
573 |
break; |
if (rc) |
574 |
case CFG_AUTOBAKMODE: |
goto leave; |
575 |
opt->backup.mode = atol (val); |
} |
576 |
break; |
|
577 |
case CFG_EXPERT: |
if (opt->backup.path) { |
578 |
opt->expert = atol (val); |
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "BackupPath", |
579 |
break; |
opt->backup.path); |
580 |
} |
if (rc) |
581 |
free_if_alloc (val); |
goto leave; |
582 |
} |
} |
583 |
|
|
584 |
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "BackupPath"); |
for (i=0; wpt_hotkeys[i].name; i++) { |
585 |
if (val && val[0] != ' ') |
if (wpt_hotkeys[i].enabled) { |
586 |
opt->backup.path = m_strdup (val); |
buf[0] = wpt_hotkeys[i].key; |
587 |
free_if_alloc (val); |
buf[1] = 0; |
588 |
|
} |
589 |
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig"); |
else |
590 |
if (val && val[0] != ' ') |
strcpy (buf, " "); |
591 |
opt->kserv_conf = m_strdup (val); |
rc = set_reg_key (HKEY_CURRENT_USER, WINPT_REG, |
592 |
free_if_alloc (val); |
wpt_hotkeys[i].name, buf); |
593 |
|
if (rc) |
594 |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
break; |
595 |
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry); |
} |
596 |
if (val && val[0] != ' ') { |
|
597 |
reg_hotkeys[i].key[0] = *val; |
leave: |
598 |
reg_hotkeys[i].enabled = 1; |
if (rc) { |
599 |
} |
msg_box (NULL, _("Could not write to Registry."), _("Preferences"), MB_ERR); |
600 |
else |
return rc; |
601 |
reg_hotkeys[i].enabled = 0; |
} |
602 |
free_if_alloc (val); |
return 0; |
603 |
} |
} |
604 |
return 0; |
|
605 |
} /* get_reg_winpt_prefs */ |
|
606 |
|
int |
607 |
|
set_reg_winpt_flag (const char *name, int val) |
608 |
char * |
{ |
609 |
get_reg_entry_keyserver (const char *name) |
return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name, val? "1" : "0"); |
610 |
{ |
} |
611 |
char * p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name); |
|
612 |
if (p && !strcmp (p, "")) { |
|
613 |
free_if_alloc (p); |
int |
614 |
return NULL; |
get_reg_winpt_flag (const char *name) |
615 |
} |
{ |
616 |
return p; |
char *buf; |
617 |
} /* get_reg_entry_keyserver */ |
int flag = 0; |
618 |
|
|
619 |
|
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name); |
620 |
void |
if (buf && buf[0] == '1') |
621 |
get_reg_proxy_prefs (char ** host, int * port, char ** user, char ** pass) |
flag = 1; |
622 |
{ |
else if (!buf || buf && buf[0] != '0') |
623 |
if (host) |
flag = -1; |
624 |
*host = get_reg_entry_keyserver ("Host"); |
free_if_alloc (buf); |
625 |
if (user) |
return flag; |
626 |
*user = get_reg_entry_keyserver ("User"); |
} |
627 |
if (pass) |
|
628 |
*pass = get_reg_entry_keyserver ("Pass"); |
|
629 |
if (port) { |
/* Retrieve the winpt preferences from the registry. */ |
630 |
char * p = get_reg_entry_keyserver ("Port"); |
int |
631 |
if (p) { |
get_reg_winpt_prefs (winpt_prefs_t opt) |
632 |
*port = atol (p); |
{ |
633 |
free_if_alloc (p); |
char *val = NULL; |
634 |
} |
size_t i; |
635 |
} |
|
636 |
} /* get_reg_proxy_prefs */ |
for (i=1; i < DIM (cfg); i++) { |
637 |
|
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]); |
638 |
|
if (!val || *val == ' ') { |
639 |
int |
free_if_alloc (val); |
640 |
set_reg_entry_keyserver( const char * name, const char * val ) |
continue; |
641 |
{ |
} |
642 |
return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val ); |
switch (i) { |
643 |
} /* set_reg_entry_keyserver */ |
case CFG_CACHETIME: |
644 |
|
opt->cache_time = atoi (val); |
645 |
|
break; |
646 |
int |
case CFG_WORDWRAP: |
647 |
set_reg_proxy_prefs( const char * host, int port, const char * user, const char * pass ) |
opt->word_wrap = atoi (val); |
648 |
{ |
break; |
649 |
int rc; |
case CFG_FILEEXT: |
650 |
|
opt->default_ext = atoi (val); |
651 |
rc = set_reg_entry_keyserver( "Host", host? host : "" ); |
break; |
652 |
if( !rc ) { |
case CFG_NOZIP_MMEDIA: |
653 |
char buf[32]; |
opt->no_zip_mmedia = atoi (val); |
654 |
sprintf( buf, "%d", port ); |
break; |
655 |
rc = set_reg_entry_keyserver( "Port", buf ); |
case CFG_VIEWER: |
656 |
} |
opt->use_viewer = atoi (val); |
657 |
if( !rc ) |
break; |
658 |
rc = set_reg_entry_keyserver( "User", user? user : "" ); |
case CFG_WIPEMODE: |
659 |
if( !rc ) |
opt->wipe_mode = atoi (val); |
660 |
rc = set_reg_entry_keyserver( "Pass", pass? pass : "" ); |
break; |
661 |
return rc; |
case CFG_DISHOTKEYS: |
662 |
} /* set_reg_proxy_prefs */ |
opt->no_hotkeys = atoi (val); |
663 |
|
break; |
664 |
|
case CFG_ALWAYSTRUST: |
665 |
|
opt->always_trust = atoi (val); |
666 |
|
break; |
667 |
|
case CFG_AUTOBACKUP: |
668 |
|
opt->auto_backup = atoi (val); |
669 |
|
break; |
670 |
|
case CFG_AUTOBAKMODE: |
671 |
|
opt->backup.mode = atoi (val); |
672 |
|
break; |
673 |
|
case CFG_EXPERT: |
674 |
|
opt->expert = atoi (val); |
675 |
|
break; |
676 |
|
case CFG_FM_PROGRESS: |
677 |
|
opt->fm.progress = atoi (val); |
678 |
|
break; |
679 |
|
|
680 |
|
case CFG_BACKUP_INC_SKR: |
681 |
|
opt->backup.include_secr = atoi (val); |
682 |
|
break; |
683 |
|
} |
684 |
|
free_if_alloc (val); |
685 |
|
} |
686 |
|
|
687 |
|
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "BackupPath"); |
688 |
|
if (val && val[0] != ' ') |
689 |
|
opt->backup.path = m_strdup (val); |
690 |
|
free_if_alloc (val); |
691 |
|
|
692 |
|
for (i=0; wpt_hotkeys[i].name; i++) { |
693 |
|
wpt_hotkeys[i].enabled = 0; |
694 |
|
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, wpt_hotkeys[i].name); |
695 |
|
if (val && val[0] != ' ') { |
696 |
|
wpt_hotkeys[i].key = *val; |
697 |
|
wpt_hotkeys[i].enabled = 1; |
698 |
|
} |
699 |
|
free_if_alloc (val); |
700 |
|
} |
701 |
|
return 0; |
702 |
|
} |
703 |
|
|
704 |
|
|
705 |
|
char* |
706 |
|
get_reg_entry_keyserver (const char *name) |
707 |
|
{ |
708 |
|
char *p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name); |
709 |
|
if (p && (!strcmp (p, "") || strlen (p) == 0)) { |
710 |
|
free_if_alloc (p); |
711 |
|
return NULL; |
712 |
|
} |
713 |
|
return p; |
714 |
|
} |
715 |
|
|
716 |
|
|
717 |
|
int |
718 |
|
set_reg_entry_keyserver (const char *name, const char *val) |
719 |
|
{ |
720 |
|
return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val); |
721 |
|
} |
722 |
|
#endif |