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