From e010591f0dceb85a67cfc6666088f2fd3e7a8561 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 a069d71c892..eb214c8f297 100644 --- a/Source/init.cpp +++ b/Source/init.cpp @@ -155,7 +155,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 b6859a2ac9d..95fe7b58d1c 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 { #if defined(NXDK) - 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 d7bdfc736e2..738addde911 100644 --- a/Source/utils/logged_fstream.hpp +++ b/Source/utils/logged_fstream.hpp @@ -17,7 +17,7 @@ struct LoggedFStream { 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()