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#pragma once
2
4
5#include "../PackFile.h"
6
7namespace vpkpp {
8
9constexpr uint8_t PAK_FILENAME_MAX_SIZE = 56;
11
12constexpr uint8_t PAK_SIN_FILENAME_MAX_SIZE = 120;
14
15constexpr uint8_t PAK_HROT_FILENAME_MAX_SIZE = 120;
17
18constexpr std::string_view PAK_EXTENSION = ".pak";
19constexpr std::string_view SIN_EXTENSION = ".sin";
20
21class PAK : public PackFile {
22public:
23 enum class Type {
24 PAK,
25 SIN,
26 HROT,
27 };
28
30 static std::unique_ptr<PackFile> create(const std::string& path, Type type = Type::PAK);
31
33 [[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);
34
35 static constexpr inline std::string_view GUID = "C282210FE64D46D1AE364D7E8E925542";
36
37 [[nodiscard]] constexpr std::string_view getGUID() const override {
38 return PAK::GUID;
39 }
40
41 [[nodiscard]] std::optional<std::vector<std::byte>> readEntry(const std::string& path_) const override;
42
43 bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override;
44
45 [[nodiscard]] Attribute getSupportedEntryAttributes() const override;
46
47 [[nodiscard]] Type getType() const;
48
49 void setType(Type type_);
50
51protected:
53
54 void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) override;
55
56 [[nodiscard]] uint32_t getSignature() const;
57
58 [[nodiscard]] uint8_t getFilenameLength() const;
59
61
62private:
65};
66
67} // namespace vpkpp
#define VPKPP_REGISTER_PACKFILE_OPEN(extension, function)
Definition: PackFile.h:252
This class represents the metadata that a file has inside a PackFile.
Definition: Entry.h:14
Definition: PAK.h:21
static std::unique_ptr< PackFile > create(const std::string &path, Type type=Type::PAK)
Create a PAK file.
Definition: PAK.cpp:10
static std::unique_ptr< PackFile > open(const std::string &path, const EntryCallback &callback=nullptr)
Open a PAK file.
Definition: PAK.cpp:31
constexpr std::string_view getGUID() const override
Get the GUID corresponding to the pack file type.
Definition: PAK.h:37
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:77
Type
Definition: PAK.h:23
Type getType() const
Definition: PAK.cpp:166
Attribute getSupportedEntryAttributes() const override
Returns a list of supported entry attributes Mostly for GUI programs that show entries and their meta...
Definition: PAK.cpp:161
uint8_t getFilenameLength() const
Definition: PAK.cpp:186
uint32_t getSignature() const
Definition: PAK.cpp:174
Type type
Definition: PAK.h:60
void addEntryInternal(Entry &entry, const std::string &path, std::vector< std::byte > &buffer, EntryOptions options) override
Definition: PAK.cpp:96
void setType(Type type_)
Definition: PAK.cpp:170
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:103
static constexpr std::string_view GUID
Definition: PAK.h:35
EntryCallbackBase< void > EntryCallback
Definition: PackFile.h:37
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:18
Definition: Attribute.h:5
constexpr auto PAK_HROT_SIGNATURE
Definition: PAK.h:16
constexpr auto PAK_SIN_SIGNATURE
Definition: PAK.h:13
constexpr auto PAK_SIGNATURE
Definition: PAK.h:10
Attribute
Definition: Attribute.h:7
constexpr std::string_view SIN_EXTENSION
Definition: PAK.h:19
constexpr uint8_t PAK_SIN_FILENAME_MAX_SIZE
Definition: PAK.h:12
constexpr uint8_t PAK_HROT_FILENAME_MAX_SIZE
Definition: PAK.h:15
constexpr uint8_t PAK_FILENAME_MAX_SIZE
Definition: PAK.h:9
constexpr std::string_view PAK_EXTENSION
Definition: PAK.h:18