From c7fefd74b677f127ec5702e418f102986fc5b8aa Mon Sep 17 00:00:00 2001 From: Gleb Mazovetskiy Date: Wed, 20 Sep 2023 09:17:14 +0100 Subject: [PATCH] `LoggedFstream`: Fix `OpenFile` error check Fixes #6626 --- Source/init.cpp | 4 +++- Source/utils/file_util.cpp | 4 ++-- Source/utils/logged_fstream.hpp | 2 +- 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/Source/init.cpp b/Source/init.cpp index 739a78b66..20c95c432 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -156,7 +156,9 @@ std::vector GetMPQSearchPaths() } #endif - paths.emplace_back(""); // PWD + if (paths.empty() || !paths.back().empty()) { + paths.emplace_back(); // PWD + } if (SDL_LOG_PRIORITY_VERBOSE >= SDL_LogGetPriority(SDL_LOG_CATEGORY_APPLICATION)) { LogVerbose("Paths:\n base: {}\n pref: {}\n config: {}\n assets: {}", diff --git a/Source/utils/file_util.cpp b/Source/utils/file_util.cpp index 18e26b780..29fd070a2 100644 --- a/Source/utils/file_util.cpp +++ b/Source/utils/file_util.cpp @@ -94,9 +94,9 @@ bool FileExists(const char *path) ::SetLastError(ERROR_SUCCESS); } else { #ifdef DEVILUTIONX_WINDOWS_NO_WCHAR - LogError("GetFileAttributesA: error code {}", ::GetLastError()); + LogError("GetFileAttributesA({}): error code {}", path, ::GetLastError()); #else - LogError("PathFileExistsW: error code {}", ::GetLastError()); + LogError("PathFileExistsW({}): error code {}", path, ::GetLastError()); #endif } return false; diff --git a/Source/utils/logged_fstream.hpp b/Source/utils/logged_fstream.hpp index 76ec9b4fd..80d358b0d 100644 --- a/Source/utils/logged_fstream.hpp +++ b/Source/utils/logged_fstream.hpp @@ -16,7 +16,7 @@ public: bool Open(const char *path, const char *mode) { s_ = OpenFile(path, mode); - return CheckError("fopen(\"{}\", \"{}\")", path, mode); + return CheckError(s_ != nullptr, "fopen(\"{}\", \"{}\")", path, mode); } void Close()