@@ -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}
0 commit comments