Skip to content

Commit

Permalink
Find wpa.exe in the path to support store versions
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
randomascii committed Jul 12, 2021
1 parent fd0a22f commit cf87c3f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 16 deletions.
5 changes: 4 additions & 1 deletion UIforETW/UIforETWDlg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -542,7 +542,10 @@ BOOL CUIforETWDlg::OnInitDialog()
}

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

// When WPT has just been installed it will not be in the path, which means
// that Python scripts which rely on xperf.exe being in the path will fail.
Expand Down
43 changes: 29 additions & 14 deletions UIforETW/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,30 @@ std::wstring GetEnvironmentVariableString(_In_z_ PCWSTR const variable)
return L"";
}

std::wstring FindInPath(const std::wstring& exeName)
{
const std::wstring path = GetEnvironmentVariableString(L"path");
if (path.empty())
{
// Nothing found.
return L"";
}

const std::vector<std::wstring> pathParts = split(path, ';');

for (const auto& part : pathParts)
{
if (part.empty())
continue;
const std::wstring foundPath = part + L'\\' + exeName;
if (::PathFileExistsW(foundPath.c_str()))
return foundPath;
}

// Nothing found.
return L"";
}

std::wstring FindPython()
{
const std::wstring pytwoseven = GetEnvironmentVariableString(L"python27");
Expand All @@ -830,25 +854,16 @@ std::wstring FindPython()
// See the issue: https://github.com/google/UIforETW/issues/13
if (!pytwoseven.empty())
return pytwoseven;
const std::wstring path = GetEnvironmentVariableString(L"path");
if (path.empty())
{
// No python found.
return L"";
}

const std::vector<std::wstring> pathParts = split(path, ';');
// First look for python.exe. If that isn't found then look for
// python.bat, part of Chromium's depot_tools
for (const auto& exeName : { L"\\python.exe", L"\\python.bat" })
for (const auto& exeName : { L"python.exe", L"python.bat" })
{
for (const auto& part : pathParts)
{
const std::wstring pythonPath = part + exeName;
if (::PathFileExistsW(pythonPath.c_str()))
return pythonPath;
}
auto result = FindInPath(exeName);
if (!result.empty())
return result;
}

// No python found.
return L"";
}
Expand Down
5 changes: 4 additions & 1 deletion UIforETW/Utility.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,10 @@ bool IsWindowsXPOrLesser();
bool IsWindowsSevenOrLesser();
bool IsWindowsVistaOrLesser();

std::wstring FindPython(); // Returns a full path to python.exe or nothing.
// Finds an executable in the path.
std::wstring FindInPath(const std::wstring& exeName);

std::wstring FindPython(); // Returns a full path to python.exe, python.bat, or nothing.

// Helpful timer class using trendy C++ 11 features.
class ElapsedTimer final
Expand Down

0 comments on commit cf87c3f

Please sign in to comment.