OLD | NEW |
---|---|
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 Loading... | |
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 |
brettw
2012/08/07 17:51:27
While you're modifying these, can you make sure th
| |
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, |
(...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 |
OLD | NEW |