Bug 572162 - Use TaskbarIDs hash as update dir root. r=rstrong

This commit is contained in:
Brian R. Bondy 2013-05-15 10:58:09 -07:00
parent a46e80d61f
commit 9227520b87

View File

@ -954,6 +954,28 @@ GetRegWindowsAppDataFolder(bool aLocal, nsAString& _retval)
return NS_OK;
}
static bool
GetCachedHash(HKEY rootKey, const nsAString &regPath, const nsAString &path,
nsAString &cachedHash)
{
HKEY baseKey;
if (RegOpenKeyExW(rootKey, regPath.BeginReading(), 0, KEY_READ, &baseKey) !=
ERROR_SUCCESS) {
return false;
}
wchar_t cachedHashRaw[512];
DWORD bufferSize = sizeof(cachedHashRaw);
LONG result = RegQueryValueExW(baseKey, path.BeginReading(), 0, NULL,
(LPBYTE)cachedHashRaw, &bufferSize);
RegCloseKey(baseKey);
if (result == ERROR_SUCCESS) {
cachedHash.Assign(cachedHashRaw);
}
return ERROR_SUCCESS == result;
}
#endif
nsresult
@ -976,6 +998,46 @@ nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult)
NS_ENSURE_SUCCESS(rv, rv);
#ifdef XP_WIN
nsAutoString pathHash;
bool pathHashResult = false;
nsAutoString appDirPath;
if (gAppData->vendor && !getenv("MOZ_UPDATE_NO_HASH_DIR") &&
SUCCEEDED(updRoot->GetPath(appDirPath))) {
// Figure out where we should check for a cached hash value
wchar_t regPath[1024] = { L'\0' };
swprintf_s(regPath, mozilla::ArrayLength(regPath), L"SOFTWARE\\%S\\%S\\TaskBarIDs",
gAppData->vendor, MOZ_APP_NAME);
// If we pre-computed the hash, grab it from the registry.
pathHashResult = GetCachedHash(HKEY_LOCAL_MACHINE,
nsDependentString(regPath), appDirPath,
pathHash);
if (!pathHashResult) {
pathHashResult = GetCachedHash(HKEY_CURRENT_USER,
nsDependentString(regPath), appDirPath,
pathHash);
}
}
// Get the local app data directory and if a vendor name exists append it.
// If only a product name exists, append it. If neither exist fallback to
// old handling. We don't use the product name on purpose because we want a
// shared update directory for different apps run from the same path (like
// Metro & Desktop).
nsCOMPtr<nsIFile> localDir;
if (pathHashResult && (gAppData->vendor || gAppData->name) &&
NS_SUCCEEDED(GetUserDataDirectoryHome(getter_AddRefs(localDir), true)) &&
NS_SUCCEEDED(localDir->AppendNative(nsDependentCString(gAppData->vendor ?
gAppData->vendor : gAppData->name))) &&
NS_SUCCEEDED(localDir->Append(NS_LITERAL_STRING("updates"))) &&
NS_SUCCEEDED(localDir->Append(pathHash))) {
NS_ADDREF(*aResult = localDir);
return NS_OK;
}
nsAutoString appPath;
rv = updRoot->GetPath(appPath);
NS_ENSURE_SUCCESS(rv, rv);