WiiRoot: Copy initial NAND files with proper metadata
This commit is contained in:
parent
037040c7a0
commit
48fa835bd3
|
@ -5,14 +5,19 @@
|
|||
#include "Core/WiiRoot.h"
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include "Common/CommonPaths.h"
|
||||
#include "Common/CommonTypes.h"
|
||||
#include "Common/File.h"
|
||||
#include "Common/FileUtil.h"
|
||||
#include "Common/Logging/Log.h"
|
||||
#include "Common/NandPaths.h"
|
||||
#include "Common/StringUtil.h"
|
||||
#include "Core/ConfigManager.h"
|
||||
#include "Core/IOS/FS/FileSystem.h"
|
||||
#include "Core/IOS/IOS.h"
|
||||
#include "Core/IOS/Uids.h"
|
||||
#include "Core/Movie.h"
|
||||
#include "Core/NetPlayClient.h"
|
||||
#include "Core/SysConf.h"
|
||||
|
@ -79,15 +84,63 @@ void ShutdownWiiRoot()
|
|||
}
|
||||
}
|
||||
|
||||
/// 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 "".
|
||||
static bool CopySysmenuFilesToFS(IOS::HLE::FS::FileSystem* fs, const std::string& host_source_path,
|
||||
const std::string& nand_target_path)
|
||||
{
|
||||
const auto entries = File::ScanDirectoryTree(host_source_path, false);
|
||||
for (const File::FSTEntry& entry : entries.children)
|
||||
{
|
||||
const std::string host_path = host_source_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;
|
||||
|
||||
if (entry.isDirectory)
|
||||
{
|
||||
fs->CreateDirectory(IOS::SYSMENU_UID, IOS::SYSMENU_GID, nand_path, 0, rw_mode, rw_mode,
|
||||
rw_mode);
|
||||
|
||||
if (!CopySysmenuFilesToFS(fs, host_path, nand_path))
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Do not overwrite any existing files.
|
||||
if (fs->GetMetadata(IOS::SYSMENU_UID, IOS::SYSMENU_UID, nand_path).Succeeded())
|
||||
continue;
|
||||
|
||||
File::IOFile host_file{host_path, "rb"};
|
||||
std::vector<u8> file_data(host_file.GetSize());
|
||||
if (!host_file.ReadBytes(file_data.data(), file_data.size()))
|
||||
return false;
|
||||
|
||||
const auto nand_file = fs->CreateAndOpenFile(IOS::SYSMENU_UID, IOS::SYSMENU_GID, nand_path,
|
||||
rw_mode, rw_mode, rw_mode);
|
||||
if (!nand_file || !nand_file->Write(file_data.data(), file_data.size()))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
void InitializeWiiFileSystemContents()
|
||||
{
|
||||
File::CopyDir(File::GetSysDirectory() + WII_USER_DIR, File::GetUserPath(D_SESSION_WIIROOT_IDX));
|
||||
const auto fs = IOS::HLE::GetIOS()->GetFS();
|
||||
|
||||
// Some games (such as Mario Kart Wii) assume that NWC24 files will always be present
|
||||
// even upon the first launch as they are normally created by the system menu.
|
||||
// Because we do not require the system menu to be run, WiiConnect24 files must be copied
|
||||
// to the NAND manually.
|
||||
if (!CopySysmenuFilesToFS(fs.get(), File::GetSysDirectory() + WII_USER_DIR, ""))
|
||||
WARN_LOG(CORE, "Failed to copy initial System Menu files to the NAND");
|
||||
|
||||
if (s_temp_wii_root.empty())
|
||||
return;
|
||||
|
||||
// Generate a SYSCONF with default settings for the temporary Wii NAND.
|
||||
SysConf sysconf{IOS::HLE::GetIOS()->GetFS()};
|
||||
SysConf sysconf{fs};
|
||||
sysconf.Save();
|
||||
|
||||
InitializeDeterministicWiiSaves();
|
||||
|
|
Loading…
Reference in New Issue