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 |
|
|
|
#define WINPT_REG "Software\\WinPT" |
|
|
|
|
52 |
|
|
53 |
/* Return != 0 if GPG4win is installed. */ |
/* Return != 0 if GPG4win is installed. */ |
54 |
int |
int |
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] == '\\') { |
409 |
} |
} |
410 |
|
|
411 |
|
|
412 |
char * |
char* |
413 |
get_reg_entry_gpg (const char *key) |
get_reg_entry_gpg (const char *key) |
414 |
{ |
{ |
415 |
return get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key); |
char *p; |
416 |
|
p = get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key); |
417 |
|
if (!p || strlen (p) == 0) { |
418 |
|
free_if_alloc (p); |
419 |
|
return NULL; |
420 |
|
} |
421 |
|
return p; |
422 |
} |
} |
423 |
|
|
424 |
|
|
455 |
return p; |
return p; |
456 |
|
|
457 |
lang = get_gettext_langid (); |
lang = get_gettext_langid (); |
458 |
if (!lang) |
if (!lang) |
459 |
return NULL; |
return NULL; |
460 |
pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8]; |
pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8]; |
461 |
if (!pp) |
if (!pp) |
462 |
BUG (NULL); |
BUG (NULL); |
468 |
|
|
469 |
|
|
470 |
/* All valid configuration commands. */ |
/* All valid configuration commands. */ |
471 |
static const char * cfg [] = { |
static const char *cfg [] = { |
472 |
NULL, |
NULL, |
473 |
"CacheTime", |
"CacheTime", |
474 |
"WordWrap", |
"WordWrap", |
475 |
"FastMode", |
"DefaultExt", |
476 |
"Viewer", |
"Viewer", |
477 |
"KeylistMode", |
"WipeMode", |
478 |
"WipeMode", |
"AlwaysTrust", |
479 |
"AlwaysTrust", |
"AutoBackup", |
480 |
"AutoBackup", |
"BackupMode", |
481 |
"BackupMode", |
"DisableHotkeys", |
482 |
"DisableHotkeys", |
"NoCompressMultiMedia", |
483 |
"NoCompressMultiMedia", |
"Expert", |
484 |
"Expert", |
"FMProgressBar", |
485 |
"FMProgressBar", |
}; |
|
}; |
|
486 |
|
|
487 |
|
|
488 |
int |
int |
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; |
572 |
if (rc) |
if (rc) |
573 |
goto leave; |
goto leave; |
574 |
} |
} |
|
if (opt->kserv_conf) { |
|
|
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig", |
|
|
opt->kserv_conf); |
|
|
if (rc) |
|
|
goto leave; |
|
|
} |
|
575 |
|
|
576 |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
for (i=0; wpt_hotkeys[i].name; i++) { |
577 |
strcpy (buf, " "); |
if (wpt_hotkeys[i].enabled) { |
578 |
if (reg_hotkeys[i].enabled) |
buf[0] = wpt_hotkeys[i].key; |
579 |
strcpy (buf, reg_hotkeys[i].key); |
buf[1] = 0; |
580 |
|
} |
581 |
|
else |
582 |
|
strcpy (buf, " "); |
583 |
rc = set_reg_key (HKEY_CURRENT_USER, WINPT_REG, |
rc = set_reg_key (HKEY_CURRENT_USER, WINPT_REG, |
584 |
reg_hotkeys[i].reg_entry, buf); |
wpt_hotkeys[i].name, buf); |
585 |
if (rc) |
if (rc) |
586 |
break; |
break; |
587 |
} |
} |
634 |
switch (i) { |
switch (i) { |
635 |
case CFG_CACHETIME: |
case CFG_CACHETIME: |
636 |
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; |
|
637 |
break; |
break; |
638 |
case CFG_WORDWRAP: |
case CFG_WORDWRAP: |
639 |
opt->word_wrap = atol (val); |
opt->word_wrap = atol (val); |
640 |
break; |
break; |
641 |
case CFG_FASTMODE: |
case CFG_FILEEXT: |
642 |
opt->use_tmpfiles = atol (val); |
opt->default_ext = atol (val); |
643 |
break; |
break; |
644 |
case CFG_NOZIP_MMEDIA: |
case CFG_NOZIP_MMEDIA: |
645 |
opt->no_zip_mmedia = atol (val); |
opt->no_zip_mmedia = atol (val); |
647 |
case CFG_VIEWER: |
case CFG_VIEWER: |
648 |
opt->use_viewer = atol (val); |
opt->use_viewer = atol (val); |
649 |
break; |
break; |
|
case CFG_KEYLISTMODE: |
|
|
opt->keylist_mode = atol (val); |
|
|
break; |
|
650 |
case CFG_WIPEMODE: |
case CFG_WIPEMODE: |
651 |
opt->wipe_mode = atol (val); |
opt->wipe_mode = atol (val); |
652 |
break; |
break; |
665 |
case CFG_EXPERT: |
case CFG_EXPERT: |
666 |
opt->expert = atol (val); |
opt->expert = atol (val); |
667 |
break; |
break; |
|
|
|
668 |
case CFG_FM_PROGRESS: |
case CFG_FM_PROGRESS: |
669 |
opt->fm.progress = atol (val); |
opt->fm.progress = atol (val); |
670 |
break; |
break; |
676 |
if (val && val[0] != ' ') |
if (val && val[0] != ' ') |
677 |
opt->backup.path = m_strdup (val); |
opt->backup.path = m_strdup (val); |
678 |
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); |
|
679 |
|
|
680 |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
for (i=0; wpt_hotkeys[i].name; i++) { |
681 |
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry); |
wpt_hotkeys[i].enabled = 0; |
682 |
|
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, wpt_hotkeys[i].name); |
683 |
if (val && val[0] != ' ') { |
if (val && val[0] != ' ') { |
684 |
reg_hotkeys[i].key[0] = *val; |
wpt_hotkeys[i].key = *val; |
685 |
reg_hotkeys[i].enabled = 1; |
wpt_hotkeys[i].enabled = 1; |
686 |
} |
} |
|
else |
|
|
reg_hotkeys[i].enabled = 0; |
|
687 |
free_if_alloc (val); |
free_if_alloc (val); |
688 |
} |
} |
689 |
return 0; |
return 0; |
690 |
} /* get_reg_winpt_prefs */ |
} |
691 |
|
|
692 |
|
|
693 |
char* |
char* |
694 |
get_reg_entry_keyserver (const char *name) |
get_reg_entry_keyserver (const char *name) |
695 |
{ |
{ |
696 |
char * p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name); |
char *p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name); |
697 |
if (p && !strcmp (p, "")) { |
if (p && (!strcmp (p, "") || strlen (p) == 0)) { |
698 |
free_if_alloc (p); |
free_if_alloc (p); |
699 |
return NULL; |
return NULL; |
700 |
} |
} |
702 |
} |
} |
703 |
|
|
704 |
|
|
705 |
|
int |
706 |
|
set_reg_entry_keyserver (const char * name, const char * val) |
707 |
|
{ |
708 |
|
return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val ); |
709 |
|
} |
710 |
|
|
711 |
|
static int |
712 |
|
get_reg_entry_keyserver_int (const char *key) |
713 |
|
{ |
714 |
|
char *p; |
715 |
|
int val = 0; |
716 |
|
|
717 |
|
p = get_reg_entry_keyserver (key); |
718 |
|
if (p && *p) |
719 |
|
val = atoi (p); |
720 |
|
free_if_alloc (p); |
721 |
|
return val; |
722 |
|
} |
723 |
|
|
724 |
|
|
725 |
void |
void |
726 |
get_reg_proxy_prefs (char ** host, int * port, char ** user, char ** pass) |
get_reg_proxy_prefs (keyserver_proxy_t prox) |
727 |
{ |
{ |
728 |
if (host) |
if (!prox) |
729 |
*host = get_reg_entry_keyserver ("Host"); |
return; |
730 |
if (user) |
|
731 |
*user = get_reg_entry_keyserver ("User"); |
free_if_alloc (prox->host); |
732 |
if (pass) |
prox->host = get_reg_entry_keyserver ("Host"); |
733 |
*pass = get_reg_entry_keyserver ("Pass"); |
free_if_alloc (prox->user); |
734 |
if (port) { |
prox->user = get_reg_entry_keyserver ("User"); |
735 |
char * p = get_reg_entry_keyserver ("Port"); |
free_if_alloc (prox->pass); |
736 |
if (p) { |
prox->pass = get_reg_entry_keyserver ("Pass"); |
737 |
*port = atol (p); |
prox->port = get_reg_entry_keyserver_int ("Port"); |
738 |
free_if_alloc (p); |
} |
|
} |
|
|
} |
|
|
} /* get_reg_proxy_prefs */ |
|
739 |
|
|
740 |
|
|
741 |
int |
static int |
742 |
set_reg_entry_keyserver( const char * name, const char * val ) |
set_reg_entry_keyserver_int (const char *key, int val) |
743 |
{ |
{ |
744 |
return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val ); |
char buf[32]; |
745 |
} /* set_reg_entry_keyserver */ |
|
746 |
|
sprintf (buf, "%d", val); |
747 |
|
return set_reg_entry_keyserver (key, buf); |
748 |
|
} |
749 |
|
|
750 |
|
|
751 |
int |
int |
752 |
set_reg_proxy_prefs( const char * host, int port, const char * user, const char * pass ) |
set_reg_proxy_prefs (keyserver_proxy_t prox) |
753 |
{ |
{ |
754 |
int rc; |
int rc; |
755 |
|
|
756 |
rc = set_reg_entry_keyserver( "Host", host? host : "" ); |
rc = set_reg_entry_keyserver_int ("Proto", prox->proto); |
757 |
if( !rc ) { |
if (!rc) |
758 |
char buf[32]; |
rc = set_reg_entry_keyserver ("Host", prox->host? prox->host : ""); |
759 |
sprintf( buf, "%d", port ); |
if (!rc) |
760 |
rc = set_reg_entry_keyserver( "Port", buf ); |
rc = set_reg_entry_keyserver_int ("Port", prox->port); |
761 |
} |
if (!rc) |
762 |
if( !rc ) |
rc = set_reg_entry_keyserver ("User", prox->user? prox->user : ""); |
763 |
rc = set_reg_entry_keyserver( "User", user? user : "" ); |
if (!rc) |
764 |
if( !rc ) |
rc = set_reg_entry_keyserver ("Pass", prox->pass? prox->pass : ""); |
|
rc = set_reg_entry_keyserver( "Pass", pass? pass : "" ); |
|
765 |
return rc; |
return rc; |
766 |
} /* set_reg_proxy_prefs */ |
} |