1 |
/* wptRegistry.cpp - W32 Registry access |
/* wptRegistry.cpp - Windows Registry access |
2 |
* Copyright (C) 2000-2005 Timo Schulz |
* Copyright (C) 2000-2006 Timo Schulz |
3 |
* |
* |
4 |
* This file is part of WinPT. |
* This file is part of WinPT. |
5 |
* |
* |
237 |
|
|
238 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, ext, ® ); |
rc = RegCreateKey( HKEY_CLASSES_ROOT, ext, ® ); |
239 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
240 |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)extname, strlen( extname ) ); |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)extname, strlen( extname ) ); |
241 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
242 |
rc = RegCloseKey( reg ); |
rc = RegCloseKey( reg ); |
243 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
244 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, ® ); |
rc = RegCreateKey( HKEY_CLASSES_ROOT, extname, ® ); |
245 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
246 |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *) extname, strlen( extname ) ); |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *) extname, strlen( extname ) ); |
247 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
248 |
rc = RegCloseKey( reg ); |
rc = RegCloseKey( reg ); |
249 |
if( !rc_ok( rc ) ) { |
if( !rc_ok( rc ) ) { |
260 |
|
|
261 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, ® ); |
rc = RegCreateKey( HKEY_CLASSES_ROOT, deficon, ® ); |
262 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
263 |
rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (byte *)iconfile, strlen( iconfile ) ); |
rc = RegSetValueEx(reg, NULL, 0, REG_SZ, (BYTE *)iconfile, strlen( iconfile ) ); |
264 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
265 |
rc = RegCloseKey( reg ); |
rc = RegCloseKey( reg ); |
266 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
267 |
rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, ® ); |
rc = RegCreateKey( HKEY_CLASSES_ROOT, defexec, ® ); |
268 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
269 |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (byte *)p_exefile, strlen( exefile ) ); |
rc = RegSetValueEx( reg, NULL, 0, REG_SZ, (BYTE *)p_exefile, strlen( exefile ) ); |
270 |
if( rc_ok( rc ) ) |
if( rc_ok( rc ) ) |
271 |
rc = RegCloseKey( reg ); |
rc = RegCloseKey( reg ); |
272 |
if( !rc_ok( rc ) ) { |
if( !rc_ok( rc ) ) { |
278 |
if( reg ) |
if( reg ) |
279 |
RegCloseKey( reg ); |
RegCloseKey( reg ); |
280 |
return rc; |
return rc; |
281 |
} /* create_file_type */ |
} |
282 |
|
|
283 |
|
|
284 |
/* Expand a string with %foo% entries so that %foo% will |
/* Expand a string with %foo% entries so that %foo% will |
309 |
and the key given in @key. |
and the key given in @key. |
310 |
Return value is the value or NULL otherwise. */ |
Return value is the value or NULL otherwise. */ |
311 |
char* |
char* |
312 |
get_reg_entry (HKEY root_key, const char * dir, const char * key) |
get_reg_entry (HKEY root_key, const char *dir, const char *key) |
313 |
{ |
{ |
|
int rc; |
|
|
char text[384] = {0}; |
|
|
DWORD nbytes, type; |
|
314 |
HKEY reg_key = NULL; |
HKEY reg_key = NULL; |
315 |
char * p = NULL; |
char *p = NULL, *pp; |
316 |
|
DWORD type = REG_SZ, nbytes = 0; |
317 |
|
int rc; |
318 |
|
|
319 |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_QUERY_VALUE, ®_key); |
320 |
if( !rc_ok( rc ) ) |
if (!rc_ok (rc)) |
321 |
goto leave; |
goto leave; |
322 |
nbytes = sizeof (text) - 1; |
rc = RegQueryValueEx (reg_key, key, NULL, &type, NULL, &nbytes); |
323 |
type = REG_SZ; |
if (!rc_ok (rc)) |
|
|
|
|
rc = RegQueryValueEx (reg_key, key, 0, &type, (BYTE *)&text, &nbytes); |
|
|
if (!rc_ok (rc) || !nbytes) |
|
324 |
goto leave; |
goto leave; |
325 |
|
if (!nbytes) |
326 |
if (type == REG_EXPAND_SZ && strchr (text, '%')) |
goto leave; /* empty */ |
327 |
p = expand_path (text); |
p = new char[nbytes+1]; |
328 |
else { |
if (!p) |
329 |
p = new char[nbytes + 1]; |
BUG (0); |
330 |
if (!p) |
rc = RegQueryValueEx (reg_key, key, NULL, &type, (BYTE*)p, &nbytes); |
331 |
BUG (0); |
if (!rc_ok (rc)) |
332 |
memcpy (p, text, nbytes); |
goto leave; |
333 |
p[nbytes] = '\0'; |
if (type == REG_EXPAND_SZ && strchr (p, '%')) { |
334 |
|
pp = p; |
335 |
|
p = expand_path (pp); |
336 |
|
free_if_alloc (pp); |
337 |
} |
} |
338 |
|
|
339 |
leave: |
leave: |
340 |
if (reg_key) |
if (reg_key != NULL) |
341 |
RegCloseKey (reg_key); |
RegCloseKey (reg_key); |
342 |
return p; |
return p; |
343 |
} |
} |
362 |
rc = WPTERR_REGISTRY; |
rc = WPTERR_REGISTRY; |
363 |
RegCloseKey( reg_key ); |
RegCloseKey( reg_key ); |
364 |
return rc; |
return rc; |
365 |
} /* set_reg_entry */ |
} |
366 |
|
|
367 |
|
|
368 |
int |
int |
369 |
set_reg_key( HKEY root_key, const char * dir, const char * key, |
set_reg_key( HKEY root_key, const char * dir, const char * key, |
370 |
const char * value ) |
const char * value ) |
371 |
{ |
{ |
372 |
int rc = 0; |
int rc; |
373 |
HKEY reg_key; |
HKEY reg_key; |
374 |
|
|
375 |
rc = RegOpenKeyEx( root_key, dir, 0, KEY_WRITE, ®_key ); |
rc = RegOpenKeyEx (root_key, dir, 0, KEY_WRITE, ®_key); |
376 |
if( !rc_ok( rc ) ) |
if (!rc_ok (rc)) |
377 |
return WPTERR_REGISTRY; |
return WPTERR_REGISTRY; |
378 |
|
|
379 |
rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) ); |
rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value)); |
380 |
if( !rc_ok( rc ) ) { |
if (!rc_ok (rc)) { |
381 |
if ( RegCreateKey( root_key, key, ®_key ) != ERROR_SUCCESS ) { |
if (RegCreateKey (root_key, key, ®_key) != ERROR_SUCCESS) { |
382 |
rc = WPTERR_REGISTRY; |
rc = WPTERR_REGISTRY; |
383 |
goto leave; |
goto leave; |
384 |
} |
} |
385 |
rc = RegSetValueEx( reg_key, key, 0, REG_SZ, (BYTE *)value, strlen( value ) ); |
rc = RegSetValueEx (reg_key, key, 0, REG_SZ, (BYTE *)value, strlen (value)); |
386 |
if ( !rc_ok( rc ) ) |
if (!rc_ok (rc)) |
387 |
rc = WPTERR_REGISTRY; |
rc = WPTERR_REGISTRY; |
388 |
} |
} |
389 |
|
|
390 |
leave: |
leave: |
391 |
RegCloseKey( reg_key ); |
RegCloseKey (reg_key); |
392 |
return rc; |
return rc; |
393 |
} /* set_reg_key */ |
} |
394 |
|
|
395 |
|
|
396 |
int |
int |
481 |
"NoCompressMultiMedia", |
"NoCompressMultiMedia", |
482 |
"Expert", |
"Expert", |
483 |
"FMProgressBar", |
"FMProgressBar", |
484 |
|
"BackupSecring" |
485 |
}; |
}; |
486 |
|
|
487 |
|
|
500 |
int |
int |
501 |
get_reg_winpt_single (int id) |
get_reg_winpt_single (int id) |
502 |
{ |
{ |
503 |
char * buf = NULL; |
char *buf; |
504 |
int val = 0; |
int val = 0; |
505 |
|
|
506 |
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]); |
buf = get_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[id]); |
560 |
case CFG_FM_PROGRESS: |
case CFG_FM_PROGRESS: |
561 |
sprintf (buf, "%d", opt->fm.progress); |
sprintf (buf, "%d", opt->fm.progress); |
562 |
break; |
break; |
563 |
|
|
564 |
|
case CFG_BACKUP_INC_SKR: |
565 |
|
sprintf (buf, "%d", opt->backup.include_secr); |
566 |
|
break; |
567 |
} |
} |
568 |
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf); |
rc = set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, cfg[i], buf); |
569 |
if (rc) |
if (rc) |
603 |
set_reg_winpt_flag (const char * name, int val) |
set_reg_winpt_flag (const char * name, int val) |
604 |
{ |
{ |
605 |
return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name, val? "1" : "0"); |
return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG, name, val? "1" : "0"); |
606 |
} /* set_reg_winpt_flag */ |
} |
607 |
|
|
608 |
|
|
609 |
int |
int |
619 |
flag = -1; |
flag = -1; |
620 |
free_if_alloc (buf); |
free_if_alloc (buf); |
621 |
return flag; |
return flag; |
622 |
} /* get_reg_winpt_flag */ |
} |
623 |
|
|
624 |
|
|
625 |
/* Retrieve the winpt preferences from the registry. */ |
/* Retrieve the winpt preferences from the registry. */ |
672 |
case CFG_FM_PROGRESS: |
case CFG_FM_PROGRESS: |
673 |
opt->fm.progress = atol (val); |
opt->fm.progress = atol (val); |
674 |
break; |
break; |
675 |
|
|
676 |
|
case CFG_BACKUP_INC_SKR: |
677 |
|
opt->backup.include_secr = atol (val); |
678 |
|
break; |
679 |
} |
} |
680 |
free_if_alloc (val); |
free_if_alloc (val); |
681 |
} |
} |
711 |
|
|
712 |
|
|
713 |
int |
int |
714 |
set_reg_entry_keyserver (const char * name, const char * val) |
set_reg_entry_keyserver (const char *name, const char *val) |
715 |
{ |
{ |
716 |
return set_reg_entry( HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val ); |
return set_reg_entry (HKEY_CURRENT_USER, WINPT_REG"\\Keyserver", name, val); |
717 |
} |
} |
718 |
|
|
719 |
static int |
static int |