Skip to content
This repository was archived by the owner on Mar 5, 2024. It is now read-only.

Commit f0d11ec

Browse files
committed
Fixed an issue that universally broke portable builds on windows 10. oops.
(cherry picked from commit c182fc7)
1 parent 8c51db1 commit f0d11ec

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

tf2_bot_detector/Platform/Windows/Windows.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,14 @@ static const tf2_bot_detector::WinRT* GetWinRTInterface()
9797
{
9898
struct WinRTHelper
9999
{
100-
WinRTHelper()
100+
WinRTHelper(const tf2_bot_detector::WinRT* fallbackInterface)
101101
{
102102
constexpr char WINRT_DLL_NAME[] = "tf2_bot_detector_winrt.dll";
103103
m_Module = mh_ensure(LoadLibraryA(WINRT_DLL_NAME));
104104

105105
CreateWinRTInterfaceFn func = reinterpret_cast<CreateWinRTInterfaceFn>(GetProcAddressHelper(WINRT_DLL_NAME, "CreateWinRTInterface"));
106106

107-
m_WinRT.reset(func());
107+
m_WinRT.reset(func(fallbackInterface));
108108

109109
struct DummyType {};
110110
m_ExceptionDetailsHandler = mh::exception_details::add_handler(
@@ -147,14 +147,14 @@ static const tf2_bot_detector::WinRT* GetWinRTInterface()
147147

148148
static const tf2_bot_detector::WinRT* s_Value = []() -> const tf2_bot_detector::WinRT*
149149
{
150+
static const FallbackWinRTInterface s_FallbackInterface;
150151
if (IsReallyWindows10OrGreater())
151152
{
152-
static WinRTHelper s_Helper;
153+
static WinRTHelper s_Helper(&s_FallbackInterface);
153154
return s_Helper.m_WinRT.get();
154155
}
155156
else
156157
{
157-
static const FallbackWinRTInterface s_FallbackInterface;
158158
return &s_FallbackInterface;
159159
}
160160
}();

tf2_bot_detector_winrt/tf2_bot_detector_winrt.cpp

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,36 +15,62 @@ namespace
1515
class WinRTImpl final : public tf2_bot_detector::WinRT
1616
{
1717
public:
18+
WinRTImpl(const tf2_bot_detector::WinRT* fallback) : m_Fallback(fallback) {}
19+
1820
std::filesystem::path GetLocalAppDataDir() const override;
1921
std::filesystem::path GetRoamingAppDataDir() const override;
2022
std::filesystem::path GetTempDir() const override;
2123
std::wstring GetCurrentPackageFamilyName() const override;
2224

2325
const mh::exception_details_handler& GetWinRTExceptionDetailsHandler() const override;
26+
27+
private:
28+
const tf2_bot_detector::WinRT* m_Fallback{};
2429
};
2530

26-
std::filesystem::path WinRTImpl::GetLocalAppDataDir() const
31+
std::filesystem::path WinRTImpl::GetLocalAppDataDir() const try
2732
{
2833
auto appData = winrt::Windows::Storage::ApplicationData::Current();
2934
auto path = appData.LocalFolder().Path();
3035
return std::filesystem::path(path.begin(), path.end());
3136
}
37+
catch (...)
38+
{
39+
if (m_Fallback)
40+
return m_Fallback->GetLocalAppDataDir();
41+
42+
throw;
43+
}
3244

33-
std::filesystem::path WinRTImpl::GetRoamingAppDataDir() const
45+
std::filesystem::path WinRTImpl::GetRoamingAppDataDir() const try
3446
{
3547
auto appData = winrt::Windows::Storage::ApplicationData::Current();
3648
auto path = appData.RoamingFolder().Path();
3749
return std::filesystem::path(path.begin(), path.end());
3850
}
51+
catch (...)
52+
{
53+
if (m_Fallback)
54+
return m_Fallback->GetRoamingAppDataDir();
55+
56+
throw;
57+
}
3958

40-
std::filesystem::path WinRTImpl::GetTempDir() const
59+
std::filesystem::path WinRTImpl::GetTempDir() const try
4160
{
4261
auto appData = winrt::Windows::Storage::ApplicationData::Current();
4362
auto path = appData.TemporaryFolder().Path();
4463
return std::filesystem::path(path.begin(), path.end());
4564
}
65+
catch (...)
66+
{
67+
if (m_Fallback)
68+
return m_Fallback->GetTempDir();
4669

47-
std::wstring WinRTImpl::GetCurrentPackageFamilyName() const
70+
throw;
71+
}
72+
73+
std::wstring WinRTImpl::GetCurrentPackageFamilyName() const try
4874
{
4975
static const std::wstring s_CurrentPackageFamilyName = []() -> std::wstring
5076
{
@@ -73,8 +99,15 @@ namespace
7399

74100
return s_CurrentPackageFamilyName;
75101
}
102+
catch (...)
103+
{
104+
if (m_Fallback)
105+
return m_Fallback->GetCurrentPackageFamilyName();
106+
107+
throw;
108+
}
76109

77-
const mh::exception_details_handler& WinRTImpl::GetWinRTExceptionDetailsHandler() const
110+
const mh::exception_details_handler& WinRTImpl::GetWinRTExceptionDetailsHandler() const try
78111
{
79112
class Handler final : public mh::exception_details_handler
80113
{
@@ -83,7 +116,7 @@ namespace
83116
{
84117
const auto FormatHRMessage = [](const winrt::hresult_error& hr)
85118
{
86-
return mh::format(MH_FMT_STRING("{:#x}: "),
119+
return mh::format(MH_FMT_STRING("{:#x}: {}"),
87120
hr.code(), mh::change_encoding<char>(hr.message().c_str()));
88121
};
89122

@@ -122,9 +155,16 @@ namespace
122155

123156
return s_Handler;
124157
}
158+
catch (...)
159+
{
160+
if (m_Fallback)
161+
return m_Fallback->GetWinRTExceptionDetailsHandler();
162+
163+
throw;
164+
}
125165
}
126166

127-
extern "C" TF2_BOT_DETECTOR_WINRT_EXPORT tf2_bot_detector::WinRT* CreateWinRTInterface()
167+
extern "C" TF2_BOT_DETECTOR_WINRT_EXPORT tf2_bot_detector::WinRT* CreateWinRTInterface(const tf2_bot_detector::WinRT* fallback)
128168
{
129-
return new WinRTImpl();
169+
return new WinRTImpl(fallback);
130170
}

tf2_bot_detector_winrt/tf2_bot_detector_winrt.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,5 @@ namespace tf2_bot_detector
2222
virtual const mh::exception_details_handler& GetWinRTExceptionDetailsHandler() const = 0;
2323
};
2424

25-
using CreateWinRTInterfaceFn = WinRT*(*)();
25+
using CreateWinRTInterfaceFn = WinRT*(*)(const WinRT* fallback);
2626
}

0 commit comments

Comments
 (0)