36 |
|
|
37 |
#define rc_ok(rc) ((rc) == ERROR_SUCCESS) |
#define rc_ok(rc) ((rc) == ERROR_SUCCESS) |
38 |
|
|
39 |
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} |
|
|
}; |
|
|
|
|
40 |
|
|
41 |
struct reg_hotkey_s reg_hotkeys[] = { |
struct reg_hotkey_s reg_hotkeys[] = { |
42 |
{"ClipEncrypt", "", 0}, |
{"ClipEncrypt", "", 0}, |
50 |
{NULL, "", 0} |
{NULL, "", 0} |
51 |
}; |
}; |
52 |
|
|
53 |
|
/* Global WinPT registry prefereneces. */ |
54 |
winpt_reg_prefs_s reg_prefs; |
winpt_reg_prefs_s reg_prefs; |
55 |
|
|
56 |
#define WINPT_REG "Software\\WinPT" |
|
57 |
|
/* Return != 0 if GPG4win is installed. */ |
58 |
|
int |
59 |
|
is_gpg4win_installed (void) |
60 |
|
{ |
61 |
|
char *p; |
62 |
|
|
63 |
|
p = get_reg_entry_gpg4win (NULL); |
64 |
|
if (!p) |
65 |
|
return 0; |
66 |
|
if (dir_exist_check (p)) { |
67 |
|
free_if_alloc (p); |
68 |
|
return 0; |
69 |
|
} |
70 |
|
free_if_alloc (p); |
71 |
|
return -1; |
72 |
|
} |
73 |
|
|
74 |
|
|
75 |
/* Return != 0 if GPGee is installed. */ |
/* Return != 0 if GPGee is installed. */ |
104 |
static int |
static int |
105 |
regist_single_filetype (gpg_filetype *gfile) |
regist_single_filetype (gpg_filetype *gfile) |
106 |
{ |
{ |
107 |
char icon[256], prog[256]; |
char icon[256]; |
108 |
|
char prog[256]; |
109 |
|
|
110 |
memset (&icon, 0, sizeof (icon)); |
memset (&icon, 0, sizeof (icon)); |
111 |
GetModuleFileName (glob_hinst, prog, sizeof (prog)-1); |
GetModuleFileName (glob_hinst, prog, sizeof (prog)-1); |
144 |
} |
} |
145 |
|
|
146 |
return 0; |
return 0; |
147 |
} /* regist_inst_gpg */ |
} |
148 |
|
|
149 |
|
|
150 |
/* Install WinPT into the W32 registry, if the entry already |
/* Install WinPT into the W32 registry, if the entry already |
154 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
155 |
int |
int |
156 |
regist_inst_winpt (int with_ext, int *created) |
regist_inst_winpt (int with_ext, int *created) |
157 |
{ |
{ |
158 |
HKEY reg; |
HKEY reg; |
159 |
char *p = NULL; |
char *p = NULL; |
160 |
char modpath[MAX_PATH+1]; |
char modpath[MAX_PATH+1]; |
161 |
int rc, i, id, n = 0; |
int rc, i, id, n; |
162 |
|
|
163 |
|
gpg_filetype gpg_filetypes[] = { |
164 |
|
{_("GPG Detached Signature"), ".sig", 1}, |
165 |
|
{_("GPG Encrypted Data"), ".gpg", 2}, |
166 |
|
{_("GPG Armored Data"), ".asc", 2}, |
167 |
|
{0} |
168 |
|
}; |
169 |
|
|
170 |
if (created) |
if (created) |
171 |
*created = 0; |
*created = 0; |
172 |
|
if (is_gpgee_installed ()) |
|
p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions"); |
|
|
if ((p && *p == '1') || is_gpgee_installed ()) |
|
173 |
with_ext = 0; |
with_ext = 0; |
|
free_if_alloc (p); |
|
174 |
|
|
|
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: |
|
175 |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, ®); |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, ®); |
176 |
if (rc_ok (rc)) { |
if (rc_ok (rc)) { |
177 |
RegCloseKey (reg); |
RegCloseKey (reg); |
178 |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, ®); |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, ®); |
179 |
if( !rc_ok (rc)) { |
if (!rc_ok (rc)) { |
180 |
RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", ®); |
RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", ®); |
181 |
RegCloseKey (reg); |
RegCloseKey (reg); |
182 |
} |
} |
188 |
set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER); |
set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER); |
189 |
} |
} |
190 |
free_if_alloc (p); |
free_if_alloc (p); |
|
if (n) |
|
|
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1"); |
|
191 |
return 0; |
return 0; |
192 |
} |
} |
193 |
rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, ®); |
rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, ®); |
196 |
if (created) |
if (created) |
197 |
*created = 1; |
*created = 1; |
198 |
RegCloseKey (reg); |
RegCloseKey (reg); |
199 |
if (n) |
if (with_ext) { |
200 |
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 " |
201 |
|
"be processed with a double click in the explorer.\n" |
202 |
|
"Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO); |
203 |
|
if (id == IDYES) { |
204 |
|
for (i = 0; gpg_filetypes[i].ext; i++) { |
205 |
|
rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, ®); |
206 |
|
if (rc_ok (rc)) { |
207 |
|
RegCloseKey (reg); |
208 |
|
id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO, |
209 |
|
_("It seems there was already a '%s' file type registered by another application.\n" |
210 |
|
"Do you want to overwrite it?"), gpg_filetypes[i].ext); |
211 |
|
if (id == IDNO) |
212 |
|
continue; |
213 |
|
} |
214 |
|
regist_single_filetype (&gpg_filetypes[i]); |
215 |
|
} |
216 |
|
} |
217 |
|
} |
218 |
if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) { |
if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) { |
219 |
while (n-- > 0) { |
while (n-- > 0) { |
220 |
if (modpath[n] == '\\') { |
if (modpath[n] == '\\') { |
231 |
/* Create a new filetype in the W32 registry. |
/* Create a new filetype in the W32 registry. |
232 |
We should really care of errors! Otherwise we can damage the registry! */ |
We should really care of errors! Otherwise we can damage the registry! */ |
233 |
int |
int |
234 |
create_file_type( const char *exefile, const char *ext, const char *extname, char *iconfile ) |
create_file_type (const char *exefile, const char *ext, |
235 |
|
const char *extname, char *iconfile) |
236 |
{ |
{ |
237 |
int rc; |
int rc; |
238 |
HKEY reg = NULL; |
HKEY reg = NULL; |
298 |
return NULL; |
return NULL; |
299 |
len += 1; |
len += 1; |
300 |
p = new char[len+1]; |
p = new char[len+1]; |
301 |
if( !p ) |
if (!p) |
302 |
return NULL; |
return NULL; |
303 |
len = ExpandEnvironmentStrings (path, p, len); |
len = ExpandEnvironmentStrings (path, p, len); |
304 |
if (!len) { |
if (!len) { |
306 |
return NULL; |
return NULL; |
307 |
} |
} |
308 |
return p; |
return p; |
309 |
} /* expand_path */ |
} |
310 |
|
|
311 |
|
|
312 |
/* Retrieve a registry entry with the directory given in @dir |
/* Retrieve a registry entry with the directory given in @dir |
319 |
char text[384] = {0}; |
char text[384] = {0}; |
320 |
DWORD nbytes, type; |
DWORD nbytes, type; |
321 |
HKEY reg_key = NULL; |
HKEY reg_key = NULL; |
322 |
char *p = NULL; |
char * p = NULL; |
323 |
|
|
324 |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
325 |
if( !rc_ok( rc ) ) |
if( !rc_ok( rc ) ) |
405 |
} |
} |
406 |
|
|
407 |
|
|
|
|
|
|
|
|
408 |
int |
int |
409 |
set_reg_entry_mo (const char * value) |
set_reg_entry_mo (const char * value) |
410 |
{ |
{ |
413 |
} |
} |
414 |
|
|
415 |
|
|
416 |
char * |
char* |
417 |
get_reg_entry_gpg (const char *key) |
get_reg_entry_gpg (const char *key) |
418 |
{ |
{ |
419 |
return get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key); |
char *p; |
420 |
|
p = get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key); |
421 |
|
if (!p || strlen (p) == 0) { |
422 |
|
free_if_alloc (p); |
423 |
|
return NULL; |
424 |
|
} |
425 |
|
return p; |
426 |
} |
} |
427 |
|
|
428 |
|
|
472 |
|
|
473 |
|
|
474 |
/* All valid configuration commands. */ |
/* All valid configuration commands. */ |
475 |
static const char * cfg [] = { |
static const char *cfg [] = { |
476 |
NULL, |
NULL, |
477 |
"CacheTime", |
"CacheTime", |
478 |
"WordWrap", |
"WordWrap", |
479 |
"FastMode", |
"FastMode", |
480 |
"Viewer", |
"Viewer", |
481 |
"KeylistMode", |
"WipeMode", |
482 |
"WipeMode", |
"AlwaysTrust", |
483 |
"AlwaysTrust", |
"AutoBackup", |
484 |
"AutoBackup", |
"BackupMode", |
485 |
"BackupMode", |
"DisableHotkeys", |
486 |
"DisableHotkeys", |
"NoCompressMultiMedia", |
487 |
"NoCompressMultiMedia", |
"Expert", |
488 |
"Expert", |
"FMProgressBar", |
489 |
"FMProgressBar", |
}; |
|
}; |
|
490 |
|
|
491 |
|
|
492 |
int |
int |
504 |
int |
int |
505 |
get_reg_winpt_single (int id) |
get_reg_winpt_single (int id) |
506 |
{ |
{ |
507 |
char *buf = NULL; |
char * buf = NULL; |
508 |
int val = 0; |
int val = 0; |
509 |
|
|
510 |
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]); |
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]); |
545 |
case CFG_VIEWER: |
case CFG_VIEWER: |
546 |
sprintf (buf, "%d", opt->use_viewer); |
sprintf (buf, "%d", opt->use_viewer); |
547 |
break; |
break; |
|
case CFG_KEYLISTMODE: |
|
|
sprintf (buf, "%d", opt->keylist_mode); |
|
|
break; |
|
548 |
case CFG_ALWAYSTRUST: |
case CFG_ALWAYSTRUST: |
549 |
sprintf (buf, "%d", opt->always_trust); |
sprintf (buf, "%d", opt->always_trust); |
550 |
break; |
break; |
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; reg_hotkeys[i].reg_entry; i++) { |
581 |
strcpy (buf, " "); |
strcpy (buf, " "); |
653 |
case CFG_VIEWER: |
case CFG_VIEWER: |
654 |
opt->use_viewer = atol (val); |
opt->use_viewer = atol (val); |
655 |
break; |
break; |
|
case CFG_KEYLISTMODE: |
|
|
opt->keylist_mode = atol (val); |
|
|
break; |
|
656 |
case CFG_WIPEMODE: |
case CFG_WIPEMODE: |
657 |
opt->wipe_mode = atol (val); |
opt->wipe_mode = atol (val); |
658 |
break; |
break; |
683 |
if (val && val[0] != ' ') |
if (val && val[0] != ' ') |
684 |
opt->backup.path = m_strdup (val); |
opt->backup.path = m_strdup (val); |
685 |
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); |
|
686 |
|
|
687 |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
688 |
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry); |
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry); |