Add support for config savegame

This commit is contained in:
zhupengfei
2019-10-02 20:06:39 +08:00
parent 380a1da748
commit 5cbe69388f
5 changed files with 56 additions and 16 deletions
+39
View File
@@ -239,6 +239,35 @@ bool SDMCImporter::ImportSysdata(u64 id, [[maybe_unused]] const ProgressCallback
file.WriteString("slot0x25KeyX=" + Key::KeyToString(Key::GetKeyX(0x25)) + "\n");
return true;
}
case 5: { // Config savegame
FileUtil::IOFile file(config.config_savegame_path, "rb");
if (!file) {
return false;
}
std::vector<u8> data(file.GetSize());
if (file.ReadBytes(data.data(), data.size()) != data.size()) {
return false;
}
DataContainer container(data);
if (!container.IsGood()) {
return false;
}
SDSavegame save(std::move(container.GetIVFCLevel4Data()));
if (!save.IsGood()) {
return false;
}
const auto target_path =
fmt::format("{}data/00000000000000000000000000000000/sysdata/00010017/00000000/",
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir));
if (!FileUtil::CreateFullPath(target_path)) {
return false;
}
return save.ExtractDirectory(target_path, 1); // 1 = root
}
default:
UNREACHABLE_MSG("Unexpected sysdata id {}", id);
}
@@ -445,6 +474,10 @@ void SDMCImporter::ListSysdata(std::vector<ContentSpecifier>& out) const {
out.push_back(
{ContentType::Sysdata, 4, FileUtil::Exists(sysdata_path + AES_KEYS), 47, AES_KEYS});
}
CHECK_CONTENT(5, config.config_savegame_path,
fmt::format("{}data/00000000000000000000000000000000/sysdata/00010017/",
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)),
"Config savegame");
}
#undef CHECK_CONTENT
@@ -545,6 +578,11 @@ void SDMCImporter::DeleteSysdata(u64 id) const {
case 4: { // aes_keys.txt
FileUtil::Delete(FileUtil::GetUserPath(FileUtil::UserPath::SysDataDir) + AES_KEYS);
}
case 5: { // Config savegame
FileUtil::DeleteDirRecursively(
fmt::format("{}data/00000000000000000000000000000000/sysdata/00010017/",
FileUtil::GetUserPath(FileUtil::UserPath::NANDDir)));
}
default:
UNREACHABLE_MSG("Unexpected sysdata id {}", id);
}
@@ -575,6 +613,7 @@ std::vector<Config> LoadPresetConfig(std::string mount_point) {
LOAD_DATA(safe_mode_firm_path, "firm/");
LOAD_DATA(seed_db_path, SEED_DB);
LOAD_DATA(secret_sector_path, SECRET_SECTOR);
LOAD_DATA(config_savegame_path, "config.sav");
LOAD_DATA(system_archives_path, "sysarchives/");
#undef LOAD_DATA
}
+3 -2
View File
@@ -57,9 +57,10 @@ struct Config {
std::string safe_mode_firm_path; ///< Path to safe mode firm (A folder) (Sysdata 1)
std::string seed_db_path; ///< Path to seeddb.bin (Sysdata 2)
std::string secret_sector_path; ///< Path to secret sector (New3DS only) (Sysdata 3)
std::string system_archives_path; ///< Path to system archives.
// Note: Sysdata 4 is aes_keys.txt (slot0x25KeyX)
std::string config_savegame_path; ///< Path to config savegame (Sysdata 5)
// Sysdata 4 is aes_keys.db (slot0x25KeyX)
std::string system_archives_path; ///< Path to system archives.
};
class SDMCImporter {
+6 -6
View File
@@ -121,12 +121,6 @@ public:
*/
virtual bool Extract(std::string path) const = 0;
protected:
/**
* Gets the ArchiveFormatInfo of this archive, used for writing the archive metadata.
*/
virtual ArchiveFormatInfo GetFormatInfo() const = 0;
/**
* Extracts the index-th file in the file entry table to a certain path. (The path does not
* contain the file name).
@@ -146,6 +140,12 @@ protected:
*/
bool WriteMetadata(const std::string& path) const;
protected:
/**
* Gets the ArchiveFormatInfo of this archive, used for writing the archive metadata.
*/
virtual ArchiveFormatInfo GetFormatInfo() const = 0;
bool is_good = false;
FATHeader header;
FileSystemInformation fs_info;