From 894773f6079d1c5a38838e77f9eec789059c925a Mon Sep 17 00:00:00 2001 From: "Admiral H. Curtiss" Date: Sat, 20 Nov 2021 21:01:12 +0100 Subject: [PATCH] Core/Boot: Add Wii FS sync data (for temp NAND/netplay) to BootSessionData and handle it in the boot and shutdown logic. --- Source/Core/Core/Boot/Boot.cpp | 24 ++++++++++++++++++++++++ Source/Core/Core/Boot/Boot.h | 17 +++++++++++++++++ Source/Core/Core/Core.cpp | 7 +++++-- Source/Core/Core/WiiRoot.cpp | 17 ++++++++++------- Source/Core/Core/WiiRoot.h | 7 +++++-- 5 files changed, 61 insertions(+), 11 deletions(-) diff --git a/Source/Core/Core/Boot/Boot.cpp b/Source/Core/Core/Boot/Boot.cpp index 39f5c1c69d..b34e9bbbe5 100644 --- a/Source/Core/Core/Boot/Boot.cpp +++ b/Source/Core/Core/Boot/Boot.cpp @@ -145,6 +145,30 @@ void BootSessionData::SetSavestateData(std::optional savestate_path m_delete_savestate = delete_savestate; } +IOS::HLE::FS::FileSystem* BootSessionData::GetWiiSyncFS() const +{ + return m_wii_sync_fs.get(); +} + +const std::vector& BootSessionData::GetWiiSyncTitles() const +{ + return m_wii_sync_titles; +} + +void BootSessionData::InvokeWiiSyncCleanup() const +{ + if (m_wii_sync_cleanup) + m_wii_sync_cleanup(); +} + +void BootSessionData::SetWiiSyncData(std::unique_ptr fs, + std::vector titles, WiiSyncCleanupFunction cleanup) +{ + m_wii_sync_fs = std::move(fs); + m_wii_sync_titles = std::move(titles); + m_wii_sync_cleanup = std::move(cleanup); +} + BootParameters::BootParameters(Parameters&& parameters_, BootSessionData boot_session_data_) : parameters(std::move(parameters_)), boot_session_data(std::move(boot_session_data_)) { diff --git a/Source/Core/Core/Boot/Boot.h b/Source/Core/Core/Boot/Boot.h index b0564f751f..e27d6a41df 100644 --- a/Source/Core/Core/Boot/Boot.h +++ b/Source/Core/Core/Boot/Boot.h @@ -24,6 +24,11 @@ namespace File class IOFile; } +namespace IOS::HLE::FS +{ +class FileSystem; +} + struct RegionSetting { std::string area; @@ -57,9 +62,21 @@ public: void SetSavestateData(std::optional savestate_path, DeleteSavestateAfterBoot delete_savestate); + using WiiSyncCleanupFunction = std::function; + + IOS::HLE::FS::FileSystem* GetWiiSyncFS() const; + const std::vector& GetWiiSyncTitles() const; + void InvokeWiiSyncCleanup() const; + void SetWiiSyncData(std::unique_ptr fs, std::vector titles, + WiiSyncCleanupFunction cleanup); + private: std::optional m_savestate_path; DeleteSavestateAfterBoot m_delete_savestate = DeleteSavestateAfterBoot::No; + + std::unique_ptr m_wii_sync_fs; + std::vector m_wii_sync_titles; + WiiSyncCleanupFunction m_wii_sync_cleanup; }; struct BootParameters diff --git a/Source/Core/Core/Core.cpp b/Source/Core/Core/Core.cpp index e4a7dc7e46..6419d13e61 100644 --- a/Source/Core/Core/Core.cpp +++ b/Source/Core/Core/Core.cpp @@ -617,9 +617,12 @@ static void EmuThread(std::unique_ptr boot, WindowSystemInfo wsi // Initialise Wii filesystem contents. // This is done here after Boot and not in BootManager to ensure that we operate // with the correct title context since save copying requires title directories to exist. - Common::ScopeGuard wiifs_guard{&Core::CleanUpWiiFileSystemContents}; + Common::ScopeGuard wiifs_guard{[&boot_session_data] { + Core::CleanUpWiiFileSystemContents(boot_session_data); + boot_session_data.InvokeWiiSyncCleanup(); + }}; if (SConfig::GetInstance().bWii) - Core::InitializeWiiFileSystemContents(savegame_redirect); + Core::InitializeWiiFileSystemContents(savegame_redirect, boot_session_data); else wiifs_guard.Dismiss(); diff --git a/Source/Core/Core/WiiRoot.cpp b/Source/Core/Core/WiiRoot.cpp index d57f194ddc..2af5901dfb 100644 --- a/Source/Core/Core/WiiRoot.cpp +++ b/Source/Core/Core/WiiRoot.cpp @@ -17,6 +17,7 @@ #include "Common/Logging/Log.h" #include "Common/NandPaths.h" #include "Common/StringUtil.h" +#include "Core/Boot/Boot.h" #include "Core/CommonTitles.h" #include "Core/Config/SessionSettings.h" #include "Core/ConfigManager.h" @@ -114,7 +115,8 @@ static bool CopyNandFile(FS::FileSystem* source_fs, const std::string& source_fi return true; } -static void InitializeDeterministicWiiSaves(FS::FileSystem* session_fs) +static void InitializeDeterministicWiiSaves(FS::FileSystem* session_fs, + const BootSessionData& boot_session_data) { const u64 title_id = SConfig::GetInstance().GetTitleID(); const auto configured_fs = FS::MakeFileSystem(FS::Location::Configured); @@ -136,8 +138,8 @@ static void InitializeDeterministicWiiSaves(FS::FileSystem* session_fs) (Movie::IsMovieActive() && !Movie::IsStartingFromClearSave())) { // Copy the current user's save to the Blank NAND - auto* sync_fs = NetPlay::GetWiiSyncFS(); - auto& sync_titles = NetPlay::GetWiiSyncTitles(); + auto* sync_fs = boot_session_data.GetWiiSyncFS(); + auto& sync_titles = boot_session_data.GetWiiSyncTitles(); if (sync_fs) { for (const u64 title : sync_titles) @@ -298,7 +300,8 @@ static bool CopySysmenuFilesToFS(FS::FileSystem* fs, const std::string& host_sou } void InitializeWiiFileSystemContents( - std::optional save_redirect) + std::optional save_redirect, + const BootSessionData& boot_session_data) { const auto fs = IOS::HLE::GetIOS()->GetFS(); @@ -315,7 +318,7 @@ void InitializeWiiFileSystemContents( SysConf sysconf{fs}; sysconf.Save(); - InitializeDeterministicWiiSaves(fs.get()); + InitializeDeterministicWiiSaves(fs.get(), boot_session_data); } else if (save_redirect) { @@ -336,10 +339,10 @@ void InitializeWiiFileSystemContents( } } -void CleanUpWiiFileSystemContents() +void CleanUpWiiFileSystemContents(const BootSessionData& boot_session_data) { if (!WiiRootIsTemporary() || !Config::Get(Config::SESSION_SAVE_DATA_WRITABLE) || - NetPlay::GetWiiSyncFS()) + boot_session_data.GetWiiSyncFS()) { return; } diff --git a/Source/Core/Core/WiiRoot.h b/Source/Core/Core/WiiRoot.h index 0b17061b19..2b029b2e17 100644 --- a/Source/Core/Core/WiiRoot.h +++ b/Source/Core/Core/WiiRoot.h @@ -8,6 +8,8 @@ #include "DiscIO/RiivolutionPatcher.h" +class BootSessionData; + namespace IOS::HLE::FS { struct NandRedirect; @@ -32,8 +34,9 @@ void RestoreWiiSettings(RestoreReason reason); // Initialize or clean up the filesystem contents. void InitializeWiiFileSystemContents( - std::optional save_redirect); -void CleanUpWiiFileSystemContents(); + std::optional save_redirect, + const BootSessionData& boot_session_data); +void CleanUpWiiFileSystemContents(const BootSessionData& boot_session_data); const std::vector& GetActiveNandRedirects(); } // namespace Core