SystemIntegrityCheck: Moved the check for each Archive to a seperate function

This commit is contained in:
B3n30 2017-09-20 12:23:10 +02:00
parent 69a36fbaec
commit 016a73127b

View File

@ -207,52 +207,72 @@ void System::Shutdown() {
LOG_DEBUG(Core, "Shutdown OK"); LOG_DEBUG(Core, "Shutdown OK");
} }
void System::SystemIntegrityCheck() { static System::Integrity::Status GetArchiveStatus(const std::string& name, const u32 id_high,
// Shared Font JP/EUR/USA const u32 id_low, std::string& settings_version,
const void* custom_data,
const size_t custom_data_length,
const std::string& legacy_path = "") {
std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX); std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
const u32 shared_font_archive_id_low = 0x00014002; std::string shared_font_path =
const u32 shared_font_archive_id_high = 0x0004009b; Common::StringFromFormat("%s%s/title/%08x/%08x/content/00000000.app.romfs",
std::string shared_font_path = Common::StringFromFormat( nand_directory.c_str(), SYSTEM_ID, id_high, id_low);
"%s%s/title/%08x/%08x/content/00000000.app.romfs", nand_directory.c_str(), SYSTEM_ID,
shared_font_archive_id_high, shared_font_archive_id_low);
if (FileUtil::Exists(shared_font_path)) { if (FileUtil::Exists(shared_font_path)) {
std::string version = Settings::values.shared_font_jeu_version; std::string version = Settings::values.shared_font_jeu_version;
if (version == "dumped") { if (version == "dumped") {
system_integrity.shared_font_JEU = Integrity::Dumped; LOG_INFO(Core, "SystemCheck: %s exists.", name.c_str());
LOG_INFO(Core, "SystemCheck: Shared Font exists."); return System::Integrity::Dumped;
} else if (version == CUSTOM_ARCHIVES_VERSION) {
system_integrity.shared_font_JEU = Integrity::Custom;
LOG_WARNING(Core, "SystemCheck: Shared Font (custom) exists.");
#ifdef ENABLE_CUSTOM_SYSTEM_ARCHIVES #ifdef ENABLE_CUSTOM_SYSTEM_ARCHIVES
} else if (settings_version == CUSTOM_ARCHIVES_VERSION) {
LOG_WARNING(Core, "SystemCheck: %s(custom) exists.", name.c_str());
return System::Integrity::Custom;
} else { } else {
FileUtil::IOFile file(shared_font_path, "wb"); FileUtil::IOFile file(shared_font_path, "wb");
file.WriteBytes(SHARED_FONT_DATA, SHARED_FONT_DATA_len); file.WriteBytes(custom_data, custom_data_length);
file.Close(); file.Close();
system_integrity.shared_font_JEU = Integrity::CreatedCustom; settings_version = CUSTOM_ARCHIVES_VERSION;
Settings::values.shared_font_jeu_version = CUSTOM_ARCHIVES_VERSION; LOG_WARNING(Core, "SystemCheck: Updated %s.", name.c_str());
LOG_WARNING(Core, "SystemCheck: Updated Shared Font."); return System::Integrity::CreatedCustom;
} #else
} else {
LOG_WARNING(Core, "SystemCheck: %s(custom) exists.", name.c_str());
return System::Integrity::Custom;
#endif #endif
}
} else { } else {
std::string shared_font_legacy_path = FileUtil::GetUserPath(D_SYSDATA_IDX) + SHARED_FONT; if (!legacy_path.empty() && FileUtil::Exists(legacy_path)) {
if (FileUtil::Exists(shared_font_legacy_path)) { LOG_INFO(Core, "SystemCheck: %s(legacy) exists.", name.c_str());
LOG_INFO(Core, "SystemCheck: Shared Font(legacy) exists."); return System::Integrity::DumpedLegacy;
system_integrity.shared_font_JEU = Integrity::DumpedLegacy;
} else { } else {
LOG_ERROR(Core, "SystemCheck: Shared Font missing."); LOG_ERROR(Core, "SystemCheck: %s missing.", name.c_str());
system_integrity.shared_font_JEU = Integrity::Missing;
#ifdef ENABLE_CUSTOM_SYSTEM_ARCHIVES #ifdef ENABLE_CUSTOM_SYSTEM_ARCHIVES
FileUtil::IOFile file(shared_font_path, "wb"); FileUtil::IOFile file(shared_font_path, "wb");
file.WriteBytes(SHARED_FONT_DATA, SHARED_FONT_DATA_len); file.WriteBytes(custom_data, custom_data_length);
file.Close(); file.Close();
system_integrity.shared_font_JEU = Integrity::CreatedCustom; settings_version = CUSTOM_ARCHIVES_VERSION;
Settings::values.shared_font_jeu_version = CUSTOM_ARCHIVES_VERSION; LOG_WARNING(Core, "SystemCheck: Created %s.", name.c_str());
LOG_WARNING(Core, "SystemCheck: Created Shared Font."); return System::Integrity::CreatedCustom;
#else
return System::Integrity::Missing;
#endif #endif
} }
} }
// TODO(B3N30): Check if the other required system archives exists
} }
} // namespace void System::SystemIntegrityCheck() {
// TODO(B3N30): Check other required system archives
// Shared Font JP/EUR/USA
std::string shared_font_legacy_path = FileUtil::GetUserPath(D_SYSDATA_IDX) + SHARED_FONT;
#ifdef ENABLE_CUSTOM_SYSTEM_ARCHIVES
system_integrity.shared_font_JEU = GetArchiveStatus(
"Shared Font JP/EUR/USA", 0x0004009b, 0x00014002, Settings::values.shared_font_jeu_version,
SHARED_FONT_DATA, SHARED_FONT_DATA_len, shared_font_legacy_path);
#else
system_integrity.shared_font_JEU = GetArchiveStatus(
"Shared Font JP/EUR/USA", 0x0004009b, 0x00014002, Settings::values.shared_font_jeu_version,
nullptr, 0, shared_font_legacy_path);
#endif
}
} // namespace Core