Skip to content

Commit 43145b4

Browse files
committed
✨ Add active runtime to reports
1 parent 4f66bf8 commit 43145b4

File tree

4 files changed

+70
-0
lines changed

4 files changed

+70
-0
lines changed

src/CMakeLists.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ add_library(
3636
std23/ranges.hpp
3737
ConstexprString.hpp
3838
StringTemplateParameter.hpp
39+
GetActiveRuntimePath.hpp
40+
windows/GetActiveRuntimePath.cpp
3941
)
4042

4143
# Using an OBJECT library instead of `STATIC`, because otherwise
@@ -105,6 +107,7 @@ if(WIN32)
105107
lib
106108
PRIVATE
107109
windows/CheckForUpdates.cpp
110+
windows/GetActiveRuntimePath.cpp
108111
)
109112

110113
target_sources(

src/GetActiveRuntimePath.hpp

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// Copyright 2023 Fred Emmott <[email protected]>
2+
// SPDX-License-Identifier: ISC
3+
4+
#pragma once
5+
6+
#include <filesystem>
7+
8+
namespace FredEmmott::OpenXRLayers {
9+
10+
/** Return the path of the active runtime.
11+
*
12+
* Will return an empty path if the active runtime can not be determined.
13+
*/
14+
std::filesystem::path GetActiveRuntimePath();
15+
16+
}// namespace FredEmmott::OpenXRLayers

src/SaveReport.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
#include "APILayerStore.hpp"
1414
#include "Config.hpp"
15+
#include "GetActiveRuntimePath.hpp"
1516
#include "Linter.hpp"
1617

1718
namespace FredEmmott::OpenXRLayers {
@@ -121,6 +122,14 @@ void SaveReport(const std::filesystem::path& path) {
121122
std::chrono::zoned_time(
122123
std::chrono::current_zone(), std::chrono::system_clock::now()));
123124

125+
const auto runtime = GetActiveRuntimePath();
126+
if (runtime.empty()) {
127+
text
128+
+= std::format("\n\n{} NO ACTIVE RUNTIME FOUND\n", Config::GLYPH_ERROR);
129+
} else {
130+
text += std::format("\n\nActive runtime: {}\n", runtime.string());
131+
}
132+
124133
for (const auto store: APILayerStore::Get()) {
125134
text += GenerateReportText(store);
126135
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright 2023 Fred Emmott <[email protected]>
2+
3+
#include "../GetActiveRuntimePath.hpp"
4+
5+
#include <Windows.h>
6+
7+
#include <assert.h>
8+
9+
namespace FredEmmott::OpenXRLayers {
10+
11+
static LSTATUS GetActiveRuntimePath(void* data, DWORD* dataSize) {
12+
return RegGetValueW(
13+
HKEY_LOCAL_MACHINE,
14+
L"SOFTWARE\\Khronos\\OpenXR\\1",
15+
L"ActiveRuntime",
16+
RRF_RT_REG_SZ,
17+
nullptr,
18+
data,
19+
dataSize);
20+
}
21+
22+
std::filesystem::path GetActiveRuntimePath() {
23+
DWORD dataSize {0};
24+
if (GetActiveRuntimePath(nullptr, &dataSize) != ERROR_SUCCESS) {
25+
return {};
26+
}
27+
if (dataSize == 0) {
28+
return {};
29+
}
30+
assert(dataSize % sizeof(wchar_t) == 0);
31+
32+
std::wstring ret;
33+
ret.resize(dataSize / sizeof(WCHAR));
34+
GetActiveRuntimePath(ret.data(), &dataSize);
35+
while (ret.back() == L'\0') {
36+
ret.pop_back();
37+
}
38+
39+
return ret;
40+
}
41+
42+
}// namespace FredEmmott::OpenXRLayers

0 commit comments

Comments
 (0)