Merge pull request #7061 from leoetlino/wiiroot
WiiRoot: Use new filesystem interface
This commit is contained in:
commit
472e0d55b8
|
@ -4,6 +4,7 @@
|
||||||
|
|
||||||
#include "Core/WiiRoot.h"
|
#include "Core/WiiRoot.h"
|
||||||
|
|
||||||
|
#include <cinttypes>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
@ -15,6 +16,7 @@
|
||||||
#include "Common/NandPaths.h"
|
#include "Common/NandPaths.h"
|
||||||
#include "Common/StringUtil.h"
|
#include "Common/StringUtil.h"
|
||||||
#include "Core/ConfigManager.h"
|
#include "Core/ConfigManager.h"
|
||||||
|
#include "Core/HW/WiiSave.h"
|
||||||
#include "Core/IOS/FS/FileSystem.h"
|
#include "Core/IOS/FS/FileSystem.h"
|
||||||
#include "Core/IOS/IOS.h"
|
#include "Core/IOS/IOS.h"
|
||||||
#include "Core/IOS/Uids.h"
|
#include "Core/IOS/Uids.h"
|
||||||
|
@ -26,12 +28,12 @@ namespace Core
|
||||||
{
|
{
|
||||||
static std::string s_temp_wii_root;
|
static std::string s_temp_wii_root;
|
||||||
|
|
||||||
static void InitializeDeterministicWiiSaves()
|
namespace FS = IOS::HLE::FS;
|
||||||
|
|
||||||
|
static void InitializeDeterministicWiiSaves(FS::FileSystem* session_fs)
|
||||||
{
|
{
|
||||||
std::string save_path =
|
const u64 title_id = SConfig::GetInstance().GetTitleID();
|
||||||
Common::GetTitleDataPath(SConfig::GetInstance().GetTitleID(), Common::FROM_SESSION_ROOT);
|
const auto configured_fs = FS::MakeFileSystem(FS::Location::Configured);
|
||||||
std::string user_save_path =
|
|
||||||
Common::GetTitleDataPath(SConfig::GetInstance().GetTitleID(), Common::FROM_CONFIGURED_ROOT);
|
|
||||||
if (Movie::IsRecordingInput())
|
if (Movie::IsRecordingInput())
|
||||||
{
|
{
|
||||||
if (NetPlay::IsNetPlayRunning() && !SConfig::GetInstance().bCopyWiiSaveNetplay)
|
if (NetPlay::IsNetPlayRunning() && !SConfig::GetInstance().bCopyWiiSaveNetplay)
|
||||||
|
@ -41,7 +43,8 @@ static void InitializeDeterministicWiiSaves()
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// TODO: Check for the actual save data
|
// 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 +52,9 @@ static void InitializeDeterministicWiiSaves()
|
||||||
(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
|
||||||
if (File::Exists(user_save_path + "/banner.bin"))
|
const auto user_save = WiiSave::MakeNandStorage(configured_fs.get(), title_id);
|
||||||
{
|
const auto session_save = WiiSave::MakeNandStorage(session_fs, title_id);
|
||||||
File::CopyDir(user_save_path, save_path);
|
WiiSave::Copy(user_save.get(), session_save.get());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -87,7 +89,7 @@ void ShutdownWiiRoot()
|
||||||
/// Copy a directory from host_source_path (on the host FS) to nand_target_path on the NAND.
|
/// Copy a directory from host_source_path (on the host FS) to nand_target_path on the NAND.
|
||||||
///
|
///
|
||||||
/// Both paths should not have trailing slashes. To specify the NAND root, use "".
|
/// Both paths should not have trailing slashes. To specify the NAND root, use "".
|
||||||
static bool CopySysmenuFilesToFS(IOS::HLE::FS::FileSystem* fs, const std::string& host_source_path,
|
static bool CopySysmenuFilesToFS(FS::FileSystem* fs, const std::string& host_source_path,
|
||||||
const std::string& nand_target_path)
|
const std::string& nand_target_path)
|
||||||
{
|
{
|
||||||
const auto entries = File::ScanDirectoryTree(host_source_path, false);
|
const auto entries = File::ScanDirectoryTree(host_source_path, false);
|
||||||
|
@ -95,8 +97,7 @@ static bool CopySysmenuFilesToFS(IOS::HLE::FS::FileSystem* fs, const std::string
|
||||||
{
|
{
|
||||||
const std::string host_path = host_source_path + '/' + entry.virtualName;
|
const std::string host_path = host_source_path + '/' + entry.virtualName;
|
||||||
const std::string nand_path = nand_target_path + '/' + entry.virtualName;
|
const std::string nand_path = nand_target_path + '/' + entry.virtualName;
|
||||||
constexpr IOS::HLE::FS::Mode rw_mode = IOS::HLE::FS::Mode::ReadWrite;
|
constexpr FS::Modes public_modes{FS::Mode::ReadWrite, FS::Mode::ReadWrite, FS::Mode::ReadWrite};
|
||||||
constexpr IOS::HLE::FS::Modes public_modes{rw_mode, rw_mode, rw_mode};
|
|
||||||
|
|
||||||
if (entry.isDirectory)
|
if (entry.isDirectory)
|
||||||
{
|
{
|
||||||
|
@ -142,32 +143,28 @@ void InitializeWiiFileSystemContents()
|
||||||
SysConf sysconf{fs};
|
SysConf sysconf{fs};
|
||||||
sysconf.Save();
|
sysconf.Save();
|
||||||
|
|
||||||
InitializeDeterministicWiiSaves();
|
InitializeDeterministicWiiSaves(fs.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
void CleanUpWiiFileSystemContents()
|
void CleanUpWiiFileSystemContents()
|
||||||
{
|
{
|
||||||
if (s_temp_wii_root.empty())
|
if (s_temp_wii_root.empty() || !SConfig::GetInstance().bEnableMemcardSdWriting)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
const u64 title_id = SConfig::GetInstance().GetTitleID();
|
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);
|
IOS::HLE::EmulationKernel* ios = IOS::HLE::GetIOS();
|
||||||
std::string user_backup_path =
|
const auto session_save = WiiSave::MakeNandStorage(ios->GetFS().get(), title_id);
|
||||||
File::GetUserPath(D_BACKUP_IDX) +
|
|
||||||
StringFromFormat("%08x/%08x/", static_cast<u32>(title_id >> 32), static_cast<u32>(title_id));
|
const auto configured_fs = FS::MakeFileSystem(FS::Location::Configured);
|
||||||
if (File::Exists(save_path + "/banner.bin") && SConfig::GetInstance().bEnableMemcardSdWriting)
|
const auto user_save = WiiSave::MakeNandStorage(configured_fs.get(), title_id);
|
||||||
{
|
|
||||||
// Backup the existing save just in case it's still needed.
|
const std::string backup_path =
|
||||||
if (File::Exists(user_save_path + "/banner.bin"))
|
File::GetUserPath(D_BACKUP_IDX) + StringFromFormat("/%016" PRIx64 ".bin", title_id);
|
||||||
{
|
const auto backup_save = WiiSave::MakeDataBinStorage(&ios->GetIOSC(), backup_path, "w+b");
|
||||||
if (File::Exists(user_backup_path))
|
|
||||||
File::DeleteDirRecursively(user_backup_path);
|
// Backup the existing save just in case it's still needed.
|
||||||
File::CopyDir(user_save_path, user_backup_path);
|
WiiSave::Copy(user_save.get(), backup_save.get());
|
||||||
File::DeleteDirRecursively(user_save_path);
|
WiiSave::Copy(session_save.get(), user_save.get());
|
||||||
}
|
|
||||||
File::CopyDir(save_path, user_save_path);
|
|
||||||
File::DeleteDirRecursively(save_path);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} // namespace Core
|
} // namespace Core
|
||||||
|
|
Loading…
Reference in New Issue