Added System::SystemIntegrityCheck; moved the Shared Font creation to SystemIntegrityCheck

This commit is contained in:
B3n30 2017-08-15 16:50:55 +02:00
parent b96e6eba37
commit 8775458054
4 changed files with 45 additions and 46 deletions

View File

@ -5,7 +5,10 @@
#include <memory>
#include <utility>
#include "audio_core/audio_core.h"
#include "common/common_paths.h"
#include "common/file_util.h"
#include "common/logging/log.h"
#include "common/string_util.h"
#include "core/arm/arm_interface.h"
#include "core/arm/dynarmic/arm_dynarmic.h"
#include "core/arm/dyncom/arm_dyncom.h"
@ -14,6 +17,7 @@
#include "core/gdbstub/gdbstub.h"
#include "core/hle/kernel/kernel.h"
#include "core/hle/kernel/thread.h"
#include "core/hle/service/fs/archive.h"
#include "core/hle/service/service.h"
#include "core/hw/hw.h"
#include "core/loader/loader.h"
@ -22,6 +26,9 @@
#include "network/network.h"
#include "video_core/video_core.h"
// System Archives
#include "../../dist/shared_font.app.romfs.h"
namespace Core {
/*static*/ System System::s_instance;
@ -151,6 +158,7 @@ System::ResultStatus System::Init(EmuWindow* emu_window, u32 system_mode) {
CoreTiming::Init();
HW::Init();
Kernel::Init(system_mode);
SystemIntegrityCheck();
Service::Init();
AudioCore::Init();
GDBStub::Init();
@ -197,4 +205,37 @@ void System::Shutdown() {
LOG_DEBUG(Core, "Shutdown OK");
}
void System::SystemIntegrityCheck() {
// Shared Font
// TODO(B3N30): check/create font archive for region CHN/KOR/TWN
std::string nand_directory = FileUtil::GetUserPath(D_NAND_IDX);
const u32 shared_font_archive_id_low = 0x00014002;
const u32_le 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);
LOG_DEBUG(Core, "%s", shared_font_path.c_str());
auto file = std::make_shared<FileUtil::IOFile>(shared_font_path, "rb");
if (file->IsOpen()) {
file->Close();
LOG_INFO(Core, "SystemCheck: Shared Font exists.");
} else {
std::string shared_font_legacy_path = FileUtil::GetUserPath(D_SYSDATA_IDX) + SHARED_FONT;
file = std::make_shared<FileUtil::IOFile>(shared_font_legacy_path, "rb");
if (file->IsOpen()) {
file->Close();
LOG_INFO(Core, "SystemCheck: Shared Font(legacy) exists.");
} else {
LOG_ERROR(Core, "SystemCheck: Shared Font missing.");
file = std::make_shared<FileUtil::IOFile>(shared_font_path, "w+b");
file->WriteBytes(SHARED_FONT_DATA, SHARED_FONT_DATA_len);
file->Close();
LOG_DEBUG(Core, "SystemCheck: Created Shared Font.");
}
}
// TODO(B3N30): Check if the other required system archives exists
}
} // namespace

View File

@ -132,6 +132,10 @@ private:
/// Reschedule the core emulation
void Reschedule();
/// Checks if required system files exist
/// If they don't exist, it will try to create them
void SystemIntegrityCheck();
/// AppLoader used to load the current executing application
std::unique_ptr<Loader::AppLoader> app_loader;

View File

@ -15,8 +15,6 @@
#include "core/file_sys/ivfc_archive.h"
#include "core/hle/service/fs/archive.h"
#include "../../dist/shared_font.app.romfs.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace
@ -84,36 +82,6 @@ ResultVal<std::unique_ptr<ArchiveBackend>> ArchiveFactory_NCCH::Open(const Path&
ResultCode ArchiveFactory_NCCH::Format(const Path& path,
const FileSys::ArchiveFormatInfo& format_info) {
// TODO(B3N30): Take care of the format_info
auto vec = path.AsBinary();
const u32* data = reinterpret_cast<u32*>(vec.data());
u32 high = data[1];
u32 low = data[0];
std::string file_path = GetNCCHPath(mount_point, high, low);
// High Title ID of the archive: The category (https://3dbrew.org/wiki/Title_list).
constexpr u32 shared_data_archive = 0x0004009B;
// Low Title IDs.
constexpr u32 shared_font_archive = 0x00014002;
if (high == shared_data_archive) {
if (low == shared_font_archive) {
auto file = std::make_shared<FileUtil::IOFile>(file_path, "w+b");
if (!file->IsOpen()) {
LOG_ERROR(Service_FS, "Could not create shared font file.");
// TODO: Verify error code
return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS,
ErrorSummary::NotSupported, ErrorLevel::Permanent);
}
file->WriteBytes(SHARED_FONT_DATA, SHARED_FONT_DATA_len);
file->Close();
file.reset();
LOG_DEBUG(Service_FS, "Created shared font file.");
return RESULT_SUCCESS;
}
}
LOG_ERROR(Service_FS, "Attempted to format a NCCH archive.");
// TODO: Verify error code
return ResultCode(ErrorDescription::NotAuthorized, ErrorModule::FS, ErrorSummary::NotSupported,

View File

@ -982,18 +982,6 @@ static bool LoadLegacySharedFont() {
return false;
}
static bool FormatSharedFont() {
// TODO (B3N30): create different font archive for region CHN/KOR/TWN
const u64_le shared_font_archive_id_low = 0x0004009b00014002;
const u64_le shared_font_archive_id_high = 0x00000001ffffff00;
std::vector<u8> shared_font_archive_id(16);
std::memcpy(&shared_font_archive_id[0], &shared_font_archive_id_low, sizeof(u64));
std::memcpy(&shared_font_archive_id[8], &shared_font_archive_id_high, sizeof(u64));
FileSys::Path archive_path(shared_font_archive_id);
return Service::FS::FormatArchive(Service::FS::ArchiveIdCode::NCCH,
FileSys::ArchiveFormatInfo{}, archive_path) == RESULT_SUCCESS;
}
void Init() {
AddService(new APT_A_Interface);
AddService(new APT_S_Interface);
@ -1012,8 +1000,6 @@ void Init() {
} else if (LoadLegacySharedFont()) {
LOG_WARNING(Service_APT, "Loaded shared font by legacy method");
shared_font_loaded = true;
} else if (FormatSharedFont() && LoadSharedFont()) {
shared_font_loaded = true;
} else {
LOG_WARNING(Service_APT, "Unable to load shared font");
shared_font_loaded = false;