/* * SHLWAPI registry functions */ #include #include "windef.h" #include "winbase.h" #include "wingdi.h" #include "winuser.h" #include "winerror.h" #include "winnls.h" #include "winreg.h" #include "debugtools.h" #include "shlwapi.h" #include "wine/unicode.h" DEFAULT_DEBUG_CHANNEL(shell); static const char *lpszContentTypeA = "Content Type"; static const WCHAR lpszContentTypeW[] = { 'C','o','n','t','e','n','t',' ','T','y','p','e','\0'}; /* internal structure of what the HUSKEY points to */ typedef struct { HKEY HKCUkey; /* HKEY of opened HKCU key */ HKEY HKLMkey; /* HKEY of opened HKLM key */ HKEY start; /* HKEY of where to start */ WCHAR key_string[MAX_PATH]; /* additional path from 'start' */ } Internal_HUSKEY, *LPInternal_HUSKEY; #define REG_HKCU TRUE #define REG_HKLM FALSE /************************************************************************* * REG_GetHKEYFromHUSKEY * * Function: Return the proper registry key from the HUSKEY structure * also allow special predefined values. */ HKEY REG_GetHKEYFromHUSKEY(HUSKEY hUSKey, BOOL which) { HKEY test = (HKEY) hUSKey; LPInternal_HUSKEY mihk = (LPInternal_HUSKEY) hUSKey; if ((test == HKEY_CLASSES_ROOT) || (test == HKEY_CURRENT_CONFIG) || (test == HKEY_CURRENT_USER) || (test == HKEY_DYN_DATA) || (test == HKEY_LOCAL_MACHINE) || (test == HKEY_PERFORMANCE_DATA) || /* FIXME: need to define for Win2k, ME, XP * (test == HKEY_PERFORMANCE_TEXT) || * (test == HKEY_PERFORMANCE_NLSTEXT) || */ (test == HKEY_USERS)) return test; if (which == REG_HKCU) return mihk->HKCUkey; return mihk->HKLMkey; } /************************************************************************* * SHRegOpenUSKeyA [SHLWAPI.@] * * Opens a user-specific registry key */ LONG WINAPI SHRegOpenUSKeyA( LPCSTR Path, REGSAM AccessType, HUSKEY hRelativeUSKey, PHUSKEY phNewUSKey, BOOL fIgnoreHKCU) { HKEY openHKCUkey=0; HKEY openHKLMkey=0; LONG ret2, ret1 = ~ERROR_SUCCESS; LPInternal_HUSKEY ihky; TRACE("(%s, 0x%lx, 0x%lx, %p, %s)\n", debugstr_a(Path), (LONG)AccessType, (LONG)hRelativeUSKey, phNewUSKey, (fIgnoreHKCU) ? "Ignoring HKCU" : "Process HKCU then HKLM"); /* now create the internal version of HUSKEY */ ihky = (LPInternal_HUSKEY)HeapAlloc(GetProcessHeap(), 0 , sizeof(Internal_HUSKEY)); MultiByteToWideChar(0, 0, Path, -1, ihky->key_string, sizeof(ihky->key_string)-1); if (hRelativeUSKey) { openHKCUkey = ((LPInternal_HUSKEY)hRelativeUSKey)->HKCUkey; openHKLMkey = ((LPInternal_HUSKEY)hRelativeUSKey)->HKLMkey; } else { openHKCUkey = HKEY_CURRENT_USER; openHKLMkey = HKEY_LOCAL_MACHINE; } ihky->HKCUkey = 0; ihky->HKLMkey = 0; if (!fIgnoreHKCU) { ret1 = RegOpenKeyExA(HKEY_CURRENT_USER, Path, 0, AccessType, &ihky->HKCUkey); /* if successful, then save real starting point */ if (ret1 != ERROR_SUCCESS) ihky->HKCUkey = 0; } ret2 = RegOpenKeyExA(HKEY_LOCAL_MACHINE, Path, 0, AccessType, &ihky->HKLMkey); if (ret2 != ERROR_SUCCESS) ihky->HKLMkey = 0; if ((ret1 != ERROR_SUCCESS) || (ret2 != ERROR_SUCCESS)) TRACE("one or more opens failed: HKCU=%ld HKLM=%ld\n", ret1, ret2); /* if all attempts have failed then bail */ if ((ret1 != ERROR_SUCCESS) && (ret2 != ERROR_SUCCESS)) { HeapFree(GetProcessHeap(), 0, ihky); if (phNewUSKey) *phNewUSKey = (HUSKEY)0; return ret2; } TRACE("HUSKEY=0x%08lx\n", (LONG)ihky); if (phNewUSKey) *phNewUSKey = (HUSKEY)ihky; return ERROR_SUCCESS; } /************************************************************************* * SHRegOpenUSKeyW [SHLWAPI.@] * * Opens a user-specific registry key */ LONG WINAPI SHRegOpenUSKeyW( LPCWSTR Path, REGSAM AccessType, HUSKEY hRelativeUSKey, PHUSKEY phNewUSKey, BOOL fIgnoreHKCU) { HKEY openHKCUkey=0; HKEY openHKLMkey=0; LONG ret2, ret1 = ~ERROR_SUCCESS; LPInternal_HUSKEY ihky; TRACE("(%s, 0x%lx, 0x%lx, %p, %s)\n", debugstr_w(Path), (LONG)AccessType, (LONG)hRelativeUSKey, phNewUSKey, (fIgnoreHKCU) ? "Ignoring HKCU" : "Process HKCU then HKLM"); /* now create the internal version of HUSKEY */ ihky = (LPInternal_HUSKEY)HeapAlloc(GetProcessHeap(), 0 , sizeof(Internal_HUSKEY)); lstrcpynW(ihky->key_string, Path, sizeof(ihky->key_string)); if (hRelativeUSKey) { openHKCUkey = ((LPInternal_HUSKEY)hRelativeUSKey)->HKCUkey; openHKLMkey = ((LPInternal_HUSKEY)hRelativeUSKey)->HKLMkey; } else { openHKCUkey = HKEY_CURRENT_USER; openHKLMkey = HKEY_LOCAL_MACHINE; } ihky->HKCUkey = 0; ihky->HKLMkey = 0; if (!fIgnoreHKCU) { ret1 = RegOpenKeyExW(HKEY_CURRENT_USER, Path, 0, AccessType, &ihky->HKCUkey); /* if successful, then save real starting point */ if (ret1 != ERROR_SUCCESS) ihky->HKCUkey = 0; } ret2 = RegOpenKeyExW(HKEY_LOCAL_MACHINE, Path, 0, AccessType, &ihky->HKLMkey); if (ret2 != ERROR_SUCCESS) ihky->HKLMkey = 0; if ((ret1 != ERROR_SUCCESS) || (ret2 != ERROR_SUCCESS)) TRACE("one or more opens failed: HKCU=%ld HKLM=%ld\n", ret1, ret2); /* if all attempts have failed then bail */ if ((ret1 != ERROR_SUCCESS) && (ret2 != ERROR_SUCCESS)) { HeapFree(GetProcessHeap(), 0, ihky); if (phNewUSKey) *phNewUSKey = (HUSKEY)0; return ret2; } TRACE("HUSKEY=0x%08lx\n", (LONG)ihky); if (phNewUSKey) *phNewUSKey = (HUSKEY)ihky; return ERROR_SUCCESS; } /************************************************************************* * SHRegCloseUSKey [SHLWAPI.@] * * Closes a user-specific registry key */ LONG WINAPI SHRegCloseUSKey( HUSKEY hUSKey) { LPInternal_HUSKEY mihk = (LPInternal_HUSKEY)hUSKey; LONG ret = ERROR_SUCCESS; if (mihk->HKCUkey) ret = RegCloseKey(mihk->HKCUkey); if (mihk->HKLMkey) ret = RegCloseKey(mihk->HKLMkey); HeapFree(GetProcessHeap(), 0, mihk); return ret; } /************************************************************************* * SHRegQueryUSValueA [SHLWAPI.@] */ LONG WINAPI SHRegQueryUSValueA( HUSKEY hUSKey, /* [in] */ LPCSTR pszValue, LPDWORD pdwType, LPVOID pvData, LPDWORD pcbData, BOOL fIgnoreHKCU, LPVOID pvDefaultData, DWORD dwDefaultDataSize) { LONG ret = ~ERROR_SUCCESS; LONG i, maxmove; HKEY dokey; CHAR *src, *dst; /* if user wants HKCU, and it exists, then try it */ if (!fIgnoreHKCU && (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) ret = RegQueryValueExA(dokey, pszValue, 0, pdwType, pvData, pcbData); /* if HKCU did not work and HKLM exists, then try it */ if ((ret != ERROR_SUCCESS) && (dokey = REG_GetHKEYFromHUSKEY(hUSKey,REG_HKCU))) ret = RegQueryValueExA(dokey, pszValue, 0, pdwType, pvData, pcbData); /* if neither worked, and default data exists, then use it */ if (ret != ERROR_SUCCESS) { if (pvDefaultData && (dwDefaultDataSize != 0)) { maxmove = (dwDefaultDataSize >= *pcbData) ? *pcbData : dwDefaultDataSize; src = (CHAR*)pvDefaultData; dst = (CHAR*)pvData; for(i=0; i= *pcbData) ? *pcbData : dwDefaultDataSize; src = (CHAR*)pvDefaultData; dst = (CHAR*)pvData; for(i=0; i