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" |
40 |
{"GPG Detached Signature", ".sig", 1}, |
|
41 |
{"GPG Encrypted Data", ".gpg", 2}, |
/* GPG file association context. */ |
42 |
{"GPG Armored Data", ".asc", 2}, |
struct gpg_filetype { |
43 |
{0} |
const char *descr; |
44 |
|
const char *ext; |
45 |
|
int nicon; |
46 |
}; |
}; |
47 |
|
|
48 |
struct reg_hotkey_s reg_hotkeys[] = { |
struct reg_hotkey_s reg_hotkeys[] = { |
57 |
{NULL, "", 0} |
{NULL, "", 0} |
58 |
}; |
}; |
59 |
|
|
60 |
|
/* Global WinPT registry prefereneces. */ |
61 |
winpt_reg_prefs_s reg_prefs; |
winpt_reg_prefs_s reg_prefs; |
62 |
|
|
|
#define WINPT_REG "Software\\WinPT" |
|
63 |
|
|
64 |
|
/* Return != 0 if GPG4win is installed. */ |
65 |
|
int |
66 |
|
is_gpg4win_installed (void) |
67 |
|
{ |
68 |
|
char *p; |
69 |
|
|
70 |
|
p = get_reg_entry_gpg4win (NULL); |
71 |
|
if (!p) |
72 |
|
return 0; |
73 |
|
if (dir_exist_check (p)) { |
74 |
|
free_if_alloc (p); |
75 |
|
return 0; |
76 |
|
} |
77 |
|
free_if_alloc (p); |
78 |
|
return -1; |
79 |
|
} |
80 |
|
|
81 |
|
|
82 |
|
/* Return != 0 if GPGee is installed. */ |
83 |
|
int |
84 |
|
is_gpgee_installed (void) |
85 |
|
{ |
86 |
|
HKEY hk; |
87 |
|
LONG ec; |
88 |
|
|
89 |
|
ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\GPGee", 0, KEY_READ, &hk); |
90 |
|
if (ec == ERROR_SUCCESS) { |
91 |
|
RegCloseKey (hk); |
92 |
|
return -1; |
93 |
|
} |
94 |
|
|
95 |
|
return 0; |
96 |
|
} |
97 |
|
|
98 |
|
|
99 |
|
/* Free all members in the registry preference struct. */ |
100 |
void |
void |
101 |
free_reg_prefs (void) |
free_reg_prefs (void) |
102 |
{ |
{ |
104 |
free_if_alloc (reg_prefs.kserv_conf); |
free_if_alloc (reg_prefs.kserv_conf); |
105 |
free_if_alloc (reg_prefs.homedir); |
free_if_alloc (reg_prefs.homedir); |
106 |
memset (®_prefs, 0, sizeof reg_prefs); |
memset (®_prefs, 0, sizeof reg_prefs); |
107 |
} /* free_reg_prefs */ |
} |
108 |
|
|
109 |
|
|
110 |
/* Register the given WinPT filetype. */ |
/* Register the given WinPT filetype. */ |
111 |
static int |
static int |
112 |
regist_single_filetype (gpg_filetype *gfile) |
regist_single_filetype (gpg_filetype *gfile) |
113 |
{ |
{ |
114 |
char icon[256], prog[256]; |
char icon[256]; |
115 |
|
char prog[256]; |
116 |
|
|
117 |
memset (&icon, 0, sizeof (icon)); |
memset (&icon, 0, sizeof (icon)); |
118 |
GetModuleFileName (glob_hinst, prog, sizeof (prog)-1); |
GetModuleFileName (glob_hinst, prog, sizeof (prog)-1); |
119 |
_snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon); |
_snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon); |
120 |
return create_file_type (prog, gfile->ext, gfile->descr, icon); |
return create_file_type (prog, gfile->ext, gfile->descr, icon); |
121 |
} /* regist_single_filetype */ |
} |
122 |
|
|
123 |
|
|
124 |
/* Install the GPG related into the W32 resgistry, if the entry already |
/* Install the GPG related into the W32 resgistry, if the entry already |
151 |
} |
} |
152 |
|
|
153 |
return 0; |
return 0; |
154 |
} /* regist_inst_gpg */ |
} |
155 |
|
|
156 |
|
|
157 |
/* Install WinPT into the W32 registry, if the entry already |
/* Install WinPT into the W32 registry, if the entry already |
158 |
exists the function returns immediately.*/ |
exists the function returns immediately. @with_ext can be |
159 |
|
used to register some file types (if 1). @created contains |
160 |
|
1 if the registry key was created. |
161 |
|
Return value: 0 on success. */ |
162 |
int |
int |
163 |
regist_inst_winpt (int with_ext, int * created) |
regist_inst_winpt (int with_ext, int *created) |
164 |
{ |
{ |
165 |
HKEY reg; |
HKEY reg; |
166 |
char *p = NULL; |
char *p = NULL; |
167 |
char modpath[MAX_PATH+1]; |
char modpath[MAX_PATH+1]; |
168 |
int rc, i, id, n = 0; |
int rc, i, id, n; |
169 |
|
|
170 |
if( created ) |
gpg_filetype gpg_filetypes[] = { |
171 |
*created = 0; |
{_("GPG Detached Signature"), ".sig", 1}, |
172 |
|
{_("GPG Encrypted Data"), ".gpg", 2}, |
173 |
|
{_("GPG Armored Data"), ".asc", 2}, |
174 |
|
{0} |
175 |
|
}; |
176 |
|
|
177 |
p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions"); |
if (created) |
178 |
if (p && *p == '1') |
*created = 0; |
179 |
|
if (is_gpgee_installed ()) |
180 |
with_ext = 0; |
with_ext = 0; |
|
free_if_alloc( p ); |
|
181 |
|
|
182 |
if( with_ext ) { |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, ®); |
183 |
id = msg_box( NULL, _("WinPT can register some GPG file types for you so they can " |
if (rc_ok (rc)) { |
184 |
"be processed with a double click in the explorer.\n" |
RegCloseKey (reg); |
185 |
"Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO ); |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, ®); |
186 |
if( id == IDNO ) { |
if (!rc_ok (rc)) { |
187 |
set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" ); |
RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", ®); |
188 |
goto start; |
RegCloseKey (reg); |
|
} |
|
|
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: |
|
|
rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, ® ); |
|
|
if( rc_ok( rc ) ) { |
|
|
RegCloseKey( reg ); |
|
|
rc = RegOpenKeyEx( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, ® ); |
|
|
if( !rc_ok( rc ) ) { |
|
|
RegCreateKey( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", ® ); |
|
|
RegCloseKey( reg ); |
|
189 |
} |
} |
190 |
p = get_reg_entry_keyserver ("Default"); |
p = get_reg_entry_keyserver ("Default"); |
191 |
if (!p) { |
if (!p) { |
194 |
set_reg_entry_keyserver ("Default_Port", buf); |
set_reg_entry_keyserver ("Default_Port", buf); |
195 |
set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER); |
set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER); |
196 |
} |
} |
197 |
free_if_alloc( p ); |
free_if_alloc (p); |
|
if( n ) |
|
|
set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" ); |
|
198 |
return 0; |
return 0; |
199 |
} |
} |
200 |
rc = RegCreateKey( HKEY_CURRENT_USER, WINPT_REG, ® ); |
rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, ®); |
201 |
if( !rc_ok( rc ) ) |
if (!rc_ok (rc)) |
202 |
return WPTERR_REGISTRY; |
return WPTERR_REGISTRY; |
203 |
if( created ) |
if (created) |
204 |
*created = 1; |
*created = 1; |
205 |
RegCloseKey( reg ); |
RegCloseKey (reg); |
206 |
if( n ) |
if (with_ext) { |
207 |
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 " |
208 |
|
"be processed with a double click in the explorer.\n" |
209 |
|
"Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO); |
210 |
|
if (id == IDYES) { |
211 |
|
for (i = 0; gpg_filetypes[i].ext; i++) { |
212 |
|
rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, ®); |
213 |
|
if (rc_ok (rc)) { |
214 |
|
RegCloseKey (reg); |
215 |
|
id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO, |
216 |
|
_("It seems there was already a '%s' file type registered by another application.\n" |
217 |
|
"Do you want to overwrite it?"), gpg_filetypes[i].ext); |
218 |
|
if (id == IDNO) |
219 |
|
continue; |
220 |
|
} |
221 |
|
regist_single_filetype (&gpg_filetypes[i]); |
222 |
|
} |
223 |
|
} |
224 |
|
} |
225 |
if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) { |
if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) { |
226 |
while (n-- > 0) { |
while (n-- > 0) { |
227 |
if (modpath[n] == '\\') { |
if (modpath[n] == '\\') { |
229 |
break; |
break; |
230 |
} |
} |
231 |
} |
} |
232 |
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, |
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath); |
|
"Install Directory", modpath); |
|
233 |
} |
} |
|
|
|
234 |
return 0; |
return 0; |
235 |
} |
} |
236 |
|
|
238 |
/* Create a new filetype in the W32 registry. |
/* Create a new filetype in the W32 registry. |
239 |
We should really care of errors! Otherwise we can damage the registry! */ |
We should really care of errors! Otherwise we can damage the registry! */ |
240 |
int |
int |
241 |
create_file_type( const char *exefile, const char *ext, const char *extname, char *iconfile ) |
create_file_type (const char *exefile, const char *ext, |
242 |
|
const char *extname, char *iconfile) |
243 |
{ |
{ |
244 |
int rc; |
int rc; |
245 |
HKEY reg = NULL; |
HKEY reg = NULL; |
305 |
return NULL; |
return NULL; |
306 |
len += 1; |
len += 1; |
307 |
p = new char[len+1]; |
p = new char[len+1]; |
308 |
if( !p ) |
if (!p) |
309 |
return NULL; |
return NULL; |
310 |
len = ExpandEnvironmentStrings (path, p, len); |
len = ExpandEnvironmentStrings (path, p, len); |
311 |
if (!len) { |
if (!len) { |
313 |
return NULL; |
return NULL; |
314 |
} |
} |
315 |
return p; |
return p; |
316 |
} /* expand_path */ |
} |
317 |
|
|
318 |
|
|
319 |
/* Retrieve a registry entry with the directory given in @dir |
/* Retrieve a registry entry with the directory given in @dir |
326 |
char text[384] = {0}; |
char text[384] = {0}; |
327 |
DWORD nbytes, type; |
DWORD nbytes, type; |
328 |
HKEY reg_key = NULL; |
HKEY reg_key = NULL; |
329 |
char *p = NULL; |
char * p = NULL; |
330 |
|
|
331 |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
332 |
if( !rc_ok( rc ) ) |
if( !rc_ok( rc ) ) |
420 |
} |
} |
421 |
|
|
422 |
|
|
423 |
char * |
char* |
424 |
get_reg_entry_gpg (const char *key) |
get_reg_entry_gpg (const char *key) |
425 |
{ |
{ |
426 |
return get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key); |
char *p; |
427 |
|
p = get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key); |
428 |
|
if (!p || strlen (p) == 0) { |
429 |
|
free_if_alloc (p); |
430 |
|
return NULL; |
431 |
|
} |
432 |
|
return p; |
433 |
} |
} |
434 |
|
|
435 |
|
|
459 |
{ |
{ |
460 |
char *p, *pp; |
char *p, *pp; |
461 |
const char *lang; |
const char *lang; |
462 |
|
|
463 |
p = get_reg_entry (HKEY_CURRENT_USER, |
p = get_reg_entry (HKEY_CURRENT_USER, |
464 |
"Control Panel\\Mingw32\\NLS", "MODir"); |
"Control Panel\\Mingw32\\NLS", "MODir"); |
465 |
if (p) |
if (p) |
466 |
return p; |
return p; |
467 |
|
|
468 |
lang = get_gettext_langid (); |
lang = get_gettext_langid (); |
469 |
if (!lang) |
if (!lang) |
470 |
return NULL; |
return NULL; |
471 |
pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8]; |
pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8]; |
472 |
if (!pp) |
if (!pp) |
473 |
BUG (NULL); |
BUG (NULL); |
474 |
sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang); |
sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang); |
475 |
p = get_reg_entry_gpg4win (pp); |
p = get_reg_entry_gpg4win (pp); |
479 |
|
|
480 |
|
|
481 |
/* All valid configuration commands. */ |
/* All valid configuration commands. */ |
482 |
static const char * cfg [] = { |
static const char *cfg [] = { |
483 |
NULL, |
NULL, |
484 |
"CacheTime", |
"CacheTime", |
485 |
"WordWrap", |
"WordWrap", |
486 |
"FastMode", |
"FastMode", |
487 |
"Viewer", |
"Viewer", |
488 |
"KeylistMode", |
"WipeMode", |
489 |
"WipeMode", |
"AlwaysTrust", |
490 |
"AlwaysTrust", |
"AutoBackup", |
491 |
"AutoBackup", |
"BackupMode", |
492 |
"BackupMode", |
"DisableHotkeys", |
493 |
"DisableHotkeys", |
"NoCompressMultiMedia", |
494 |
"NoCompressMultiMedia", |
"Expert", |
495 |
"Expert", |
"FMProgressBar", |
496 |
"FMProgressBar", |
}; |
|
}; |
|
497 |
|
|
498 |
|
|
499 |
int |
int |
552 |
case CFG_VIEWER: |
case CFG_VIEWER: |
553 |
sprintf (buf, "%d", opt->use_viewer); |
sprintf (buf, "%d", opt->use_viewer); |
554 |
break; |
break; |
|
case CFG_KEYLISTMODE: |
|
|
sprintf (buf, "%d", opt->keylist_mode); |
|
|
break; |
|
555 |
case CFG_ALWAYSTRUST: |
case CFG_ALWAYSTRUST: |
556 |
sprintf (buf, "%d", opt->always_trust); |
sprintf (buf, "%d", opt->always_trust); |
557 |
break; |
break; |
583 |
if (rc) |
if (rc) |
584 |
goto leave; |
goto leave; |
585 |
} |
} |
|
if (opt->kserv_conf) { |
|
|
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig", |
|
|
opt->kserv_conf); |
|
|
if (rc) |
|
|
goto leave; |
|
|
} |
|
586 |
|
|
587 |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
588 |
strcpy (buf, " "); |
strcpy (buf, " "); |
630 |
int |
int |
631 |
get_reg_winpt_prefs (winpt_reg_prefs_s * opt) |
get_reg_winpt_prefs (winpt_reg_prefs_s * opt) |
632 |
{ |
{ |
633 |
char * val = NULL; |
char *val = NULL; |
634 |
size_t i; |
size_t i; |
635 |
|
|
636 |
for (i=1; i < DIM (cfg); i++) { |
for (i=1; i < DIM (cfg); i++) { |
660 |
case CFG_VIEWER: |
case CFG_VIEWER: |
661 |
opt->use_viewer = atol (val); |
opt->use_viewer = atol (val); |
662 |
break; |
break; |
|
case CFG_KEYLISTMODE: |
|
|
opt->keylist_mode = atol (val); |
|
|
break; |
|
663 |
case CFG_WIPEMODE: |
case CFG_WIPEMODE: |
664 |
opt->wipe_mode = atol (val); |
opt->wipe_mode = atol (val); |
665 |
break; |
break; |
690 |
if (val && val[0] != ' ') |
if (val && val[0] != ' ') |
691 |
opt->backup.path = m_strdup (val); |
opt->backup.path = m_strdup (val); |
692 |
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); |
|
693 |
|
|
694 |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
695 |
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); |