mirror of
https://github.com/PabloMK7/citra.git
synced 2024-11-24 16:34:24 +00:00
layered_fs: Do not open all replacement files on load
Instead open them when we want to read them. This is because the standard library has a limit on the number of opened files.
This commit is contained in:
parent
b87bc5d351
commit
d9ae4c332d
1 changed files with 12 additions and 11 deletions
|
@ -18,7 +18,7 @@ namespace FileSys {
|
|||
struct FileRelocationInfo {
|
||||
int type; // 0 - none, 1 - replaced / created, 2 - patched, 3 - removed
|
||||
u64 original_offset; // Type 0. Offset is absolute
|
||||
FileUtil::IOFile replace_file; // Type 1
|
||||
std::string replace_file_path; // Type 1
|
||||
std::vector<u8> patched_file; // Type 2
|
||||
u64 size; // Relocated file size
|
||||
};
|
||||
|
@ -175,14 +175,9 @@ void LayeredFS::LoadRelocations() {
|
|||
}
|
||||
|
||||
auto* file = file_path_map.at(path);
|
||||
file->relocation.replace_file = FileUtil::IOFile(directory + virtual_name, "rb");
|
||||
if (file->relocation.replace_file) {
|
||||
file->relocation.type = 1;
|
||||
file->relocation.size = file->relocation.replace_file.GetSize();
|
||||
LOG_INFO(Service_FS, "LayeredFS replacement file in use for {}", path);
|
||||
} else {
|
||||
LOG_ERROR(Service_FS, "Could not open replacement file for {}", path);
|
||||
}
|
||||
file->relocation.type = 1;
|
||||
file->relocation.replace_file_path = directory + virtual_name;
|
||||
LOG_INFO(Service_FS, "LayeredFS replacement file in use for {}", path);
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -524,8 +519,14 @@ std::size_t LayeredFS::ReadFile(std::size_t offset, std::size_t length, u8* buff
|
|||
romfs->ReadFile(relocation.original_offset + relative_offset, to_read,
|
||||
buffer + read_size);
|
||||
} else if (relocation.type == 1) { // replace
|
||||
relocation.replace_file.Seek(relative_offset, SEEK_SET);
|
||||
relocation.replace_file.ReadBytes(buffer + read_size, to_read);
|
||||
FileUtil::IOFile replace_file(relocation.replace_file_path, "rb");
|
||||
if (replace_file) {
|
||||
replace_file.Seek(relative_offset, SEEK_SET);
|
||||
replace_file.ReadBytes(buffer + read_size, to_read);
|
||||
} else {
|
||||
LOG_ERROR(Service_FS, "Could not open replacement file for {}",
|
||||
current->second->path);
|
||||
}
|
||||
} else if (relocation.type == 2) { // patch
|
||||
std::memcpy(buffer + read_size, relocation.patched_file.data() + relative_offset,
|
||||
to_read);
|
||||
|
|
Loading…
Reference in a new issue