36 |
|
|
37 |
#define rc_ok(rc) ((rc) == ERROR_SUCCESS) |
#define rc_ok(rc) ((rc) == ERROR_SUCCESS) |
38 |
|
|
39 |
static gpg_filetype gpg_filetypes[] = { |
|
|
{"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}, |
55 |
#define WINPT_REG "Software\\WinPT" |
#define WINPT_REG "Software\\WinPT" |
56 |
|
|
57 |
|
|
58 |
|
/* Return != 0 if GPG4win is installed. */ |
59 |
|
int |
60 |
|
is_gpg4win_installed (void) |
61 |
|
{ |
62 |
|
char *p; |
63 |
|
|
64 |
|
p = get_reg_entry_gpg4win (NULL); |
65 |
|
if (!p) |
66 |
|
return 0; |
67 |
|
if (dir_exist_check (p)) { |
68 |
|
free_if_alloc (p); |
69 |
|
return 0; |
70 |
|
} |
71 |
|
free_if_alloc (p); |
72 |
|
return -1; |
73 |
|
} |
74 |
|
|
75 |
|
|
76 |
|
/* Return != 0 if GPGee is installed. */ |
77 |
|
int |
78 |
|
is_gpgee_installed (void) |
79 |
|
{ |
80 |
|
HKEY hk; |
81 |
|
LONG ec; |
82 |
|
|
83 |
|
ec = RegOpenKeyEx (HKEY_CURRENT_USER, "Software\\GPGee", 0, KEY_READ, &hk); |
84 |
|
if (ec == ERROR_SUCCESS) { |
85 |
|
RegCloseKey (hk); |
86 |
|
return -1; |
87 |
|
} |
88 |
|
|
89 |
|
return 0; |
90 |
|
} |
91 |
|
|
92 |
|
|
93 |
|
/* Free all members in the registry preference struct. */ |
94 |
void |
void |
95 |
free_reg_prefs (void) |
free_reg_prefs (void) |
96 |
{ |
{ |
98 |
free_if_alloc (reg_prefs.kserv_conf); |
free_if_alloc (reg_prefs.kserv_conf); |
99 |
free_if_alloc (reg_prefs.homedir); |
free_if_alloc (reg_prefs.homedir); |
100 |
memset (®_prefs, 0, sizeof reg_prefs); |
memset (®_prefs, 0, sizeof reg_prefs); |
101 |
} /* free_reg_prefs */ |
} |
102 |
|
|
103 |
|
|
104 |
/* Register the given WinPT filetype. */ |
/* Register the given WinPT filetype. */ |
105 |
static int |
static int |
106 |
regist_single_filetype (gpg_filetype *gfile) |
regist_single_filetype (gpg_filetype *gfile) |
107 |
{ |
{ |
108 |
char icon[256], prog[256]; |
char icon[256]; |
109 |
|
char prog[256]; |
110 |
|
|
111 |
memset (&icon, 0, sizeof (icon)); |
memset (&icon, 0, sizeof (icon)); |
112 |
GetModuleFileName (glob_hinst, prog, sizeof (prog)-1); |
GetModuleFileName (glob_hinst, prog, sizeof (prog)-1); |
113 |
_snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon); |
_snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon); |
114 |
return create_file_type (prog, gfile->ext, gfile->descr, icon); |
return create_file_type (prog, gfile->ext, gfile->descr, icon); |
115 |
} /* regist_single_filetype */ |
} |
116 |
|
|
117 |
|
|
118 |
/* Install the GPG related into the W32 resgistry, if the entry already |
/* Install the GPG related into the W32 resgistry, if the entry already |
145 |
} |
} |
146 |
|
|
147 |
return 0; |
return 0; |
148 |
} /* regist_inst_gpg */ |
} |
149 |
|
|
150 |
|
|
151 |
/* Install WinPT into the W32 registry, if the entry already |
/* Install WinPT into the W32 registry, if the entry already |
152 |
exists the function returns immediately. @with_ext can be |
exists the function returns immediately. @with_ext can be |
153 |
used to register some file types (if 1). @created contains |
used to register some file types (if 1). @created contains |
154 |
1 if the registry key was created. |
1 if the registry key was created. |
155 |
Return value: 0 on success. */ |
Return value: 0 on success. */ |
156 |
int |
int |
157 |
regist_inst_winpt (int with_ext, int * created) |
regist_inst_winpt (int with_ext, int *created) |
158 |
{ |
{ |
159 |
HKEY reg; |
HKEY reg; |
160 |
char *p = NULL; |
char *p = NULL; |
161 |
char modpath[MAX_PATH+1]; |
char modpath[MAX_PATH+1]; |
162 |
int rc, i, id, n = 0; |
int rc, i, id, n = 0; |
163 |
|
|
164 |
|
gpg_filetype gpg_filetypes[] = { |
165 |
|
{_("GPG Detached Signature"), ".sig", 1}, |
166 |
|
{_("GPG Encrypted Data"), ".gpg", 2}, |
167 |
|
{_("GPG Armored Data"), ".asc", 2}, |
168 |
|
{0} |
169 |
|
}; |
170 |
|
|
171 |
if (created) |
if (created) |
172 |
*created = 0; |
*created = 0; |
173 |
|
|
174 |
p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions"); |
p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions"); |
175 |
if (p && *p == '1') |
if ((p && *p == '1') || is_gpgee_installed ()) |
176 |
with_ext = 0; |
with_ext = 0; |
177 |
free_if_alloc (p); |
free_if_alloc (p); |
178 |
|
|
201 |
|
|
202 |
start: |
start: |
203 |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, ®); |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, ®); |
204 |
if (rc_ok (rc)) { |
if (rc_ok (rc)) { |
205 |
RegCloseKey (reg); |
RegCloseKey (reg); |
206 |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, ®); |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, ®); |
207 |
if (!rc_ok (rc)) { |
if( !rc_ok (rc)) { |
208 |
RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", ®); |
RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", ®); |
209 |
RegCloseKey (reg); |
RegCloseKey (reg); |
210 |
} |
} |
217 |
} |
} |
218 |
free_if_alloc (p); |
free_if_alloc (p); |
219 |
if (n) |
if (n) |
220 |
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1"); |
set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" ); |
221 |
return 0; |
return 0; |
222 |
} |
} |
223 |
rc = RegCreateKey(HKEY_CURRENT_USER, WINPT_REG, ®); |
rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, ®); |
224 |
if (!rc_ok (rc)) |
if (!rc_ok (rc)) |
225 |
return WPTERR_REGISTRY; |
return WPTERR_REGISTRY; |
226 |
if (created) |
if (created) |
227 |
*created = 1; |
*created = 1; |
228 |
RegCloseKey (reg); |
RegCloseKey (reg); |
229 |
if (n) |
if (n > 0 || is_gpgee_installed ()) |
230 |
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1"); |
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1"); |
231 |
if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) { |
if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) { |
232 |
while (n-- > 0) { |
while (n-- > 0) { |
235 |
break; |
break; |
236 |
} |
} |
237 |
} |
} |
238 |
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, |
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath); |
|
"Install Directory", modpath); |
|
239 |
} |
} |
|
|
|
240 |
return 0; |
return 0; |
241 |
} |
} |
242 |
|
|
244 |
/* Create a new filetype in the W32 registry. |
/* Create a new filetype in the W32 registry. |
245 |
We should really care of errors! Otherwise we can damage the registry! */ |
We should really care of errors! Otherwise we can damage the registry! */ |
246 |
int |
int |
247 |
create_file_type( const char *exefile, const char *ext, const char *extname, char *iconfile ) |
create_file_type (const char *exefile, const char *ext, |
248 |
|
const char *extname, char *iconfile) |
249 |
{ |
{ |
250 |
int rc; |
int rc; |
251 |
HKEY reg = NULL; |
HKEY reg = NULL; |
311 |
return NULL; |
return NULL; |
312 |
len += 1; |
len += 1; |
313 |
p = new char[len+1]; |
p = new char[len+1]; |
314 |
if( !p ) |
if (!p) |
315 |
return NULL; |
return NULL; |
316 |
len = ExpandEnvironmentStrings (path, p, len); |
len = ExpandEnvironmentStrings (path, p, len); |
317 |
if (!len) { |
if (!len) { |
319 |
return NULL; |
return NULL; |
320 |
} |
} |
321 |
return p; |
return p; |
322 |
} /* expand_path */ |
} |
323 |
|
|
324 |
|
|
325 |
/* Retrieve a registry entry with the directory given in @dir |
/* Retrieve a registry entry with the directory given in @dir |
332 |
char text[384] = {0}; |
char text[384] = {0}; |
333 |
DWORD nbytes, type; |
DWORD nbytes, type; |
334 |
HKEY reg_key = NULL; |
HKEY reg_key = NULL; |
335 |
char *p = NULL; |
char * p = NULL; |
336 |
|
|
337 |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
338 |
if( !rc_ok( rc ) ) |
if( !rc_ok( rc ) ) |
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); |
640 |
int |
int |
641 |
get_reg_winpt_prefs (winpt_reg_prefs_s * opt) |
get_reg_winpt_prefs (winpt_reg_prefs_s * opt) |
642 |
{ |
{ |
643 |
char * val = NULL; |
char *val = NULL; |
644 |
size_t i; |
size_t i; |
645 |
|
|
646 |
for (i=1; i < DIM (cfg); i++) { |
for (i=1; i < DIM (cfg); i++) { |