core: Use LayeredFS while reading RomFS

Only enabled for NCCHs that do not have an override romfs.

LayeredFS files should be put in the `load` directory in User Directory. The directory structure is similar to yuzu's but currently does not allow named mods yet. Replacement files should be put in `load/mods/<Title ID>/romfs` while patches/stubs should be put in `load/mods/<Title ID>/romfs_ext`.
This commit is contained in:
zhupengfei 2020-02-07 13:45:10 +08:00
parent 890405bb7c
commit 8a570bf00c
No known key found for this signature in database
GPG Key ID: DD129E108BD09378
2 changed files with 23 additions and 9 deletions

View File

@ -11,6 +11,7 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/logging/log.h" #include "common/logging/log.h"
#include "core/core.h" #include "core/core.h"
#include "core/file_sys/layered_fs.h"
#include "core/file_sys/ncch_container.h" #include "core/file_sys/ncch_container.h"
#include "core/file_sys/patch.h" #include "core/file_sys/patch.h"
#include "core/file_sys/seed_db.h" #include "core/file_sys/seed_db.h"
@ -597,12 +598,24 @@ Loader::ResultStatus NCCHContainer::ReadRomFS(std::shared_ptr<RomFSReader>& romf
if (!romfs_file_inner.IsOpen()) if (!romfs_file_inner.IsOpen())
return Loader::ResultStatus::Error; return Loader::ResultStatus::Error;
std::shared_ptr<RomFSReader> direct_romfs;
if (is_encrypted) { if (is_encrypted) {
romfs_file = std::make_shared<RomFSReader>(std::move(romfs_file_inner), romfs_offset, direct_romfs =
std::make_shared<DirectRomFSReader>(std::move(romfs_file_inner), romfs_offset,
romfs_size, secondary_key, romfs_ctr, 0x1000); romfs_size, secondary_key, romfs_ctr, 0x1000);
} else { } else {
romfs_file = direct_romfs = std::make_shared<DirectRomFSReader>(std::move(romfs_file_inner),
std::make_shared<RomFSReader>(std::move(romfs_file_inner), romfs_offset, romfs_size); romfs_offset, romfs_size);
}
const auto path =
fmt::format("{}mods/{:016X}/", FileUtil::GetUserPath(FileUtil::UserPath::LoadDir),
ncch_header.program_id);
if (FileUtil::Exists(path + "romfs/") || FileUtil::Exists(path + "romfs_ext/")) {
romfs_file = std::make_shared<LayeredFS>(std::move(direct_romfs), path + "romfs/",
path + "romfs_ext/");
} else {
romfs_file = std::move(direct_romfs);
} }
return Loader::ResultStatus::Success; return Loader::ResultStatus::Success;
@ -614,8 +627,9 @@ Loader::ResultStatus NCCHContainer::ReadOverrideRomFS(std::shared_ptr<RomFSReade
if (FileUtil::Exists(split_filepath)) { if (FileUtil::Exists(split_filepath)) {
FileUtil::IOFile romfs_file_inner(split_filepath, "rb"); FileUtil::IOFile romfs_file_inner(split_filepath, "rb");
if (romfs_file_inner.IsOpen()) { if (romfs_file_inner.IsOpen()) {
LOG_WARNING(Service_FS, "File {} overriding built-in RomFS", split_filepath); LOG_WARNING(Service_FS, "File {} overriding built-in RomFS; LayeredFS not enabled",
romfs_file = std::make_shared<RomFSReader>(std::move(romfs_file_inner), 0, split_filepath);
romfs_file = std::make_shared<DirectRomFSReader>(std::move(romfs_file_inner), 0,
romfs_file_inner.GetSize()); romfs_file_inner.GetSize());
return Loader::ResultStatus::Success; return Loader::ResultStatus::Success;
} }

View File

@ -309,7 +309,7 @@ ResultStatus AppLoader_THREEDSX::ReadRomFS(std::shared_ptr<FileSys::RomFSReader>
if (!romfs_file_inner.IsOpen()) if (!romfs_file_inner.IsOpen())
return ResultStatus::Error; return ResultStatus::Error;
romfs_file = std::make_shared<FileSys::RomFSReader>(std::move(romfs_file_inner), romfs_file = std::make_shared<FileSys::DirectRomFSReader>(std::move(romfs_file_inner),
romfs_offset, romfs_size); romfs_offset, romfs_size);
return ResultStatus::Success; return ResultStatus::Success;