| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 // | 4 // |
| 5 // See the corresponding header file for description of the functions in this | 5 // See the corresponding header file for description of the functions in this |
| 6 // file. | 6 // file. |
| 7 | 7 |
| 8 #include "chrome/installer/util/install_util.h" | 8 #include "chrome/installer/util/install_util.h" |
| 9 | 9 |
| 10 #include <shellapi.h> | 10 #include <shellapi.h> |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 75 RegKey key(root, dist->GetUninstallRegPath().c_str(), KEY_READ); | 75 RegKey key(root, dist->GetUninstallRegPath().c_str(), KEY_READ); |
| 76 std::wstring uninstall_cmd; | 76 std::wstring uninstall_cmd; |
| 77 key.ReadValue(installer::kUninstallStringField, &uninstall_cmd); | 77 key.ReadValue(installer::kUninstallStringField, &uninstall_cmd); |
| 78 return uninstall_cmd; | 78 return uninstall_cmd; |
| 79 } | 79 } |
| 80 | 80 |
| 81 Version* InstallUtil::GetChromeVersion(BrowserDistribution* dist, | 81 Version* InstallUtil::GetChromeVersion(BrowserDistribution* dist, |
| 82 bool system_install) { | 82 bool system_install) { |
| 83 DCHECK(dist); | 83 DCHECK(dist); |
| 84 RegKey key; | 84 RegKey key; |
| 85 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; |
| 86 LONG result = key.Open(reg_root, dist->GetVersionKey().c_str(), KEY_READ); |
| 87 |
| 85 std::wstring version_str; | 88 std::wstring version_str; |
| 89 if (result == ERROR_SUCCESS) |
| 90 result = key.ReadValue(google_update::kRegVersionField, &version_str); |
| 86 | 91 |
| 87 HKEY reg_root = (system_install) ? HKEY_LOCAL_MACHINE : HKEY_CURRENT_USER; | 92 Version* ret = NULL; |
| 88 if (!key.Open(reg_root, dist->GetVersionKey().c_str(), KEY_READ) || | 93 if (result == ERROR_SUCCESS && !version_str.empty()) { |
| 89 !key.ReadValue(google_update::kRegVersionField, &version_str)) { | 94 VLOG(1) << "Existing " << dist->GetApplicationName() |
| 95 << " version found " << version_str; |
| 96 ret = Version::GetVersionFromString(WideToASCII(version_str)); |
| 97 } else { |
| 90 VLOG(1) << "No existing " << dist->GetApplicationName() | 98 VLOG(1) << "No existing " << dist->GetApplicationName() |
| 91 << " install found."; | 99 << " install found."; |
| 92 key.Close(); | |
| 93 return NULL; | |
| 94 } | 100 } |
| 95 key.Close(); | 101 |
| 96 VLOG(1) << "Existing " << dist->GetApplicationName() | 102 return ret; |
| 97 << " version found " << version_str; | |
| 98 return Version::GetVersionFromString(WideToASCII(version_str)); | |
| 99 } | 103 } |
| 100 | 104 |
| 101 bool InstallUtil::IsOSSupported() { | 105 bool InstallUtil::IsOSSupported() { |
| 102 int major, minor; | 106 int major, minor; |
| 103 base::win::Version version = base::win::GetVersion(); | 107 base::win::Version version = base::win::GetVersion(); |
| 104 base::win::GetServicePackLevel(&major, &minor); | 108 base::win::GetServicePackLevel(&major, &minor); |
| 105 | 109 |
| 106 // We do not support Win2K or older, or XP without service pack 2. | 110 // We do not support Win2K or older, or XP without service pack 2. |
| 107 VLOG(1) << "Windows Version: " << version | 111 VLOG(1) << "Windows Version: " << version |
| 108 << ", Service Pack: " << major << "." << minor; | 112 << ", Service Pack: " << major << "." << minor; |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 188 } | 192 } |
| 189 return (dll_names_count > 0) && success; | 193 return (dll_names_count > 0) && success; |
| 190 } | 194 } |
| 191 | 195 |
| 192 // This method tries to delete a registry key and logs an error message | 196 // This method tries to delete a registry key and logs an error message |
| 193 // in case of failure. It returns true if deletion is successful, | 197 // in case of failure. It returns true if deletion is successful, |
| 194 // otherwise false. | 198 // otherwise false. |
| 195 bool InstallUtil::DeleteRegistryKey(RegKey& root_key, | 199 bool InstallUtil::DeleteRegistryKey(RegKey& root_key, |
| 196 const std::wstring& key_path) { | 200 const std::wstring& key_path) { |
| 197 VLOG(1) << "Deleting registry key " << key_path; | 201 VLOG(1) << "Deleting registry key " << key_path; |
| 198 if (!root_key.DeleteKey(key_path.c_str()) && | 202 LONG result = root_key.DeleteKey(key_path.c_str()); |
| 199 ::GetLastError() != ERROR_FILE_NOT_FOUND) { | 203 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { |
| 200 PLOG(ERROR) << "Failed to delete registry key: " << key_path; | 204 PLOG(ERROR) << "Failed to delete registry key: " << key_path |
| 205 << " error: " << result; |
| 201 return false; | 206 return false; |
| 202 } | 207 } |
| 203 return true; | 208 return true; |
| 204 } | 209 } |
| 205 | 210 |
| 206 // This method tries to delete a registry value and logs an error message | 211 // This method tries to delete a registry value and logs an error message |
| 207 // in case of failure. It returns true if deletion is successful, | 212 // in case of failure. It returns true if deletion is successful, |
| 208 // otherwise false. | 213 // otherwise false. |
| 209 bool InstallUtil::DeleteRegistryValue(HKEY reg_root, | 214 bool InstallUtil::DeleteRegistryValue(HKEY reg_root, |
| 210 const std::wstring& key_path, | 215 const std::wstring& key_path, |
| 211 const std::wstring& value_name) { | 216 const std::wstring& value_name) { |
| 212 RegKey key(reg_root, key_path.c_str(), KEY_ALL_ACCESS); | 217 RegKey key(reg_root, key_path.c_str(), KEY_ALL_ACCESS); |
| 213 VLOG(1) << "Deleting registry value " << value_name; | 218 VLOG(1) << "Deleting registry value " << value_name; |
| 214 if (key.ValueExists(value_name.c_str()) && | 219 if (key.ValueExists(value_name.c_str())) { |
| 215 !key.DeleteValue(value_name.c_str())) { | 220 LONG result = key.DeleteValue(value_name.c_str()); |
| 216 LOG(ERROR) << "Failed to delete registry value: " << value_name; | 221 if (result != ERROR_SUCCESS) { |
| 217 return false; | 222 LOG(ERROR) << "Failed to delete registry value: " << value_name |
| 223 << " error: " << result; |
| 224 return false; |
| 225 } |
| 218 } | 226 } |
| 219 return true; | 227 return true; |
| 220 } | 228 } |
| 221 | 229 |
| 222 // static | 230 // static |
| 223 int InstallUtil::GetInstallReturnCode(installer::InstallStatus status) { | 231 int InstallUtil::GetInstallReturnCode(installer::InstallStatus status) { |
| 224 switch (status) { | 232 switch (status) { |
| 225 case installer::FIRST_INSTALL_SUCCESS: | 233 case installer::FIRST_INSTALL_SUCCESS: |
| 226 case installer::INSTALL_REPAIRED: | 234 case installer::INSTALL_REPAIRED: |
| 227 case installer::NEW_VERSION_UPDATED: | 235 case installer::NEW_VERSION_UPDATED: |
| 228 case installer::IN_USE_UPDATED: | 236 case installer::IN_USE_UPDATED: |
| 229 return 0; | 237 return 0; |
| 230 default: | 238 default: |
| 231 return status; | 239 return status; |
| 232 } | 240 } |
| 233 } | 241 } |
| OLD | NEW |