]> khamidou — GitHub mirrors - electron.git/commitdiff
Always fall back to OpenFolderViaShell when trying to reveal a file
authorPaul Betts <paul@paulbetts.org>
Wed, 13 Jan 2016 20:26:57 +0000 (12:26 -0800)
committerCheng Zhao <zcbenz@gmail.com>
Thu, 28 Jan 2016 11:05:16 +0000 (19:05 +0800)
We should always fallback to OpenFolderViaShell when revealing a file fails,
since this API seems to be highly subject to Random Bad Things happening to
you.

atom/common/platform_util_win.cc

index 735e974d1f8a0961d778e5649ed183e7a9060de1..4de5224668b67323e7012c043175a61b3061e281 100644 (file)
@@ -238,7 +238,7 @@ void ShowItemInFolder(const base::FilePath& full_path) {
             (GetProcAddress(shell32_base, "SHOpenFolderAndSelectItems"));
   }
   if (!open_folder_and_select_itemsPtr) {
-    ShellExecute(NULL, L"open", dir.value().c_str(), NULL, NULL, SW_SHOW);
+    ui::win::OpenFolderViaShell(dir);
     return;
   }
 
@@ -251,15 +251,19 @@ void ShowItemInFolder(const base::FilePath& full_path) {
   hr = desktop->ParseDisplayName(NULL, NULL,
                                  const_cast<wchar_t *>(dir.value().c_str()),
                                  NULL, &dir_item, NULL);
-  if (FAILED(hr))
+  if (FAILED(hr)) {
+    ui::win::OpenFolderViaShell(dir);
     return;
+  }
 
   base::win::ScopedCoMem<ITEMIDLIST> file_item;
   hr = desktop->ParseDisplayName(NULL, NULL,
       const_cast<wchar_t *>(full_path.value().c_str()),
       NULL, &file_item, NULL);
-  if (FAILED(hr))
+  if (FAILED(hr)) {
+    ui::win::OpenFolderViaShell(dir);
     return;
+  }
 
   const ITEMIDLIST* highlight[] = { file_item };
 
@@ -271,7 +275,7 @@ void ShowItemInFolder(const base::FilePath& full_path) {
     // 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) {
-      ShellExecute(NULL, L"open", dir.value().c_str(), NULL, NULL, SW_SHOW);
+      ui::win::OpenFolderViaShell(dir);
     } else {
       LPTSTR message = NULL;
       DWORD message_length = FormatMessage(
@@ -284,6 +288,8 @@ void ShowItemInFolder(const base::FilePath& full_path) {
                    << " " << reinterpret_cast<LPTSTR>(&message);
       if (message)
         LocalFree(message);
+
+      ui::win::OpenFolderViaShell(dir);
     }
   }
 }