yuzu-emu
/
yuzu-android
Archived
1
0
Fork 0

romfs: Implement CreateRomFS

This commit is contained in:
Zach Hilman 2018-09-19 22:04:51 -04:00
parent 6eada3c57d
commit 050547b801
2 changed files with 25 additions and 4 deletions

View File

@ -4,8 +4,10 @@
#include "common/common_types.h" #include "common/common_types.h"
#include "common/swap.h" #include "common/swap.h"
#include "core/file_sys/fsmitm_romfsbuild.hpp"
#include "core/file_sys/romfs.h" #include "core/file_sys/romfs.h"
#include "core/file_sys/vfs.h" #include "core/file_sys/vfs.h"
#include "core/file_sys/vfs_concat.h"
#include "core/file_sys/vfs_offset.h" #include "core/file_sys/vfs_offset.h"
#include "core/file_sys/vfs_vector.h" #include "core/file_sys/vfs_vector.h"
@ -98,7 +100,7 @@ void ProcessDirectory(VirtualFile file, std::size_t dir_offset, std::size_t file
} }
} }
VirtualDir ExtractRomFS(VirtualFile file) { VirtualDir ExtractRomFS(VirtualFile file, bool traverse_into_data) {
RomFSHeader header{}; RomFSHeader header{};
if (file->ReadObject(&header) != sizeof(RomFSHeader)) if (file->ReadObject(&header) != sizeof(RomFSHeader))
return nullptr; return nullptr;
@ -117,9 +119,21 @@ VirtualDir ExtractRomFS(VirtualFile file) {
VirtualDir out = std::move(root); VirtualDir out = std::move(root);
while (out->GetSubdirectory("") != nullptr) while (out->GetSubdirectories().size() == 1 && out->GetFiles().size() == 0) {
out = out->GetSubdirectory(""); if (out->GetSubdirectories().front()->GetName() == "data" && !traverse_into_data)
break;
out = out->GetSubdirectories().front();
}
return out; return out;
} }
VirtualFile CreateRomFS(VirtualDir dir) {
if (dir == nullptr)
return nullptr;
RomFSBuildContext ctx{dir};
return ConcatenateFiles<0>(ctx.Build(), dir->GetName());
}
} // namespace FileSys } // namespace FileSys

View File

@ -5,6 +5,7 @@
#pragma once #pragma once
#include <array> #include <array>
#include <map>
#include "common/common_funcs.h" #include "common/common_funcs.h"
#include "common/common_types.h" #include "common/common_types.h"
#include "common/swap.h" #include "common/swap.h"
@ -12,6 +13,8 @@
namespace FileSys { namespace FileSys {
struct RomFSHeader;
struct IVFCLevel { struct IVFCLevel {
u64_le offset; u64_le offset;
u64_le size; u64_le size;
@ -31,6 +34,10 @@ static_assert(sizeof(IVFCHeader) == 0xE0, "IVFCHeader has incorrect size.");
// Converts a RomFS binary blob to VFS Filesystem // Converts a RomFS binary blob to VFS Filesystem
// Returns nullptr on failure // Returns nullptr on failure
VirtualDir ExtractRomFS(VirtualFile file); VirtualDir ExtractRomFS(VirtualFile file, bool traverse_into_data = true);
// Converts a VFS filesystem into a RomFS binary
// Returns nullptr on failure
VirtualFile CreateRomFS(VirtualDir dir);
} // namespace FileSys } // namespace FileSys