From 5f69216f70f714c46e450bf2d75838efe76aa1ca Mon Sep 17 00:00:00 2001 From: Connor McLaughlin Date: Fri, 27 Nov 2020 17:57:20 +1000 Subject: [PATCH] HostInterface: Add OpenPackageFile method --- src/core/host_interface.h | 4 ++++ .../libretro_host_interface.cpp | 6 ++++++ src/duckstation-libretro/libretro_host_interface.h | 1 + src/frontend-common/common_host_interface.cpp | 14 +++++++++++--- src/frontend-common/common_host_interface.h | 4 ++++ 5 files changed, 26 insertions(+), 3 deletions(-) diff --git a/src/core/host_interface.h b/src/core/host_interface.h index 9f2d39f01..4a6b7f193 100644 --- a/src/core/host_interface.h +++ b/src/core/host_interface.h @@ -133,6 +133,10 @@ public: /// Returns true if any BIOS images are found in the configured BIOS directory. bool HasAnyBIOSImages(); + /// Opens a file in the DuckStation "package". + /// This is the APK for Android builds, or the program directory for standalone builds. + virtual std::unique_ptr OpenPackageFile(const char* path, u32 flags) = 0; + virtual void OnRunningGameChanged(); virtual void OnSystemPerformanceCountersUpdated(); diff --git a/src/duckstation-libretro/libretro_host_interface.cpp b/src/duckstation-libretro/libretro_host_interface.cpp index 83d0c1481..158083bd8 100644 --- a/src/duckstation-libretro/libretro_host_interface.cpp +++ b/src/duckstation-libretro/libretro_host_interface.cpp @@ -864,6 +864,12 @@ std::string LibretroHostInterface::GetBIOSDirectory() return system_directory; } +std::unique_ptr LibretroHostInterface::OpenPackageFile(const char* path, u32 flags) +{ + Log_ErrorPrintf("Ignoring request for package file '%s'", path); + return {}; +} + void LibretroHostInterface::LoadSettings() { LibretroSettingsInterface si; diff --git a/src/duckstation-libretro/libretro_host_interface.h b/src/duckstation-libretro/libretro_host_interface.h index 6529a494f..6dc71e1cb 100644 --- a/src/duckstation-libretro/libretro_host_interface.h +++ b/src/duckstation-libretro/libretro_host_interface.h @@ -33,6 +33,7 @@ public: std::string GetShaderCacheBasePath() const override; std::string GetStringSettingValue(const char* section, const char* key, const char* default_value = "") override; std::string GetBIOSDirectory() override; + std::unique_ptr OpenPackageFile(const char* path, u32 flags) override; bool UpdateSystemAVInfo(bool use_resolution_scale); diff --git a/src/frontend-common/common_host_interface.cpp b/src/frontend-common/common_host_interface.cpp index dbb7d9d59..0b9170174 100644 --- a/src/frontend-common/common_host_interface.cpp +++ b/src/frontend-common/common_host_interface.cpp @@ -70,9 +70,7 @@ bool CommonHostInterface::Initialize() m_game_list = std::make_unique(); m_game_list->SetCacheFilename(GetUserDirectoryRelativePath("cache/gamelist.cache")); - m_game_list->SetDatabaseFilename(GetUserDirectoryRelativePath("cache/redump.dat")); - m_game_list->SetCompatibilityFilename(GetProgramDirectoryRelativePath("database/compatibility.xml")); - m_game_list->SetGameSettingsFilename(GetProgramDirectoryRelativePath("database/gamesettings.ini")); + m_game_list->SetUserCompatibilityListFilename(GetProgramDirectoryRelativePath("compatibility.xml")); m_game_list->SetUserGameSettingsFilename(GetUserDirectoryRelativePath("gamesettings.ini")); m_save_state_selector_ui = std::make_unique(this); @@ -2613,6 +2611,16 @@ bool CommonHostInterface::RequestRenderWindowScale(float scale) return RequestRenderWindowSize(static_cast(requested_width), static_cast(requested_height)); } +std::unique_ptr CommonHostInterface::OpenPackageFile(const char* path, u32 flags) +{ + const u32 allowed_flags = (BYTESTREAM_OPEN_READ | BYTESTREAM_OPEN_SEEKABLE | BYTESTREAM_OPEN_STREAMED); + const std::string full_path( + StringUtil::StdStringFromFormat("%s" FS_OSPATH_SEPARATOR_STR "%s", m_program_directory.c_str(), path)); + const u32 real_flags = (flags & allowed_flags) | BYTESTREAM_OPEN_READ; + Log_DevPrintf("Requesting package file '%s'", path); + return FileSystem::OpenFile(full_path.c_str(), real_flags); +} + #ifdef WITH_DISCORD_PRESENCE void CommonHostInterface::SetDiscordPresenceEnabled(bool enabled) diff --git a/src/frontend-common/common_host_interface.h b/src/frontend-common/common_host_interface.h index af57c6df6..f79c27d10 100644 --- a/src/frontend-common/common_host_interface.h +++ b/src/frontend-common/common_host_interface.h @@ -190,6 +190,10 @@ public: /// Requests a resize to a multiple of the render window size. bool RequestRenderWindowScale(float scale); + /// Opens a file in the DuckStation "package". + /// This is the APK for Android builds, or the program directory for standalone builds. + virtual std::unique_ptr OpenPackageFile(const char* path, u32 flags) override; + protected: enum : u32 {