Skip to content

Commit

Permalink
Fallback to open folder when file does not exist
Browse files Browse the repository at this point in the history
  • Loading branch information
Aemony committed Jun 8, 2024
1 parent 663859e commit 209ac30
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/utility/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2636,20 +2636,27 @@ SKIF_Util_FileExplorer_SelectFile (PCWSTR filePath)
// Unused
SFGAOF flags = 0;

// You should call this function from a background thread. Failure to do so could cause the UI to stop responding.
if (S_OK == SHParseDisplayName (_data->path.c_str(), nullptr, &iidlPtr, 0, &flags))
if (PathFileExists (_data->path.c_str()))
{
// CoInitialize or CoInitializeEx must be called before using SHOpenFolderAndSelectItems.
// Not doing so causes SHOpenFolderAndSelectItems to fail.
if (S_OK == SHOpenFolderAndSelectItems (iidlPtr, 0, nullptr, 0))
// You should call this function from a background thread. Failure to do so could cause the UI to stop responding.
if (S_OK == SHParseDisplayName (_data->path.c_str(), nullptr, &iidlPtr, 0, &flags))
{
// Success !
// CoInitialize or CoInitializeEx must be called before using SHOpenFolderAndSelectItems.
// Not doing so causes SHOpenFolderAndSelectItems to fail.
if (S_OK == SHOpenFolderAndSelectItems (iidlPtr, 0, nullptr, 0))
{ } // Success

// Use the task allocator to free to returned pidl
ILFree (iidlPtr);
}
}

// Use the task allocator to free to returned pidl
ILFree (iidlPtr);
else {
SKIF_Util_ExplorePath (std::filesystem::path(_data->path).parent_path().wstring());
}

PLOG_VERBOSE << "Worker_SelectFile shutting down...";

// Free up the memory we allocated
delete _data;

Expand Down

0 comments on commit 209ac30

Please sign in to comment.