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

Side by Side Diff: base/win/shortcut.cc

Issue 108193019: Installer: adding ResolveShortcutProperties(); updating shortcut icons during shortcut migration. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Adding ResolveShortcutProperties() to read thumbnails; requiring old target to matchs icon to for i… Created 7 years 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 | Annotate | Revision Log
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 "base/win/shortcut.h" 5 #include "base/win/shortcut.h"
6 6
7 #include <shellapi.h> 7 #include <shellapi.h>
8 #include <shlobj.h> 8 #include <shlobj.h>
9 #include <propkey.h> 9 #include <propkey.h>
10 10
(...skipping 154 matching lines...) Expand 10 before | Expand all | Expand 10 after
165 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL); 165 SHChangeNotify(SHCNE_ASSOCCHANGED, SHCNF_IDLIST, NULL, NULL);
166 } else { 166 } else {
167 SHChangeNotify(SHCNE_CREATE, SHCNF_PATH, shortcut_path.value().c_str(), 167 SHChangeNotify(SHCNE_CREATE, SHCNF_PATH, shortcut_path.value().c_str(),
168 NULL); 168 NULL);
169 } 169 }
170 } 170 }
171 171
172 return succeeded; 172 return succeeded;
173 } 173 }
174 174
175 bool ResolveShortcut(const FilePath& shortcut_path, 175 bool ResolveShortcutProperties(const FilePath& shortcut_path,
176 FilePath* target_path, 176 uint32 options,
177 string16* args) { 177 ShortcutProperties* p) {
gab 2013/12/23 14:25:01 s/p/properties Chromium doesn't encourage abbrevi
huangs 2013/12/30 20:15:10 Done (also .h and comments).
178 DCHECK(p != NULL);
gab 2013/12/23 14:25:01 DCHECK(properties); (i.e. no need for "!= NULL")
huangs 2013/12/30 20:15:10 Done.
178 base::ThreadRestrictions::AssertIOAllowed(); 179 base::ThreadRestrictions::AssertIOAllowed();
179 180
180 HRESULT result; 181 HRESULT result;
181 ScopedComPtr<IShellLink> i_shell_link; 182 ScopedComPtr<IShellLink> i_shell_link;
182 183
183 // Get pointer to the IShellLink interface. 184 // Get pointer to the IShellLink interface.
184 result = i_shell_link.CreateInstance(CLSID_ShellLink, NULL, 185 result = i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
185 CLSCTX_INPROC_SERVER); 186 CLSCTX_INPROC_SERVER);
186 if (FAILED(result)) 187 if (FAILED(result))
187 return false; 188 return false;
188 189
189 ScopedComPtr<IPersistFile> persist; 190 ScopedComPtr<IPersistFile> persist;
190 // Query IShellLink for the IPersistFile interface. 191 // Query IShellLink for the IPersistFile interface.
191 result = persist.QueryFrom(i_shell_link); 192 result = persist.QueryFrom(i_shell_link);
192 if (FAILED(result)) 193 if (FAILED(result))
193 return false; 194 return false;
194 195
195 // Load the shell link. 196 // Load the shell link.
196 result = persist->Load(shortcut_path.value().c_str(), STGM_READ); 197 result = persist->Load(shortcut_path.value().c_str(), STGM_READ);
197 if (FAILED(result)) 198 if (FAILED(result))
198 return false; 199 return false;
199 200
201 p->options = 0;
200 WCHAR temp[MAX_PATH]; 202 WCHAR temp[MAX_PATH];
201 if (target_path) { 203 if (options & ShortcutProperties::PROPERTIES_TARGET) {
202 // Try to find the target of a shortcut. 204 // Try to find the target of a shortcut.
203 result = i_shell_link->Resolve(0, SLR_NO_UI | SLR_NOSEARCH); 205 result = i_shell_link->Resolve(0, SLR_NO_UI | SLR_NOSEARCH);
204 if (FAILED(result)) 206 if (FAILED(result))
205 return false; 207 return false;
206 208
207 result = i_shell_link->GetPath(temp, MAX_PATH, NULL, SLGP_UNCPRIORITY); 209 result = i_shell_link->GetPath(temp, MAX_PATH, NULL, SLGP_UNCPRIORITY);
208 if (FAILED(result)) 210 if (FAILED(result))
209 return false; 211 return false;
210 212
211 *target_path = FilePath(temp); 213 p->set_target(FilePath(temp));
212 } 214 }
213 215
214 if (args) { 216 if (options & ShortcutProperties::PROPERTIES_ARGUMENTS) {
215 result = i_shell_link->GetArguments(temp, MAX_PATH); 217 result = i_shell_link->GetArguments(temp, MAX_PATH);
gab 2013/12/23 14:25:01 Looks like |result| is a write-only variable here
huangs 2013/12/30 20:15:10 Done.
216 if (FAILED(result)) 218 if (FAILED(result))
217 return false; 219 return false;
218 220
219 *args = string16(temp); 221 p->set_arguments(string16(temp));
220 } 222 }
223
224 if (options & ShortcutProperties::PROPERTIES_ICON) {
225 int temp_index;
226 if (FAILED(i_shell_link->GetIconLocation(temp, MAX_PATH, &temp_index)))
227 return false;
228
229 p->set_icon(FilePath(temp), temp_index);
230 }
231
232 // Implement other options if the need arise.
233
221 return true; 234 return true;
222 } 235 }
223 236
237 bool ResolveShortcut(const FilePath& shortcut_path,
238 FilePath* target_path,
239 string16* args) {
240 uint32 options = 0;
241 options |= target_path ? ShortcutProperties::PROPERTIES_TARGET : 0;
242 options |= args ? ShortcutProperties::PROPERTIES_ARGUMENTS : 0;
gab 2013/12/23 14:25:01 Change these two lines to: if (target_path) opt
huangs 2013/12/30 20:15:10 Done. Also, being defensive: return true if option
243 ShortcutProperties p;
244 if (!ResolveShortcutProperties(shortcut_path, options, &p))
245 return false;
246
247 if (target_path)
248 *target_path = p.target;
249 if (args)
250 *args = p.arguments;
251 return true;
252 }
253
224 bool TaskbarPinShortcutLink(const wchar_t* shortcut) { 254 bool TaskbarPinShortcutLink(const wchar_t* shortcut) {
225 base::ThreadRestrictions::AssertIOAllowed(); 255 base::ThreadRestrictions::AssertIOAllowed();
226 256
227 // "Pin to taskbar" is only supported after Win7. 257 // "Pin to taskbar" is only supported after Win7.
228 if (GetVersion() < VERSION_WIN7) 258 if (GetVersion() < VERSION_WIN7)
229 return false; 259 return false;
230 260
231 int result = reinterpret_cast<int>(ShellExecute(NULL, L"taskbarpin", shortcut, 261 int result = reinterpret_cast<int>(ShellExecute(NULL, L"taskbarpin", shortcut,
232 NULL, NULL, 0)); 262 NULL, NULL, 0));
233 return result > 32; 263 return result > 32;
234 } 264 }
235 265
236 bool TaskbarUnpinShortcutLink(const wchar_t* shortcut) { 266 bool TaskbarUnpinShortcutLink(const wchar_t* shortcut) {
237 base::ThreadRestrictions::AssertIOAllowed(); 267 base::ThreadRestrictions::AssertIOAllowed();
238 268
239 // "Unpin from taskbar" is only supported after Win7. 269 // "Unpin from taskbar" is only supported after Win7.
240 if (base::win::GetVersion() < base::win::VERSION_WIN7) 270 if (base::win::GetVersion() < base::win::VERSION_WIN7)
241 return false; 271 return false;
242 272
243 int result = reinterpret_cast<int>(ShellExecute(NULL, L"taskbarunpin", 273 int result = reinterpret_cast<int>(ShellExecute(NULL, L"taskbarunpin",
244 shortcut, NULL, NULL, 0)); 274 shortcut, NULL, NULL, 0));
245 return result > 32; 275 return result > 32;
246 } 276 }
247 277
248 } // namespace win 278 } // namespace win
249 } // namespace base 279 } // namespace base
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698