Permalink
Browse files

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
  • Loading branch information...
leoetlino committed May 27, 2018
1 parent 8fce18e commit c1428b6da0428285778ed65b03ecfa00fd3e1962
Showing with 26 additions and 30 deletions.
  1. +26 −30 Source/Core/Core/WiiRoot.cpp
@@ -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,18 +41,18 @@ 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));
}
}
if ((NetPlay::IsNetPlayRunning() && SConfig::GetInstance().bCopyWiiSaveNetplay) ||
(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

0 comments on commit c1428b6

Please sign in to comment.