Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "chrome/installer/setup/update_shortcuts.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/files/file_enumerator.h" | |
| 9 #include "base/files/file_path.h" | |
| 10 #include "base/logging.h" | |
| 11 #include "base/strings/string16.h" | |
| 12 #include "base/strings/string_util.h" | |
| 13 #include "base/win/shortcut.h" | |
| 14 #include "chrome/common/chrome_switches.h" | |
| 15 | |
| 16 namespace installer { | |
| 17 | |
| 18 void UpdateShortcuts(const ShellUtil::ShortcutLocation shortcut_location, | |
| 19 const ShellUtil::ShellChange shortcut_level, | |
| 20 BrowserDistribution* dist, | |
| 21 const base::FilePath& old_target_path_prefix, | |
| 22 const base::FilePath& old_target_path_suffix, | |
| 23 const base::FilePath& new_target_path) { | |
| 24 base::FilePath shortcut_path; | |
| 25 const bool get_shortcut_path_return = ShellUtil::GetShortcutPath( | |
| 26 shortcut_location, dist, shortcut_level, &shortcut_path); | |
| 27 DCHECK(get_shortcut_path_return); | |
| 28 | |
| 29 base::FileEnumerator shortcuts_enum(shortcut_path, true, // recursive | |
|
gab
2016/03/09 20:10:44
Blind recursion here is potentially dangerous (i.e
fdoray
2016/03/09 22:13:03
ok, I now use recursion only for taskbar pins.
| |
| 30 base::FileEnumerator::FILES); | |
| 31 | |
| 32 base::FilePath existing_target_path; | |
| 33 base::string16 existing_args_unused; | |
|
gab
2016/03/09 20:10:44
ResolveShortcut() supports null arguments, so no n
fdoray
2016/03/09 22:13:03
Done.
| |
| 34 for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); | |
| 35 shortcut = shortcuts_enum.Next()) { | |
| 36 if (!base::win::ResolveShortcut(shortcut, &existing_target_path, | |
| 37 &existing_args_unused) || | |
| 38 !base::StartsWith(existing_target_path.value(), | |
| 39 old_target_path_prefix.value(), | |
| 40 base::CompareCase::INSENSITIVE_ASCII) || | |
| 41 !base::EndsWith(existing_target_path.value(), | |
| 42 old_target_path_suffix.value(), | |
| 43 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 44 continue; | |
| 45 } | |
| 46 | |
| 47 base::win::ShortcutProperties updated_properties; | |
| 48 updated_properties.set_target(new_target_path); | |
| 49 | |
| 50 base::win::CreateOrUpdateShortcutLink(shortcut, updated_properties, | |
| 51 base::win::SHORTCUT_UPDATE_EXISTING); | |
| 52 } | |
| 53 } | |
| 54 | |
| 55 } // namespace installer | |
| OLD | NEW |