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

Unified Diff: chrome/installer/util/shell_util.cc

Issue 11743022: Windows: Remove desktop profile shortcuts (and any others pointing to the exe) on uninstall. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 7 years, 12 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | chrome/installer/util/shell_util_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/installer/util/shell_util.cc
===================================================================
--- chrome/installer/util/shell_util.cc (revision 174984)
+++ chrome/installer/util/shell_util.cc (working copy)
@@ -1154,6 +1154,35 @@
return ProbeOpenCommandHandlers(protocols, num_protocols);
}
+// Removes shortcut at |shortcut_path| if it is a shortcut that points to
+// |target_exe|. If |delete_folder| is true, deletes the parent folder of
+// the shortcut completely. Returns true if either the shortcut was deleted
+// successfully or if the shortcut did not point to |target_exe|.
+bool MaybeRemoveShortcutAtPath(const FilePath& shortcut_path,
+ const FilePath& target_exe,
+ bool delete_folder) {
+ FilePath target_path;
+ if (!base::win::ResolveShortcut(shortcut_path, &target_path, NULL))
+ return false;
+
+ if (InstallUtil::ProgramCompare(target_exe).EvaluatePath(target_path)) {
+ // Unpin the shortcut if it was ever pinned by the user or the installer.
+ VLOG(1) << "Trying to unpin " << shortcut_path.value();
+ if (!base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str())) {
+ VLOG(1) << shortcut_path.value()
+ << " wasn't pinned (or the unpin failed).";
+ }
+ if (delete_folder)
+ return file_util::Delete(shortcut_path.DirName(), true);
+ else
+ return file_util::Delete(shortcut_path, false);
+ }
+
+ // The shortcut at |shortcut_path| doesn't point to |target_exe|, act as if
+ // our shortcut had been deleted.
+ return true;
+}
+
} // namespace
const wchar_t* ShellUtil::kRegDefaultIcon = L"\\DefaultIcon";
@@ -1277,13 +1306,13 @@
user_shortcut_path = user_shortcut_path.Append(shortcut_name);
system_shortcut_path = system_shortcut_path.Append(shortcut_name);
- FilePath *chosen_path;
+ FilePath* chosen_path;
bool should_install_shortcut = true;
if (properties.level == SYSTEM_LEVEL) {
// Install the system-level shortcut if requested.
chosen_path = &system_shortcut_path;
} else if (operation != SHELL_SHORTCUT_CREATE_IF_NO_SYSTEM_LEVEL ||
- !file_util::PathExists(system_shortcut_path)){
+ !file_util::PathExists(system_shortcut_path)) {
// Otherwise install the user-level shortcut, unless the system-level
// variant of this shortcut is present on the machine and |operation| states
// not to create a user-level shortcut in that case.
@@ -1795,10 +1824,10 @@
bool ShellUtil::RemoveShortcut(ShellUtil::ShortcutLocation location,
BrowserDistribution* dist,
- const string16& target_exe,
+ const FilePath& target_exe,
ShellChange level,
const string16* shortcut_name) {
- bool delete_folder = (location == SHORTCUT_LOCATION_START_MENU);
+ const bool delete_folder = (location == SHORTCUT_LOCATION_START_MENU);
FilePath shortcut_folder;
if (!GetShortcutPath(location, dist, level, &shortcut_folder) ||
@@ -1807,43 +1836,29 @@
return false;
}
- string16 shortcut_base_name(
+ if (!delete_folder && !shortcut_name) {
+ file_util::FileEnumerator enumerator(shortcut_folder, false,
+ file_util::FileEnumerator::FILES);
+ bool had_failures = false;
+ for (FilePath path = enumerator.Next(); !path.empty();
+ path = enumerator.Next()) {
+ if (path.Extension() != installer::kLnkExt)
+ continue;
+
+ if (!MaybeRemoveShortcutAtPath(path, target_exe, delete_folder))
+ had_failures = true;
+ }
+ return !had_failures;
+ }
+
+ const string16 shortcut_base_name(
(shortcut_name ? *shortcut_name : dist->GetAppShortCutName()) +
installer::kLnkExt);
- FilePath shortcut_path(shortcut_folder.Append(shortcut_base_name));
-
+ const FilePath shortcut_path(shortcut_folder.Append(shortcut_base_name));
if (!file_util::PathExists(shortcut_path))
return true;
- base::win::ScopedComPtr<IShellLink> i_shell_link;
- base::win::ScopedComPtr<IPersistFile> i_persist_file;
- wchar_t read_target[MAX_PATH] = {};
- if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
- CLSCTX_INPROC_SERVER)) ||
- FAILED(i_persist_file.QueryFrom(i_shell_link)) ||
- FAILED(i_persist_file->Load(shortcut_path.value().c_str(), STGM_READ)) ||
- FAILED(i_shell_link->GetPath(read_target, MAX_PATH, NULL,
- SLGP_SHORTPATH))) {
- NOTREACHED();
- return false;
- }
-
- if (InstallUtil::ProgramCompare(FilePath(target_exe)).Evaluate(read_target)) {
- // Unpin the shortcut if it was ever pinned by the user or the installer.
- VLOG(1) << "Trying to unpin " << shortcut_path.value();
- if (!base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str())) {
- VLOG(1) << shortcut_path.value()
- << " wasn't pinned (or the unpin failed).";
- }
- if (delete_folder)
- return file_util::Delete(shortcut_folder, true);
- else
- return file_util::Delete(shortcut_path, false);
- }
-
- // The shortcut at |shortcut_path| doesn't point to |target_exe|, act as if
- // our shortcut had been deleted.
- return true;
+ return MaybeRemoveShortcutAtPath(shortcut_path, target_exe, delete_folder);
}
void ShellUtil::RemoveTaskbarShortcuts(const string16& target_exe) {
@@ -1870,7 +1885,7 @@
LOG(ERROR) << "Couldn't resolve shortcut at " << shortcut_path.value();
continue;
}
- if (target_compare.Evaluate(read_target.value())) {
+ if (target_compare.EvaluatePath(read_target)) {
// Unpin this shortcut if it points to |target_exe|.
base::win::TaskbarUnpinShortcutLink(shortcut_path.value().c_str());
}
« no previous file with comments | « chrome/installer/util/shell_util.h ('k') | chrome/installer/util/shell_util_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698