|
|
1.1.1.3 ! root 1: /* Copyright (C) 2004 TrueCrypt Team */
1.1 root 2:
3: #include "TCdefs.h"
4:
5: #define TC_REG_SUBKEY "Software\\TrueCrypt"
6:
7: int ReadRegistryInt (char *name, int defaultValue)
8: {
9: HKEY hkey = 0;
10: DWORD value, size = sizeof (DWORD);
11:
12: if (RegOpenKeyEx (HKEY_CURRENT_USER, TC_REG_SUBKEY,
13: 0, KEY_READ, &hkey) != ERROR_SUCCESS)
14: return defaultValue;
15:
16: if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) &value, &size) != ERROR_SUCCESS)
17: value = defaultValue;
18:
19: RegCloseKey (hkey);
20: return value;
21: }
22:
23: char *ReadRegistryString (char *name, char *defaultValue, char *str, int maxLen)
24: {
25: HKEY hkey = 0;
26: char value[256];
27: DWORD size = sizeof (value);
28:
29: strncpy (str, defaultValue, maxLen-1);
30:
31: ZeroMemory (value, sizeof value);
32: if (RegOpenKeyEx (HKEY_CURRENT_USER, TC_REG_SUBKEY,
33: 0, KEY_READ, &hkey) == ERROR_SUCCESS)
34: if (RegQueryValueEx (hkey, name, 0, 0, (LPBYTE) &value, &size) == ERROR_SUCCESS)
35: strncpy (str, value, maxLen-1);
36:
37: RegCloseKey (hkey);
38: return str;
39: }
40:
41: void WriteRegistryInt (char *name, int value)
42: {
43: HKEY hkey = 0;
44: DWORD disp;
45:
46: if (RegCreateKeyEx (HKEY_CURRENT_USER, TC_REG_SUBKEY,
47: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
48: return;
49:
50: RegSetValueEx (hkey, name, 0, REG_DWORD, (BYTE *) &value, sizeof value);
51: RegCloseKey (hkey);
52: }
53:
54: void WriteRegistryString (char *name, char *str)
55: {
56: HKEY hkey = 0;
57: DWORD disp;
58:
59: if (RegCreateKeyEx (HKEY_CURRENT_USER, TC_REG_SUBKEY,
60: 0, NULL, REG_OPTION_NON_VOLATILE, KEY_WRITE, NULL, &hkey, &disp) != ERROR_SUCCESS)
61: return;
62:
63: RegSetValueEx (hkey, name, 0, REG_SZ, (BYTE *) str, strlen (str) + 1);
64: RegCloseKey (hkey);
65: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.