Skip to content

Commit b2c7cda

Browse files
committed
Key active/available runtimes by architecture
1 parent c590c85 commit b2c7cda

5 files changed

Lines changed: 49 additions & 56 deletions

File tree

src/Platform.cpp

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,8 @@ AvailableRuntime::AvailableRuntime(
5959
Platform::Platform() = default;
6060
Platform::~Platform() = default;
6161

62-
std::optional<Runtime> Platform::Get32BitRuntime() {
63-
return GetRuntimeFromPath(Get32BitRuntimePath());
64-
}
65-
66-
std::optional<Runtime> Platform::Get64BitRuntime() {
67-
return GetRuntimeFromPath(Get64BitRuntimePath());
68-
}
69-
std::optional<Runtime> Platform::GetActiveRuntime() {
70-
if constexpr (sizeof(void*) == 8) {
71-
return Get64BitRuntime();
72-
} else if constexpr (sizeof(void*) == 4) {
73-
return Get32BitRuntime();
74-
}
75-
std::unreachable();
62+
std::optional<Runtime> Platform::GetActiveRuntime(const Architecture arch) {
63+
return GetRuntimeFromPath(GetActiveRuntimePath(arch));
7664
}
7765

7866
}// namespace FredEmmott::OpenXRLayers

src/Platform.hpp

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,6 @@ class Platform {
5858
static Platform& Get();
5959
virtual ~Platform();
6060

61-
std::optional<Runtime> Get32BitRuntime();
62-
std::optional<Runtime> Get64BitRuntime();
63-
std::optional<Runtime> GetActiveRuntime();
64-
6561
virtual void GUIMain(std::function<void()> drawFrame) = 0;
6662

6763
/// Unlike `std::filesystem::last_write_time()`, this should
@@ -83,8 +79,9 @@ class Platform {
8379
virtual std::vector<std::string> GetEnabledExplicitAPILayers() = 0;
8480
virtual float GetDPIScaling() = 0;
8581

86-
virtual std::vector<AvailableRuntime> GetAvailable32BitRuntimes() = 0;
87-
virtual std::vector<AvailableRuntime> GetAvailable64BitRuntimes() = 0;
82+
virtual std::vector<AvailableRuntime> GetAvailableRuntimes(Architecture) = 0;
83+
std::optional<Runtime> GetActiveRuntime(
84+
Architecture = GetBuildArchitecture());
8885

8986
// Use OS/environment equivalent to Explorer
9087
virtual void ShowFolderContainingFile(const std::filesystem::path&) = 0;
@@ -112,8 +109,7 @@ class Platform {
112109
boost::signals2::signal<void()> mOnLoaderDataSignal;
113110

114111
Platform();
115-
virtual std::filesystem::path Get32BitRuntimePath() = 0;
116-
virtual std::filesystem::path Get64BitRuntimePath() = 0;
112+
virtual std::filesystem::path GetActiveRuntimePath(Architecture) = 0;
117113
};
118114

119115
constexpr Architecture Platform::GetBuildArchitecture() {

src/SaveReport.cpp

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -148,34 +148,36 @@ static std::string GenerateReportText(const APILayerStore* store) {
148148
}
149149

150150
static std::string GenerateActiveRuntimeText(
151-
const uint8_t bitness,
151+
const Architecture arch,
152152
const std::optional<Runtime>& runtime) {
153+
const auto archName = magic_enum::enum_name(arch);
153154
if (!runtime) {
154-
return std::format("❌ Active {}-bit runtime: NONE\n", bitness);
155+
return std::format("❌ Active {} runtime: NONE\n", archName);
155156
}
156157

157158
if (!runtime->mName) {
158159
if (runtime->mName.error() != Runtime::ManifestError::FieldNotPresent) {
159160
return std::format(
160-
"🚨 Active {}-bit runtime: CORRUPTED - {}\n",
161-
bitness,
161+
"🚨 Active {} runtime: CORRUPTED - {}\n",
162+
archName,
162163
runtime->mPath.string());
163164
}
164165
return std::format(
165-
"✅ Active {}-bit runtime: {}\n", bitness, runtime->mPath.string());
166+
"✅ Active {} runtime: {}\n", archName, runtime->mPath.string());
166167
}
167168

168169
return std::format(
169-
"✅ Active {}-bit runtime: \"{}\" - {}\n",
170-
bitness,
170+
"✅ Active {} runtime: \"{}\" - {}\n",
171+
archName,
171172
runtime->mName.value(),
172173
runtime->mPath.string());
173174
}
174175

175176
static std::string GenerateAvailableRuntimesText(
176-
const uint8_t bitness,
177+
const Architecture arch,
177178
const std::vector<AvailableRuntime>& runtimes) {
178-
auto ret = std::format("\nAvailable {}-bit runtimes:\n", bitness);
179+
const auto archName = magic_enum::enum_name(arch);
180+
auto ret = std::format("\nAvailable {} runtimes:\n", archName);
179181
if (runtimes.empty()) {
180182
return ret + " NONE\n";
181183
}
@@ -336,13 +338,13 @@ std::string GenerateReport() {
336338
std::chrono::current_zone(), std::chrono::system_clock::now()));
337339

338340
auto& platform = Platform::Get();
339-
text += GenerateActiveRuntimeText(64, platform.Get64BitRuntime());
340-
text += GenerateActiveRuntimeText(32, platform.Get32BitRuntime());
341-
342-
text
343-
+= GenerateAvailableRuntimesText(64, platform.GetAvailable64BitRuntimes());
344-
text
345-
+= GenerateAvailableRuntimesText(32, platform.GetAvailable32BitRuntimes());
341+
for (const auto arch: platform.GetArchitectures().enumerate()) {
342+
text += GenerateActiveRuntimeText(arch, platform.GetActiveRuntime(arch));
343+
}
344+
for (const auto arch: platform.GetArchitectures().enumerate()) {
345+
text += GenerateAvailableRuntimesText(
346+
arch, platform.GetAvailableRuntimes(arch));
347+
}
346348

347349
for (const auto store: APILayerStore::Get()) {
348350
text += GenerateReportText(store);

src/windows/WindowsPlatform.cpp

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ namespace FredEmmott::OpenXRLayers {
4848

4949
namespace {
5050

51-
std::vector<AvailableRuntime> GetAvailableRuntimes(const REGSAM bitness) {
51+
std::vector<AvailableRuntime> GetAvailableRuntimesByWowFlag(
52+
const REGSAM bitness) {
5253
const REGSAM desiredAccess = bitness | KEY_READ;
5354
wil::unique_hkey hkey;
5455
RegOpenKeyExW(
@@ -104,7 +105,7 @@ GetActiveRuntimePath(const REGSAM desiredAccess, void* data, DWORD* dataSize) {
104105
dataSize);
105106
}
106107

107-
std::filesystem::path GetActiveRuntimePath(const REGSAM wowFlag) {
108+
std::filesystem::path GetActiveRuntimePathByWowFlag(const REGSAM wowFlag) {
108109
const REGSAM desiredAccess = wowFlag | KEY_QUERY_VALUE;
109110

110111
DWORD dataSize {0};
@@ -351,12 +352,16 @@ std::map<std::string, std::string> WindowsPlatform::GetEnvironmentVariables() {
351352
return ret;
352353
}
353354

354-
std::vector<AvailableRuntime> WindowsPlatform::GetAvailable32BitRuntimes() {
355-
return GetAvailableRuntimes(KEY_WOW64_32KEY);
356-
}
357-
358-
std::vector<AvailableRuntime> WindowsPlatform::GetAvailable64BitRuntimes() {
359-
return GetAvailableRuntimes(KEY_WOW64_64KEY);
355+
std::vector<AvailableRuntime> WindowsPlatform::GetAvailableRuntimes(
356+
const Architecture arch) {
357+
switch (arch) {
358+
case Architecture::x64:
359+
return GetAvailableRuntimesByWowFlag(KEY_WOW64_64KEY);
360+
case Architecture::x86:
361+
return GetAvailableRuntimesByWowFlag(KEY_WOW64_32KEY);
362+
default:
363+
throw std::logic_error("Unsupported architecture");
364+
}
360365
}
361366
std::filesystem::file_time_type WindowsPlatform::GetFileChangeTime(
362367
const std::filesystem::path& path) {
@@ -1059,12 +1064,16 @@ Platform& Platform::Get() {
10591064
return sInstance;
10601065
}
10611066

1062-
std::filesystem::path WindowsPlatform::Get32BitRuntimePath() {
1063-
return GetActiveRuntimePath(KEY_WOW64_32KEY);
1064-
}
1065-
1066-
std::filesystem::path WindowsPlatform::Get64BitRuntimePath() {
1067-
return GetActiveRuntimePath(KEY_WOW64_64KEY);
1067+
std::filesystem::path WindowsPlatform::GetActiveRuntimePath(
1068+
const Architecture arch) {
1069+
switch (arch) {
1070+
case Architecture::x86:
1071+
return GetActiveRuntimePathByWowFlag(KEY_WOW64_32KEY);
1072+
case Architecture::x64:
1073+
return GetActiveRuntimePathByWowFlag(KEY_WOW64_64KEY);
1074+
default:
1075+
throw std::logic_error("Unsupported architecture");
1076+
}
10681077
}
10691078

10701079
}// namespace FredEmmott::OpenXRLayers

src/windows/WindowsPlatform.hpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,7 @@ class WindowsPlatform final : public Platform {
3535
void ShowFolderContainingFile(const std::filesystem::path& path) override;
3636
std::map<std::string, std::string> GetEnvironmentVariables() override;
3737

38-
std::vector<AvailableRuntime> GetAvailable32BitRuntimes() override;
39-
std::vector<AvailableRuntime> GetAvailable64BitRuntimes() override;
38+
std::vector<AvailableRuntime> GetAvailableRuntimes(Architecture) override;
4039
std::filesystem::file_time_type GetFileChangeTime(
4140
const std::filesystem::path& path) override;
4241

@@ -52,8 +51,7 @@ class WindowsPlatform final : public Platform {
5251
const std::filesystem::path&) const override;
5352

5453
protected:
55-
std::filesystem::path Get32BitRuntimePath() override;
56-
std::filesystem::path Get64BitRuntimePath() override;
54+
std::filesystem::path GetActiveRuntimePath(Architecture) override;
5755

5856
private:
5957
wil::unique_hwnd mWindowHandle {};

0 commit comments

Comments
 (0)