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>
18 #include <WINNT/settings.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 = (PVOID)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 = (PVOID)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 BOOL GetMultiStringRegValue (HKEY hk,
178 if (RegOpenKey (hk, pszBase, &hkFinal) == ERROR_SUCCESS)
182 RegQueryValueEx (hkFinal, pszValue, NULL, &dwType, NULL, &dwSize);
184 if ((dwType == REG_MULTI_SZ) && (dwSize != 0))
186 *pmszData = AllocateString (dwSize);
188 if (RegQueryValueEx (hkFinal, pszValue, NULL, &dwType, (LPBYTE)*pmszData, &dwSize) == ERROR_SUCCESS)
192 FreeString (*pmszData);
204 BOOL SetMultiStringRegValue (HKEY hk,
212 if (RegCreateKey (hk, pszBase, &hkFinal) == ERROR_SUCCESS)
214 DWORD dwSize = sizeof(TCHAR);
215 for (LPCTSTR psz = mszData; psz && *psz; psz += 1+lstrlen(psz))
216 dwSize += sizeof(TCHAR) * (1+lstrlen(psz));
218 if (RegSetValueEx (hkFinal, pszValue, NULL, REG_MULTI_SZ, (LPBYTE)mszData, dwSize) == ERROR_SUCCESS)
228 // Under Windows NT, RegDeleteKey() is not recursive--under Windows 95,
229 // it is. Sigh. This routine works recursively on either OS.
231 BOOL RegDeltreeKey (HKEY hk, LPTSTR pszKey)
234 if (RegOpenKey (hk, pszKey, &hkSub) == 0)
236 TCHAR szFound[ MAX_PATH ];
237 while (RegEnumKey (hkSub, 0, szFound, MAX_PATH) == 0)
239 if (!RegDeltreeKey (hkSub, szFound))
249 if (RegDeleteKey (hk, pszKey) != 0)