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 |
* |
* |
33 |
#include "wptTypes.h" |
#include "wptTypes.h" |
34 |
#include "wptNLS.h" |
#include "wptNLS.h" |
35 |
#include "wptVersion.h" |
#include "wptVersion.h" |
36 |
|
#include "wptHotkey.h" |
37 |
|
|
38 |
#define rc_ok(rc) ((rc) == ERROR_SUCCESS) |
#define rc_ok(rc) ((rc) == ERROR_SUCCESS) |
39 |
|
|
40 |
static gpg_filetype gpg_filetypes[] = { |
#define WINPT_REG "Software\\WinPT" |
|
{"GPG Detached Signature", ".sig", 1}, |
|
|
{"GPG Encrypted Data", ".gpg", 2}, |
|
|
{"GPG Armored Data", ".asc", 2}, |
|
|
{0} |
|
|
}; |
|
|
|
|
41 |
|
|
42 |
struct reg_hotkey_s reg_hotkeys[] = { |
/* GPG file association context. */ |
43 |
{"ClipEncrypt", "", 0}, |
struct gpg_filetype { |
44 |
{"ClipDecrypt", "", 0}, |
const char *descr; |
45 |
{"ClipSign", "", 0}, |
const char *ext; |
46 |
{"ClipSignEnc", "", 0}, |
int nicon; |
|
{"CwsEncrypt", "", 0}, |
|
|
{"CwsDecrypt", "", 0}, |
|
|
{"CwsSign", "", 0}, |
|
|
{"CwsSignEnc", "", 0}, |
|
|
{NULL, "", 0} |
|
47 |
}; |
}; |
48 |
|
|
49 |
|
/* Global WinPT registry prefereneces. */ |
50 |
winpt_reg_prefs_s reg_prefs; |
winpt_reg_prefs_s reg_prefs; |
51 |
|
|
52 |
#define WINPT_REG "Software\\WinPT" |
|
53 |
|
/* Return != 0 if GPG4win is installed. */ |
54 |
|
int |
55 |
|
is_gpg4win_installed (void) |
56 |
|
{ |
57 |
|
char *p; |
58 |
|
|
59 |
|
p = get_reg_entry_gpg4win (NULL); |
60 |
|
if (!p) |
61 |
|
return 0; |
62 |
|
if (dir_exist_check (p)) { |
63 |
|
free_if_alloc (p); |
64 |
|
return 0; |
65 |
|
} |
66 |
|
free_if_alloc (p); |
67 |
|
return -1; |
68 |
|
} |
69 |
|
|
70 |
|
|
71 |
/* Return != 0 if GPGee is installed. */ |
/* Return != 0 if GPGee is installed. */ |
100 |
static int |
static int |
101 |
regist_single_filetype (gpg_filetype *gfile) |
regist_single_filetype (gpg_filetype *gfile) |
102 |
{ |
{ |
103 |
char icon[256], prog[256]; |
char icon[256]; |
104 |
|
char prog[256]; |
105 |
|
|
106 |
memset (&icon, 0, sizeof (icon)); |
memset (&icon, 0, sizeof (icon)); |
107 |
GetModuleFileName (glob_hinst, prog, sizeof (prog)-1); |
GetModuleFileName (glob_hinst, prog, sizeof (prog)-1); |
140 |
} |
} |
141 |
|
|
142 |
return 0; |
return 0; |
143 |
} /* regist_inst_gpg */ |
} |
144 |
|
|
145 |
|
|
146 |
/* Install WinPT into the W32 registry, if the entry already |
/* Install WinPT into the W32 registry, if the entry already |
150 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
151 |
int |
int |
152 |
regist_inst_winpt (int with_ext, int *created) |
regist_inst_winpt (int with_ext, int *created) |
153 |
{ |
{ |
154 |
HKEY reg; |
HKEY reg; |
155 |
char *p = NULL; |
char *p = NULL; |
156 |
char modpath[MAX_PATH+1]; |
char modpath[MAX_PATH+1]; |
157 |
int rc, i, id, n = 0; |
int rc, i, id, n; |
158 |
|
|
159 |
|
gpg_filetype gpg_filetypes[] = { |
160 |
|
{_("GPG Detached Signature"), ".sig", 1}, |
161 |
|
{_("GPG Encrypted Data"), ".gpg", 2}, |
162 |
|
{_("GPG Armored Data"), ".asc", 2}, |
163 |
|
{0} |
164 |
|
}; |
165 |
|
|
166 |
if (created) |
if (created) |
167 |
*created = 0; |
*created = 0; |
168 |
|
if (is_gpgee_installed ()) |
|
p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions"); |
|
|
if ((p && *p == '1') || is_gpgee_installed ()) |
|
169 |
with_ext = 0; |
with_ext = 0; |
|
free_if_alloc (p); |
|
170 |
|
|
|
if (with_ext) { |
|
|
id = msg_box (NULL, _("WinPT can register some GPG file types for you so they can " |
|
|
"be processed with a double click in the explorer.\n" |
|
|
"Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO); |
|
|
if (id == IDNO) { |
|
|
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1"); |
|
|
goto start; |
|
|
} |
|
|
for (i = 0; gpg_filetypes[i].ext; i++) { |
|
|
rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, ®); |
|
|
if (rc_ok (rc)) { |
|
|
RegCloseKey (reg); |
|
|
id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO, |
|
|
_("It seems there was already a '%s' file type registered by another application.\n" |
|
|
"Do you want to overwrite it?"), gpg_filetypes[i].ext); |
|
|
if (id == IDNO) |
|
|
continue; |
|
|
} |
|
|
regist_single_filetype (&gpg_filetypes[i]); |
|
|
n++; |
|
|
} |
|
|
} |
|
|
|
|
|
start: |
|
171 |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, ®); |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, ®); |
172 |
if (rc_ok (rc)) { |
if (rc_ok (rc)) { |
173 |
RegCloseKey (reg); |
RegCloseKey (reg); |
174 |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, ®); |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, ®); |
175 |
if( !rc_ok (rc)) { |
if (!rc_ok (rc)) { |
176 |
RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", ®); |
RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", ®); |
177 |
RegCloseKey (reg); |
RegCloseKey (reg); |
178 |
} |
} |
184 |
set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER); |
set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER); |
185 |
} |
} |
186 |
free_if_alloc (p); |
free_if_alloc (p); |
|
if (n) |
|
|
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1"); |
|
187 |
return 0; |
return 0; |
188 |
} |
} |
189 |
rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, ®); |
rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, ®); |
192 |
if (created) |
if (created) |
193 |
*created = 1; |
*created = 1; |
194 |
RegCloseKey (reg); |
RegCloseKey (reg); |
195 |
if (n) |
if (with_ext) { |
196 |
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1"); |
id = msg_box (NULL, _("WinPT can register some GPG file types for you so they can " |
197 |
|
"be processed with a double click in the explorer.\n" |
198 |
|
"Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO); |
199 |
|
if (id == IDYES) { |
200 |
|
for (i = 0; gpg_filetypes[i].ext; i++) { |
201 |
|
rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, ®); |
202 |
|
if (rc_ok (rc)) { |
203 |
|
RegCloseKey (reg); |
204 |
|
id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO, |
205 |
|
_("It seems there was already a '%s' file type registered by another application.\n" |
206 |
|
"Do you want to overwrite it?"), gpg_filetypes[i].ext); |
207 |
|
if (id == IDNO) |
208 |
|
continue; |
209 |
|
} |
210 |
|
regist_single_filetype (&gpg_filetypes[i]); |
211 |
|
} |
212 |
|
} |
213 |
|
} |
214 |
if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) { |
if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) { |
215 |
while (n-- > 0) { |
while (n-- > 0) { |
216 |
if (modpath[n] == '\\') { |
if (modpath[n] == '\\') { |
227 |
/* Create a new filetype in the W32 registry. |
/* Create a new filetype in the W32 registry. |
228 |
We should really care of errors! Otherwise we can damage the registry! */ |
We should really care of errors! Otherwise we can damage the registry! */ |
229 |
int |
int |
230 |
create_file_type( const char *exefile, const char *ext, const char *extname, char *iconfile ) |
create_file_type (const char *exefile, const char *ext, |
231 |
|
const char *extname, char *iconfile) |
232 |
{ |
{ |
233 |
int rc; |
int rc; |
234 |
HKEY reg = NULL; |
HKEY reg = NULL; |
237 |
|
|
238 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, ext, ® ); |
rc = RegCreateKey( HKEY_CLASSES_ROOT, ext, ® ); |
239 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
240 |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)extname, strlen( extname ) ); |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)extname, strlen( extname ) ); |
241 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
242 |
rc = RegCloseKey( reg ); |
rc = RegCloseKey( reg ); |
243 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
244 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, ® ); |
rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, ® ); |
245 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
246 |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *) extname, strlen( extname ) ); |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *) extname, strlen( extname ) ); |
247 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
248 |
rc = RegCloseKey( reg ); |
rc = RegCloseKey( reg ); |
249 |
if( !rc_ok( rc ) ) { |
if( !rc_ok( rc ) ) { |
260 |
|
|
261 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, ® ); |
rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, ® ); |
262 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
263 |
rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (byte *)iconfile, strlen( iconfile ) ); |
rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (BYTE *)iconfile, strlen( iconfile ) ); |
264 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
265 |
rc = RegCloseKey( reg ); |
rc = RegCloseKey( reg ); |
266 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
267 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, ® ); |
rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, ® ); |
268 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
269 |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)p_exefile, strlen( exefile ) ); |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)p_exefile, strlen( exefile ) ); |
270 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
271 |
rc = RegCloseKey( reg ); |
rc = RegCloseKey( reg ); |
272 |
if( !rc_ok( rc ) ) { |
if( !rc_ok( rc ) ) { |
278 |
if( reg ) |
if( reg ) |
279 |
RegCloseKey( reg ); |
RegCloseKey( reg ); |
280 |
return rc; |
return rc; |
281 |
} /* create_file_type */ |
} |
282 |
|
|
283 |
|
|
284 |
/* Expand a string with %foo% entries so that %foo% will |
/* Expand a string with %foo% entries so that %foo% will |
294 |
return NULL; |
return NULL; |
295 |
len += 1; |
len += 1; |
296 |
p = new char[len+1]; |
p = new char[len+1]; |
297 |
if( !p ) |
if (!p) |
298 |
return NULL; |
return NULL; |
299 |
len = ExpandEnvironmentStrings (path, p, len); |
len = ExpandEnvironmentStrings (path, p, len); |
300 |
if (!len) { |
if (!len) { |
302 |
return NULL; |
return NULL; |
303 |
} |
} |
304 |
return p; |
return p; |
305 |
} /* expand_path */ |
} |
306 |
|
|
307 |
|
|
308 |
/* Retrieve a registry entry with the directory given in @dir |
/* Retrieve a registry entry with the directory given in @dir |
309 |
and the key given in @key. |
and the key given in @key. |
310 |
Return value is the value or NULL otherwise. */ |
Return value is the value or NULL otherwise. */ |
311 |
char* |
char* |
312 |
get_reg_entry (HKEY root_key, const char * dir, const char * key) |
get_reg_entry (HKEY root_key, const char *dir, const char *key) |
313 |
{ |
{ |
|
int rc; |
|
|
char text[384] = {0}; |
|
|
DWORD nbytes, type; |
|
314 |
HKEY reg_key = NULL; |
HKEY reg_key = NULL; |
315 |
char *p = NULL; |
char *p = NULL, *pp; |
316 |
|
DWORD type = REG_SZ, nbytes = 0; |
317 |
|
int rc; |
318 |
|
|
319 |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
320 |
if( !rc_ok( rc ) ) |
if (!rc_ok (rc)) |
321 |
goto leave; |
goto leave; |
322 |
nbytes = sizeof (text) - 1; |
rc = RegQueryValueEx (reg_key, key, NULL, &type, NULL, &nbytes); |
323 |
type = REG_SZ; |
if (!rc_ok (rc)) |
|
|
|
|
rc = RegQueryValueEx (reg_key, key, 0, &type, (BYTE *)&text, &nbytes); |
|
|
if (!rc_ok (rc) || !nbytes) |
|
324 |
goto leave; |
goto leave; |
325 |
|
if (!nbytes) |
326 |
if (type == REG_EXPAND_SZ && strchr (text, '%')) |
goto leave; /* empty */ |
327 |
p = expand_path (text); |
p = new char[nbytes+1]; |
328 |
else { |
if (!p) |
329 |
p = new char[nbytes + 1]; |
BUG (0); |
330 |
if (!p) |
rc = RegQueryValueEx (reg_key, key, NULL, &type, (BYTE*)p, &nbytes); |
331 |
BUG (0); |
if (!rc_ok (rc)) |
332 |
memcpy (p, text, nbytes); |
goto leave; |
333 |
p[nbytes] = '\0'; |
if (type == REG_EXPAND_SZ && strchr (p, '%')) { |
334 |
|
pp = p; |
335 |
|
p = expand_path (pp); |
336 |
|
free_if_alloc (pp); |
337 |
} |
} |
338 |
|
|
339 |
leave: |
leave: |
340 |
if (reg_key) |
if (reg_key != NULL) |
341 |
RegCloseKey (reg_key); |
RegCloseKey (reg_key); |
342 |
return p; |
return p; |
343 |
} |
} |
362 |
rc = WPTERR_REGISTRY; |
rc = WPTERR_REGISTRY; |
363 |
RegCloseKey( reg_key ); |
RegCloseKey( reg_key ); |
364 |
return rc; |
return rc; |
365 |
} /* set_reg_entry */ |
} |
366 |
|
|
367 |
|
|
368 |
int |
int |
369 |
set_reg_key( HKEY root_key, const char * dir, const char * key, |
set_reg_key( HKEY root_key, const char * dir, const char * key, |
370 |
const char * value ) |
const char * value ) |
371 |
{ |
{ |
372 |
int rc = 0; |
int rc; |
373 |
HKEY reg_key; |
HKEY reg_key; |
374 |
|
|
375 |
rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, ®_key ); |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_WRITE, ®_key); |
376 |
if( !rc_ok( rc ) ) |
if (!rc_ok (rc)) |
377 |
return WPTERR_REGISTRY; |
return WPTERR_REGISTRY; |
378 |
|
|
379 |
rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) ); |
rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value)); |
380 |
if( !rc_ok( rc ) ) { |
if (!rc_ok (rc)) { |
381 |
if ( RegCreateKey( root_key, key, ®_key ) != ERROR_SUCCESS ) { |
if (RegCreateKey (root_key, key, ®_key) != ERROR_SUCCESS) { |
382 |
rc = WPTERR_REGISTRY; |
rc = WPTERR_REGISTRY; |
383 |
goto leave; |
goto leave; |
384 |
} |
} |
385 |
rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) ); |
rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value)); |
386 |
if ( !rc_ok( rc ) ) |
if (!rc_ok (rc)) |
387 |
rc = WPTERR_REGISTRY; |
rc = WPTERR_REGISTRY; |
388 |
} |
} |
389 |
|
|
390 |
leave: |
leave: |
391 |
RegCloseKey( reg_key ); |
RegCloseKey (reg_key); |
392 |
return rc; |
return rc; |
393 |
} /* set_reg_key */ |
} |
394 |
|
|
395 |
|
|
396 |
int |
int |
400 |
} |
} |
401 |
|
|
402 |
|
|
|
|
|
|
|
|
403 |
int |
int |
404 |
set_reg_entry_mo (const char * value) |
set_reg_entry_mo (const char * value) |
405 |
{ |
{ |
408 |
} |
} |
409 |
|
|
410 |
|
|
411 |
char * |
char* |
412 |
get_reg_entry_gpg (const char *key) |
get_reg_entry_gpg (const char *key) |
413 |
{ |
{ |
414 |
return get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key); |
char *p; |
415 |
|
p = get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key); |
416 |
|
if (!p || strlen (p) == 0) { |
417 |
|
free_if_alloc (p); |
418 |
|
return NULL; |
419 |
|
} |
420 |
|
return p; |
421 |
} |
} |
422 |
|
|
423 |
|
|
454 |
return p; |
return p; |
455 |
|
|
456 |
lang = get_gettext_langid (); |
lang = get_gettext_langid (); |
457 |
if (!lang) |
if (!lang) |
458 |
return NULL; |
return NULL; |
459 |
pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8]; |
pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8]; |
460 |
if (!pp) |
if (!pp) |
461 |
BUG (NULL); |
BUG (NULL); |
467 |
|
|
468 |
|
|
469 |
/* All valid configuration commands. */ |
/* All valid configuration commands. */ |
470 |
static const char * cfg [] = { |
static const char *cfg [] = { |
471 |
NULL, |
NULL, |
472 |
"CacheTime", |
"CacheTime", |
473 |
"WordWrap", |
"WordWrap", |
474 |
"FastMode", |
"DefaultExt", |
475 |
"Viewer", |
"Viewer", |
476 |
"KeylistMode", |
"WipeMode", |
477 |
"WipeMode", |
"AlwaysTrust", |
478 |
"AlwaysTrust", |
"AutoBackup", |
479 |
"AutoBackup", |
"BackupMode", |
480 |
"BackupMode", |
"DisableHotkeys", |
481 |
"DisableHotkeys", |
"NoCompressMultiMedia", |
482 |
"NoCompressMultiMedia", |
"Expert", |
483 |
"Expert", |
"FMProgressBar", |
484 |
"FMProgressBar", |
"BackupSecring" |
485 |
}; |
}; |
486 |
|
|
487 |
|
|
488 |
int |
int |
500 |
int |
int |
501 |
get_reg_winpt_single (int id) |
get_reg_winpt_single (int id) |
502 |
{ |
{ |
503 |
char *buf = NULL; |
char *buf; |
504 |
int val = 0; |
int val = 0; |
505 |
|
|
506 |
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]); |
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]); |
532 |
case CFG_WIPEMODE: |
case CFG_WIPEMODE: |
533 |
sprintf (buf, "%d", opt->wipe_mode); |
sprintf (buf, "%d", opt->wipe_mode); |
534 |
break; |
break; |
535 |
case CFG_FASTMODE: |
case CFG_FILEEXT: |
536 |
sprintf (buf, "%d", opt->use_tmpfiles); |
sprintf (buf, "%d", opt->default_ext); |
537 |
break; |
break; |
538 |
case CFG_NOZIP_MMEDIA: |
case CFG_NOZIP_MMEDIA: |
539 |
sprintf (buf, "%d", opt->no_zip_mmedia); |
sprintf (buf, "%d", opt->no_zip_mmedia); |
541 |
case CFG_VIEWER: |
case CFG_VIEWER: |
542 |
sprintf (buf, "%d", opt->use_viewer); |
sprintf (buf, "%d", opt->use_viewer); |
543 |
break; |
break; |
|
case CFG_KEYLISTMODE: |
|
|
sprintf (buf, "%d", opt->keylist_mode); |
|
|
break; |
|
544 |
case CFG_ALWAYSTRUST: |
case CFG_ALWAYSTRUST: |
545 |
sprintf (buf, "%d", opt->always_trust); |
sprintf (buf, "%d", opt->always_trust); |
546 |
break; |
break; |
560 |
case CFG_FM_PROGRESS: |
case CFG_FM_PROGRESS: |
561 |
sprintf (buf, "%d", opt->fm.progress); |
sprintf (buf, "%d", opt->fm.progress); |
562 |
break; |
break; |
563 |
|
|
564 |
|
case CFG_BACKUP_INC_SKR: |
565 |
|
sprintf (buf, "%d", opt->backup.include_secr); |
566 |
|
break; |
567 |
} |
} |
568 |
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf); |
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf); |
569 |
if (rc) |
if (rc) |
576 |
if (rc) |
if (rc) |
577 |
goto leave; |
goto leave; |
578 |
} |
} |
|
if (opt->kserv_conf) { |
|
|
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig", |
|
|
opt->kserv_conf); |
|
|
if (rc) |
|
|
goto leave; |
|
|
} |
|
579 |
|
|
580 |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
for (i=0; wpt_hotkeys[i].name; i++) { |
581 |
strcpy (buf, " "); |
if (wpt_hotkeys[i].enabled) { |
582 |
if (reg_hotkeys[i].enabled) |
buf[0] = wpt_hotkeys[i].key; |
583 |
strcpy (buf, reg_hotkeys[i].key); |
buf[1] = 0; |
584 |
|
} |
585 |
|
else |
586 |
|
strcpy (buf, " "); |
587 |
rc = set_reg_key (HKEY_CURRENT_USER, WINPT_REG, |
rc = set_reg_key (HKEY_CURRENT_USER, WINPT_REG, |
588 |
reg_hotkeys[i].reg_entry, buf); |
wpt_hotkeys[i].name, buf); |
589 |
if (rc) |
if (rc) |
590 |
break; |
break; |
591 |
} |
} |
603 |
set_reg_winpt_flag (const char * name, int val) |
set_reg_winpt_flag (const char * name, int val) |
604 |
{ |
{ |
605 |
return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name, val? "1" : "0"); |
return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name, val? "1" : "0"); |
606 |
} /* set_reg_winpt_flag */ |
} |
607 |
|
|
608 |
|
|
609 |
int |
int |
619 |
flag = -1; |
flag = -1; |
620 |
free_if_alloc (buf); |
free_if_alloc (buf); |
621 |
return flag; |
return flag; |
622 |
} /* get_reg_winpt_flag */ |
} |
623 |
|
|
624 |
|
|
625 |
/* Retrieve the winpt preferences from the registry. */ |
/* Retrieve the winpt preferences from the registry. */ |
638 |
switch (i) { |
switch (i) { |
639 |
case CFG_CACHETIME: |
case CFG_CACHETIME: |
640 |
opt->cache_time = atol (val); |
opt->cache_time = atol (val); |
|
/* We do NOT support passphrase caching for more than an hour. |
|
|
* Perhaps we should allow it, but for now we silently drop this. |
|
|
*/ |
|
|
if (opt->cache_time > 3600) |
|
|
opt->cache_time = 3600; |
|
641 |
break; |
break; |
642 |
case CFG_WORDWRAP: |
case CFG_WORDWRAP: |
643 |
opt->word_wrap = atol (val); |
opt->word_wrap = atol (val); |
644 |
break; |
break; |
645 |
case CFG_FASTMODE: |
case CFG_FILEEXT: |
646 |
opt->use_tmpfiles = atol (val); |
opt->default_ext = atol (val); |
647 |
break; |
break; |
648 |
case CFG_NOZIP_MMEDIA: |
case CFG_NOZIP_MMEDIA: |
649 |
opt->no_zip_mmedia = atol (val); |
opt->no_zip_mmedia = atol (val); |
651 |
case CFG_VIEWER: |
case CFG_VIEWER: |
652 |
opt->use_viewer = atol (val); |
opt->use_viewer = atol (val); |
653 |
break; |
break; |
|
case CFG_KEYLISTMODE: |
|
|
opt->keylist_mode = atol (val); |
|
|
break; |
|
654 |
case CFG_WIPEMODE: |
case CFG_WIPEMODE: |
655 |
opt->wipe_mode = atol (val); |
opt->wipe_mode = atol (val); |
656 |
break; |
break; |
669 |
case CFG_EXPERT: |
case CFG_EXPERT: |
670 |
opt->expert = atol (val); |
opt->expert = atol (val); |
671 |
break; |
break; |
|
|
|
672 |
case CFG_FM_PROGRESS: |
case CFG_FM_PROGRESS: |
673 |
opt->fm.progress = atol (val); |
opt->fm.progress = atol (val); |
674 |
break; |
break; |
675 |
|
|
676 |
|
case CFG_BACKUP_INC_SKR: |
677 |
|
opt->backup.include_secr = atol (val); |
678 |
|
break; |
679 |
} |
} |
680 |
free_if_alloc (val); |
free_if_alloc (val); |
681 |
} |
} |
684 |
if (val && val[0] != ' ') |
if (val && val[0] != ' ') |
685 |
opt->backup.path = m_strdup (val); |
opt->backup.path = m_strdup (val); |
686 |
free_if_alloc (val); |
free_if_alloc (val); |
|
|
|
|
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig"); |
|
|
if (val && val[0] != ' ') |
|
|
opt->kserv_conf = m_strdup (val); |
|
|
free_if_alloc (val); |
|
687 |
|
|
688 |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
for (i=0; wpt_hotkeys[i].name; i++) { |
689 |
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry); |
wpt_hotkeys[i].enabled = 0; |
690 |
|
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, wpt_hotkeys[i].name); |
691 |
if (val && val[0] != ' ') { |
if (val && val[0] != ' ') { |
692 |
reg_hotkeys[i].key[0] = *val; |
wpt_hotkeys[i].key = *val; |
693 |
reg_hotkeys[i].enabled = 1; |
wpt_hotkeys[i].enabled = 1; |
694 |
} |
} |
|
else |
|
|
reg_hotkeys[i].enabled = 0; |
|
695 |
free_if_alloc (val); |
free_if_alloc (val); |
696 |
} |
} |
697 |
return 0; |
return 0; |
698 |
} /* get_reg_winpt_prefs */ |
} |
699 |
|
|
700 |
|
|
701 |
char* |
char* |
702 |
get_reg_entry_keyserver (const char *name) |
get_reg_entry_keyserver (const char *name) |
703 |
{ |
{ |
704 |
char * p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name); |
char *p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name); |
705 |
if (p && !strcmp (p, "")) { |
if (p && (!strcmp (p, "") || strlen (p) == 0)) { |
706 |
free_if_alloc (p); |
free_if_alloc (p); |
707 |
return NULL; |
return NULL; |
708 |
} |
} |
710 |
} |
} |
711 |
|
|
712 |
|
|
713 |
|
int |
714 |
|
set_reg_entry_keyserver (const char *name, const char *val) |
715 |
|
{ |
716 |
|
return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val); |
717 |
|
} |
718 |
|
|
719 |
|
static int |
720 |
|
get_reg_entry_keyserver_int (const char *key) |
721 |
|
{ |
722 |
|
char *p; |
723 |
|
int val = 0; |
724 |
|
|
725 |
|
p = get_reg_entry_keyserver (key); |
726 |
|
if (p && *p) |
727 |
|
val = atoi (p); |
728 |
|
free_if_alloc (p); |
729 |
|
return val; |
730 |
|
} |
731 |
|
|
732 |
|
|
733 |
void |
void |
734 |
get_reg_proxy_prefs (char ** host, int * port, char ** user, char ** pass) |
get_reg_proxy_prefs (keyserver_proxy_t prox) |
735 |
{ |
{ |
736 |
if (host) |
if (!prox) |
737 |
*host = get_reg_entry_keyserver ("Host"); |
return; |
738 |
if (user) |
|
739 |
*user = get_reg_entry_keyserver ("User"); |
free_if_alloc (prox->host); |
740 |
if (pass) |
prox->host = get_reg_entry_keyserver ("Host"); |
741 |
*pass = get_reg_entry_keyserver ("Pass"); |
free_if_alloc (prox->user); |
742 |
if (port) { |
prox->user = get_reg_entry_keyserver ("User"); |
743 |
char * p = get_reg_entry_keyserver ("Port"); |
free_if_alloc (prox->pass); |
744 |
if (p) { |
prox->pass = get_reg_entry_keyserver ("Pass"); |
745 |
*port = atol (p); |
prox->port = get_reg_entry_keyserver_int ("Port"); |
746 |
free_if_alloc (p); |
} |
|
} |
|
|
} |
|
|
} /* get_reg_proxy_prefs */ |
|
747 |
|
|
748 |
|
|
749 |
int |
static int |
750 |
set_reg_entry_keyserver( const char * name, const char * val ) |
set_reg_entry_keyserver_int (const char *key, int val) |
751 |
{ |
{ |
752 |
return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val ); |
char buf[32]; |
753 |
} /* set_reg_entry_keyserver */ |
|
754 |
|
sprintf (buf, "%d", val); |
755 |
|
return set_reg_entry_keyserver (key, buf); |
756 |
|
} |
757 |
|
|
758 |
|
|
759 |
int |
int |
760 |
set_reg_proxy_prefs( const char * host, int port, const char * user, const char * pass ) |
set_reg_proxy_prefs (keyserver_proxy_t prox) |
761 |
{ |
{ |
762 |
int rc; |
int rc; |
763 |
|
|
764 |
rc = set_reg_entry_keyserver( "Host", host? host : "" ); |
rc = set_reg_entry_keyserver_int ("Proto", prox->proto); |
765 |
if( !rc ) { |
if (!rc) |
766 |
char buf[32]; |
rc = set_reg_entry_keyserver ("Host", prox->host? prox->host : ""); |
767 |
sprintf( buf, "%d", port ); |
if (!rc) |
768 |
rc = set_reg_entry_keyserver( "Port", buf ); |
rc = set_reg_entry_keyserver_int ("Port", prox->port); |
769 |
} |
if (!rc) |
770 |
if( !rc ) |
rc = set_reg_entry_keyserver ("User", prox->user? prox->user : ""); |
771 |
rc = set_reg_entry_keyserver( "User", user? user : "" ); |
if (!rc) |
772 |
if( !rc ) |
rc = set_reg_entry_keyserver ("Pass", prox->pass? prox->pass : ""); |
|
rc = set_reg_entry_keyserver( "Pass", pass? pass : "" ); |
|
773 |
return rc; |
return rc; |
774 |
} /* set_reg_proxy_prefs */ |
} |