10std::unique_ptr<PackFile>
FPX::create(
const std::string& path) {
12 FileStream stream{path, FileStream::OPT_TRUNCATE | FileStream::OPT_CREATE_IF_NONEXISTENT};
26 std::unique_ptr<PackFile> fpx;
29 if (path.length() >= 8) {
30 auto dirPath = path.substr(0, path.length() - 8) +
"_fdr.fpx";
31 auto pathEnd = path.substr(path.length() - 8, path.length());
32 if (
string::matches(pathEnd,
"_%d%d%d.fpx") && std::filesystem::exists(dirPath)) {
44 if (!std::filesystem::exists(path)) {
49 auto* fpx =
new FPX{path};
50 auto packFile = std::unique_ptr<PackFile>(fpx);
52 FileStream reader{fpx->fullFilePath};
54 reader.read(fpx->header1);
59 if (fpx->header1.version != 10) {
66 std::string extension;
67 reader.read(extension);
68 if (extension.empty())
73 std::string directory;
74 reader.read(directory);
75 if (directory.empty())
79 if (directory ==
" ") {
87 std::string entryName;
88 reader.read(entryName);
89 if (entryName.empty())
94 std::string entryPath;
95 if (extension ==
" ") {
96 entryPath = fullDir.empty() ?
"" : fullDir +
'/';
97 entryPath += entryName;
99 entryPath = fullDir.empty() ?
"" : fullDir +
'/';
100 entryPath += entryName +
'.';
101 entryPath += extension;
103 entryPath = fpx->cleanEntryPath(entryPath);
105 reader.read(entry.
crc32);
106 auto preloadedDataSize = reader.read<uint16_t>();
108 entry.
offset = reader.read<uint32_t>();
109 entry.
length = reader.read<uint32_t>();
116 if (preloadedDataSize > 0) {
117 entry.
extraData = reader.read_bytes(preloadedDataSize);
118 entry.
length += preloadedDataSize;
125 fpx->entries.emplace(entryPath, entry);
128 callback(entryPath, entry);
This class represents the metadata that a file has inside a PackFile.
uint64_t offset
Offset, format-specific meaning - 0 if unused, or if the offset genuinely is 0.
uint32_t archiveIndex
Which external archive this entry is in.
uint32_t crc32
CRC32 checksum - 0 if unused.
uint64_t length
Length in bytes (in formats with compression, this is the uncompressed length)
std::vector< std::byte > extraData
Format-specific (PCK: MD5 hash, VPK: Preloaded data)
static std::unique_ptr< PackFile > openInternal(const std::string &path, const EntryCallback &callback=nullptr)
static std::unique_ptr< PackFile > open(const std::string &path, const EntryCallback &callback=nullptr)
Open an FPX file.
static std::unique_ptr< PackFile > create(const std::string &path)
Create a new directory FPX file - should end in "_dir.fpx"! This is not enforced but STRONGLY recomme...
EntryCallbackBase< void > EntryCallback
static Entry createNewEntry()
bool matches(std::string_view in, std::string_view search)
A very basic regex-like pattern checker for ASCII strings.
constexpr uint16_t VPK_ENTRY_TERM
constexpr uint32_t FPX_SIGNATURE
constexpr uint16_t VPK_DIR_INDEX