android: Fix IOFile::GetFd not functioning as expected in vanilla

This fixes the cheats menu not loading correctly
This commit is contained in:
OpenSauce04 2026-03-10 15:54:07 +00:00 committed by OpenSauce
parent 98910fed1c
commit 845fadf49e
4 changed files with 19 additions and 4 deletions

View File

@ -3,6 +3,7 @@
// Refer to the license.txt file included. // Refer to the license.txt file included.
#ifdef ANDROID #ifdef ANDROID
#include <boost/algorithm/string/replace.hpp>
#include <boost/uuid/uuid_generators.hpp> #include <boost/uuid/uuid_generators.hpp>
#include <boost/uuid/uuid_io.hpp> #include <boost/uuid/uuid_io.hpp>
#include "common/android_storage.h" #include "common/android_storage.h"
@ -317,7 +318,9 @@ std::string TranslateFilePath(const std::string& filepath) {
} }
std::optional<std::string> userDirLocation = GetUserDirectory(); std::optional<std::string> userDirLocation = GetUserDirectory();
if (userDirLocation) { if (userDirLocation) {
return *userDirLocation + "/" + filepath; std::string translatedPath = *userDirLocation + "/" + filepath;
boost::replace_all(translatedPath, "//", "/");
return translatedPath;
} }
return ""; return "";
} }

View File

@ -34,6 +34,9 @@
#ifdef _MSC_VER #ifdef _MSC_VER
#include "common/string_util.h" #include "common/string_util.h"
#endif #endif
#if defined(ANDROID) && !defined(HAVE_LIBRETRO_VFS)
#include "android_storage.h"
#endif
#ifdef HAVE_LIBRETRO_VFS #ifdef HAVE_LIBRETRO_VFS
#define SKIP_STDIO_REDEFINES #define SKIP_STDIO_REDEFINES
@ -438,13 +441,16 @@ public:
if (m_file == nullptr) if (m_file == nullptr)
return -1; return -1;
return fileno(filestream_get_vfs_handle(m_file)->fp); return fileno(filestream_get_vfs_handle(m_file)->fp);
#elif defined(ANDROID)
return m_fd;
#else #else
#ifdef ANDROID
if (!AndroidStorage::CanUseRawFS()) {
return m_fd;
}
#endif // ANDROID
if (m_file == nullptr) if (m_file == nullptr)
return -1; return -1;
return fileno(m_file); return fileno(m_file);
#endif #endif // HAVE_LIBRETRO_VFS
} }
[[nodiscard]] explicit operator bool() const { [[nodiscard]] explicit operator bool() const {
return IsGood(); return IsGood();

View File

@ -65,6 +65,8 @@ void CheatEngine::SaveCheatFile(u64 title_id) const {
const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir); const std::string cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id); 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)) { if (!FileUtil::IsDirectory(cheat_dir)) {
FileUtil::CreateDir(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 cheat_dir = FileUtil::GetUserPath(FileUtil::UserPath::CheatsDir);
const std::string filepath = fmt::format("{}{:016X}.txt", cheat_dir, title_id); 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)) { if (!FileUtil::IsDirectory(cheat_dir)) {
FileUtil::CreateDir(cheat_dir); FileUtil::CreateDir(cheat_dir);
} }

View File

@ -488,12 +488,14 @@ std::vector<std::shared_ptr<CheatBase>> GatewayCheat::LoadFile(const std::string
std::vector<std::shared_ptr<CheatBase>> cheats; std::vector<std::shared_ptr<CheatBase>> cheats;
if (!FileUtil::Exists(filepath)) { if (!FileUtil::Exists(filepath)) {
LOG_INFO(Core_Cheats, "GatewayCheat::LoadFile failed, file doesn't exist: {}", filepath);
return cheats; return cheats;
} }
boost::iostreams::stream<boost::iostreams::file_descriptor_source> file; boost::iostreams::stream<boost::iostreams::file_descriptor_source> file;
FileUtil::OpenFStream<std::ios_base::in>(file, filepath); FileUtil::OpenFStream<std::ios_base::in>(file, filepath);
if (!file.is_open()) { if (!file.is_open()) {
LOG_INFO(Core_Cheats, "GatewayCheat::LoadFile failed, file failed to open: {}", filepath);
return cheats; return cheats;
} }