SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
PAK.h
Go to the documentation of this file.
1// ReSharper disable CppRedundantQualifier
2
3#pragma once
4
6
7#include "../PackFile.h"
8
9namespace vpkpp {
10
11constexpr uint8_t PAK_FILENAME_MAX_SIZE = 56;
13
14constexpr uint8_t PAK_SIN_FILENAME_MAX_SIZE = 120;
16
17constexpr uint8_t PAK_HROT_FILENAME_MAX_SIZE = 120;
19
20constexpr std::string_view PAK_EXTENSION = ".pak";
21constexpr std::string_view SIN_EXTENSION = ".sin";
22
23class PAK : public PackFile {
24public:
25 enum class Type {
29 };
30
32 static std::unique_ptr<PackFile> create(const std::string& path, Type type = Type::PAK);
33
35 [[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);
36
37 static constexpr std::string_view GUID = "C282210FE64D46D1AE364D7E8E925542";
38
39 [[nodiscard]] constexpr std::string_view getGUID() const override {
40 return PAK::GUID;
41 }
42
43 [[nodiscard]] std::optional<std::vector<std::byte>> readEntry(const std::string& path_) const override;
44
45 bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override;
46
47 [[nodiscard]] Attribute getSupportedEntryAttributes() const override;
48
49 [[nodiscard]] Type getType() const;
50
51 void setType(Type type_);
52
53protected:
55
56 void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) override;
57
58 [[nodiscard]] uint32_t getSignature() const;
59
60 [[nodiscard]] uint8_t getFilenameLength() const;
61
63
64private:
67};
68
69} // namespace vpkpp
#define VPKPP_REGISTER_PACKFILE_OPEN(extension, function)
Definition PackFile.h:255
This class represents the metadata that a file has inside a PackFile.
Definition Entry.h:14
static std::unique_ptr< PackFile > create(const std::string &path, Type type=Type::PAK)
Create a PAK file.
Definition PAK.cpp:12
static std::unique_ptr< PackFile > open(const std::string &path, const EntryCallback &callback=nullptr)
Open a PAK file.
Definition PAK.cpp:33
constexpr std::string_view getGUID() const override
Get the GUID corresponding to the pack file type.
Definition PAK.h:39
std::optional< std::vector< std::byte > > readEntry(const std::string &path_) const override
Try to read the entry's data to a bytebuffer.
Definition PAK.cpp:79
Type getType() const
Definition PAK.cpp:169
Attribute getSupportedEntryAttributes() const override
Returns a list of supported entry attributes Mostly for GUI programs that show entries and their meta...
Definition PAK.cpp:164
uint8_t getFilenameLength() const
Definition PAK.cpp:189
uint32_t getSignature() const
Definition PAK.cpp:177
Type type
Definition PAK.h:62
void addEntryInternal(Entry &entry, const std::string &path, std::vector< std::byte > &buffer, EntryOptions options) override
Definition PAK.cpp:98
void setType(Type type_)
Definition PAK.cpp:173
bool bake(const std::string &outputDir_, BakeOptions options, const EntryCallback &callback) override
If output folder is an empty string, it will overwrite the original.
Definition PAK.cpp:105
PackFile(const PackFile &other)=delete
static constexpr std::string_view GUID
Definition PAK.h:37
EntryCallbackBase< void > EntryCallback
Definition PackFile.h:38
PackFile(const PackFile &other)=delete
consteval uint32_t makeFourCC(const char fourCC[4])
Creates a FourCC identifier from a string of 4 characters.
Definition Binary.h:20
constexpr auto PAK_HROT_SIGNATURE
Definition PAK.h:18
constexpr auto PAK_SIN_SIGNATURE
Definition PAK.h:15
constexpr auto PAK_SIGNATURE
Definition PAK.h:12
Attribute
Definition Attribute.h:7
constexpr std::string_view SIN_EXTENSION
Definition PAK.h:21
constexpr uint8_t PAK_SIN_FILENAME_MAX_SIZE
Definition PAK.h:14
constexpr uint8_t PAK_HROT_FILENAME_MAX_SIZE
Definition PAK.h:17
constexpr uint8_t PAK_FILENAME_MAX_SIZE
Definition PAK.h:11
constexpr std::string_view PAK_EXTENSION
Definition PAK.h:20