From 3a661a1c3dfc4509f995a8a0be56e9ba0ecacbb9 Mon Sep 17 00:00:00 2001 From: Stenzek Date: Fri, 6 Dec 2024 22:05:19 +1000 Subject: [PATCH] Cheats: Move file clearing into core Needed for Android. --- src/core/cheats.cpp | 43 ++++++++++++++++--- src/core/cheats.h | 3 ++ src/core/settings.h | 2 +- .../gamecheatsettingswidget.cpp | 29 +------------ src/util/imgui_manager.h | 4 ++ src/util/page_fault_handler.cpp | 4 +- 6 files changed, 49 insertions(+), 36 deletions(-) diff --git a/src/core/cheats.cpp b/src/core/cheats.cpp index 10a59564a..3ccf355a7 100644 --- a/src/core/cheats.cpp +++ b/src/core/cheats.cpp @@ -107,11 +107,17 @@ public: ALWAYS_INLINE bool IsOpen() const { return static_cast(m_zip); } - bool Open(const char* name) + bool Open(bool cheats) { if (m_zip) return true; +#ifndef __ANDROID__ + const char* name = cheats ? "cheats.zip" : "patches.zip"; +#else + const char* name = cheats ? "patchcodes.zip" : "patches.zip"; +#endif + Error error; std::optional> data = Host::ReadResourceFile(name, false, &error); if (!data.has_value()) @@ -398,10 +404,7 @@ void Cheats::EnumerateChtFiles(const std::string_view serial, std::optional hash) +{ + Error error; + std::string path = GetChtFilename(serial, hash, true); + if (FileSystem::FileExists(path.c_str())) + { + if (!FileSystem::DeleteFile(path.c_str(), &error)) + ERROR_LOG("Failed to remove cht file '{}': {}", Path::GetFileName(path), error.GetDescription()); + } + + // check for a non-hashed path and remove that too + path = GetChtFilename(serial, std::nullopt, true); + if (FileSystem::FileExists(path.c_str())) + { + if (!FileSystem::DeleteFile(path.c_str(), &error)) + ERROR_LOG("Failed to remove cht file '{}': {}", Path::GetFileName(path), error.GetDescription()); + } + + // and a legacy cht file with the game title + if (!title.empty()) + { + path = fmt::format("{}" FS_OSPATH_SEPARATOR_STR "{}.cht", EmuFolders::Cheats, Path::SanitizeFileName(title)); + if (FileSystem::FileExists(path.c_str())) + { + if (!FileSystem::DeleteFile(path.c_str(), &error)) + ERROR_LOG("Failed to remove cht file '{}': {}", Path::GetFileName(path), error.GetDescription()); + } + } +} + std::string Cheats::GetChtFilename(const std::string_view serial, std::optional hash, bool cheats) { return Path::Combine(cheats ? EmuFolders::Cheats : EmuFolders::Patches, GetChtTemplate(serial, hash, false)); diff --git a/src/core/cheats.h b/src/core/cheats.h index 5d7d8e307..893e77600 100644 --- a/src/core/cheats.h +++ b/src/core/cheats.h @@ -117,6 +117,9 @@ extern bool UpdateCodeInFile(const char* path, const std::string_view name, cons /// Updates or adds multiple codes to the file, rewriting it. extern bool SaveCodesToFile(const char* path, const CodeInfoList& codes, Error* error); +/// Removes any .cht files for the specified game. +extern void RemoveAllCodes(const std::string_view serial, const std::string_view title, std::optional hash); + /// Returns the path to a new cheat/patch cht for the specified serial and hash. extern std::string GetChtFilename(const std::string_view serial, std::optional hash, bool cheats); diff --git a/src/core/settings.h b/src/core/settings.h index 418bacc25..cdb1e5f57 100644 --- a/src/core/settings.h +++ b/src/core/settings.h @@ -170,7 +170,7 @@ struct Settings bool display_stretch_vertically : 1 = false; bool display_auto_resize_window : 1 = false; float display_pre_frame_sleep_buffer = DEFAULT_DISPLAY_PRE_FRAME_SLEEP_BUFFER; - float display_osd_scale = 100.0f; + float display_osd_scale = DEFAULT_OSD_SCALE; float display_osd_margin = 0.0f; float gpu_pgxp_tolerance = -1.0f; float gpu_pgxp_depth_clear_threshold = DEFAULT_GPU_PGXP_DEPTH_THRESHOLD / GPU_PGXP_DEPTH_THRESHOLD_SCALE; diff --git a/src/duckstation-qt/gamecheatsettingswidget.cpp b/src/duckstation-qt/gamecheatsettingswidget.cpp index eba4f7d43..dd365fb9b 100644 --- a/src/duckstation-qt/gamecheatsettingswidget.cpp +++ b/src/duckstation-qt/gamecheatsettingswidget.cpp @@ -626,34 +626,7 @@ void GameCheatSettingsWidget::onClearClicked() } disableAllCheats(); - - Error error; - std::string path = Cheats::GetChtFilename(m_dialog->getGameSerial(), m_dialog->getGameHash(), true); - if (FileSystem::FileExists(path.c_str())) - { - if (!FileSystem::DeleteFile(path.c_str(), &error)) - ERROR_LOG("Failed to remove cht file '{}': {}", Path::GetFileName(path), error.GetDescription()); - } - - // check for a non-hashed path and remove that too - path = Cheats::GetChtFilename(m_dialog->getGameSerial(), std::nullopt, true); - if (FileSystem::FileExists(path.c_str())) - { - if (!FileSystem::DeleteFile(path.c_str(), &error)) - ERROR_LOG("Failed to remove cht file '{}': {}", Path::GetFileName(path), error.GetDescription()); - } - - // and a legacy cht file with the game title - if (const std::string& title = m_dialog->getGameTitle(); !title.empty()) - { - path = fmt::format("{}" FS_OSPATH_SEPARATOR_STR "{}.cht", EmuFolders::Cheats, Path::SanitizeFileName(title)); - if (FileSystem::FileExists(path.c_str())) - { - if (!FileSystem::DeleteFile(path.c_str(), &error)) - ERROR_LOG("Failed to remove cht file '{}': {}", Path::GetFileName(path), error.GetDescription()); - } - } - + Cheats::RemoveAllCodes(m_dialog->getGameSerial(), m_dialog->getGameTitle(), m_dialog->getGameHash()); reloadList(); } diff --git a/src/util/imgui_manager.h b/src/util/imgui_manager.h index 71f97818e..e3998a811 100644 --- a/src/util/imgui_manager.h +++ b/src/util/imgui_manager.h @@ -54,7 +54,11 @@ namespace ImGuiManager { using WCharType = u32; /// Default size for screen margins. +#ifndef __ANDROID__ static constexpr float DEFAULT_SCREEN_MARGIN = 10.0f; +#else +static constexpr float DEFAULT_SCREEN_MARGIN = 16.0f; +#endif /// Sets the path to the font to use. Empty string means to use the default. void SetFontPathAndRange(std::string path, std::vector range); diff --git a/src/util/page_fault_handler.cpp b/src/util/page_fault_handler.cpp index f235f882d..5b4a7fc5c 100644 --- a/src/util/page_fault_handler.cpp +++ b/src/util/page_fault_handler.cpp @@ -15,7 +15,7 @@ #if defined(_WIN32) #include "common/windows_headers.h" -#elif defined(__linux__) +#elif defined(__linux__) && !defined(__ANDROID__) #include #include #include @@ -136,7 +136,7 @@ bool PageFaultHandler::Install(Error* error) return true; } -#else +#elif !defined(__ANDROID__) namespace PageFaultHandler { static void SignalHandler(int sig, siginfo_t* info, void* ctx);