close
Skip to content
This repository was archived by the owner on May 29, 2025. It is now read-only.

Commit cf87c3f

Browse files
committed
Find wpa.exe in the path to support store versions
There are now previous versions of WPA in the Microsoft store and these versions are newer than the versions shipped through the SDK. This change teaches UIforETW how to search the path to find wpa.exe. This lets developers configure their system path so that the desired version of wpa.exe comes earliest in the path. This should be sufficient to finally resolve issue #118.
1 parent fd0a22f commit cf87c3f

3 files changed

Lines changed: 37 additions & 16 deletions

File tree

‎UIforETW/UIforETWDlg.cpp‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -542,7 +542,10 @@ BOOL CUIforETWDlg::OnInitDialog()
542542
}
543543

544544
gpuViewPath_ = wpt10Dir_ + L"gpuview\\gpuview.exe";
545-
wpa10Path_ = wpt10Dir_ + L"wpa.exe";
545+
// look for wpa.exe in the path so that the store version can be used.
546+
wpa10Path_ = FindInPath(L"wpa.exe");
547+
if (wpa10Path_.empty())
548+
wpa10Path_ = wpt10Dir_ + L"wpa.exe";
546549

547550
// When WPT has just been installed it will not be in the path, which means
548551
// that Python scripts which rely on xperf.exe being in the path will fail.

‎UIforETW/Utility.cpp‎

Lines changed: 29 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,30 @@ std::wstring GetEnvironmentVariableString(_In_z_ PCWSTR const variable)
820820
return L"";
821821
}
822822

823+
std::wstring FindInPath(const std::wstring& exeName)
824+
{
825+
const std::wstring path = GetEnvironmentVariableString(L"path");
826+
if (path.empty())
827+
{
828+
// Nothing found.
829+
return L"";
830+
}
831+
832+
const std::vector<std::wstring> pathParts = split(path, ';');
833+
834+
for (const auto& part : pathParts)
835+
{
836+
if (part.empty())
837+
continue;
838+
const std::wstring foundPath = part + L'\\' + exeName;
839+
if (::PathFileExistsW(foundPath.c_str()))
840+
return foundPath;
841+
}
842+
843+
// Nothing found.
844+
return L"";
845+
}
846+
823847
std::wstring FindPython()
824848
{
825849
const std::wstring pytwoseven = GetEnvironmentVariableString(L"python27");
@@ -830,25 +854,16 @@ std::wstring FindPython()
830854
// See the issue: https://github.com/google/UIforETW/issues/13
831855
if (!pytwoseven.empty())
832856
return pytwoseven;
833-
const std::wstring path = GetEnvironmentVariableString(L"path");
834-
if (path.empty())
835-
{
836-
// No python found.
837-
return L"";
838-
}
839857

840-
const std::vector<std::wstring> pathParts = split(path, ';');
841858
// First look for python.exe. If that isn't found then look for
842859
// python.bat, part of Chromium's depot_tools
843-
for (const auto& exeName : { L"\\python.exe", L"\\python.bat" })
860+
for (const auto& exeName : { L"python.exe", L"python.bat" })
844861
{
845-
for (const auto& part : pathParts)
846-
{
847-
const std::wstring pythonPath = part + exeName;
848-
if (::PathFileExistsW(pythonPath.c_str()))
849-
return pythonPath;
850-
}
862+
auto result = FindInPath(exeName);
863+
if (!result.empty())
864+
return result;
851865
}
866+
852867
// No python found.
853868
return L"";
854869
}

‎UIforETW/Utility.h‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,10 @@ bool IsWindowsXPOrLesser();
101101
bool IsWindowsSevenOrLesser();
102102
bool IsWindowsVistaOrLesser();
103103

104-
std::wstring FindPython(); // Returns a full path to python.exe or nothing.
104+
// Finds an executable in the path.
105+
std::wstring FindInPath(const std::wstring& exeName);
106+
107+
std::wstring FindPython(); // Returns a full path to python.exe, python.bat, or nothing.
105108

106109
// Helpful timer class using trendy C++ 11 features.
107110
class ElapsedTimer final

0 commit comments

Comments
 (0)