From 845fadf49eea3b503195124f7a1b24f9fccb5d5f Mon Sep 17 00:00:00 2001 From: OpenSauce04 Date: Tue, 10 Mar 2026 15:54:07 +0000 Subject: [PATCH] android: Fix IOFile::GetFd not functioning as expected in vanilla This fixes the cheats menu not loading correctly --- src/common/android_storage.cpp | 5 ++++- src/common/file_util.h | 12 +++++++++--- src/core/cheats/cheats.cpp | 4 ++++ src/core/cheats/gateway_cheat.cpp | 2 ++ 4 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/common/android_storage.cpp b/src/common/android_storage.cpp index 372fb66b8..0fb6ceaaf 100644 --- a/src/common/android_storage.cpp +++ b/src/common/android_storage.cpp @@ -3,6 +3,7 @@ // Refer to the license.txt file included. #ifdef ANDROID +#include #include #include #include "common/android_storage.h" @@ -317,7 +318,9 @@ std::string TranslateFilePath(const std::string& filepath) { } std::optional userDirLocation = GetUserDirectory(); if (userDirLocation) { - return *userDirLocation + "/" + filepath; + std::string translatedPath = *userDirLocation + "/" + filepath; + boost::replace_all(translatedPath, "//", "/"); + return translatedPath; } return ""; } diff --git a/src/common/file_util.h b/src/common/file_util.h index ea4af8cb3..56dbeea93 100644 --- a/src/common/file_util.h +++ b/src/common/file_util.h @@ -34,6 +34,9 @@ #ifdef _MSC_VER #include "common/string_util.h" #endif +#if defined(ANDROID) && !defined(HAVE_LIBRETRO_VFS) +#include "android_storage.h" +#endif #ifdef HAVE_LIBRETRO_VFS #define SKIP_STDIO_REDEFINES @@ -438,13 +441,16 @@ public: if (m_file == nullptr) return -1; return fileno(filestream_get_vfs_handle(m_file)->fp); -#elif defined(ANDROID) - return m_fd; #else +#ifdef ANDROID + if (!AndroidStorage::CanUseRawFS()) { + return m_fd; + } +#endif // ANDROID if (m_file == nullptr) return -1; return fileno(m_file); -#endif +#endif // HAVE_LIBRETRO_VFS } [[nodiscard]] explicit operator bool() const { return IsGood(); diff --git a/src/core/cheats/cheats.cpp b/src/core/cheats/cheats.cpp index ebc783ad9..5cb7f526b 100644 --- a/src/core/cheats/cheats.cpp +++ b/src/core/cheats/cheats.cpp @@ -65,6 +65,8 @@ void CheatEngine::SaveCheatFile(u64 title_id) const { const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir); const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id); + LOG_INFO(Core_Cheats, "Attempting to save cheats file: {}", filepath); + if (!FileUtil::IsDirectory(cheat_dir)) { FileUtil::CreateDir(cheat_dir); } @@ -87,6 +89,8 @@ void CheatEngine::LoadCheatFile(u64 title_id) { const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir); const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id); + LOG_INFO(Core_Cheats, "Attempting to load cheats file: {}", filepath); + if (!FileUtil::IsDirectory(cheat_dir)) { FileUtil::CreateDir(cheat_dir); } diff --git a/src/core/cheats/gateway_cheat.cpp b/src/core/cheats/gateway_cheat.cpp index b7cd229ac..c4dfe7fa2 100644 --- a/src/core/cheats/gateway_cheat.cpp +++ b/src/core/cheats/gateway_cheat.cpp @@ -488,12 +488,14 @@ std::vector> GatewayCheat::LoadFile(const std::string std::vector> cheats; if (!FileUtil::Exists(filepath)) { + LOG_INFO(Core_Cheats, "GatewayCheat::LoadFile failed, file doesn't exist: {}", filepath); return cheats; } boost::iostreams::stream file; FileUtil::OpenFStream(file, filepath); if (!file.is_open()) { + LOG_INFO(Core_Cheats, "GatewayCheat::LoadFile failed, file failed to open: {}", filepath); return cheats; }