Merge pull request #12263 from liamwhite/null-romfs

file_sys: handle null romfs
This commit is contained in:
liamwhite 2023-12-03 16:26:14 -05:00 committed by GitHub
commit fedeff7a89
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 21 deletions

View File

@ -429,10 +429,6 @@ VirtualFile PatchManager::PatchRomFS(const NCA* base_nca, VirtualFile base_romfs
LOG_DEBUG(Loader, "{}", log_string); LOG_DEBUG(Loader, "{}", log_string);
} }
if (base_romfs == nullptr) {
return base_romfs;
}
auto romfs = base_romfs; auto romfs = base_romfs;
// Game Updates // Game Updates

View File

@ -3,6 +3,7 @@
#include <memory> #include <memory>
#include "common/assert.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/string_util.h" #include "common/string_util.h"
#include "common/swap.h" #include "common/swap.h"
@ -101,24 +102,30 @@ void ProcessDirectory(const VirtualFile& file, std::size_t dir_offset, std::size
} // Anonymous namespace } // Anonymous namespace
VirtualDir ExtractRomFS(VirtualFile file) { VirtualDir ExtractRomFS(VirtualFile file) {
RomFSHeader header{}; auto root_container = std::make_shared<VectorVfsDirectory>();
if (file->ReadObject(&header) != sizeof(RomFSHeader)) if (!file) {
return nullptr; return root_container;
}
if (header.header_size != sizeof(RomFSHeader)) RomFSHeader header{};
return nullptr; if (file->ReadObject(&header) != sizeof(RomFSHeader)) {
return root_container;
}
if (header.header_size != sizeof(RomFSHeader)) {
return root_container;
}
const u64 file_offset = header.file_meta.offset; const u64 file_offset = header.file_meta.offset;
const u64 dir_offset = header.directory_meta.offset; const u64 dir_offset = header.directory_meta.offset;
auto root_container = std::make_shared<VectorVfsDirectory>();
ProcessDirectory(file, dir_offset, file_offset, header.data_offset, 0, root_container); ProcessDirectory(file, dir_offset, file_offset, header.data_offset, 0, root_container);
if (auto root = root_container->GetSubdirectory(""); root) { if (auto root = root_container->GetSubdirectory(""); root) {
return std::make_shared<CachedVfsDirectory>(std::move(root)); return std::make_shared<CachedVfsDirectory>(std::move(root));
} }
ASSERT(false);
return nullptr; return nullptr;
} }

View File

@ -22,7 +22,7 @@ RomFSFactory::RomFSFactory(Loader::AppLoader& app_loader, ContentProvider& provi
: content_provider{provider}, filesystem_controller{controller} { : content_provider{provider}, filesystem_controller{controller} {
// Load the RomFS from the app // Load the RomFS from the app
if (app_loader.ReadRomFS(file) != Loader::ResultStatus::Success) { if (app_loader.ReadRomFS(file) != Loader::ResultStatus::Success) {
LOG_ERROR(Service_FS, "Unable to read RomFS!"); LOG_WARNING(Service_FS, "Unable to read base RomFS");
} }
updatable = app_loader.IsRomFSUpdatable(); updatable = app_loader.IsRomFSUpdatable();

View File

@ -74,10 +74,8 @@ AppLoader_NCA::LoadResult AppLoader_NCA::Load(Kernel::KProcess& process, Core::S
return load_result; return load_result;
} }
if (nca->GetRomFS() != nullptr && nca->GetRomFS()->GetSize() > 0) {
system.GetFileSystemController().RegisterRomFS(std::make_unique<FileSys::RomFSFactory>( system.GetFileSystemController().RegisterRomFS(std::make_unique<FileSys::RomFSFactory>(
*this, system.GetContentProvider(), system.GetFileSystemController())); *this, system.GetContentProvider(), system.GetFileSystemController()));
}
is_loaded = true; is_loaded = true;
return load_result; return load_result;

View File

@ -2713,11 +2713,6 @@ void GMainWindow::OnGameListDumpRomFS(u64 program_id, const std::string& game_pa
} }
const auto base_romfs = base_nca->GetRomFS(); const auto base_romfs = base_nca->GetRomFS();
if (!base_romfs) {
failed();
return;
}
const auto dump_dir = const auto dump_dir =
target == DumpRomFSTarget::Normal target == DumpRomFSTarget::Normal
? Common::FS::GetYuzuPath(Common::FS::YuzuPath::DumpDir) ? Common::FS::GetYuzuPath(Common::FS::YuzuPath::DumpDir)