OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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> |
11 #include <shlobj.h> | 11 #include <shlobj.h> |
12 #include <shlwapi.h> | 12 #include <shlwapi.h> |
13 | 13 |
14 #include <algorithm> | 14 #include <algorithm> |
| 15 #include <vector> |
15 | 16 |
16 #include "base/command_line.h" | 17 #include "base/command_line.h" |
17 #include "base/files/file_util.h" | 18 #include "base/files/file_util.h" |
18 #include "base/logging.h" | 19 #include "base/logging.h" |
19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
20 #include "base/path_service.h" | 21 #include "base/path_service.h" |
21 #include "base/process/launch.h" | 22 #include "base/process/launch.h" |
| 23 #include "base/strings/string16.h" |
| 24 #include "base/strings/string_number_conversions.h" |
| 25 #include "base/strings/string_split.h" |
22 #include "base/strings/string_util.h" | 26 #include "base/strings/string_util.h" |
23 #include "base/strings/utf_string_conversions.h" | 27 #include "base/strings/utf_string_conversions.h" |
24 #include "base/sys_info.h" | 28 #include "base/sys_info.h" |
25 #include "base/values.h" | 29 #include "base/values.h" |
26 #include "base/version.h" | 30 #include "base/version.h" |
27 #include "base/win/metro.h" | 31 #include "base/win/metro.h" |
28 #include "base/win/registry.h" | 32 #include "base/win/registry.h" |
29 #include "base/win/windows_version.h" | 33 #include "base/win/windows_version.h" |
30 #include "chrome/common/chrome_constants.h" | 34 #include "chrome/common/chrome_constants.h" |
31 #include "chrome/common/chrome_paths.h" | 35 #include "chrome/common/chrome_paths.h" |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 } else { | 125 } else { |
122 NOTREACHED() << "Unable to get default monitor"; | 126 NOTREACHED() << "Unable to get default monitor"; |
123 } | 127 } |
124 ::SetForegroundWindow(foreground_window); | 128 ::SetForegroundWindow(foreground_window); |
125 } | 129 } |
126 return foreground_window; | 130 return foreground_window; |
127 } | 131 } |
128 | 132 |
129 } // namespace | 133 } // namespace |
130 | 134 |
| 135 base::string16 InstallUtil::GetActiveSetupVersionFromExisting( |
| 136 ActiveSetupVersionComponent component, |
| 137 ActiveSetupVersionOperation operation, |
| 138 int value, |
| 139 const base::string16& existing_version) { |
| 140 std::vector<base::string16> version_components = base::SplitString( |
| 141 existing_version, L",", base::TRIM_WHITESPACE, base::SPLIT_WANT_NONEMPTY); |
| 142 |
| 143 // If |existing_version| was empty or otherwise corrupted, turn it into a |
| 144 // valid one. |
| 145 if (version_components.size() != 4U) |
| 146 version_components.assign(4U, L"0"); |
| 147 |
| 148 switch (operation) { |
| 149 case SET: |
| 150 version_components[component] = base::IntToString16(value); |
| 151 break; |
| 152 case BUMP: |
| 153 int previous_value; |
| 154 if (base::StringToInt(version_components[component], &previous_value)) { |
| 155 version_components[component] = |
| 156 base::IntToString16(previous_value + value); |
| 157 } |
| 158 break; |
| 159 } |
| 160 |
| 161 return JoinString(version_components, L','); |
| 162 } |
| 163 |
| 164 bool InstallUtil::UpdateActiveSetupVersion( |
| 165 BrowserDistribution* dist, |
| 166 ActiveSetupVersionComponent component, |
| 167 ActiveSetupVersionOperation operation, |
| 168 int value) { |
| 169 base::string16 active_setup_reg(GetActiveSetupPath(dist)); |
| 170 base::win::RegKey active_setup_key; |
| 171 if (active_setup_key.Open(HKEY_LOCAL_MACHINE, active_setup_reg.c_str(), |
| 172 KEY_QUERY_VALUE | KEY_SET_VALUE) != ERROR_SUCCESS) { |
| 173 VLOG(1) << "Unable to open Active Setup key."; |
| 174 return false; |
| 175 } |
| 176 |
| 177 base::string16 existing_version; |
| 178 if (active_setup_key.ReadValue(L"Version", |
| 179 &existing_version) != ERROR_SUCCESS) { |
| 180 VLOG(1) << "Unable to read Active Setup key to string."; |
| 181 return false; |
| 182 } |
| 183 |
| 184 base::string16 updated_version = GetActiveSetupVersionFromExisting( |
| 185 component, operation, value, existing_version); |
| 186 |
| 187 return active_setup_key.WriteValue(L"Version", updated_version.c_str()) == |
| 188 ERROR_SUCCESS; |
| 189 } |
| 190 |
131 base::string16 InstallUtil::GetActiveSetupPath(BrowserDistribution* dist) { | 191 base::string16 InstallUtil::GetActiveSetupPath(BrowserDistribution* dist) { |
132 static const wchar_t kInstalledComponentsPath[] = | 192 static const wchar_t kInstalledComponentsPath[] = |
133 L"Software\\Microsoft\\Active Setup\\Installed Components\\"; | 193 L"Software\\Microsoft\\Active Setup\\Installed Components\\"; |
134 return kInstalledComponentsPath + dist->GetActiveSetupGuid(); | 194 return kInstalledComponentsPath + dist->GetActiveSetupGuid(); |
135 } | 195 } |
136 | 196 |
137 void InstallUtil::TriggerActiveSetupCommand() { | 197 void InstallUtil::TriggerActiveSetupCommand() { |
138 base::string16 active_setup_reg( | 198 base::string16 active_setup_reg( |
139 GetActiveSetupPath(BrowserDistribution::GetDistribution())); | 199 GetActiveSetupPath(BrowserDistribution::GetDistribution())); |
140 base::win::RegKey active_setup_key( | 200 base::win::RegKey active_setup_key( |
(...skipping 510 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
651 // Open the program and see if it references the expected file. | 711 // Open the program and see if it references the expected file. |
652 base::File file; | 712 base::File file; |
653 BY_HANDLE_FILE_INFORMATION info = {}; | 713 BY_HANDLE_FILE_INFORMATION info = {}; |
654 | 714 |
655 return (OpenForInfo(path, &file) && | 715 return (OpenForInfo(path, &file) && |
656 GetInfo(file, &info) && | 716 GetInfo(file, &info) && |
657 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && | 717 info.dwVolumeSerialNumber == file_info_.dwVolumeSerialNumber && |
658 info.nFileIndexHigh == file_info_.nFileIndexHigh && | 718 info.nFileIndexHigh == file_info_.nFileIndexHigh && |
659 info.nFileIndexLow == file_info_.nFileIndexLow); | 719 info.nFileIndexLow == file_info_.nFileIndexLow); |
660 } | 720 } |
OLD | NEW |