18 , tempPakLumpPath((std::filesystem::temp_directory_path() / (string::generateUUIDv4() +
".zip")).string()) {}
27 if (!std::filesystem::exists(path)) {
33 auto packFile = std::unique_ptr<PackFile>(bsp);
43 bsp->mapRevision = reader.getMapRevision();
47 FileStream writer{bsp->tempPakLumpPath, FileStream::OPT_TRUNCATE | FileStream::OPT_CREATE_IF_NONEXISTENT};
48 writer.write(*pakFileLump);
57 if (!bsp->openZIP(bsp->tempPakLumpPath)) {
61 for (
auto code = mz_zip_goto_first_entry(bsp->zipHandle); code == MZ_OK; code = mz_zip_goto_next_entry(bsp->zipHandle)) {
62 mz_zip_file* fileInfo =
nullptr;
63 if (mz_zip_entry_get_info(bsp->zipHandle, &fileInfo)) {
66 if (mz_zip_entry_is_dir(bsp->zipHandle) == MZ_OK) {
70 auto entryPath = bsp->cleanEntryPath(fileInfo->filename);
73 entry.
flags = fileInfo->compression_method << 16;
74 entry.
length = fileInfo->uncompressed_size;
76 entry.
crc32 = fileInfo->crc;
78 bsp->entries.emplace(entryPath, entry);
81 callback(entryPath, entry);
91 const std::string outputPath = outputDir +
'/' + this->
getFilename();
95 std::filesystem::copy_file(this->
fullFilePath, outputPath, std::filesystem::copy_options::overwrite_existing);
123PakLump::operator std::string()
const {
124 return PackFile::operator std::string() +
125 " | Version v" + std::to_string(this->version) +
126 " | Map Revision " + std::to_string(this->mapRevision);
uint32_t getVersion() const
Utility class for vpkpp integration - you need to include this header in a C++ file somewhere in your...
PakLump(const std::string &fullFilePath_)
bool bake(const std::string &outputDir_, vpkpp::BakeOptions options, const EntryCallback &callback) override
If output folder is an empty string, it will overwrite the original.
static std::unique_ptr< PackFile > open(const std::string &path, const EntryCallback &callback=nullptr)
Open a BSP file.
const std::string tempPakLumpPath
This class represents the metadata that a file has inside a PackFile.
uint32_t flags
Format-specific flags (PCK: File flags, VPK: Internal parser state, ZIP: Compression method / strengt...
uint64_t compressedLength
If the format supports compression, this is the compressed length.
uint32_t crc32
CRC32 checksum - 0 if unused.
uint64_t length
Length in bytes (in formats with compression, this is the uncompressed length)
EntryCallbackBase< void > EntryCallback
void mergeUnbakedEntries()
std::string getFilename() const
/home/user/pak01_dir.vpk -> pak01_dir.vpk
std::string getBakeOutputDir(const std::string &outputDir) const
void setFullFilePath(const std::string &outputDir)
static Entry createNewEntry()
const std::string tempZIPPath
bool openZIP(std::string_view path)
bool bakeTempZip(const std::string &writeZipPath, BakeOptions options, const EntryCallback &callback) const
static std::unique_ptr< PackFile > create(const std::string &path)
Create a ZIP file.
std::vector< std::byte > readFileBuffer(const std::string &filepath, std::size_t startOffset=0)