mirror of
https://github.com/dolphin-emu/dolphin.git
synced 2025-07-22 22:00:39 -06:00
NetPlay: Synchronize Mii data
It's bundled with the Wii saves for simplicity, since it's quite small.
This commit is contained in:
@ -41,6 +41,36 @@ static void CopySave(FS::FileSystem* source, FS::FileSystem* dest, const u64 tit
|
||||
WiiSave::Copy(source_save.get(), dest_save.get());
|
||||
}
|
||||
|
||||
static bool CopyNandFile(FS::FileSystem* source_fs, const std::string& source_file,
|
||||
FS::FileSystem* dest_fs, const std::string& dest_file)
|
||||
{
|
||||
const auto last_slash = dest_file.find_last_of('/');
|
||||
if (last_slash != std::string::npos && last_slash > 0)
|
||||
{
|
||||
const std::string dir = dest_file.substr(0, last_slash);
|
||||
dest_fs->CreateDirectory(IOS::PID_KERNEL, IOS::PID_KERNEL, dir, 0,
|
||||
{IOS::HLE::FS::Mode::ReadWrite, IOS::HLE::FS::Mode::ReadWrite,
|
||||
IOS::HLE::FS::Mode::ReadWrite});
|
||||
}
|
||||
|
||||
auto source_handle =
|
||||
source_fs->OpenFile(IOS::PID_KERNEL, IOS::PID_KERNEL, source_file, IOS::HLE::FS::Mode::Read);
|
||||
auto dest_handle =
|
||||
dest_fs->CreateAndOpenFile(IOS::PID_KERNEL, IOS::PID_KERNEL, source_file,
|
||||
{IOS::HLE::FS::Mode::ReadWrite, IOS::HLE::FS::Mode::ReadWrite,
|
||||
IOS::HLE::FS::Mode::ReadWrite});
|
||||
if (!source_handle || !dest_handle)
|
||||
return false;
|
||||
|
||||
std::vector<u8> buffer(source_handle->GetStatus()->size);
|
||||
if (!source_handle->Read(buffer.data(), buffer.size()))
|
||||
return false;
|
||||
if (!dest_handle->Write(buffer.data(), buffer.size()))
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
static void InitializeDeterministicWiiSaves(FS::FileSystem* session_fs)
|
||||
{
|
||||
const u64 title_id = SConfig::GetInstance().GetTitleID();
|
||||
@ -71,6 +101,13 @@ static void InitializeDeterministicWiiSaves(FS::FileSystem* session_fs)
|
||||
{
|
||||
CopySave(sync_fs, session_fs, title);
|
||||
}
|
||||
|
||||
// Copy Mii data
|
||||
if (!CopyNandFile(sync_fs, Common::GetMiiDatabasePath(), session_fs,
|
||||
Common::GetMiiDatabasePath()))
|
||||
{
|
||||
WARN_LOG(CORE, "Failed to copy Mii database to the NAND");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -85,6 +122,13 @@ static void InitializeDeterministicWiiSaves(FS::FileSystem* session_fs)
|
||||
{
|
||||
CopySave(configured_fs.get(), session_fs, title_id);
|
||||
}
|
||||
|
||||
// Copy Mii data
|
||||
if (!CopyNandFile(configured_fs.get(), Common::GetMiiDatabasePath(), session_fs,
|
||||
Common::GetMiiDatabasePath()))
|
||||
{
|
||||
WARN_LOG(CORE, "Failed to copy Mii database to the NAND");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -198,13 +242,20 @@ void CleanUpWiiFileSystemContents()
|
||||
return;
|
||||
}
|
||||
|
||||
IOS::HLE::EmulationKernel* ios = IOS::HLE::GetIOS();
|
||||
const auto configured_fs = FS::MakeFileSystem(FS::Location::Configured);
|
||||
|
||||
// Copy back Mii data
|
||||
if (!CopyNandFile(ios->GetFS().get(), Common::GetMiiDatabasePath(), configured_fs.get(),
|
||||
Common::GetMiiDatabasePath()))
|
||||
{
|
||||
WARN_LOG(CORE, "Failed to copy Mii database to the NAND");
|
||||
}
|
||||
|
||||
const u64 title_id = SConfig::GetInstance().GetTitleID();
|
||||
|
||||
IOS::HLE::EmulationKernel* ios = IOS::HLE::GetIOS();
|
||||
const auto session_save = WiiSave::MakeNandStorage(ios->GetFS().get(), title_id);
|
||||
|
||||
const auto configured_fs = FS::MakeFileSystem(FS::Location::Configured);
|
||||
|
||||
// FS won't write the save if the directory doesn't exist
|
||||
const std::string title_path = Common::GetTitleDataPath(title_id);
|
||||
if (!configured_fs->GetMetadata(IOS::PID_KERNEL, IOS::PID_KERNEL, title_path))
|
||||
|
Reference in New Issue
Block a user