diff --git a/UIforETW/UIforETWDlg.cpp b/UIforETW/UIforETWDlg.cpp index b4f3a841..e000ce85 100644 --- a/UIforETW/UIforETWDlg.cpp +++ b/UIforETW/UIforETWDlg.cpp @@ -2130,7 +2130,7 @@ void CUIforETWDlg::OnContextMenu(CWnd* pWnd, CPoint point) AfxMessageBox(L"Not implemented yet."); break; case ID_TRACES_BROWSEFOLDER: - ShellExecute(NULL, L"open", GetTraceDir().c_str(), NULL, GetTraceDir().c_str(), SW_SHOW); + OpenFolderAndSelectItem(tracePath, GetTraceDir()); break; case ID_TRACES_STRIPCHROMESYMBOLS: outputPrintf(L"\n"); diff --git a/UIforETW/Utility.cpp b/UIforETW/Utility.cpp index 4f77072b..0ec69bd4 100644 --- a/UIforETW/Utility.cpp +++ b/UIforETW/Utility.cpp @@ -1040,3 +1040,27 @@ HeapTracedProcesses ParseHeapTracingSettings(std::wstring heapTracingExes) return result; } + +// This should really be called from a background thread to avoid UI hangs. +void OpenFolderAndSelectItem(std::wstring filename, std::wstring dir) +{ + bool opened = false; + + if (!filename.empty()) + { + // Parse the full filename into a pidl + PIDLIST_ABSOLUTE pidl; + SFGAOF flags; + if (SHParseDisplayName(filename.c_str(), nullptr, &pidl, 0, &flags) == S_OK) + { + // Open Explorer and select the thing + if (SHOpenFolderAndSelectItems(pidl, 0, nullptr, 0) == S_OK) + opened = true; + // Use the task allocator to free the pidl + CoTaskMemFree(pidl); + } + } + + if (!opened) + ShellExecute(NULL, L"open", dir.c_str(), NULL, dir.c_str(), SW_SHOW); +} diff --git a/UIforETW/Utility.h b/UIforETW/Utility.h index c10250ae..6484fe24 100644 --- a/UIforETW/Utility.h +++ b/UIforETW/Utility.h @@ -238,3 +238,6 @@ struct HeapTracedProcesses // Parse the semi-colon separated heap trace settings HeapTracedProcesses ParseHeapTracingSettings(std::wstring heapTracingExes); + +// This should really be called from a background thread to avoid UI hangs. +void OpenFolderAndSelectItem(std::wstring filename, std::wstring dir);