1 |
werner |
36 |
/* wptRegistry.cpp - W32 Registry access |
2 |
|
|
* Copyright (C) 2000-2005 Timo Schulz |
3 |
|
|
* |
4 |
|
|
* This file is part of WinPT. |
5 |
|
|
* |
6 |
|
|
* WinPT is free software; you can redistribute it and/or |
7 |
|
|
* modify it under the terms of the GNU General Public License |
8 |
|
|
* as published by the Free Software Foundation; either version 2 |
9 |
|
|
* of the License, or (at your option) any later version. |
10 |
|
|
* |
11 |
|
|
* WinPT is distributed in the hope that it will be useful, |
12 |
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
13 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
14 |
|
|
* General Public License for more details. |
15 |
|
|
* |
16 |
|
|
* You should have received a copy of the GNU General Public License |
17 |
|
|
* along with WinPT; if not, write to the Free Software Foundation, |
18 |
|
|
* Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 |
|
|
*/ |
20 |
|
|
|
21 |
|
|
#ifdef HAVE_CONFIG_H |
22 |
|
|
#include <config.h> |
23 |
|
|
#endif |
24 |
|
|
|
25 |
|
|
#include <windows.h> |
26 |
|
|
#include <stdio.h> |
27 |
|
|
|
28 |
|
|
#include "wptErrors.h" |
29 |
|
|
#include "wptW32API.h" |
30 |
|
|
#include "wptGPG.h" |
31 |
|
|
#include "wptRegistry.h" |
32 |
|
|
#include "wptKeyserver.h" |
33 |
|
|
#include "wptTypes.h" |
34 |
|
|
#include "wptNLS.h" |
35 |
|
|
#include "wptVersion.h" |
36 |
|
|
|
37 |
|
|
#define rc_ok(rc) ((rc) == ERROR_SUCCESS) |
38 |
|
|
|
39 |
werner |
48 |
static gpg_filetype gpg_filetypes[] = { |
40 |
|
|
{"GPG Detached Signature", ".sig", 1}, |
41 |
|
|
{"GPG Encrypted Data", ".gpg", 2}, |
42 |
|
|
{"GPG Armored Data", ".asc", 2}, |
43 |
|
|
{0} |
44 |
|
|
}; |
45 |
|
|
|
46 |
twoaday |
117 |
|
47 |
werner |
36 |
struct reg_hotkey_s reg_hotkeys[] = { |
48 |
twoaday |
69 |
{"ClipEncrypt", "", 0}, |
49 |
|
|
{"ClipDecrypt", "", 0}, |
50 |
|
|
{"ClipSign", "", 0}, |
51 |
|
|
{"ClipSignEnc", "", 0}, |
52 |
|
|
{"CwsEncrypt", "", 0}, |
53 |
|
|
{"CwsDecrypt", "", 0}, |
54 |
|
|
{"CwsSign", "", 0}, |
55 |
|
|
{"CwsSignEnc", "", 0}, |
56 |
|
|
{NULL, "", 0} |
57 |
werner |
36 |
}; |
58 |
|
|
|
59 |
|
|
winpt_reg_prefs_s reg_prefs; |
60 |
|
|
|
61 |
|
|
#define WINPT_REG "Software\\WinPT" |
62 |
|
|
|
63 |
|
|
|
64 |
twoaday |
128 |
/* 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 |
twoaday |
117 |
/* 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 |
werner |
36 |
void |
101 |
|
|
free_reg_prefs (void) |
102 |
|
|
{ |
103 |
|
|
free_if_alloc (reg_prefs.backup.path); |
104 |
|
|
free_if_alloc (reg_prefs.kserv_conf); |
105 |
|
|
free_if_alloc (reg_prefs.homedir); |
106 |
|
|
memset (®_prefs, 0, sizeof reg_prefs); |
107 |
twoaday |
117 |
} |
108 |
werner |
36 |
|
109 |
|
|
|
110 |
|
|
/* Register the given WinPT filetype. */ |
111 |
|
|
static int |
112 |
|
|
regist_single_filetype (gpg_filetype *gfile) |
113 |
|
|
{ |
114 |
twoaday |
128 |
char icon[256]; |
115 |
|
|
char prog[256]; |
116 |
werner |
36 |
|
117 |
|
|
memset (&icon, 0, sizeof (icon)); |
118 |
|
|
GetModuleFileName (glob_hinst, prog, sizeof (prog)-1); |
119 |
|
|
_snprintf (icon, sizeof (icon) -1, "%s,%d", prog, gfile->nicon); |
120 |
|
|
return create_file_type (prog, gfile->ext, gfile->descr, icon); |
121 |
twoaday |
117 |
} |
122 |
werner |
36 |
|
123 |
|
|
|
124 |
|
|
/* Install the GPG related into the W32 resgistry, if the entry already |
125 |
|
|
exists the function returns immediately. */ |
126 |
|
|
int |
127 |
|
|
regist_inst_gnupg (int create_mokey) |
128 |
|
|
{ |
129 |
|
|
int rc; |
130 |
|
|
HKEY reg; |
131 |
|
|
|
132 |
|
|
rc = RegOpenKeyEx( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", 0, KEY_READ, ® ); |
133 |
|
|
if( rc_ok( rc ) ) { |
134 |
|
|
RegCloseKey( reg ); |
135 |
|
|
return 0; |
136 |
|
|
} |
137 |
|
|
rc = RegCreateKey( HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", ® ); |
138 |
|
|
if( !rc_ok( rc ) ) |
139 |
|
|
return WPTERR_REGISTRY; |
140 |
|
|
RegCloseKey( reg ); |
141 |
|
|
if( create_mokey ) { |
142 |
|
|
rc = RegOpenKeyEx( HKEY_CURRENT_USER, "Control Panel\\MingW32\\NLS", 0, KEY_READ, ® ); |
143 |
|
|
if( rc_ok( rc ) ) { |
144 |
|
|
RegCloseKey( reg ); |
145 |
|
|
return 0; |
146 |
|
|
} |
147 |
|
|
rc = RegCreateKey( HKEY_CURRENT_USER, "Control Panel\\MingW32\\NLS", ® ); |
148 |
|
|
if( !rc_ok( rc ) ) |
149 |
|
|
return WPTERR_REGISTRY; |
150 |
|
|
RegCloseKey( reg ); |
151 |
|
|
} |
152 |
|
|
|
153 |
|
|
return 0; |
154 |
twoaday |
128 |
} |
155 |
werner |
36 |
|
156 |
|
|
|
157 |
twoaday |
117 |
/* Install WinPT into the W32 registry, if the entry already |
158 |
twoaday |
85 |
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 |
werner |
36 |
int |
163 |
twoaday |
117 |
regist_inst_winpt (int with_ext, int *created) |
164 |
werner |
36 |
{ |
165 |
|
|
HKEY reg; |
166 |
twoaday |
80 |
char *p = NULL; |
167 |
|
|
char modpath[MAX_PATH+1]; |
168 |
werner |
36 |
int rc, i, id, n = 0; |
169 |
|
|
|
170 |
twoaday |
85 |
if (created) |
171 |
werner |
36 |
*created = 0; |
172 |
|
|
|
173 |
|
|
p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions"); |
174 |
twoaday |
117 |
if ((p && *p == '1') || is_gpgee_installed ()) |
175 |
werner |
36 |
with_ext = 0; |
176 |
twoaday |
85 |
free_if_alloc (p); |
177 |
werner |
36 |
|
178 |
twoaday |
85 |
if (with_ext) { |
179 |
|
|
id = msg_box (NULL, _("WinPT can register some GPG file types for you so they can " |
180 |
werner |
36 |
"be processed with a double click in the explorer.\n" |
181 |
twoaday |
85 |
"Do you want to continue?"), _("WinPT"), MB_YESNO|MB_INFO); |
182 |
|
|
if (id == IDNO) { |
183 |
|
|
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1"); |
184 |
werner |
36 |
goto start; |
185 |
|
|
} |
186 |
twoaday |
85 |
for (i = 0; gpg_filetypes[i].ext; i++) { |
187 |
|
|
rc = RegOpenKeyEx (HKEY_CLASSES_ROOT, gpg_filetypes[i].ext, 0, KEY_READ, ®); |
188 |
|
|
if (rc_ok (rc)) { |
189 |
|
|
RegCloseKey (reg); |
190 |
|
|
id = log_box (_("WinPT WARNING"), MB_YESNO|MB_INFO, |
191 |
werner |
36 |
_("It seems there was already a '%s' file type registered by another application.\n" |
192 |
twoaday |
85 |
"Do you want to overwrite it?"), gpg_filetypes[i].ext); |
193 |
|
|
if (id == IDNO) |
194 |
werner |
36 |
continue; |
195 |
|
|
} |
196 |
twoaday |
85 |
regist_single_filetype (&gpg_filetypes[i]); |
197 |
werner |
36 |
n++; |
198 |
|
|
} |
199 |
|
|
} |
200 |
|
|
|
201 |
|
|
start: |
202 |
twoaday |
85 |
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG, 0, KEY_READ, ®); |
203 |
twoaday |
117 |
if (rc_ok (rc)) { |
204 |
twoaday |
85 |
RegCloseKey (reg); |
205 |
|
|
rc = RegOpenKeyEx (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", 0, KEY_READ, ®); |
206 |
twoaday |
117 |
if( !rc_ok (rc)) { |
207 |
twoaday |
85 |
RegCreateKey (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", ®); |
208 |
|
|
RegCloseKey (reg); |
209 |
werner |
36 |
} |
210 |
|
|
p = get_reg_entry_keyserver ("Default"); |
211 |
|
|
if (!p) { |
212 |
|
|
char buf[16]; |
213 |
|
|
sprintf (buf, "%d", HKP_PORT); |
214 |
|
|
set_reg_entry_keyserver ("Default_Port", buf); |
215 |
|
|
set_reg_entry_keyserver ("Default", DEF_HKP_KEYSERVER); |
216 |
|
|
} |
217 |
twoaday |
85 |
free_if_alloc (p); |
218 |
|
|
if (n) |
219 |
twoaday |
128 |
set_reg_entry( HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1" ); |
220 |
werner |
36 |
return 0; |
221 |
|
|
} |
222 |
twoaday |
117 |
rc = RegCreateKey (HKEY_CURRENT_USER, WINPT_REG, ®); |
223 |
twoaday |
85 |
if (!rc_ok (rc)) |
224 |
werner |
36 |
return WPTERR_REGISTRY; |
225 |
twoaday |
85 |
if (created) |
226 |
werner |
36 |
*created = 1; |
227 |
twoaday |
85 |
RegCloseKey (reg); |
228 |
|
|
if (n) |
229 |
|
|
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Extensions", "1"); |
230 |
twoaday |
80 |
if ((n=GetModuleFileName (NULL, modpath, MAX_PATH-1)) > 0) { |
231 |
|
|
while (n-- > 0) { |
232 |
|
|
if (modpath[n] == '\\') { |
233 |
|
|
modpath[n] = 0; |
234 |
|
|
break; |
235 |
|
|
} |
236 |
|
|
} |
237 |
twoaday |
117 |
set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "Install Directory", modpath); |
238 |
twoaday |
80 |
} |
239 |
werner |
36 |
return 0; |
240 |
twoaday |
80 |
} |
241 |
werner |
36 |
|
242 |
|
|
|
243 |
|
|
/* Create a new filetype in the W32 registry. |
244 |
|
|
We should really care of errors! Otherwise we can damage the registry! */ |
245 |
|
|
int |
246 |
twoaday |
128 |
create_file_type (const char *exefile, const char *ext, |
247 |
|
|
const char *extname, char *iconfile) |
248 |
werner |
36 |
{ |
249 |
|
|
int rc; |
250 |
|
|
HKEY reg = NULL; |
251 |
|
|
char deficon[256], defexec[256], p_exefile[256]; |
252 |
|
|
|
253 |
|
|
|
254 |
|
|
rc = RegCreateKey( HKEY_CLASSES_ROOT, ext, ® ); |
255 |
|
|
if( rc_ok( rc ) ) |
256 |
|
|
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)extname, strlen( extname ) ); |
257 |
|
|
if( rc_ok( rc ) ) |
258 |
|
|
rc = RegCloseKey( reg ); |
259 |
|
|
if( rc_ok( rc ) ) |
260 |
|
|
rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, ® ); |
261 |
|
|
if( rc_ok( rc ) ) |
262 |
|
|
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *) extname, strlen( extname ) ); |
263 |
|
|
if( rc_ok( rc ) ) |
264 |
|
|
rc = RegCloseKey( reg ); |
265 |
|
|
if( !rc_ok( rc ) ) { |
266 |
|
|
rc = WPTERR_REGISTRY; |
267 |
|
|
goto leave; |
268 |
|
|
} |
269 |
|
|
|
270 |
|
|
memset( &deficon, 0, sizeof deficon ); |
271 |
|
|
_snprintf( deficon, sizeof deficon - 1, "%s\\DefaultIcon", extname ); |
272 |
|
|
memset( &defexec, 0, sizeof defexec ); |
273 |
|
|
_snprintf( defexec, sizeof defexec - 1, "%s\\shell\\open\\command", extname ); |
274 |
|
|
memset( &p_exefile, 0, sizeof p_exefile ); |
275 |
|
|
_snprintf( p_exefile, sizeof p_exefile - 1, "%s %%1", exefile ); |
276 |
|
|
|
277 |
|
|
rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, ® ); |
278 |
|
|
if( rc_ok( rc ) ) |
279 |
|
|
rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (byte *)iconfile, strlen( iconfile ) ); |
280 |
|
|
if( rc_ok( rc ) ) |
281 |
|
|
rc = RegCloseKey( reg ); |
282 |
|
|
if( rc_ok( rc ) ) |
283 |
|
|
rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, ® ); |
284 |
|
|
if( rc_ok( rc ) ) |
285 |
|
|
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)p_exefile, strlen( exefile ) ); |
286 |
|
|
if( rc_ok( rc ) ) |
287 |
|
|
rc = RegCloseKey( reg ); |
288 |
|
|
if( !rc_ok( rc ) ) { |
289 |
|
|
rc = WPTERR_REGISTRY; |
290 |
|
|
goto leave; |
291 |
|
|
} |
292 |
|
|
|
293 |
|
|
leave: |
294 |
|
|
if( reg ) |
295 |
|
|
RegCloseKey( reg ); |
296 |
|
|
return rc; |
297 |
|
|
} /* create_file_type */ |
298 |
|
|
|
299 |
|
|
|
300 |
|
|
/* Expand a string with %foo% entries so that %foo% will |
301 |
|
|
be replaced with its actual value. */ |
302 |
|
|
static char * |
303 |
|
|
expand_path (const char *path) |
304 |
|
|
{ |
305 |
|
|
DWORD len; |
306 |
|
|
char *p; |
307 |
|
|
|
308 |
|
|
len = ExpandEnvironmentStrings (path, NULL, 0); |
309 |
|
|
if (!len) |
310 |
|
|
return NULL; |
311 |
|
|
len += 1; |
312 |
|
|
p = new char[len+1]; |
313 |
twoaday |
128 |
if (!p) |
314 |
werner |
36 |
return NULL; |
315 |
|
|
len = ExpandEnvironmentStrings (path, p, len); |
316 |
|
|
if (!len) { |
317 |
|
|
free_if_alloc (p); |
318 |
|
|
return NULL; |
319 |
|
|
} |
320 |
|
|
return p; |
321 |
twoaday |
128 |
} |
322 |
werner |
36 |
|
323 |
|
|
|
324 |
|
|
/* Retrieve a registry entry with the directory given in @dir |
325 |
|
|
and the key given in @key. |
326 |
|
|
Return value is the value or NULL otherwise. */ |
327 |
|
|
char* |
328 |
|
|
get_reg_entry (HKEY root_key, const char * dir, const char * key) |
329 |
|
|
{ |
330 |
|
|
int rc; |
331 |
|
|
char text[384] = {0}; |
332 |
twoaday |
69 |
DWORD nbytes, type; |
333 |
werner |
36 |
HKEY reg_key = NULL; |
334 |
twoaday |
128 |
char * p = NULL; |
335 |
werner |
36 |
|
336 |
|
|
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
337 |
|
|
if( !rc_ok( rc ) ) |
338 |
|
|
goto leave; |
339 |
|
|
nbytes = sizeof (text) - 1; |
340 |
|
|
type = REG_SZ; |
341 |
|
|
|
342 |
|
|
rc = RegQueryValueEx (reg_key, key, 0, &type, (BYTE *)&text, &nbytes); |
343 |
|
|
if (!rc_ok (rc) || !nbytes) |
344 |
|
|
goto leave; |
345 |
|
|
|
346 |
|
|
if (type == REG_EXPAND_SZ && strchr (text, '%')) |
347 |
|
|
p = expand_path (text); |
348 |
|
|
else { |
349 |
|
|
p = new char[nbytes + 1]; |
350 |
|
|
if (!p) |
351 |
|
|
BUG (0); |
352 |
|
|
memcpy (p, text, nbytes); |
353 |
|
|
p[nbytes] = '\0'; |
354 |
|
|
} |
355 |
|
|
|
356 |
|
|
leave: |
357 |
|
|
if (reg_key) |
358 |
|
|
RegCloseKey (reg_key); |
359 |
|
|
return p; |
360 |
|
|
} |
361 |
|
|
|
362 |
|
|
|
363 |
|
|
/* XXX: use REG_EXPAND_SZ to support multi user environments. |
364 |
|
|
keep this type and do not overwrite it with REG_SZ. */ |
365 |
|
|
|
366 |
|
|
/* Set a registry entry. */ |
367 |
|
|
int |
368 |
|
|
set_reg_entry (HKEY root_key, const char *dir, const char *key, |
369 |
|
|
const char *value) |
370 |
|
|
{ |
371 |
|
|
int rc = 0; |
372 |
|
|
HKEY reg_key; |
373 |
|
|
|
374 |
|
|
rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, ®_key ); |
375 |
|
|
if( !rc_ok( rc ) ) |
376 |
|
|
return WPTERR_REGISTRY; |
377 |
|
|
rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) ); |
378 |
|
|
if( !rc_ok( rc ) ) |
379 |
|
|
rc = WPTERR_REGISTRY; |
380 |
|
|
RegCloseKey( reg_key ); |
381 |
|
|
return rc; |
382 |
|
|
} /* set_reg_entry */ |
383 |
|
|
|
384 |
|
|
|
385 |
|
|
int |
386 |
|
|
set_reg_key( HKEY root_key, const char * dir, const char * key, |
387 |
|
|
const char * value ) |
388 |
|
|
{ |
389 |
|
|
int rc = 0; |
390 |
|
|
HKEY reg_key; |
391 |
|
|
|
392 |
|
|
rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, ®_key ); |
393 |
|
|
if( !rc_ok( rc ) ) |
394 |
|
|
return WPTERR_REGISTRY; |
395 |
|
|
|
396 |
|
|
rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) ); |
397 |
|
|
if( !rc_ok( rc ) ) { |
398 |
|
|
if ( RegCreateKey( root_key, key, ®_key ) != ERROR_SUCCESS ) { |
399 |
|
|
rc = WPTERR_REGISTRY; |
400 |
|
|
goto leave; |
401 |
|
|
} |
402 |
|
|
rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) ); |
403 |
|
|
if ( !rc_ok( rc ) ) |
404 |
|
|
rc = WPTERR_REGISTRY; |
405 |
|
|
} |
406 |
|
|
|
407 |
|
|
leave: |
408 |
|
|
RegCloseKey( reg_key ); |
409 |
|
|
return rc; |
410 |
|
|
} /* set_reg_key */ |
411 |
|
|
|
412 |
|
|
|
413 |
|
|
int |
414 |
|
|
set_reg_entry_gpg (const char * key, const char * value) |
415 |
|
|
{ |
416 |
|
|
return set_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key, value); |
417 |
|
|
} |
418 |
|
|
|
419 |
|
|
|
420 |
|
|
int |
421 |
|
|
set_reg_entry_mo (const char * value) |
422 |
|
|
{ |
423 |
|
|
return set_reg_entry (HKEY_CURRENT_USER, "Control Panel\\Mingw32\\NLS", |
424 |
|
|
"MODir", value); |
425 |
|
|
} |
426 |
|
|
|
427 |
|
|
|
428 |
|
|
char * |
429 |
|
|
get_reg_entry_gpg (const char *key) |
430 |
|
|
{ |
431 |
|
|
return get_reg_entry (HKEY_CURRENT_USER, "Software\\GNU\\GnuPG", key); |
432 |
|
|
} |
433 |
|
|
|
434 |
|
|
|
435 |
twoaday |
73 |
/* Return if possible the GPG4Win installation directory concatenated |
436 |
|
|
with the string in @path if given. */ |
437 |
|
|
char* |
438 |
|
|
get_reg_entry_gpg4win (const char *path) |
439 |
|
|
{ |
440 |
|
|
char *p, *pp; |
441 |
|
|
p = get_reg_entry (HKEY_LOCAL_MACHINE, |
442 |
|
|
"Software\\GNU\\GnuPG", "Install Directory"); |
443 |
|
|
if (!p) |
444 |
|
|
return NULL; |
445 |
|
|
if (!path) |
446 |
|
|
return p; |
447 |
|
|
pp = new char[strlen (p) + strlen (path) + 4]; |
448 |
|
|
if (!pp) |
449 |
|
|
BUG (NULL); |
450 |
|
|
sprintf (pp, "%s\\%s", p, path); |
451 |
|
|
free_if_alloc (p); |
452 |
|
|
return pp; |
453 |
|
|
} |
454 |
|
|
|
455 |
|
|
|
456 |
|
|
char* |
457 |
|
|
get_reg_entry_mo (void) |
458 |
werner |
36 |
{ |
459 |
twoaday |
76 |
char *p, *pp; |
460 |
|
|
const char *lang; |
461 |
twoaday |
117 |
|
462 |
twoaday |
73 |
p = get_reg_entry (HKEY_CURRENT_USER, |
463 |
|
|
"Control Panel\\Mingw32\\NLS", "MODir"); |
464 |
twoaday |
76 |
if (p) |
465 |
|
|
return p; |
466 |
twoaday |
117 |
|
467 |
twoaday |
76 |
lang = get_gettext_langid (); |
468 |
twoaday |
117 |
if (!lang) |
469 |
|
|
return NULL; |
470 |
twoaday |
76 |
pp = new char[strlen ("share\\xxxxx\\locale\\LC_MESSAGES")+8]; |
471 |
twoaday |
117 |
if (!pp) |
472 |
twoaday |
76 |
BUG (NULL); |
473 |
|
|
sprintf (pp, "share\\locale\\%s\\LC_MESSAGES", lang); |
474 |
|
|
p = get_reg_entry_gpg4win (pp); |
475 |
|
|
free_if_alloc (pp); |
476 |
twoaday |
73 |
return p; |
477 |
werner |
36 |
} |
478 |
|
|
|
479 |
|
|
|
480 |
|
|
/* All valid configuration commands. */ |
481 |
|
|
static const char * cfg [] = { |
482 |
|
|
NULL, |
483 |
|
|
"CacheTime", |
484 |
|
|
"WordWrap", |
485 |
|
|
"FastMode", |
486 |
|
|
"Viewer", |
487 |
|
|
"KeylistMode", |
488 |
|
|
"WipeMode", |
489 |
|
|
"AlwaysTrust", |
490 |
|
|
"AutoBackup", |
491 |
|
|
"BackupMode", |
492 |
|
|
"DisableHotkeys", |
493 |
|
|
"NoCompressMultiMedia", |
494 |
|
|
"Expert", |
495 |
|
|
"FMProgressBar", |
496 |
|
|
}; |
497 |
|
|
|
498 |
|
|
|
499 |
|
|
int |
500 |
|
|
set_reg_winpt_single (int id, int val) |
501 |
|
|
{ |
502 |
|
|
char buf[64]; |
503 |
|
|
int rc; |
504 |
|
|
|
505 |
|
|
sprintf (buf, "%d", val); |
506 |
|
|
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id], buf); |
507 |
|
|
return rc; |
508 |
|
|
} |
509 |
|
|
|
510 |
|
|
|
511 |
|
|
int |
512 |
|
|
get_reg_winpt_single (int id) |
513 |
|
|
{ |
514 |
twoaday |
128 |
char * buf = NULL; |
515 |
werner |
36 |
int val = 0; |
516 |
|
|
|
517 |
|
|
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]); |
518 |
|
|
if (buf && *buf != ' ') |
519 |
|
|
val = 1; |
520 |
|
|
else if (!buf) |
521 |
|
|
val = -1; |
522 |
|
|
free_if_alloc (buf); |
523 |
|
|
return val; |
524 |
|
|
} |
525 |
|
|
|
526 |
|
|
|
527 |
|
|
/* Saves the winpt preferences in the registry. */ |
528 |
|
|
int |
529 |
|
|
set_reg_winpt_prefs (winpt_reg_prefs_s * opt) |
530 |
|
|
{ |
531 |
|
|
char buf[128]; |
532 |
twoaday |
73 |
size_t i; |
533 |
|
|
int rc = 0; |
534 |
werner |
36 |
|
535 |
|
|
for (i=1; i < DIM (cfg); i++) { |
536 |
|
|
switch (i) { |
537 |
|
|
case CFG_CACHETIME: |
538 |
|
|
sprintf (buf, "%d", opt->cache_time); |
539 |
|
|
break; |
540 |
|
|
case CFG_WORDWRAP: |
541 |
|
|
sprintf (buf, "%d", opt->word_wrap); |
542 |
|
|
break; |
543 |
|
|
case CFG_WIPEMODE: |
544 |
|
|
sprintf (buf, "%d", opt->wipe_mode); |
545 |
|
|
break; |
546 |
|
|
case CFG_FASTMODE: |
547 |
|
|
sprintf (buf, "%d", opt->use_tmpfiles); |
548 |
|
|
break; |
549 |
|
|
case CFG_NOZIP_MMEDIA: |
550 |
|
|
sprintf (buf, "%d", opt->no_zip_mmedia); |
551 |
|
|
break; |
552 |
|
|
case CFG_VIEWER: |
553 |
|
|
sprintf (buf, "%d", opt->use_viewer); |
554 |
|
|
break; |
555 |
|
|
case CFG_KEYLISTMODE: |
556 |
|
|
sprintf (buf, "%d", opt->keylist_mode); |
557 |
|
|
break; |
558 |
|
|
case CFG_ALWAYSTRUST: |
559 |
|
|
sprintf (buf, "%d", opt->always_trust); |
560 |
|
|
break; |
561 |
|
|
case CFG_AUTOBACKUP: |
562 |
|
|
sprintf (buf, "%d", opt->auto_backup); |
563 |
|
|
break; |
564 |
|
|
case CFG_AUTOBAKMODE: |
565 |
|
|
sprintf (buf, "%d", opt->backup.mode); |
566 |
|
|
break; |
567 |
|
|
case CFG_DISHOTKEYS: |
568 |
|
|
sprintf (buf, "%d", opt->no_hotkeys); |
569 |
|
|
break; |
570 |
|
|
case CFG_EXPERT: |
571 |
|
|
sprintf (buf, "%d", opt->expert); |
572 |
|
|
break; |
573 |
|
|
|
574 |
|
|
case CFG_FM_PROGRESS: |
575 |
|
|
sprintf (buf, "%d", opt->fm.progress); |
576 |
|
|
break; |
577 |
|
|
} |
578 |
|
|
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf); |
579 |
|
|
if (rc) |
580 |
|
|
goto leave; |
581 |
|
|
} |
582 |
|
|
|
583 |
|
|
if (opt->backup.path) { |
584 |
|
|
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "BackupPath", |
585 |
|
|
opt->backup.path); |
586 |
|
|
if (rc) |
587 |
|
|
goto leave; |
588 |
|
|
} |
589 |
|
|
if (opt->kserv_conf) { |
590 |
|
|
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig", |
591 |
|
|
opt->kserv_conf); |
592 |
|
|
if (rc) |
593 |
|
|
goto leave; |
594 |
|
|
} |
595 |
|
|
|
596 |
|
|
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
597 |
|
|
strcpy (buf, " "); |
598 |
|
|
if (reg_hotkeys[i].enabled) |
599 |
|
|
strcpy (buf, reg_hotkeys[i].key); |
600 |
|
|
rc = set_reg_key (HKEY_CURRENT_USER, WINPT_REG, |
601 |
|
|
reg_hotkeys[i].reg_entry, buf); |
602 |
|
|
if (rc) |
603 |
|
|
break; |
604 |
|
|
} |
605 |
|
|
|
606 |
|
|
leave: |
607 |
|
|
if (rc) { |
608 |
|
|
msg_box (NULL, _("Could not write to Registry."), _("Preferences"), MB_ERR); |
609 |
|
|
return rc; |
610 |
|
|
} |
611 |
|
|
return 0; |
612 |
|
|
} |
613 |
|
|
|
614 |
|
|
|
615 |
|
|
int |
616 |
|
|
set_reg_winpt_flag (const char * name, int val) |
617 |
|
|
{ |
618 |
|
|
return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name, val? "1" : "0"); |
619 |
|
|
} /* set_reg_winpt_flag */ |
620 |
|
|
|
621 |
|
|
|
622 |
|
|
int |
623 |
|
|
get_reg_winpt_flag (const char * name) |
624 |
|
|
{ |
625 |
|
|
char * buf; |
626 |
|
|
int flag = 0; |
627 |
|
|
|
628 |
|
|
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name); |
629 |
|
|
if (buf && buf[0] == '1') |
630 |
|
|
flag = 1; |
631 |
|
|
else if (!buf || buf && buf[0] != '0') |
632 |
|
|
flag = -1; |
633 |
|
|
free_if_alloc (buf); |
634 |
|
|
return flag; |
635 |
|
|
} /* get_reg_winpt_flag */ |
636 |
|
|
|
637 |
|
|
|
638 |
|
|
/* Retrieve the winpt preferences from the registry. */ |
639 |
|
|
int |
640 |
|
|
get_reg_winpt_prefs (winpt_reg_prefs_s * opt) |
641 |
|
|
{ |
642 |
twoaday |
117 |
char *val = NULL; |
643 |
twoaday |
73 |
size_t i; |
644 |
werner |
36 |
|
645 |
|
|
for (i=1; i < DIM (cfg); i++) { |
646 |
|
|
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i]); |
647 |
|
|
if (!val || *val == ' ') { |
648 |
|
|
free_if_alloc (val); |
649 |
|
|
continue; |
650 |
|
|
} |
651 |
|
|
switch (i) { |
652 |
|
|
case CFG_CACHETIME: |
653 |
|
|
opt->cache_time = atol (val); |
654 |
|
|
/* We do NOT support passphrase caching for more than an hour. |
655 |
|
|
* Perhaps we should allow it, but for now we silently drop this. |
656 |
|
|
*/ |
657 |
|
|
if (opt->cache_time > 3600) |
658 |
|
|
opt->cache_time = 3600; |
659 |
|
|
break; |
660 |
|
|
case CFG_WORDWRAP: |
661 |
|
|
opt->word_wrap = atol (val); |
662 |
|
|
break; |
663 |
|
|
case CFG_FASTMODE: |
664 |
|
|
opt->use_tmpfiles = atol (val); |
665 |
|
|
break; |
666 |
|
|
case CFG_NOZIP_MMEDIA: |
667 |
|
|
opt->no_zip_mmedia = atol (val); |
668 |
|
|
break; |
669 |
|
|
case CFG_VIEWER: |
670 |
|
|
opt->use_viewer = atol (val); |
671 |
|
|
break; |
672 |
|
|
case CFG_KEYLISTMODE: |
673 |
|
|
opt->keylist_mode = atol (val); |
674 |
|
|
break; |
675 |
|
|
case CFG_WIPEMODE: |
676 |
|
|
opt->wipe_mode = atol (val); |
677 |
|
|
break; |
678 |
|
|
case CFG_DISHOTKEYS: |
679 |
|
|
opt->no_hotkeys = atol (val); |
680 |
|
|
break; |
681 |
|
|
case CFG_ALWAYSTRUST: |
682 |
|
|
opt->always_trust = atol (val); |
683 |
|
|
break; |
684 |
|
|
case CFG_AUTOBACKUP: |
685 |
|
|
opt->auto_backup = atol (val); |
686 |
|
|
break; |
687 |
|
|
case CFG_AUTOBAKMODE: |
688 |
|
|
opt->backup.mode = atol (val); |
689 |
|
|
break; |
690 |
|
|
case CFG_EXPERT: |
691 |
|
|
opt->expert = atol (val); |
692 |
|
|
break; |
693 |
|
|
|
694 |
|
|
case CFG_FM_PROGRESS: |
695 |
|
|
opt->fm.progress = atol (val); |
696 |
|
|
break; |
697 |
|
|
} |
698 |
|
|
free_if_alloc (val); |
699 |
|
|
} |
700 |
|
|
|
701 |
|
|
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "BackupPath"); |
702 |
|
|
if (val && val[0] != ' ') |
703 |
|
|
opt->backup.path = m_strdup (val); |
704 |
|
|
free_if_alloc (val); |
705 |
|
|
|
706 |
|
|
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, "KeyserverConfig"); |
707 |
|
|
if (val && val[0] != ' ') |
708 |
|
|
opt->kserv_conf = m_strdup (val); |
709 |
|
|
free_if_alloc (val); |
710 |
|
|
|
711 |
|
|
for (i=0; reg_hotkeys[i].reg_entry; i++) { |
712 |
|
|
val = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, reg_hotkeys[i].reg_entry); |
713 |
|
|
if (val && val[0] != ' ') { |
714 |
|
|
reg_hotkeys[i].key[0] = *val; |
715 |
|
|
reg_hotkeys[i].enabled = 1; |
716 |
|
|
} |
717 |
|
|
else |
718 |
|
|
reg_hotkeys[i].enabled = 0; |
719 |
|
|
free_if_alloc (val); |
720 |
|
|
} |
721 |
|
|
return 0; |
722 |
|
|
} /* get_reg_winpt_prefs */ |
723 |
|
|
|
724 |
|
|
|
725 |
|
|
char* |
726 |
|
|
get_reg_entry_keyserver (const char *name) |
727 |
|
|
{ |
728 |
|
|
char * p = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name); |
729 |
|
|
if (p && !strcmp (p, "")) { |
730 |
|
|
free_if_alloc (p); |
731 |
|
|
return NULL; |
732 |
|
|
} |
733 |
|
|
return p; |
734 |
|
|
} |
735 |
|
|
|
736 |
|
|
|
737 |
|
|
void |
738 |
|
|
get_reg_proxy_prefs (char ** host, int * port, char ** user, char ** pass) |
739 |
|
|
{ |
740 |
|
|
if (host) |
741 |
|
|
*host = get_reg_entry_keyserver ("Host"); |
742 |
|
|
if (user) |
743 |
|
|
*user = get_reg_entry_keyserver ("User"); |
744 |
|
|
if (pass) |
745 |
|
|
*pass = get_reg_entry_keyserver ("Pass"); |
746 |
|
|
if (port) { |
747 |
|
|
char * p = get_reg_entry_keyserver ("Port"); |
748 |
|
|
if (p) { |
749 |
|
|
*port = atol (p); |
750 |
|
|
free_if_alloc (p); |
751 |
|
|
} |
752 |
|
|
} |
753 |
|
|
} /* get_reg_proxy_prefs */ |
754 |
|
|
|
755 |
|
|
|
756 |
|
|
int |
757 |
|
|
set_reg_entry_keyserver( const char * name, const char * val ) |
758 |
|
|
{ |
759 |
|
|
return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val ); |
760 |
|
|
} /* set_reg_entry_keyserver */ |
761 |
|
|
|
762 |
|
|
|
763 |
|
|
int |
764 |
|
|
set_reg_proxy_prefs( const char * host, int port, const char * user, const char * pass ) |
765 |
|
|
{ |
766 |
|
|
int rc; |
767 |
|
|
|
768 |
|
|
rc = set_reg_entry_keyserver( "Host", host? host : "" ); |
769 |
|
|
if( !rc ) { |
770 |
|
|
char buf[32]; |
771 |
|
|
sprintf( buf, "%d", port ); |
772 |
|
|
rc = set_reg_entry_keyserver( "Port", buf ); |
773 |
|
|
} |
774 |
|
|
if( !rc ) |
775 |
|
|
rc = set_reg_entry_keyserver( "User", user? user : "" ); |
776 |
|
|
if( !rc ) |
777 |
|
|
rc = set_reg_entry_keyserver( "Pass", pass? pass : "" ); |
778 |
|
|
return rc; |
779 |
|
|
} /* set_reg_proxy_prefs */ |