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

Side by Side Diff: base/file_util_win.cc

Issue 10837034: Remove packaged app Windows shortcuts when app is uninstalled. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Android compile Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « base/file_util_unittest.cc ('k') | chrome/browser/extensions/app_shortcut_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/file_util.h" 5 #include "base/file_util.h"
6 6
7 #include <windows.h> 7 #include <windows.h>
8 #include <propvarutil.h> 8 #include <propvarutil.h>
9 #include <psapi.h> 9 #include <psapi.h>
10 #include <shellapi.h> 10 #include <shellapi.h>
(...skipping 314 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 325
326 bool GetFileCreationLocalTime(const std::wstring& filename, 326 bool GetFileCreationLocalTime(const std::wstring& filename,
327 LPSYSTEMTIME creation_time) { 327 LPSYSTEMTIME creation_time) {
328 base::ThreadRestrictions::AssertIOAllowed(); 328 base::ThreadRestrictions::AssertIOAllowed();
329 base::win::ScopedHandle file_handle( 329 base::win::ScopedHandle file_handle(
330 CreateFile(filename.c_str(), GENERIC_READ, kFileShareAll, NULL, 330 CreateFile(filename.c_str(), GENERIC_READ, kFileShareAll, NULL,
331 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL)); 331 OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL));
332 return GetFileCreationLocalTimeFromHandle(file_handle.Get(), creation_time); 332 return GetFileCreationLocalTimeFromHandle(file_handle.Get(), creation_time);
333 } 333 }
334 334
335 bool ResolveShortcut(FilePath* path) { 335 bool ResolveShortcut(const FilePath& shortcut_path,
336 FilePath* target_path,
337 string16* args) {
336 base::ThreadRestrictions::AssertIOAllowed(); 338 base::ThreadRestrictions::AssertIOAllowed();
337 339
338 HRESULT result; 340 HRESULT result;
339 base::win::ScopedComPtr<IShellLink> i_shell_link; 341 base::win::ScopedComPtr<IShellLink> i_shell_link;
340 bool is_resolved = false;
341 342
342 // Get pointer to the IShellLink interface 343 // Get pointer to the IShellLink interface.
343 result = i_shell_link.CreateInstance(CLSID_ShellLink, NULL, 344 result = i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
344 CLSCTX_INPROC_SERVER); 345 CLSCTX_INPROC_SERVER);
345 if (SUCCEEDED(result)) { 346 if (FAILED(result))
346 base::win::ScopedComPtr<IPersistFile> persist; 347 return false;
347 // Query IShellLink for the IPersistFile interface 348
348 result = persist.QueryFrom(i_shell_link); 349 base::win::ScopedComPtr<IPersistFile> persist;
349 if (SUCCEEDED(result)) { 350 // Query IShellLink for the IPersistFile interface.
350 WCHAR temp_path[MAX_PATH]; 351 result = persist.QueryFrom(i_shell_link);
351 // Load the shell link 352 if (FAILED(result))
352 result = persist->Load(path->value().c_str(), STGM_READ); 353 return false;
353 if (SUCCEEDED(result)) { 354
354 // Try to find the target of a shortcut 355 // Load the shell link.
355 result = i_shell_link->Resolve(0, SLR_NO_UI); 356 result = persist->Load(shortcut_path.value().c_str(), STGM_READ);
356 if (SUCCEEDED(result)) { 357 if (FAILED(result))
357 result = i_shell_link->GetPath(temp_path, MAX_PATH, 358 return false;
358 NULL, SLGP_UNCPRIORITY); 359
359 *path = FilePath(temp_path); 360 WCHAR temp[MAX_PATH];
360 is_resolved = true; 361 if (target_path) {
361 } 362 // Try to find the target of a shortcut.
362 } 363 result = i_shell_link->Resolve(0, SLR_NO_UI);
363 } 364 if (FAILED(result))
365 return false;
366
367 result = i_shell_link->GetPath(temp, MAX_PATH, NULL, SLGP_UNCPRIORITY);
368 if (FAILED(result))
369 return false;
370
371 *target_path = FilePath(temp);
364 } 372 }
365 373
366 return is_resolved; 374 if (args) {
375 result = i_shell_link->GetArguments(temp, MAX_PATH);
376 if (FAILED(result))
377 return false;
378
379 *args = string16(temp);
380 }
381 return true;
367 } 382 }
368 383
369 bool CreateOrUpdateShortcutLink(const wchar_t *source, 384 bool CreateOrUpdateShortcutLink(const wchar_t *source,
370 const wchar_t *destination, 385 const wchar_t *destination,
371 const wchar_t *working_dir, 386 const wchar_t *working_dir,
372 const wchar_t *arguments, 387 const wchar_t *arguments,
373 const wchar_t *description, 388 const wchar_t *description,
374 const wchar_t *icon, 389 const wchar_t *icon,
375 int icon_index, 390 int icon_index,
376 const wchar_t* app_id, 391 const wchar_t* app_id,
377 uint32 options) { 392 uint32 options) {
378 base::ThreadRestrictions::AssertIOAllowed(); 393 base::ThreadRestrictions::AssertIOAllowed();
379 394
380 bool create = (options & SHORTCUT_CREATE_ALWAYS) != 0; 395 bool create = (options & SHORTCUT_CREATE_ALWAYS) != 0;
381 396
382 // |source| is required when SHORTCUT_CREATE_ALWAYS is specified. 397 // |source| is required when SHORTCUT_CREATE_ALWAYS is specified.
383 DCHECK(source || !create); 398 DCHECK(source || !create);
384 399
385 // Length of arguments and description must be less than MAX_PATH. 400 // Length of arguments and description must be less than MAX_PATH.
386 DCHECK(lstrlen(arguments) < MAX_PATH); 401 DCHECK(lstrlen(arguments) < MAX_PATH);
387 DCHECK(lstrlen(description) < MAX_PATH); 402 DCHECK(lstrlen(description) < MAX_PATH);
388 403
389 base::win::ScopedComPtr<IShellLink> i_shell_link; 404 base::win::ScopedComPtr<IShellLink> i_shell_link;
390 base::win::ScopedComPtr<IPersistFile> i_persist_file; 405 base::win::ScopedComPtr<IPersistFile> i_persist_file;
391 406
392 // Get pointer to the IShellLink interface 407 // Get pointer to the IShellLink interface.
393 if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL, 408 if (FAILED(i_shell_link.CreateInstance(CLSID_ShellLink, NULL,
394 CLSCTX_INPROC_SERVER)) || 409 CLSCTX_INPROC_SERVER)) ||
395 FAILED(i_persist_file.QueryFrom(i_shell_link))) { 410 FAILED(i_persist_file.QueryFrom(i_shell_link))) {
396 return false; 411 return false;
397 } 412 }
398 413
399 if (!create && FAILED(i_persist_file->Load(destination, STGM_READWRITE))) 414 if (!create && FAILED(i_persist_file->Load(destination, STGM_READWRITE)))
400 return false; 415 return false;
401 416
402 if ((source || create) && FAILED(i_shell_link->SetPath(source))) 417 if ((source || create) && FAILED(i_shell_link->SetPath(source)))
(...skipping 704 matching lines...) Expand 10 before | Expand all | Expand 10 after
1107 HANDLE cp = GetCurrentProcess(); 1122 HANDLE cp = GetCurrentProcess();
1108 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) { 1123 if (::GetMappedFileNameW(cp, file_view, mapped_file_path, kMaxPathLength)) {
1109 *nt_path = FilePath(mapped_file_path); 1124 *nt_path = FilePath(mapped_file_path);
1110 success = true; 1125 success = true;
1111 } 1126 }
1112 ::UnmapViewOfFile(file_view); 1127 ::UnmapViewOfFile(file_view);
1113 return success; 1128 return success;
1114 } 1129 }
1115 1130
1116 } // namespace file_util 1131 } // namespace file_util
OLDNEW
« no previous file with comments | « base/file_util_unittest.cc ('k') | chrome/browser/extensions/app_shortcut_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698