WiiRoot: Use new filesystem interface

This gets rid of remaining direct accesses to the Wii filesystem
in WiiRoot by using WiiSave to copy saves and the FS interface
This commit is contained in:
Léo Lam 2018-05-27 20:45:05 +02:00
parent 8fce18e4ff
commit c1428b6da0
1 changed files with 26 additions and 30 deletions

View File

@ -4,6 +4,7 @@
#include "Core/WiiRoot.h"
#include <cinttypes>
#include <string>
#include <vector>
@ -15,6 +16,7 @@
#include "Common/NandPaths.h"
#include "Common/StringUtil.h"
#include "Core/ConfigManager.h"
#include "Core/HW/WiiSave.h"
#include "Core/IOS/FS/FileSystem.h"
#include "Core/IOS/IOS.h"
#include "Core/IOS/Uids.h"
@ -26,12 +28,10 @@ namespace Core
{
static std::string s_temp_wii_root;
static void InitializeDeterministicWiiSaves()
static void InitializeDeterministicWiiSaves(IOS::HLE::FS::FileSystem* session_fs)
{
std::string save_path =
Common::GetTitleDataPath(SConfig::GetInstance().GetTitleID(), Common::FROM_SESSION_ROOT);
std::string user_save_path =
Common::GetTitleDataPath(SConfig::GetInstance().GetTitleID(), Common::FROM_CONFIGURED_ROOT);
const u64 title_id = SConfig::GetInstance().GetTitleID();
const auto configured_fs = IOS::HLE::FS::MakeFileSystem(IOS::HLE::FS::Location::Configured);
if (Movie::IsRecordingInput())
{
if (NetPlay::IsNetPlayRunning() && !SConfig::GetInstance().bCopyWiiSaveNetplay)
@ -41,7 +41,8 @@ static void InitializeDeterministicWiiSaves()
else
{
// TODO: Check for the actual save data
Movie::SetClearSave(!File::Exists(user_save_path + "/banner.bin"));
const std::string path = Common::GetTitleDataPath(title_id) + "/banner.bin";
Movie::SetClearSave(!configured_fs->GetMetadata(IOS::PID_KERNEL, IOS::PID_KERNEL, path));
}
}
@ -49,10 +50,9 @@ static void InitializeDeterministicWiiSaves()
(Movie::IsMovieActive() && !Movie::IsStartingFromClearSave()))
{
// Copy the current user's save to the Blank NAND
if (File::Exists(user_save_path + "/banner.bin"))
{
File::CopyDir(user_save_path, save_path);
}
const auto user_save = WiiSave::MakeNandStorage(configured_fs.get(), title_id);
const auto session_save = WiiSave::MakeNandStorage(session_fs, title_id);
WiiSave::Copy(user_save.get(), session_save.get());
}
}
@ -142,32 +142,28 @@ void InitializeWiiFileSystemContents()
SysConf sysconf{fs};
sysconf.Save();
InitializeDeterministicWiiSaves();
InitializeDeterministicWiiSaves(fs.get());
}
void CleanUpWiiFileSystemContents()
{
if (s_temp_wii_root.empty())
if (s_temp_wii_root.empty() || !SConfig::GetInstance().bEnableMemcardSdWriting)
return;
const u64 title_id = SConfig::GetInstance().GetTitleID();
std::string save_path = Common::GetTitleDataPath(title_id, Common::FROM_SESSION_ROOT);
std::string user_save_path = Common::GetTitleDataPath(title_id, Common::FROM_CONFIGURED_ROOT);
std::string user_backup_path =
File::GetUserPath(D_BACKUP_IDX) +
StringFromFormat("%08x/%08x/", static_cast<u32>(title_id >> 32), static_cast<u32>(title_id));
if (File::Exists(save_path + "/banner.bin") && SConfig::GetInstance().bEnableMemcardSdWriting)
{
// Backup the existing save just in case it's still needed.
if (File::Exists(user_save_path + "/banner.bin"))
{
if (File::Exists(user_backup_path))
File::DeleteDirRecursively(user_backup_path);
File::CopyDir(user_save_path, user_backup_path);
File::DeleteDirRecursively(user_save_path);
}
File::CopyDir(save_path, user_save_path);
File::DeleteDirRecursively(save_path);
}
IOS::HLE::EmulationKernel* ios = IOS::HLE::GetIOS();
const auto session_save = WiiSave::MakeNandStorage(ios->GetFS().get(), title_id);
const auto configured_fs = IOS::HLE::FS::MakeFileSystem(IOS::HLE::FS::Location::Configured);
const auto user_save = WiiSave::MakeNandStorage(configured_fs.get(), title_id);
const std::string backup_path =
File::GetUserPath(D_BACKUP_IDX) + StringFromFormat("/%016" PRIx64 ".bin", title_id);
const auto backup_save = WiiSave::MakeDataBinStorage(&ios->GetIOSC(), backup_path, "w+b");
// Backup the existing save just in case it's still needed.
WiiSave::Copy(user_save.get(), backup_save.get());
WiiSave::Copy(session_save.get(), user_save.get());
}
} // namespace Core