Chromium Code Reviews| 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 key.Close(); |
|
grt (UTC plus 2)
2011/01/11 03:51:30
Remove
amit
2011/01/12 04:11:23
Done.
| |
| 88 if (!key.Open(reg_root, dist->GetVersionKey().c_str(), KEY_READ) || | 93 Version* ret = NULL; |
| 89 !key.ReadValue(google_update::kRegVersionField, &version_str)) { | 94 if (result == ERROR_SUCCESS && !version_str.empty()) { |
| 95 VLOG(1) << "Existing " << dist->GetApplicationName() | |
| 96 << " version found " << version_str; | |
| 97 ret = Version::GetVersionFromString(WideToASCII(version_str)); | |
| 98 } else { | |
| 90 VLOG(1) << "No existing " << dist->GetApplicationName() | 99 VLOG(1) << "No existing " << dist->GetApplicationName() |
| 91 << " install found."; | 100 << " install found."; |
| 92 key.Close(); | |
| 93 return NULL; | |
| 94 } | 101 } |
| 95 key.Close(); | 102 |
| 96 VLOG(1) << "Existing " << dist->GetApplicationName() | 103 return ret; |
| 97 << " version found " << version_str; | |
| 98 return Version::GetVersionFromString(WideToASCII(version_str)); | |
| 99 } | 104 } |
| 100 | 105 |
| 101 bool InstallUtil::IsOSSupported() { | 106 bool InstallUtil::IsOSSupported() { |
| 102 int major, minor; | 107 int major, minor; |
| 103 base::win::Version version = base::win::GetVersion(); | 108 base::win::Version version = base::win::GetVersion(); |
| 104 base::win::GetServicePackLevel(&major, &minor); | 109 base::win::GetServicePackLevel(&major, &minor); |
| 105 | 110 |
| 106 // We do not support Win2K or older, or XP without service pack 2. | 111 // We do not support Win2K or older, or XP without service pack 2. |
| 107 VLOG(1) << "Windows Version: " << version | 112 VLOG(1) << "Windows Version: " << version |
| 108 << ", Service Pack: " << major << "." << minor; | 113 << ", Service Pack: " << major << "." << minor; |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 160 } | 165 } |
| 161 return (dll_names_count > 0) && success; | 166 return (dll_names_count > 0) && success; |
| 162 } | 167 } |
| 163 | 168 |
| 164 // This method tries to delete a registry key and logs an error message | 169 // This method tries to delete a registry key and logs an error message |
| 165 // in case of failure. It returns true if deletion is successful, | 170 // in case of failure. It returns true if deletion is successful, |
| 166 // otherwise false. | 171 // otherwise false. |
| 167 bool InstallUtil::DeleteRegistryKey(RegKey& root_key, | 172 bool InstallUtil::DeleteRegistryKey(RegKey& root_key, |
| 168 const std::wstring& key_path) { | 173 const std::wstring& key_path) { |
| 169 VLOG(1) << "Deleting registry key " << key_path; | 174 VLOG(1) << "Deleting registry key " << key_path; |
| 170 if (!root_key.DeleteKey(key_path.c_str()) && | 175 LONG result = root_key.DeleteKey(key_path.c_str()); |
| 171 ::GetLastError() != ERROR_FILE_NOT_FOUND) { | 176 if (result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) { |
| 172 PLOG(ERROR) << "Failed to delete registry key: " << key_path; | 177 PLOG(ERROR) << "Failed to delete registry key: " << key_path |
| 178 << " error: " << result; | |
| 173 return false; | 179 return false; |
| 174 } | 180 } |
| 175 return true; | 181 return true; |
| 176 } | 182 } |
| 177 | 183 |
| 178 // This method tries to delete a registry value and logs an error message | 184 // This method tries to delete a registry value and logs an error message |
| 179 // in case of failure. It returns true if deletion is successful, | 185 // in case of failure. It returns true if deletion is successful, |
| 180 // otherwise false. | 186 // otherwise false. |
| 181 bool InstallUtil::DeleteRegistryValue(HKEY reg_root, | 187 bool InstallUtil::DeleteRegistryValue(HKEY reg_root, |
| 182 const std::wstring& key_path, | 188 const std::wstring& key_path, |
| 183 const std::wstring& value_name) { | 189 const std::wstring& value_name) { |
| 184 RegKey key(reg_root, key_path.c_str(), KEY_ALL_ACCESS); | 190 RegKey key(reg_root, key_path.c_str(), KEY_ALL_ACCESS); |
| 185 VLOG(1) << "Deleting registry value " << value_name; | 191 VLOG(1) << "Deleting registry value " << value_name; |
| 186 if (key.ValueExists(value_name.c_str()) && | 192 if (key.ValueExists(value_name.c_str())) { |
| 187 !key.DeleteValue(value_name.c_str())) { | 193 LONG result = key.DeleteValue(value_name.c_str()); |
| 188 LOG(ERROR) << "Failed to delete registry value: " << value_name; | 194 if (result != ERROR_SUCCESS) { |
| 189 return false; | 195 LOG(ERROR) << "Failed to delete registry value: " << value_name |
| 196 << " error: " << result; | |
| 197 return false; | |
| 198 } | |
| 190 } | 199 } |
| 191 return true; | 200 return true; |
| 192 } | 201 } |
| 193 | 202 |
| 194 // static | 203 // static |
| 195 int InstallUtil::GetInstallReturnCode(installer::InstallStatus status) { | 204 int InstallUtil::GetInstallReturnCode(installer::InstallStatus status) { |
| 196 switch (status) { | 205 switch (status) { |
| 197 case installer::FIRST_INSTALL_SUCCESS: | 206 case installer::FIRST_INSTALL_SUCCESS: |
| 198 case installer::INSTALL_REPAIRED: | 207 case installer::INSTALL_REPAIRED: |
| 199 case installer::NEW_VERSION_UPDATED: | 208 case installer::NEW_VERSION_UPDATED: |
| 200 case installer::IN_USE_UPDATED: | 209 case installer::IN_USE_UPDATED: |
| 201 return 0; | 210 return 0; |
| 202 default: | 211 default: |
| 203 return status; | 212 return status; |
| 204 } | 213 } |
| 205 } | 214 } |
| OLD | NEW |