5#include "../PackFile.h"
16constexpr std::string_view
VPK_KEYPAIR_PRIVATE_KEY_TEMPLATE =
"private_key\n{\n\ttype \"rsa\"\n\trsa_private_key \"%s\"\n\tprivate_key_encrypted 0\n\tpublic_key\n\t{\n\t\ttype \"rsa\"\n\t\trsa_public_key \"%s\"\n\t}\n}\n";
68 static std::unique_ptr<PackFile>
create(
const std::string& path, uint32_t version = 2);
71 [[nodiscard]]
static std::unique_ptr<PackFile>
open(
const std::string& path,
const EntryCallback& callback =
nullptr);
73 static constexpr inline std::string_view
GUID =
"98148F7C8701469CB2D8F8620FD738A3";
75 [[nodiscard]]
constexpr std::string_view
getGUID()
const override {
93 [[nodiscard]] std::optional<std::vector<std::byte>>
readEntry(
const std::string& path_)
const override;
95 bool removeEntry(
const std::string& filename_)
override;
105 [[nodiscard]]
explicit operator std::string()
const override;
113 bool sign(
const std::string& filename_);
116 bool sign(
const std::vector<std::byte>& privateKey,
const std::vector<std::byte>& publicKey);
133 [[nodiscard]]
static std::unique_ptr<PackFile>
openInternal(
const std::string& path,
const EntryCallback& callback =
nullptr);
#define VPKPP_REGISTER_PACKFILE_OPEN(extension, function)
This class represents the metadata that a file has inside a PackFile.
EntryCallbackBase< void > EntryCallback
PackFile(const PackFile &other)=delete
Attribute getSupportedEntryAttributes() const override
Returns a list of supported entry attributes Mostly for GUI programs that show entries and their meta...
static std::unique_ptr< PackFile > create(const std::string &path, uint32_t version=2)
Create a new directory VPK file - should end in "_dir.vpk"! This is not enforced but STRONGLY recomme...
std::size_t removeDirectory(const std::string &dirName_) override
Remove a directory.
void setChunkSize(uint32_t newChunkSize)
Set the VPK chunk size in bytes (size of generated archives when baking)
uint32_t getHeaderLength() const
bool hasCompression() const
bool verifyPackFileSignature() const override
Verify the file signature, returns true on success Will return true if there is no signature ability ...
uint32_t getChunkSize() const
Get the VPK chunk size in bytes (size of generated archives when baking)
std::vector< std::string > verifyEntryChecksums() const override
Verify the checksums of each file, if a file fails the check its path will be added to the vector If ...
uint32_t getVersion() const
Returns 1 for v1, 2 for v2.
uint32_t currentlyFilledChunkSize
bool hasPackFileSignature() const override
Returns true if the file is signed.
bool hasExtendedHeader() const
static bool generateKeyPairFiles(const std::string &name)
Generate keypair files, which can be used to sign a VPK Input is a truncated file path,...
constexpr bool hasEntryChecksums() const override
Returns true if the format has a checksum for each entry.
std::vector< FreedChunk > freedChunks
bool hasPackFileChecksum() const override
Returns true if the entire file has a checksum.
static constexpr std::string_view GUID
bool verifyPackFileChecksum() const override
Verify the checksum of the entire file, returns true on success Will return true if there is no check...
void setVersion(uint32_t version)
Change the version of the VPK. Valid values are 1 and 2.
std::optional< std::vector< std::byte > > readEntry(const std::string &path_) const override
Try to read the entry's data to a bytebuffer.
bool sign(const std::string &filename_)
Sign the VPK with the given private key KeyValues file. (See below comment)
bool removeEntry(const std::string &filename_) override
Remove an entry.
constexpr std::string_view getGUID() const override
Get the GUID corresponding to the pack file type.
std::string getTruncatedFilestem() const override
/home/user/pak01_dir.vpk -> pak01
std::vector< MD5Entry > md5Entries
bool bake(const std::string &outputDir_, BakeOptions options, const EntryCallback &callback) override
If output folder is an empty string, it will overwrite the original.
void addEntryInternal(Entry &entry, const std::string &path, std::vector< std::byte > &buffer, EntryOptions options) override
static std::unique_ptr< PackFile > open(const std::string &path, const EntryCallback &callback=nullptr)
Open a VPK file.
static std::unique_ptr< PackFile > openInternal(const std::string &path, const EntryCallback &callback=nullptr)
constexpr uint32_t VPK_SIGNATURE
constexpr std::string_view VPK_DIR_SUFFIX
constexpr std::string_view VPK_KEYPAIR_PUBLIC_KEY_TEMPLATE
constexpr uint16_t VPK_ENTRY_TERM
constexpr std::string_view VPK_EXTENSION
constexpr std::string_view VPK_KEYPAIR_PRIVATE_KEY_TEMPLATE
constexpr uint32_t VPK_DEFAULT_CHUNK_SIZE
Chunk size in bytes (default is 200mb)
constexpr uint16_t VPK_DIR_INDEX
constexpr uint16_t VPK_MAX_PRELOAD_BYTES
Maximum preload data size in bytes.
uint32_t length
The length in bytes.
std::array< std::byte, 16 > checksum
The CRC32 checksum of this entry.
uint32_t archiveIndex
The archive index of the file.
uint32_t offset
The offset in the archive.