2 * Copyright 2000, International Business Machines Corporation and others.
5 * This software has been released under the terms of the IBM Public
6 * License. For details, see the LICENSE file in the top-level source
7 * directory or online at http://www.openafs.org/dl/license10.html
14 #include <afsconfig.h>
15 #include <afs/param.h>
21 #include <WINNT/TaLocale.h>
27 * ROUTINES ___________________________________________________________________
31 BOOL RestoreSettings (HKEY hkParent,
41 if ((cbStored = GetRegValueSize (hkParent, pszBase, pszValue)) != 0)
43 if (cbStored >= sizeof(WORD)+cbStructure)
45 PVOID pStructureFinal;
46 if ((pStructureFinal = Allocate (cbStored)) != NULL)
48 if (GetBinaryRegValue (hkParent, pszBase, pszValue, pStructureFinal, cbStored))
50 WORD wVerStored = *(LPWORD)pStructureFinal;
52 if ( (HIBYTE(wVerStored) == HIBYTE(wVerExpected)) &&
53 (LOBYTE(wVerStored) >= LOBYTE(wVerExpected)) )
55 memcpy (pStructure, &((LPBYTE)pStructureFinal)[ sizeof(WORD) ], cbStructure);
60 Free (pStructureFinal);
69 BOOL StoreSettings (HKEY hkParent,
78 PVOID pStructureFinal;
79 if ((pStructureFinal = Allocate (sizeof(WORD) + cbStructure)) != NULL)
81 *(LPWORD)pStructureFinal = wVersion;
82 memcpy (&((LPBYTE)pStructureFinal)[ sizeof(WORD) ], pStructure, cbStructure);
84 rc = SetBinaryRegValue (hkParent, pszBase, pszValue, pStructureFinal, sizeof(WORD) + cbStructure);
86 Free (pStructureFinal);
93 void EraseSettings (HKEY hkParent, LPCTSTR pszBase, LPCTSTR pszValue)
96 if (RegOpenKeyEx (hkParent, pszBase, 0,
97 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_SET_VALUE, &hk) == 0)
99 RegDeleteValue (hk, pszValue);
105 BOOL GetBinaryRegValue (HKEY hk,
114 if (RegOpenKeyEx (hk, pszBase, 0,
115 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hkFinal) == ERROR_SUCCESS)
118 DWORD dwSize = (DWORD)cbData;
120 if (RegQueryValueEx (hkFinal, pszValue, NULL, &dwType, (LPBYTE)pData, &dwSize) == ERROR_SUCCESS)
130 size_t GetRegValueSize (HKEY hk,
137 if (RegOpenKeyEx (hk, pszBase, 0,
138 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_QUERY_VALUE, &hkFinal) == ERROR_SUCCESS)
143 if (RegQueryValueEx (hkFinal, pszValue, NULL, &dwType, NULL, &dwSize) == ERROR_SUCCESS)
155 BOOL SetBinaryRegValue (HKEY hk,
164 if (RegCreateKeyEx (hk, pszBase, 0, NULL, 0,
165 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE, NULL, &hkFinal, NULL) == ERROR_SUCCESS)
167 DWORD dwSize = (DWORD)cbData;
169 if (RegSetValueEx (hkFinal, pszValue, NULL, REG_BINARY, (LPBYTE)pData, dwSize) == ERROR_SUCCESS)
179 // Under Windows NT, RegDeleteKey() is not recursive--under Windows 95,
180 // it is. Sigh. This routine works recursively on either OS.
182 BOOL RegDeltreeKey (HKEY hk, LPTSTR pszKey)
185 if (RegOpenKeyEx (hk, pszKey, 0,
186 (IsWow64()?KEY_WOW64_64KEY:0)|KEY_WRITE, &hkSub) == 0)
188 TCHAR szFound[ MAX_PATH ];
189 while (RegEnumKey (hkSub, 0, szFound, MAX_PATH) == 0)
191 if (!RegDeltreeKey (hkSub, szFound))
201 if (RegDeleteKey (hk, pszKey) != 0)