SourcePP
Several modern C++20 libraries for sanely parsing Valve's formats.
Loading...
Searching...
No Matches
ZIP.h
Go to the documentation of this file.
1#pragma once
2
3#include "../PackFile.h"
4
5namespace vpkpp {
6
7constexpr std::string_view BEE_EXTENSION = ".bee_pack";
8constexpr std::string_view BMZ_EXTENSION = ".bmz";
9constexpr std::string_view FPK_EXTENSION = ".fpk";
10constexpr std::string_view PK3_EXTENSION = ".pk3";
11constexpr std::string_view PK4_EXTENSION = ".pk4";
12constexpr std::string_view PKZ_EXTENSION = ".pkz";
13constexpr std::string_view ZIP_EXTENSION = ".zip";
14
15class ZIP : public PackFile {
16public:
17 ~ZIP() override;
18
20 static std::unique_ptr<PackFile> create(const std::string& path);
21
23 [[nodiscard]] static std::unique_ptr<PackFile> open(const std::string& path, const EntryCallback& callback = nullptr);
24
25 static constexpr inline std::string_view GUID = "3F3FDBC4F5D44B1F8A8E3AF5611B561B";
26
27 [[nodiscard]] constexpr std::string_view getGUID() const override {
28 return ZIP::GUID;
29 }
30
31 [[nodiscard]] constexpr bool hasEntryChecksums() const override {
32 return true;
33 }
34
35 [[nodiscard]] std::vector<std::string> verifyEntryChecksums() const override;
36
37 [[nodiscard]] constexpr bool isCaseSensitive() const override {
38 return true;
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]] EntryCompressionType getEntryCompressionType(const std::string& path_) const;
48
49 void setEntryCompressionType(const std::string& path_, EntryCompressionType type);
50
51 [[nodiscard]] int16_t getEntryCompressionStrength(const std::string& path_) const;
52
53 void setEntryCompressionStrength(const std::string& path_, int16_t strength);
54
55protected:
56 explicit ZIP(const std::string& fullFilePath_);
57
58 void addEntryInternal(Entry& entry, const std::string& path, std::vector<std::byte>& buffer, EntryOptions options) override;
59
60 bool bakeTempZip(const std::string& writeZipPath, BakeOptions options, const EntryCallback& callback) const; // NOLINT(*-use-nodiscard)
61
62 bool openZIP(std::string_view path);
63
64 void closeZIP();
65
66 const std::string tempZIPPath;
67
68 void* streamHandle = nullptr;
69 bool streamOpen = false;
70
71 void* zipHandle = nullptr;
72 bool zipOpen = false;
73
74private:
82};
83
84} // namespace vpkpp
#define VPKPP_REGISTER_PACKFILE_OPEN(extension, function)
Definition: PackFile.h:242
This class represents the metadata that a file has inside a PackFile.
Definition: Entry.h:14
EntryCallbackBase< void > EntryCallback
Definition: PackFile.h:30
Definition: ZIP.h:15
void addEntryInternal(Entry &entry, const std::string &path, std::vector< std::byte > &buffer, EntryOptions options) override
Definition: ZIP.cpp:118
Attribute getSupportedEntryAttributes() const override
Returns a list of supported entry attributes Mostly for GUI programs that show entries and their meta...
Definition: ZIP.cpp:146
constexpr bool hasEntryChecksums() const override
Returns true if the format has a checksum for each entry.
Definition: ZIP.h:31
const std::string tempZIPPath
Definition: ZIP.h:66
void setEntryCompressionType(const std::string &path_, EntryCompressionType type)
Definition: ZIP.cpp:159
void setEntryCompressionStrength(const std::string &path_, int16_t strength)
Definition: ZIP.cpp:174
void closeZIP()
Definition: ZIP.cpp:265
void * streamHandle
Definition: ZIP.h:68
static std::unique_ptr< PackFile > open(const std::string &path, const EntryCallback &callback=nullptr)
Open a ZIP file.
Definition: ZIP.cpp:46
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 ...
Definition: ZIP.cpp:87
int16_t getEntryCompressionStrength(const std::string &path_) const
Definition: ZIP.cpp:166
bool streamOpen
Definition: ZIP.h:69
bool openZIP(std::string_view path)
Definition: ZIP.cpp:247
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: ZIP.cpp:125
bool zipOpen
Definition: ZIP.h:72
static constexpr std::string_view GUID
Definition: ZIP.h:25
std::optional< std::vector< std::byte > > readEntry(const std::string &path_) const override
Try to read the entry's data to a bytebuffer.
Definition: ZIP.cpp:91
void * zipHandle
Definition: ZIP.h:71
~ZIP() override
Definition: ZIP.cpp:25
bool bakeTempZip(const std::string &writeZipPath, BakeOptions options, const EntryCallback &callback) const
Definition: ZIP.cpp:181
constexpr bool isCaseSensitive() const override
Does the format support case-sensitive file names?
Definition: ZIP.h:37
constexpr std::string_view getGUID() const override
Get the GUID corresponding to the pack file type.
Definition: ZIP.h:27
static std::unique_ptr< PackFile > create(const std::string &path)
Create a ZIP file.
Definition: ZIP.cpp:29
EntryCompressionType getEntryCompressionType(const std::string &path_) const
Definition: ZIP.cpp:151
Definition: Attribute.h:5
constexpr std::string_view FPK_EXTENSION
Definition: ZIP.h:9
constexpr std::string_view ZIP_EXTENSION
Definition: ZIP.h:13
Attribute
Definition: Attribute.h:7
constexpr std::string_view PKZ_EXTENSION
Definition: ZIP.h:12
constexpr std::string_view BEE_EXTENSION
Definition: ZIP.h:7
constexpr std::string_view PK3_EXTENSION
Definition: ZIP.h:10
EntryCompressionType
Definition: Options.h:7
constexpr std::string_view BMZ_EXTENSION
Definition: ZIP.h:8
constexpr std::string_view PK4_EXTENSION
Definition: ZIP.h:11