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_per_user_shortcuts_in_location.h" | |
| 6 | |
| 7 #include "base/command_line.h" | |
|
gab
2016/03/10 06:01:03
Not required?
fdoray
2016/03/10 14:32:46
Done.
| |
| 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" | |
|
gab
2016/03/10 06:01:03
Which switch is used? I don't see anything requiri
fdoray
2016/03/10 14:32:46
Done.
| |
| 15 | |
| 16 namespace installer { | |
| 17 | |
| 18 void UpdatePerUserShortcutsInLocation( | |
| 19 const ShellUtil::ShortcutLocation shortcut_location, | |
| 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, ShellUtil::CURRENT_USER, &shortcut_path); | |
| 27 DCHECK(get_shortcut_path_return); | |
| 28 | |
| 29 bool recursive = false; | |
| 30 | |
| 31 // TODO(fdoray): Modify GetShortcutPath such that it returns | |
| 32 // ...\Quick Launch\User Pinned instead of | |
| 33 // ...\Quick Launch\User Pinned\TaskBar for SHORTCUT_LOCATION_TASKBAR_PINS. | |
| 34 if (shortcut_location == ShellUtil::SHORTCUT_LOCATION_TASKBAR_PINS) { | |
| 35 shortcut_path = shortcut_path.DirName(); | |
| 36 recursive = true; | |
| 37 } | |
| 38 | |
| 39 base::FileEnumerator shortcuts_enum(shortcut_path, recursive, | |
| 40 base::FileEnumerator::FILES); | |
| 41 for (base::FilePath shortcut = shortcuts_enum.Next(); !shortcut.empty(); | |
| 42 shortcut = shortcuts_enum.Next()) { | |
| 43 base::FilePath existing_target_path; | |
| 44 if (!base::win::ResolveShortcut(shortcut, &existing_target_path, nullptr) || | |
| 45 !base::StartsWith(existing_target_path.value(), | |
| 46 old_target_path_prefix.value(), | |
| 47 base::CompareCase::INSENSITIVE_ASCII) || | |
| 48 !base::EndsWith(existing_target_path.value(), | |
| 49 old_target_path_suffix.value(), | |
| 50 base::CompareCase::INSENSITIVE_ASCII)) { | |
| 51 continue; | |
| 52 } | |
| 53 | |
| 54 base::win::ShortcutProperties updated_properties; | |
| 55 updated_properties.set_target(new_target_path); | |
| 56 base::win::CreateOrUpdateShortcutLink(shortcut, updated_properties, | |
| 57 base::win::SHORTCUT_UPDATE_EXISTING); | |
| 58 } | |
| 59 } | |
| 60 | |
| 61 } // namespace installer | |
| OLD | NEW |