create shared font if it is missing

This commit is contained in:
B3n30 2017-08-15 09:44:47 +02:00
parent 22fc378fe9
commit b96e6eba37
4 changed files with 87436 additions and 2 deletions

87385
dist/shared_font.app.romfs.h vendored Normal file

File diff suppressed because it is too large Load Diff

View File

@ -386,8 +386,11 @@ set(HEADERS
telemetry_session.h
)
create_directory_groups(${SRCS} ${HEADERS})
add_library(core STATIC ${SRCS} ${HEADERS})
set(SYSTEM_ARCHIVES
../../dist/shared_font.app.romfs.h
)
create_directory_groups(${SRCS} ${HEADERS} ${SYSTEM_ARCHIVES})
add_library(core STATIC ${SRCS} ${HEADERS} ${SYSTEM_ARCHIVES})
target_link_libraries(core PUBLIC common PRIVATE audio_core network video_core)
target_link_libraries(core PUBLIC Boost::boost PRIVATE cryptopp dynarmic fmt)
if (ENABLE_WEB_SERVICE)

View File

@ -15,6 +15,8 @@
#include "core/file_sys/ivfc_archive.h"
#include "core/hle/service/fs/archive.h"
#include "../../dist/shared_font.app.romfs.h"
////////////////////////////////////////////////////////////////////////////////////////////////////
// FileSys namespace
@ -82,6 +84,36 @@ 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,6 +982,18 @@ 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);
@ -1000,6 +1012,8 @@ 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;