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