From ad0dde0725256c54cdd321c2d03492c7e2930a97 Mon Sep 17 00:00:00 2001 From: PabloMK7 Date: Sun, 5 Jul 2026 00:00:57 +0200 Subject: [PATCH] common: Detect and print AppData folder get failures (#2259) --- src/common/file_util.cpp | 16 ++++++++++------ src/common/logging/backend.cpp | 6 ++++-- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/common/file_util.cpp b/src/common/file_util.cpp index 2e3874de8..b6df4b953 100644 --- a/src/common/file_util.cpp +++ b/src/common/file_util.cpp @@ -864,12 +864,16 @@ const std::string& GetExeDirectory() { } std::string AppDataRoamingDirectory() { - PWSTR pw_local_path = nullptr; - // Only supported by Windows Vista or later - SHGetKnownFolderPath(FOLDERID_RoamingAppData, 0, nullptr, &pw_local_path); - std::string local_path = Common::UTF16ToUTF8(pw_local_path); - CoTaskMemFree(pw_local_path); - return local_path; + PWSTR path = nullptr; + + const HRESULT hr = + SHGetKnownFolderPath(FOLDERID_RoamingAppData, KF_FLAG_DEFAULT, nullptr, &path); + + ASSERT_MSG(SUCCEEDED(hr) && path != nullptr, "Failed to get AppData directory: {:X}", hr); + + std::string result = Common::UTF16ToUTF8(path); + CoTaskMemFree(path); + return result; } #else /** diff --git a/src/common/logging/backend.cpp b/src/common/logging/backend.cpp index 837911981..610715cf7 100644 --- a/src/common/logging/backend.cpp +++ b/src/common/logging/backend.cpp @@ -573,7 +573,9 @@ void Start() { } void Stop() { - Impl::Stop(); + if (logging_initialized) { + Impl::Stop(); + } } void DisableLoggingInTests() { @@ -595,7 +597,7 @@ void SetColorConsoleBackendEnabled(bool enabled) { void FmtLogMessageImpl(Class log_class, Level log_level, const char* filename, unsigned int line_num, const char* function, fmt::string_view format, const fmt::format_args& args) { - if (initialization_in_progress_suppress_logging) [[unlikely]] { + if (initialization_in_progress_suppress_logging && log_level < Level::Critical) [[unlikely]] { return; }