Skip to content

Commit

Permalink
Improve Browse Folder to select current trace
Browse files Browse the repository at this point in the history
When opening the folder containing ETW traces it is helpful to select
the one that was selected in UIfroETW. Now this happens.
  • Loading branch information
randomascii committed Jul 8, 2020
1 parent 57f370f commit 9684759
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion UIforETW/UIforETWDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down
24 changes: 24 additions & 0 deletions UIforETW/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
3 changes: 3 additions & 0 deletions UIforETW/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);

0 comments on commit 9684759

Please sign in to comment.