namespace platform_util {
-void ShowItemInFolder(const base::FilePath& path) {
+bool ShowItemInFolder(const base::FilePath& path) {
// The API only takes absolute path.
base::FilePath full_path =
path.IsAbsolute() ? path : base::MakeAbsoluteFilePath(path);
DCHECK([NSThread isMainThread]);
NSString* path_string = base::SysUTF8ToNSString(full_path.value());
if (!path_string || ![[NSWorkspace sharedWorkspace] selectFile:path_string
- inFileViewerRootedAtPath:@""])
+ inFileViewerRootedAtPath:@""]) {
LOG(WARNING) << "NSWorkspace failed to select file " << full_path.value();
+ return false;
+ }
+ return true;
}
// This function opens a file. This doesn't use LaunchServices or NSWorkspace
namespace platform_util {
-void ShowItemInFolder(const base::FilePath& full_path) {
+bool ShowItemInFolder(const base::FilePath& full_path) {
base::win::ScopedCOMInitializer com_initializer;
if (!com_initializer.succeeded())
return;
base::FilePath dir = full_path.DirName().AsEndingWithSeparator();
// ParseDisplayName will fail if the directory is "C:", it must be "C:\\".
if (dir.empty())
- return;
+ return false;
typedef HRESULT (WINAPI *SHOpenFolderAndSelectItemsFuncPtr)(
PCIDLIST_ABSOLUTE pidl_Folder,
HMODULE shell32_base = GetModuleHandle(L"shell32.dll");
if (!shell32_base) {
NOTREACHED() << " " << __FUNCTION__ << "(): Can't open shell32.dll";
- return;
+ return false;
}
open_folder_and_select_itemsPtr =
reinterpret_cast<SHOpenFolderAndSelectItemsFuncPtr>
(GetProcAddress(shell32_base, "SHOpenFolderAndSelectItems"));
}
if (!open_folder_and_select_itemsPtr) {
- ui::win::OpenFolderViaShell(dir);
- return;
+ return ui::win::OpenFolderViaShell(dir);
}
base::win::ScopedComPtr<IShellFolder> desktop;
HRESULT hr = SHGetDesktopFolder(desktop.Receive());
if (FAILED(hr))
- return;
+ return false;
base::win::ScopedCoMem<ITEMIDLIST> dir_item;
hr = desktop->ParseDisplayName(NULL, NULL,
const_cast<wchar_t *>(dir.value().c_str()),
NULL, &dir_item, NULL);
if (FAILED(hr)) {
- ui::win::OpenFolderViaShell(dir);
- return;
+ return ui::win::OpenFolderViaShell(dir);
}
base::win::ScopedCoMem<ITEMIDLIST> file_item;
const_cast<wchar_t *>(full_path.value().c_str()),
NULL, &file_item, NULL);
if (FAILED(hr)) {
- ui::win::OpenFolderViaShell(dir);
- return;
+ return ui::win::OpenFolderViaShell(dir);
}
const ITEMIDLIST* highlight[] = { file_item };
hr = (*open_folder_and_select_itemsPtr)(dir_item, arraysize(highlight),
highlight, NULL);
-
- if (FAILED(hr)) {
- // On some systems, the above call mysteriously fails with "file not
- // found" even though the file is there. In these cases, ShellExecute()
- // seems to work as a fallback (although it won't select the file).
- if (hr == ERROR_FILE_NOT_FOUND) {
- ui::win::OpenFolderViaShell(dir);
- } else {
- LPTSTR message = NULL;
- DWORD message_length = FormatMessage(
- FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
- 0, hr, 0, reinterpret_cast<LPTSTR>(&message), 0, NULL);
- LOG(WARNING) << " " << __FUNCTION__
- << "(): Can't open full_path = \""
- << full_path.value() << "\""
- << " hr = " << hr
- << " " << reinterpret_cast<LPTSTR>(&message);
- if (message)
- LocalFree(message);
-
- ui::win::OpenFolderViaShell(dir);
- }
+ if (!FAILED(hr))
+ return true;
+
+ // On some systems, the above call mysteriously fails with "file not
+ // found" even though the file is there. In these cases, ShellExecute()
+ // seems to work as a fallback (although it won't select the file).
+ if (hr == ERROR_FILE_NOT_FOUND) {
+ return ui::win::OpenFolderViaShell(dir);
+ } else {
+ LPTSTR message = NULL;
+ DWORD message_length = FormatMessage(
+ FORMAT_MESSAGE_ALLOCATE_BUFFER | FORMAT_MESSAGE_FROM_SYSTEM,
+ 0, hr, 0, reinterpret_cast<LPTSTR>(&message), 0, NULL);
+ LOG(WARNING) << " " << __FUNCTION__
+ << "(): Can't open full_path = \""
+ << full_path.value() << "\""
+ << " hr = " << hr
+ << " " << reinterpret_cast<LPTSTR>(&message);
+ if (message)
+ LocalFree(message);
+
+ return ui::win::OpenFolderViaShell(dir);
}
}