-
Notifications
You must be signed in to change notification settings - Fork 0
/
pfs.cpp
58 lines (44 loc) · 1.91 KB
/
pfs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
// Copyright (C) 2020 averne
//
// This file is part of Fuse-Nx.
//
// Fuse-Nx is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Fuse-Nx is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Fuse-Nx. If not, see <http://www.gnu.org/licenses/>.
#include <memory>
#include <fnx/io.hpp>
#include <fnx/formats/pfs.hpp>
namespace fnx::hac {
Pfs::Pfs(std::unique_ptr<io::FileBase> &&base): FormatBase(std::move(base)) {
this->base->read_at(0, this->header);
}
bool Pfs::parse() {
auto num_files = this->get_num_entries();
std::vector<FileEntryMeta> file_entries;
file_entries.resize(num_files);
this->base->read_at(sizeof(Header), file_entries);
this->strings_offset = sizeof(Header) + num_files * sizeof(FileEntryMeta);
this->data_offset = this->strings_offset + this->header.string_table_size;
this->names_table.resize(this->header.string_table_size);
this->base->read_at(this->strings_offset, this->names_table);
this->entries.resize(num_files);
for (std::size_t i = 0; i < num_files; ++i) {
this->entries[i].offset = file_entries[i].offset;
this->entries[i].size = file_entries[i].size;
this->entries[i].name = std::string_view(&this->names_table[file_entries[i].name_offset]);
}
return true;
}
std::unique_ptr<io::OffsetFile> Pfs::open(const Entry &entry) const {
return std::make_unique<io::OffsetFile>(this->clone_base(), entry.size, entry.offset + this->data_offset);
}
} // namespace fnx::hac