Core/Boot: Add Wii FS sync data (for temp NAND/netplay) to BootSessionData and handle it in the boot and shutdown logic.

This commit is contained in:
Admiral H. Curtiss 2021-11-20 21:01:12 +01:00
parent 7b776f3769
commit 894773f607
No known key found for this signature in database
GPG Key ID: F051B4C4044F33FB
5 changed files with 61 additions and 11 deletions

View File

@ -145,6 +145,30 @@ void BootSessionData::SetSavestateData(std::optional<std::string> savestate_path
m_delete_savestate = delete_savestate; m_delete_savestate = delete_savestate;
} }
IOS::HLE::FS::FileSystem* BootSessionData::GetWiiSyncFS() const
{
return m_wii_sync_fs.get();
}
const std::vector<u64>& 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<IOS::HLE::FS::FileSystem> fs,
std::vector<u64> 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_) BootParameters::BootParameters(Parameters&& parameters_, BootSessionData boot_session_data_)
: parameters(std::move(parameters_)), boot_session_data(std::move(boot_session_data_)) : parameters(std::move(parameters_)), boot_session_data(std::move(boot_session_data_))
{ {

View File

@ -24,6 +24,11 @@ namespace File
class IOFile; class IOFile;
} }
namespace IOS::HLE::FS
{
class FileSystem;
}
struct RegionSetting struct RegionSetting
{ {
std::string area; std::string area;
@ -57,9 +62,21 @@ public:
void SetSavestateData(std::optional<std::string> savestate_path, void SetSavestateData(std::optional<std::string> savestate_path,
DeleteSavestateAfterBoot delete_savestate); DeleteSavestateAfterBoot delete_savestate);
using WiiSyncCleanupFunction = std::function<void()>;
IOS::HLE::FS::FileSystem* GetWiiSyncFS() const;
const std::vector<u64>& GetWiiSyncTitles() const;
void InvokeWiiSyncCleanup() const;
void SetWiiSyncData(std::unique_ptr<IOS::HLE::FS::FileSystem> fs, std::vector<u64> titles,
WiiSyncCleanupFunction cleanup);
private: private:
std::optional<std::string> m_savestate_path; std::optional<std::string> m_savestate_path;
DeleteSavestateAfterBoot m_delete_savestate = DeleteSavestateAfterBoot::No; DeleteSavestateAfterBoot m_delete_savestate = DeleteSavestateAfterBoot::No;
std::unique_ptr<IOS::HLE::FS::FileSystem> m_wii_sync_fs;
std::vector<u64> m_wii_sync_titles;
WiiSyncCleanupFunction m_wii_sync_cleanup;
}; };
struct BootParameters struct BootParameters

View File

@ -617,9 +617,12 @@ static void EmuThread(std::unique_ptr<BootParameters> boot, WindowSystemInfo wsi
// Initialise Wii filesystem contents. // Initialise Wii filesystem contents.
// This is done here after Boot and not in BootManager to ensure that we operate // 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. // 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) if (SConfig::GetInstance().bWii)
Core::InitializeWiiFileSystemContents(savegame_redirect); Core::InitializeWiiFileSystemContents(savegame_redirect, boot_session_data);
else else
wiifs_guard.Dismiss(); wiifs_guard.Dismiss();

View File

@ -17,6 +17,7 @@
#include "Common/Logging/Log.h" #include "Common/Logging/Log.h"
#include "Common/NandPaths.h" #include "Common/NandPaths.h"
#include "Common/StringUtil.h" #include "Common/StringUtil.h"
#include "Core/Boot/Boot.h"
#include "Core/CommonTitles.h" #include "Core/CommonTitles.h"
#include "Core/Config/SessionSettings.h" #include "Core/Config/SessionSettings.h"
#include "Core/ConfigManager.h" #include "Core/ConfigManager.h"
@ -114,7 +115,8 @@ static bool CopyNandFile(FS::FileSystem* source_fs, const std::string& source_fi
return true; 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 u64 title_id = SConfig::GetInstance().GetTitleID();
const auto configured_fs = FS::MakeFileSystem(FS::Location::Configured); const auto configured_fs = FS::MakeFileSystem(FS::Location::Configured);
@ -136,8 +138,8 @@ static void InitializeDeterministicWiiSaves(FS::FileSystem* session_fs)
(Movie::IsMovieActive() && !Movie::IsStartingFromClearSave())) (Movie::IsMovieActive() && !Movie::IsStartingFromClearSave()))
{ {
// Copy the current user's save to the Blank NAND // Copy the current user's save to the Blank NAND
auto* sync_fs = NetPlay::GetWiiSyncFS(); auto* sync_fs = boot_session_data.GetWiiSyncFS();
auto& sync_titles = NetPlay::GetWiiSyncTitles(); auto& sync_titles = boot_session_data.GetWiiSyncTitles();
if (sync_fs) if (sync_fs)
{ {
for (const u64 title : sync_titles) for (const u64 title : sync_titles)
@ -298,7 +300,8 @@ static bool CopySysmenuFilesToFS(FS::FileSystem* fs, const std::string& host_sou
} }
void InitializeWiiFileSystemContents( void InitializeWiiFileSystemContents(
std::optional<DiscIO::Riivolution::SavegameRedirect> save_redirect) std::optional<DiscIO::Riivolution::SavegameRedirect> save_redirect,
const BootSessionData& boot_session_data)
{ {
const auto fs = IOS::HLE::GetIOS()->GetFS(); const auto fs = IOS::HLE::GetIOS()->GetFS();
@ -315,7 +318,7 @@ void InitializeWiiFileSystemContents(
SysConf sysconf{fs}; SysConf sysconf{fs};
sysconf.Save(); sysconf.Save();
InitializeDeterministicWiiSaves(fs.get()); InitializeDeterministicWiiSaves(fs.get(), boot_session_data);
} }
else if (save_redirect) 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) || if (!WiiRootIsTemporary() || !Config::Get(Config::SESSION_SAVE_DATA_WRITABLE) ||
NetPlay::GetWiiSyncFS()) boot_session_data.GetWiiSyncFS())
{ {
return; return;
} }

View File

@ -8,6 +8,8 @@
#include "DiscIO/RiivolutionPatcher.h" #include "DiscIO/RiivolutionPatcher.h"
class BootSessionData;
namespace IOS::HLE::FS namespace IOS::HLE::FS
{ {
struct NandRedirect; struct NandRedirect;
@ -32,8 +34,9 @@ void RestoreWiiSettings(RestoreReason reason);
// Initialize or clean up the filesystem contents. // Initialize or clean up the filesystem contents.
void InitializeWiiFileSystemContents( void InitializeWiiFileSystemContents(
std::optional<DiscIO::Riivolution::SavegameRedirect> save_redirect); std::optional<DiscIO::Riivolution::SavegameRedirect> save_redirect,
void CleanUpWiiFileSystemContents(); const BootSessionData& boot_session_data);
void CleanUpWiiFileSystemContents(const BootSessionData& boot_session_data);
const std::vector<IOS::HLE::FS::NandRedirect>& GetActiveNandRedirects(); const std::vector<IOS::HLE::FS::NandRedirect>& GetActiveNandRedirects();
} // namespace Core } // namespace Core