summaryrefslogtreecommitdiffstats
path: root/base/file_util_win.cc
diff options
context:
space:
mode:
authorgab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-06 19:23:11 +0000
committergab@chromium.org <gab@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-04-06 19:23:11 +0000
commit2e1a4a80ce1c1f986beb6d9ab38bb1a166ccb6d8 (patch)
tree50a44ed10db0ef30ed1a3c315ea72f77ad07c094 /base/file_util_win.cc
parent4d3ec0fa36368b7534a35400e75e00910f296a58 (diff)
downloadchromium_src-2e1a4a80ce1c1f986beb6d9ab38bb1a166ccb6d8.zip
chromium_src-2e1a4a80ce1c1f986beb6d9ab38bb1a166ccb6d8.tar.gz
chromium_src-2e1a4a80ce1c1f986beb6d9ab38bb1a166ccb6d8.tar.bz2
Win 8 Start Menu shortcut changes
BUG=119242 TEST=Test DualModeApp properties are correctly set in Windows 8 on Start Menu shortcut. Review URL: http://codereview.chromium.org/9837120 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131163 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/file_util_win.cc')
-rw-r--r--base/file_util_win.cc104
1 files changed, 36 insertions, 68 deletions
diff --git a/base/file_util_win.cc b/base/file_util_win.cc
index 7ea1aa3..7d28f5c 100644
--- a/base/file_util_win.cc
+++ b/base/file_util_win.cc
@@ -365,81 +365,40 @@ bool ResolveShortcut(FilePath* path) {
return is_resolved;
}
-bool CreateShortcutLink(const wchar_t *source, const wchar_t *destination,
- const wchar_t *working_dir, const wchar_t *arguments,
- const wchar_t *description, const wchar_t *icon,
- int icon_index, const wchar_t* app_id) {
+bool CreateOrUpdateShortcutLink(const wchar_t *source,
+ const wchar_t *destination,
+ const wchar_t *working_dir,
+ const wchar_t *arguments,
+ const wchar_t *description,
+ const wchar_t *icon,
+ int icon_index,
+ const wchar_t* app_id,
+ uint32 options) {
base::ThreadRestrictions::AssertIOAllowed();
- // Length of description must be less than MAX_PATH.
- DCHECK(lstrlen(description) < MAX_PATH);
-
- base::win::ScopedComPtr<IShellLink> i_shell_link;
- base::win::ScopedComPtr<IPersistFile> i_persist_file;
-
- // Get pointer to the IShellLink interface
- HRESULT result = i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
- CLSCTX_INPROC_SERVER);
- if (FAILED(result))
- return false;
-
- // Query IShellLink for the IPersistFile interface
- result = i_persist_file.QueryFrom(i_shell_link);
- if (FAILED(result))
- return false;
+ bool create = (options & SHORTCUT_CREATE_ALWAYS) != 0;
- if (FAILED(i_shell_link->SetPath(source)))
- return false;
-
- if (working_dir && FAILED(i_shell_link->SetWorkingDirectory(working_dir)))
- return false;
-
- if (arguments && FAILED(i_shell_link->SetArguments(arguments)))
- return false;
-
- if (description && FAILED(i_shell_link->SetDescription(description)))
- return false;
-
- if (icon && FAILED(i_shell_link->SetIconLocation(icon, icon_index)))
- return false;
-
- if (app_id && (base::win::GetVersion() >= base::win::VERSION_WIN7)) {
- base::win::ScopedComPtr<IPropertyStore> property_store;
- if (FAILED(property_store.QueryFrom(i_shell_link)))
- return false;
-
- if (!base::win::SetAppIdForPropertyStore(property_store, app_id))
- return false;
- }
-
- result = i_persist_file->Save(destination, TRUE);
- return SUCCEEDED(result);
-}
-
-bool UpdateShortcutLink(const wchar_t *source, const wchar_t *destination,
- const wchar_t *working_dir, const wchar_t *arguments,
- const wchar_t *description, const wchar_t *icon,
- int icon_index, const wchar_t* app_id) {
- base::ThreadRestrictions::AssertIOAllowed();
+ // |source| is required when SHORTCUT_CREATE_ALWAYS is specified.
+ DCHECK(source || !create);
// Length of arguments and description must be less than MAX_PATH.
DCHECK(lstrlen(arguments) < MAX_PATH);
DCHECK(lstrlen(description) < MAX_PATH);
- // Get pointer to the IPersistFile interface and load existing link
base::win::ScopedComPtr<IShellLink> i_shell_link;
- if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
- CLSCTX_INPROC_SERVER)))
- return false;
-
base::win::ScopedComPtr<IPersistFile> i_persist_file;
- if (FAILED(i_persist_file.QueryFrom(i_shell_link)))
+
+ // Get pointer to the IShellLink interface
+ if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
+ CLSCTX_INPROC_SERVER)) ||
+ FAILED(i_persist_file.QueryFrom(i_shell_link))) {
return false;
+ }
- if (FAILED(i_persist_file->Load(destination, STGM_READWRITE)))
+ if (!create && FAILED(i_persist_file->Load(destination, STGM_READWRITE)))
return false;
- if (source && FAILED(i_shell_link->SetPath(source)))
+ if ((source || create) && FAILED(i_shell_link->SetPath(source)))
return false;
if (working_dir && FAILED(i_shell_link->SetWorkingDirectory(working_dir)))
@@ -454,22 +413,31 @@ bool UpdateShortcutLink(const wchar_t *source, const wchar_t *destination,
if (icon && FAILED(i_shell_link->SetIconLocation(icon, icon_index)))
return false;
- if (app_id && base::win::GetVersion() >= base::win::VERSION_WIN7) {
+ bool is_dual_mode = (options & SHORTCUT_DUAL_MODE) != 0;
+ if ((app_id || is_dual_mode) &&
+ base::win::GetVersion() >= base::win::VERSION_WIN7) {
base::win::ScopedComPtr<IPropertyStore> property_store;
- if (FAILED(property_store.QueryFrom(i_shell_link)))
+ if (FAILED(property_store.QueryFrom(i_shell_link)) || !property_store.get())
return false;
- if (!base::win::SetAppIdForPropertyStore(property_store, app_id))
+ if (app_id && !base::win::SetAppIdForPropertyStore(property_store, app_id))
return false;
+ if (is_dual_mode &&
+ base::win::GetVersion() >= base::win::VERSION_WIN8 &&
+ !base::win::SetDualModeForPropertyStore(property_store)) {
+ return false;
+ }
}
HRESULT result = i_persist_file->Save(destination, TRUE);
- i_persist_file.Release();
- i_shell_link.Release();
-
// If we successfully updated the icon, notify the shell that we have done so.
- if (SUCCEEDED(result)) {
+ if (!create && SUCCEEDED(result)) {
+ // Release the interfaces in case the SHChangeNotify call below depends on
+ // the operations above being fully completed.
+ i_persist_file.Release();
+ i_shell_link.Release();
+
SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST | SHCNF_FLUSHNOWAIT,
NULL, NULL);
}