Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1860)

Side by Side Diff: chrome/installer/setup/install.cc

Issue 1800303006: Fix the path of shortcuts with an icon in the current install dir. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix nit Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/installer/setup/install.h ('k') | chrome/installer/setup/install_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 #include "chrome/installer/setup/install.h" 5 #include "chrome/installer/setup/install.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <time.h> 9 #include <time.h>
10 10
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 return installer::NEW_VERSION_UPDATED; 246 return installer::NEW_VERSION_UPDATED;
247 } 247 }
248 248
249 LOG(ERROR) << "Not sure how we got here while updating" 249 LOG(ERROR) << "Not sure how we got here while updating"
250 << ", new version: " << new_version 250 << ", new version: " << new_version
251 << ", old version: " << **current_version; 251 << ", old version: " << **current_version;
252 252
253 return installer::INSTALL_FAILED; 253 return installer::INSTALL_FAILED;
254 } 254 }
255 255
256 // Returns the number of components in |file_path|.
257 size_t GetNumPathComponents(const base::FilePath& file_path) {
258 std::vector<base::FilePath::StringType> components;
259 file_path.GetComponents(&components);
260 return components.size();
261 }
262
263 // Returns a path made with the |num_components| first components of
264 // |file_path|. |file_path| is returned as-is if it contains less than
265 // |num_components| components.
266 base::FilePath TruncatePath(const base::FilePath& file_path,
267 size_t num_components) {
268 std::vector<base::FilePath::StringType> components;
269 file_path.GetComponents(&components);
270 if (components.size() <= num_components)
271 return file_path;
272 base::FilePath truncated_file_path;
273 for (size_t i = 0; i < num_components; ++i)
274 truncated_file_path = truncated_file_path.Append(components[i]);
275 return truncated_file_path;
276 }
277
256 } // namespace 278 } // namespace
257 279
258 namespace installer { 280 namespace installer {
259 281
260 void UpdatePerUserShortcutsInLocation( 282 void UpdatePerUserShortcutsInLocation(
261 const ShellUtil::ShortcutLocation shortcut_location, 283 const ShellUtil::ShortcutLocation shortcut_location,
262 BrowserDistribution* dist, 284 BrowserDistribution* dist,
263 const base::FilePath& old_target_dir, 285 const base::FilePath& old_target_dir,
264 const base::FilePath& old_target_path_suffix, 286 const base::FilePath& old_target_name_suffix,
265 const base::FilePath& new_target_path) { 287 const base::FilePath& new_target_path) {
266 base::FilePath shortcut_path; 288 base::FilePath shortcut_path;
267 const bool get_shortcut_path_return = ShellUtil::GetShortcutPath( 289 const bool get_shortcut_path_return = ShellUtil::GetShortcutPath(
268 shortcut_location, dist, ShellUtil::CURRENT_USER, &shortcut_path); 290 shortcut_location, dist, ShellUtil::CURRENT_USER, &shortcut_path);
269 DCHECK(get_shortcut_path_return); 291 DCHECK(get_shortcut_path_return);
270 292
271 bool recursive = false; 293 bool recursive = false;
272 294
273 // TODO(fdoray): Modify GetShortcutPath such that it returns 295 // TODO(fdoray): Modify GetShortcutPath such that it returns
274 // ...\Quick Launch\User Pinned instead of 296 // ...\Quick Launch\User Pinned instead of
275 // ...\Quick Launch\User Pinned\TaskBar for SHORTCUT_LOCATION_TASKBAR_PINS. 297 // ...\Quick Launch\User Pinned\TaskBar for SHORTCUT_LOCATION_TASKBAR_PINS.
276 if (shortcut_location == ShellUtil::SHORTCUT_LOCATION_TASKBAR_PINS) { 298 if (shortcut_location == ShellUtil::SHORTCUT_LOCATION_TASKBAR_PINS) {
277 shortcut_path = shortcut_path.DirName(); 299 shortcut_path = shortcut_path.DirName();
278 recursive = true; 300 recursive = true;
279 } 301 }
280 302
303 const size_t num_old_target_dir_components =
304 GetNumPathComponents(old_target_dir);
305 InstallUtil::ProgramCompare old_target_dir_comparator(
306 old_target_dir,
307 true); // Support directories.
308
281 base::FileEnumerator shortcuts_enum(shortcut_path, recursive, 309 base::FileEnumerator shortcuts_enum(shortcut_path, recursive,
282 base::FileEnumerator::FILES); 310 base::FileEnumerator::FILES);
283 for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); 311 for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty();
284 shortcut = shortcuts_enum.Next()) { 312 shortcut = shortcuts_enum.Next()) {
285 base::FilePath existing_target_path; 313 base::win::ShortcutProperties shortcut_properties;
286 if (!base::win::ResolveShortcut(shortcut, &existing_target_path, nullptr) || 314 if (!base::win::ResolveShortcutProperties(
287 !base::StartsWith(existing_target_path.value(), 315 shortcut, (base::win::ShortcutProperties::PROPERTIES_TARGET |
288 old_target_dir.AsEndingWithSeparator().value(), 316 base::win::ShortcutProperties::PROPERTIES_ICON),
289 base::CompareCase::INSENSITIVE_ASCII) || 317 &shortcut_properties)) {
290 !base::EndsWith(existing_target_path.value(),
291 old_target_path_suffix.value(),
292 base::CompareCase::INSENSITIVE_ASCII)) {
293 continue; 318 continue;
294 } 319 }
295 320
321 // Skip shortcuts whose target isn't a file rooted at |old_target_dir| with
322 // a name ending in |old_target_name_suffix|. Except for shortcuts whose
323 // icon is rooted at |old_target_dir|.
324 // TODO(fdoray): The second condition is only intended to fix Canary
325 // shortcuts broken by crbug.com/595374, remove it in May 2016.
326 if (!(old_target_dir_comparator.EvaluatePath(TruncatePath(
327 shortcut_properties.target, num_old_target_dir_components)) &&
gab 2016/03/21 15:06:59 Truncating to specific number of components could
328 base::EndsWith(shortcut_properties.target.BaseName().value(),
329 old_target_name_suffix.value(),
330 base::CompareCase::INSENSITIVE_ASCII)) &&
331 !old_target_dir_comparator.EvaluatePath(TruncatePath(
332 shortcut_properties.icon, num_old_target_dir_components))) {
333 continue;
334 }
335
296 base::win::ShortcutProperties updated_properties; 336 base::win::ShortcutProperties updated_properties;
297 updated_properties.set_target(new_target_path); 337 updated_properties.set_target(new_target_path);
298 base::win::CreateOrUpdateShortcutLink(shortcut, updated_properties, 338 base::win::CreateOrUpdateShortcutLink(shortcut, updated_properties,
299 base::win::SHORTCUT_UPDATE_EXISTING); 339 base::win::SHORTCUT_UPDATE_EXISTING);
300 } 340 }
301 } 341 }
302 342
303 void EscapeXmlAttributeValueInSingleQuotes(base::string16* att_value) { 343 void EscapeXmlAttributeValueInSingleQuotes(base::string16* att_value) {
304 base::ReplaceChars(*att_value, base::ASCIIToUTF16("&"), 344 base::ReplaceChars(*att_value, base::ASCIIToUTF16("&"),
305 base::ASCIIToUTF16("&amp;"), att_value); 345 base::ASCIIToUTF16("&amp;"), att_value);
(...skipping 407 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 // Read master_preferences copied beside chrome.exe at install. 753 // Read master_preferences copied beside chrome.exe at install.
714 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs)); 754 MasterPreferences prefs(installation_root.AppendASCII(kDefaultMasterPrefs));
715 base::FilePath chrome_exe(installation_root.Append(kChromeExe)); 755 base::FilePath chrome_exe(installation_root.Append(kChromeExe));
716 CreateOrUpdateShortcuts( 756 CreateOrUpdateShortcuts(
717 chrome_exe, chrome, prefs, CURRENT_USER, install_operation); 757 chrome_exe, chrome, prefs, CURRENT_USER, install_operation);
718 758
719 UpdateDefaultBrowserBeaconForPath(chrome_exe); 759 UpdateDefaultBrowserBeaconForPath(chrome_exe);
720 } 760 }
721 761
722 } // namespace installer 762 } // namespace installer
OLDNEW
« no previous file with comments | « chrome/installer/setup/install.h ('k') | chrome/installer/setup/install_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698