diff --git a/src/core/core.cpp b/src/core/core.cpp index 781264b9e..629e90607 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -207,52 +207,72 @@ void System::Shutdown() { LOG_DEBUG(Core, "Shutdown OK"); } -void System::SystemIntegrityCheck() { - // Shared Font JP/EUR/USA +static System::Integrity::Status GetArchiveStatus(const std::string& name, const u32 id_high, + 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); - const u32 shared_font_archive_id_low = 0x00014002; - const u32 shared_font_archive_id_high = 0x0004009b; - std::string shared_font_path = Common::StringFromFormat( - "%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); + std::string shared_font_path = + Common::StringFromFormat("%s%s/title/%08x/%08x/content/00000000.app.romfs", + nand_directory.c_str(), SYSTEM_ID, id_high, id_low); + if (FileUtil::Exists(shared_font_path)) { std::string version = Settings::values.shared_font_jeu_version; if (version == "dumped") { - system_integrity.shared_font_JEU = Integrity::Dumped; - LOG_INFO(Core, "SystemCheck: Shared Font exists."); - } else if (version == CUSTOM_ARCHIVES_VERSION) { - system_integrity.shared_font_JEU = Integrity::Custom; - LOG_WARNING(Core, "SystemCheck: Shared Font (custom) exists."); + LOG_INFO(Core, "SystemCheck: %s exists.", name.c_str()); + return System::Integrity::Dumped; #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 { 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(); - system_integrity.shared_font_JEU = Integrity::CreatedCustom; - Settings::values.shared_font_jeu_version = CUSTOM_ARCHIVES_VERSION; - LOG_WARNING(Core, "SystemCheck: Updated Shared Font."); - } + settings_version = CUSTOM_ARCHIVES_VERSION; + LOG_WARNING(Core, "SystemCheck: Updated %s.", name.c_str()); + return System::Integrity::CreatedCustom; +#else + } else { + LOG_WARNING(Core, "SystemCheck: %s(custom) exists.", name.c_str()); + return System::Integrity::Custom; #endif + } } else { - std::string shared_font_legacy_path = FileUtil::GetUserPath(D_SYSDATA_IDX) + SHARED_FONT; - if (FileUtil::Exists(shared_font_legacy_path)) { - LOG_INFO(Core, "SystemCheck: Shared Font(legacy) exists."); - system_integrity.shared_font_JEU = Integrity::DumpedLegacy; + if (!legacy_path.empty() && FileUtil::Exists(legacy_path)) { + LOG_INFO(Core, "SystemCheck: %s(legacy) exists.", name.c_str()); + return System::Integrity::DumpedLegacy; } else { - LOG_ERROR(Core, "SystemCheck: Shared Font missing."); - system_integrity.shared_font_JEU = Integrity::Missing; + LOG_ERROR(Core, "SystemCheck: %s missing.", name.c_str()); #ifdef ENABLE_CUSTOM_SYSTEM_ARCHIVES 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(); - system_integrity.shared_font_JEU = Integrity::CreatedCustom; - Settings::values.shared_font_jeu_version = CUSTOM_ARCHIVES_VERSION; - LOG_WARNING(Core, "SystemCheck: Created Shared Font."); + settings_version = CUSTOM_ARCHIVES_VERSION; + LOG_WARNING(Core, "SystemCheck: Created %s.", name.c_str()); + return System::Integrity::CreatedCustom; +#else + return System::Integrity::Missing; #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