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
11 #include <afs/param.h>
17 #include <WINNT/TaLocale.h>
22 * ROUTINES ___________________________________________________________________
26 BOOL RestoreSettings (HKEY hkParent,
36 if ((cbStored = GetRegValueSize (hkParent, pszBase, pszValue)) != 0)
38 if (cbStored >= sizeof(WORD)+cbStructure)
40 PVOID pStructureFinal;
41 if ((pStructureFinal = Allocate (cbStored)) != NULL)
43 if (GetBinaryRegValue (hkParent, pszBase, pszValue, pStructureFinal, cbStored))
45 WORD wVerStored = *(LPWORD)pStructureFinal;
47 if ( (HIBYTE(wVerStored) == HIBYTE(wVerExpected)) &&
48 (LOBYTE(wVerStored) >= LOBYTE(wVerExpected)) )
50 memcpy (pStructure, &((LPBYTE)pStructureFinal)[ sizeof(WORD) ], cbStructure);
55 Free (pStructureFinal);
64 BOOL StoreSettings (HKEY hkParent,
73 PVOID pStructureFinal;
74 if ((pStructureFinal = Allocate (sizeof(WORD) + cbStructure)) != NULL)
76 *(LPWORD)pStructureFinal = wVersion;
77 memcpy (&((LPBYTE)pStructureFinal)[ sizeof(WORD) ], pStructure, cbStructure);
79 rc = SetBinaryRegValue (hkParent, pszBase, pszValue, pStructureFinal, sizeof(WORD) + cbStructure);
81 Free (pStructureFinal);
88 void EraseSettings (HKEY hkParent, LPCTSTR pszBase, LPCTSTR pszValue)
91 if (RegOpenKey (hkParent, pszBase, &hk) == 0)
93 RegDeleteValue (hk, pszValue);
99 BOOL GetBinaryRegValue (HKEY hk,
108 if (RegOpenKey (hk, pszBase, &hkFinal) == ERROR_SUCCESS)
111 DWORD dwSize = (DWORD)cbData;
113 if (RegQueryValueEx (hkFinal, pszValue, NULL, &dwType, (LPBYTE)pData, &dwSize) == ERROR_SUCCESS)
123 size_t GetRegValueSize (HKEY hk,
130 if (RegOpenKey (hk, pszBase, &hkFinal) == ERROR_SUCCESS)
135 if (RegQueryValueEx (hkFinal, pszValue, NULL, &dwType, NULL, &dwSize) == ERROR_SUCCESS)
147 BOOL SetBinaryRegValue (HKEY hk,
156 if (RegCreateKey (hk, pszBase, &hkFinal) == ERROR_SUCCESS)
158 DWORD dwSize = (DWORD)cbData;
160 if (RegSetValueEx (hkFinal, pszValue, NULL, REG_BINARY, (LPBYTE)pData, dwSize) == ERROR_SUCCESS)
170 // Under Windows NT, RegDeleteKey() is not recursive--under Windows 95,
171 // it is. Sigh. This routine works recursively on either OS.
173 BOOL RegDeltreeKey (HKEY hk, LPTSTR pszKey)
176 if (RegOpenKey (hk, pszKey, &hkSub) == 0)
178 TCHAR szFound[ MAX_PATH ];
179 while (RegEnumKey (hkSub, 0, szFound, MAX_PATH) == 0)
181 if (!RegDeltreeKey (hkSub, szFound))
191 if (RegDeleteKey (hk, pszKey) != 0)