From be97344949cb89c134f01c91a5e6e03b3b8c1c79 Mon Sep 17 00:00:00 2001 From: craftablescience Date: Mon, 30 Dec 2024 03:53:19 -0500 Subject: [PATCH] vpkpp: switch to GUID system over type enum, revamp C# bindings, update C options header --- include/vpkpp/Options.h | 6 +- include/vpkpp/PackFile.h | 17 +- include/vpkpp/PackFileType.h | 20 -- include/vpkpp/format/BSP.h | 37 --- include/vpkpp/format/FPX.h | 8 +- include/vpkpp/format/GCF.h | 12 +- include/vpkpp/format/GMA.h | 8 +- include/vpkpp/format/ORE.h | 8 +- include/vpkpp/format/PAK.h | 8 +- include/vpkpp/format/PCK.h | 10 +- include/vpkpp/format/VPK.h | 10 +- include/vpkpp/format/VPK_VTMB.h | 8 +- include/vpkpp/format/WAD3.h | 8 +- include/vpkpp/format/ZIP.h | 12 +- include/vpkpp/vpkpp.h | 1 - lang/c/include/vpkppc/Options.h | 24 +- lang/c/include/vpkppc/PackFile.h | 4 +- lang/c/include/vpkppc/PackFileType.h | 24 -- lang/c/include/vpkppc/format/BSP.h | 6 - lang/c/include/vpkppc/format/FPX.h | 3 + lang/c/include/vpkppc/format/GCF.h | 3 + lang/c/include/vpkppc/format/GMA.h | 3 + lang/c/include/vpkppc/format/ORE.h | 3 + lang/c/include/vpkppc/format/PAK.h | 3 + lang/c/include/vpkppc/format/PCK.h | 3 + lang/c/include/vpkppc/format/VPK.h | 3 + lang/c/include/vpkppc/format/VPK_VTMB.h | 3 + lang/c/include/vpkppc/format/WAD3.h | 3 + lang/c/include/vpkppc/format/ZIP.h | 11 + lang/c/src/vpkppc/Convert.cpp | 12 +- lang/c/src/vpkppc/PackFile.cpp | 6 +- lang/c/src/vpkppc/_vpkppc.cmake | 3 - lang/c/src/vpkppc/format/BSP.cpp | 19 -- lang/c/src/vpkppc/format/FPX.cpp | 8 + lang/c/src/vpkppc/format/GCF.cpp | 8 + lang/c/src/vpkppc/format/GMA.cpp | 8 + lang/c/src/vpkppc/format/ORE.cpp | 8 + lang/c/src/vpkppc/format/PAK.cpp | 8 + lang/c/src/vpkppc/format/PCK.cpp | 8 + lang/c/src/vpkppc/format/VPK.cpp | 20 +- lang/c/src/vpkppc/format/VPK_VTMB.cpp | 8 + lang/c/src/vpkppc/format/WAD3.cpp | 8 + lang/c/src/vpkppc/format/ZIP.cpp | 53 ++++ lang/csharp/src/sourcepp/Buffer.cs.in | 22 +- lang/csharp/src/sourcepp/String.cs.in | 32 +- lang/csharp/src/vpkpp/Entry.cs | 59 ++-- lang/csharp/src/vpkpp/Format/BSP.cs | 40 --- lang/csharp/src/vpkpp/Format/FPX.cs | 34 +- lang/csharp/src/vpkpp/Format/GCF.cs | 30 +- lang/csharp/src/vpkpp/Format/GMA.cs | 30 +- lang/csharp/src/vpkpp/Format/ORE.cs | 34 +- lang/csharp/src/vpkpp/Format/PAK.cs | 34 +- lang/csharp/src/vpkpp/Format/PCK.cs | 40 ++- lang/csharp/src/vpkpp/Format/VPK.cs | 72 +++-- lang/csharp/src/vpkpp/Format/VPK_VTMB.cs | 34 +- lang/csharp/src/vpkpp/Format/WAD3.cs | 34 +- lang/csharp/src/vpkpp/Format/ZIP.cs | 80 ++++- lang/csharp/src/vpkpp/Options.cs | 29 +- lang/csharp/src/vpkpp/PackFile.cs | 297 +++++++++--------- lang/csharp/test/vpkpp.test/PackFileTest.cs | 122 ++++--- src/vpkpp/PackFile.cpp | 5 - src/vpkpp/_vpkpp.cmake | 3 - src/vpkpp/format/BSP.cpp | 128 -------- src/vpkpp/format/FPX.cpp | 5 - src/vpkpp/format/GCF.cpp | 5 - src/vpkpp/format/GMA.cpp | 5 - src/vpkpp/format/ORE.cpp | 5 - src/vpkpp/format/PAK.cpp | 5 - src/vpkpp/format/PCK.cpp | 5 - src/vpkpp/format/VPK.cpp | 9 +- src/vpkpp/format/VPK_VTMB.cpp | 5 - src/vpkpp/format/WAD3.cpp | 5 - src/vpkpp/format/ZIP.cpp | 10 +- .../format/example/ExamplePackFileImpl.cpp | 6 - .../format/example/ExamplePackFileImpl.h | 10 +- 75 files changed, 924 insertions(+), 756 deletions(-) delete mode 100644 include/vpkpp/PackFileType.h delete mode 100644 include/vpkpp/format/BSP.h delete mode 100644 lang/c/include/vpkppc/PackFileType.h delete mode 100644 lang/c/include/vpkppc/format/BSP.h delete mode 100644 lang/c/src/vpkppc/format/BSP.cpp delete mode 100644 lang/csharp/src/vpkpp/Format/BSP.cs delete mode 100644 src/vpkpp/format/BSP.cpp diff --git a/include/vpkpp/Options.h b/include/vpkpp/Options.h index 4102057b7..99a4c09d9 100644 --- a/include/vpkpp/Options.h +++ b/include/vpkpp/Options.h @@ -37,11 +37,11 @@ struct EntryOptions { /// BSP/ZIP - The compression strength int16_t zip_compressionStrength = 5; + /// VPK - The amount in bytes of the file to preload. Maximum is controlled by VPK_MAX_PRELOAD_BYTES (format/VPK.h) + uint16_t vpk_preloadBytes = 0; + /// VPK - Save this entry to the directory VPK bool vpk_saveToDirectory = false; - - /// VPK - The amount in bytes of the file to preload. Maximum is controlled by VPK_MAX_PRELOAD_BYTES (format/VPK.h) - uint32_t vpk_preloadBytes = 0; }; } // namespace vpkpp diff --git a/include/vpkpp/PackFile.h b/include/vpkpp/PackFile.h index ccd9a59e9..1a4904b98 100644 --- a/include/vpkpp/PackFile.h +++ b/include/vpkpp/PackFile.h @@ -14,7 +14,6 @@ #include "Attribute.h" #include "Entry.h" #include "Options.h" -#include "PackFileType.h" namespace vpkpp { @@ -50,8 +49,15 @@ class PackFile { /// Returns a sorted list of supported extensions for opening, e.g. {".bsp", ".vpk"} [[nodiscard]] static std::vector getOpenableExtensions(); - /// Get the file type of the pack file - [[nodiscard]] PackFileType getType() const; + /// Get the GUID corresponding to the pack file type + [[nodiscard]] virtual constexpr std::string_view getGUID() const = 0; + + /// Check if the pack file is an instance of the given pack file class + template + requires requires (const T&) {{T::GUID} -> std::convertible_to;} + [[nodiscard]] bool isInstanceOf() const { + return this->getGUID() == T::GUID; + } /// Returns true if the format has a checksum for each entry [[nodiscard]] virtual constexpr bool hasEntryChecksums() const { @@ -77,7 +83,7 @@ class PackFile { [[nodiscard]] virtual bool verifyPackFileSignature() const; /// Does the format support case-sensitive file names? - [[nodiscard]] virtual constexpr bool isCaseSensitive() const noexcept { + [[nodiscard]] virtual constexpr bool isCaseSensitive() const { return false; } @@ -211,9 +217,6 @@ class PackFile { static const OpenFactoryFunction& registerOpenExtensionForTypeFactory(std::string_view extension, const OpenFactoryFunction& factory); std::string fullFilePath; - - PackFileType type = PackFileType::UNKNOWN; - EntryTrie entries; EntryTrie unbakedEntries; }; diff --git a/include/vpkpp/PackFileType.h b/include/vpkpp/PackFileType.h deleted file mode 100644 index e54bee9a3..000000000 --- a/include/vpkpp/PackFileType.h +++ /dev/null @@ -1,20 +0,0 @@ -#pragma once - -namespace vpkpp { - -enum class PackFileType { - UNKNOWN, - BSP, - FPX, - GCF, - GMA, - ORE, - PAK, - PCK, - VPK, - VPK_VTMB, - WAD3, - ZIP, -}; - -} // namespace vpkpp diff --git a/include/vpkpp/format/BSP.h b/include/vpkpp/format/BSP.h deleted file mode 100644 index d4a83e158..000000000 --- a/include/vpkpp/format/BSP.h +++ /dev/null @@ -1,37 +0,0 @@ -#pragma once - -#include - -#include "ZIP.h" - -namespace vpkpp { - -constexpr std::string_view BSP_EXTENSION = ".bsp"; - -class BSP : public ZIP { -public: - ~BSP() override; - - /// Open a BSP file - [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); - - [[nodiscard]] constexpr bool isCaseSensitive() const noexcept override { - return false; - } - - bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override; - - [[nodiscard]] explicit operator std::string() const override; - -protected: - explicit BSP(const std::string& fullFilePath_); - - const std::string tempPakLumpPath; - uint32_t version{}; - uint32_t mapRevision{}; - -private: - VPKPP_REGISTER_PACKFILE_OPEN(BSP_EXTENSION, &BSP::open); -}; - -} // namespace vpkpp diff --git a/include/vpkpp/format/FPX.h b/include/vpkpp/format/FPX.h index 665bbff4b..8bdff6cf5 100644 --- a/include/vpkpp/format/FPX.h +++ b/include/vpkpp/format/FPX.h @@ -16,8 +16,14 @@ class FPX : public VPK { /// Open an FPX file [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); + static constexpr inline std::string_view GUID = "57D4C78A6198489C81D715D42DD21D2F"; + + [[nodiscard]] constexpr std::string_view getGUID() const override { + return FPX::GUID; + } + protected: - explicit FPX(const std::string& fullFilePath_); + using VPK::VPK; [[nodiscard]] static std::unique_ptr openInternal(const std::string& path, const EntryCallback& callback = nullptr); diff --git a/include/vpkpp/format/GCF.h b/include/vpkpp/format/GCF.h index 43d0b58a8..297e833e1 100644 --- a/include/vpkpp/format/GCF.h +++ b/include/vpkpp/format/GCF.h @@ -112,16 +112,18 @@ class GCF : public PackFileReadOnly { public: [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); + static constexpr inline std::string_view GUID = "0C088488F666451E9361297528F2446D"; + + [[nodiscard]] constexpr std::string_view getGUID() const override { + return GCF::GUID; + } + [[nodiscard]] constexpr bool hasEntryChecksums() const override { return true; } [[nodiscard]] std::vector verifyEntryChecksums() const override; - [[nodiscard]] constexpr bool isCaseSensitive() const noexcept override { - return true; - } - [[nodiscard]] std::optional> readEntry(const std::string& path_) const override; [[nodiscard]] Attribute getSupportedEntryAttributes() const override; @@ -129,7 +131,7 @@ class GCF : public PackFileReadOnly { [[nodiscard]] explicit operator std::string() const override; protected: - explicit GCF(const std::string& fullFilePath_); + using PackFileReadOnly::PackFileReadOnly; Header header{}; BlockHeader blockheader{}; diff --git a/include/vpkpp/format/GMA.h b/include/vpkpp/format/GMA.h index d6b29998a..c9af89e54 100644 --- a/include/vpkpp/format/GMA.h +++ b/include/vpkpp/format/GMA.h @@ -27,6 +27,12 @@ class GMA : public PackFile { /// Open a GMA file [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); + static constexpr inline std::string_view GUID = "49191CA83B7B4EBBA86D0EA364AAC457"; + + [[nodiscard]] constexpr std::string_view getGUID() const override { + return GMA::GUID; + } + [[nodiscard]] constexpr bool hasEntryChecksums() const override { return true; } @@ -46,7 +52,7 @@ class GMA : public PackFile { [[nodiscard]] explicit operator std::string() const override; protected: - explicit GMA(const std::string& fullFilePath_); + using PackFile::PackFile; void addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions options) override; diff --git a/include/vpkpp/format/ORE.h b/include/vpkpp/format/ORE.h index 91642efc8..daf140132 100644 --- a/include/vpkpp/format/ORE.h +++ b/include/vpkpp/format/ORE.h @@ -16,12 +16,18 @@ class ORE : public PackFileReadOnly { /// Open an ORE file [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); + static constexpr inline std::string_view GUID = "E7E541C05CFE4934B1CDA931EF2E1D99"; + + [[nodiscard]] constexpr std::string_view getGUID() const override { + return ORE::GUID; + } + [[nodiscard]] std::optional> readEntry(const std::string& path_) const override; [[nodiscard]] Attribute getSupportedEntryAttributes() const override; protected: - explicit ORE(const std::string& fullFilePath_); + using PackFileReadOnly::PackFileReadOnly; private: VPKPP_REGISTER_PACKFILE_OPEN(ORE_EXTENSION, &ORE::open); diff --git a/include/vpkpp/format/PAK.h b/include/vpkpp/format/PAK.h index 91034da20..01cb191a5 100644 --- a/include/vpkpp/format/PAK.h +++ b/include/vpkpp/format/PAK.h @@ -18,6 +18,12 @@ class PAK : public PackFile { /// Open a PAK file [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); + static constexpr inline std::string_view GUID = "C282210FE64D46D1AE364D7E8E925542"; + + [[nodiscard]] constexpr std::string_view getGUID() const override { + return PAK::GUID; + } + [[nodiscard]] std::optional> readEntry(const std::string& path_) const override; bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override; @@ -25,7 +31,7 @@ class PAK : public PackFile { [[nodiscard]] Attribute getSupportedEntryAttributes() const override; protected: - explicit PAK(const std::string& fullFilePath_); + using PackFile::PackFile; void addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions options) override; diff --git a/include/vpkpp/format/PCK.h b/include/vpkpp/format/PCK.h index 68712d624..15c7df067 100644 --- a/include/vpkpp/format/PCK.h +++ b/include/vpkpp/format/PCK.h @@ -39,7 +39,13 @@ class PCK : public PackFile { /// Open a PCK file (potentially embedded in an executable) [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); - [[nodiscard]] constexpr bool isCaseSensitive() const noexcept override { + static constexpr inline std::string_view GUID = "28F4A6FF40EB46E38D47EEC6EFB47C4F"; + + [[nodiscard]] constexpr std::string_view getGUID() const override { + return PCK::GUID; + } + + [[nodiscard]] constexpr bool isCaseSensitive() const override { return true; } @@ -62,7 +68,7 @@ class PCK : public PackFile { void setGodotVersion(uint32_t major, uint32_t minor = 0, uint32_t patch = 0); protected: - explicit PCK(const std::string& fullFilePath_); + using PackFile::PackFile; void addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions options) override; diff --git a/include/vpkpp/format/VPK.h b/include/vpkpp/format/VPK.h index ea7a0d047..5c0994565 100644 --- a/include/vpkpp/format/VPK.h +++ b/include/vpkpp/format/VPK.h @@ -16,7 +16,7 @@ constexpr std::string_view VPK_KEYPAIR_PUBLIC_KEY_TEMPLATE = "public_key\n{\n\tt constexpr 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"; /// Maximum preload data size in bytes -constexpr uint32_t VPK_MAX_PRELOAD_BYTES = 1024; +constexpr uint16_t VPK_MAX_PRELOAD_BYTES = 1024; /// Chunk size in bytes (default is 200mb) constexpr uint32_t VPK_DEFAULT_CHUNK_SIZE = 200 * 1024 * 1024; @@ -70,6 +70,12 @@ class VPK : public PackFile { /// Open a VPK file [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); + static constexpr inline std::string_view GUID = "98148F7C8701469CB2D8F8620FD738A3"; + + [[nodiscard]] constexpr std::string_view getGUID() const override { + return VPK::GUID; + } + [[nodiscard]] constexpr bool hasEntryChecksums() const override { return true; } @@ -122,7 +128,7 @@ class VPK : public PackFile { void setChunkSize(uint32_t newChunkSize); protected: - explicit VPK(const std::string& fullFilePath_); + using PackFile::PackFile; [[nodiscard]] static std::unique_ptr openInternal(const std::string& path, const EntryCallback& callback = nullptr); diff --git a/include/vpkpp/format/VPK_VTMB.h b/include/vpkpp/format/VPK_VTMB.h index e83fe345e..ecc920990 100644 --- a/include/vpkpp/format/VPK_VTMB.h +++ b/include/vpkpp/format/VPK_VTMB.h @@ -14,6 +14,12 @@ class VPK_VTMB : public PackFile { /// Open Vampire: The Masquerade - Bloodlines VPK files [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); + static constexpr inline std::string_view GUID = "5942653FBD0F4A2D9EF33CDDA668C396"; + + [[nodiscard]] constexpr std::string_view getGUID() const override { + return VPK_VTMB::GUID; + } + [[nodiscard]] std::optional> readEntry(const std::string& path_) const override; bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override; @@ -23,7 +29,7 @@ class VPK_VTMB : public PackFile { [[nodiscard]] Attribute getSupportedEntryAttributes() const override; protected: - explicit VPK_VTMB(const std::string& fullFilePath_); + using PackFile::PackFile; void openNumbered(uint32_t archiveIndex, const std::string& path, const EntryCallback& callback); diff --git a/include/vpkpp/format/WAD3.h b/include/vpkpp/format/WAD3.h index 41b08ed7c..6555eb03a 100644 --- a/include/vpkpp/format/WAD3.h +++ b/include/vpkpp/format/WAD3.h @@ -21,6 +21,12 @@ class WAD3 : public PackFile { /// Open a WAD3 file [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); + static constexpr inline std::string_view GUID = "1B4D626A278F47B9B2D4ADB244218B03"; + + [[nodiscard]] constexpr std::string_view getGUID() const override { + return WAD3::GUID; + } + [[nodiscard]] std::optional> readEntry(const std::string& path_) const override; bool bake(const std::string& outputDir_ /*= ""*/, BakeOptions options /*= {}*/, const EntryCallback& callback /*= nullptr*/) override; @@ -28,7 +34,7 @@ class WAD3 : public PackFile { [[nodiscard]] Attribute getSupportedEntryAttributes() const override; protected: - explicit WAD3(const std::string& fullFilePath_); + using PackFile::PackFile; void addEntryInternal(Entry& entry, const std::string& path, std::vector& buffer, EntryOptions options) override; diff --git a/include/vpkpp/format/ZIP.h b/include/vpkpp/format/ZIP.h index a0d7249d4..40e41173e 100644 --- a/include/vpkpp/format/ZIP.h +++ b/include/vpkpp/format/ZIP.h @@ -19,13 +19,19 @@ class ZIP : public PackFile { /// Open a ZIP file [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); + static constexpr inline std::string_view GUID = "3F3FDBC4F5D44B1F8A8E3AF5611B561B"; + + [[nodiscard]] constexpr std::string_view getGUID() const override { + return ZIP::GUID; + } + [[nodiscard]] constexpr bool hasEntryChecksums() const override { return true; } [[nodiscard]] std::vector verifyEntryChecksums() const override; - [[nodiscard]] constexpr bool isCaseSensitive() const noexcept override { + [[nodiscard]] constexpr bool isCaseSensitive() const override { return true; } @@ -39,9 +45,9 @@ class ZIP : public PackFile { void setEntryCompressionType(const std::string& path_, EntryCompressionType type); - [[nodiscard]] uint16_t getEntryCompressionStrength(const std::string& path_) const; + [[nodiscard]] int16_t getEntryCompressionStrength(const std::string& path_) const; - void setEntryCompressionStrength(const std::string& path_, uint16_t strength); + void setEntryCompressionStrength(const std::string& path_, int16_t strength); protected: explicit ZIP(const std::string& fullFilePath_); diff --git a/include/vpkpp/vpkpp.h b/include/vpkpp/vpkpp.h index 2c92d2f99..220a32d66 100644 --- a/include/vpkpp/vpkpp.h +++ b/include/vpkpp/vpkpp.h @@ -20,4 +20,3 @@ #include "Entry.h" #include "Options.h" #include "PackFile.h" -#include "PackFileType.h" diff --git a/lang/c/include/vpkppc/Options.h b/lang/c/include/vpkppc/Options.h index 5d96c587c..1571273a9 100644 --- a/lang/c/include/vpkppc/Options.h +++ b/lang/c/include/vpkppc/Options.h @@ -6,14 +6,28 @@ extern "C" { #endif +typedef enum { + ENTRY_COMPRESSION_TYPE_NO_OVERRIDE = -1, + ENTRY_COMPRESSION_TYPE_NO_COMPRESS = 0, + ENTRY_COMPRESSION_TYPE_DEFLATE = 8, + ENTRY_COMPRESSION_TYPE_BZIP2 = 12, + ENTRY_COMPRESSION_TYPE_LZMA = 14, + ENTRY_COMPRESSION_TYPE_ZSTD = 93, + ENTRY_COMPRESSION_TYPE_XZ = 95, +} vpkpp_entry_compression_type_e; + typedef struct { - int32_t gma_writeCRCs; - int32_t vpk_generateMD5Entries; -} vpkpp_bake_options_t; + int16_t zip_compressionTypeOverride; + int16_t zip_compressionStrength; + uint8_t gma_writeCRCs; + uint8_t vpk_generateMD5Entries; +} vpkpp_bake_options_t; typedef struct { - int32_t vpk_saveToDirectory; - uint32_t vpk_preloadBytes; + int16_t zip_compressionType; + int16_t zip_compressionStrength; + uint16_t vpk_preloadBytes; + uint8_t vpk_saveToDirectory; } vpkpp_entry_options_t; #ifdef __cplusplus diff --git a/lang/c/include/vpkppc/PackFile.h b/lang/c/include/vpkppc/PackFile.h index 7f92ab3aa..291c90340 100644 --- a/lang/c/include/vpkppc/PackFile.h +++ b/lang/c/include/vpkppc/PackFile.h @@ -6,7 +6,6 @@ #include "Attribute.h" #include "Entry.h" #include "Options.h" -#include "PackFileType.h" #ifdef __cplusplus extern "C" { @@ -30,7 +29,8 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_open(const char* path, vpkpp_entry_c // REQUIRES MANUAL FREE: sourcepp_string_array_free SOURCEPP_API sourcepp_string_array_t vpkpp_get_openable_extensions(); -SOURCEPP_API vpkpp_pack_file_type_e vpkpp_get_type(vpkpp_pack_file_handle_t handle); +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_get_guid(vpkpp_pack_file_handle_t handle); SOURCEPP_API int vpkpp_has_entry_checksums(vpkpp_pack_file_handle_t handle); diff --git a/lang/c/include/vpkppc/PackFileType.h b/lang/c/include/vpkppc/PackFileType.h deleted file mode 100644 index 16415dc56..000000000 --- a/lang/c/include/vpkppc/PackFileType.h +++ /dev/null @@ -1,24 +0,0 @@ -#pragma once - -#ifdef __cplusplus -extern "C" { -#endif - -typedef enum { - VPKPP_PACK_FILE_TYPE_UNKNOWN, - VPKPP_PACK_FILE_TYPE_BSP, - VPKPP_PACK_FILE_TYPE_FPX, - VPKPP_PACK_FILE_TYPE_GCF, - VPKPP_PACK_FILE_TYPE_GMA, - VPKPP_PACK_FILE_TYPE_ORE, - VPKPP_PACK_FILE_TYPE_PAK, - VPKPP_PACK_FILE_TYPE_PCK, - VPKPP_PACK_FILE_TYPE_VPK, - VPKPP_PACK_FILE_TYPE_VPK_VTMB, - VPKPP_PACK_FILE_TYPE_WAD3, - VPKPP_PACK_FILE_TYPE_ZIP, -} vpkpp_pack_file_type_e; - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/lang/c/include/vpkppc/format/BSP.h b/lang/c/include/vpkppc/format/BSP.h deleted file mode 100644 index 266584486..000000000 --- a/lang/c/include/vpkppc/format/BSP.h +++ /dev/null @@ -1,6 +0,0 @@ -#pragma once - -#include "../PackFile.h" - -// REQUIRES MANUAL FREE: vpkpp_close -SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_bsp_open(const char* path, vpkpp_entry_callback_t callback /*= NULL*/); diff --git a/lang/c/include/vpkppc/format/FPX.h b/lang/c/include/vpkppc/format/FPX.h index 418468921..2de30c6be 100644 --- a/lang/c/include/vpkppc/format/FPX.h +++ b/lang/c/include/vpkppc/format/FPX.h @@ -7,3 +7,6 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_fpx_create(const char* path); // REQUIRES MANUAL FREE: vpkpp_close SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_fpx_open(const char* path, vpkpp_entry_callback_t callback); + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_fpx_guid(vpkpp_pack_file_handle_t handle); diff --git a/lang/c/include/vpkppc/format/GCF.h b/lang/c/include/vpkppc/format/GCF.h index 3704b8c09..ea3de3dd9 100644 --- a/lang/c/include/vpkppc/format/GCF.h +++ b/lang/c/include/vpkppc/format/GCF.h @@ -4,3 +4,6 @@ // REQUIRES MANUAL FREE: vpkpp_close SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_gcf_open(const char* path, vpkpp_entry_callback_t callback); + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_gcf_guid(vpkpp_pack_file_handle_t handle); diff --git a/lang/c/include/vpkppc/format/GMA.h b/lang/c/include/vpkppc/format/GMA.h index fbf7bb576..e8d1759d5 100644 --- a/lang/c/include/vpkppc/format/GMA.h +++ b/lang/c/include/vpkppc/format/GMA.h @@ -4,3 +4,6 @@ // REQUIRES MANUAL FREE: vpkpp_close SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_gma_open(const char* path, vpkpp_entry_callback_t callback); + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_gma_guid(vpkpp_pack_file_handle_t handle); diff --git a/lang/c/include/vpkppc/format/ORE.h b/lang/c/include/vpkppc/format/ORE.h index a7bc2db35..101629917 100644 --- a/lang/c/include/vpkppc/format/ORE.h +++ b/lang/c/include/vpkppc/format/ORE.h @@ -7,3 +7,6 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_ore_create(const char* path); // REQUIRES MANUAL FREE: vpkpp_close SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_ore_open(const char* path, vpkpp_entry_callback_t callback); + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_ore_guid(vpkpp_pack_file_handle_t handle); diff --git a/lang/c/include/vpkppc/format/PAK.h b/lang/c/include/vpkppc/format/PAK.h index 62a9a34eb..f9fd8f72c 100644 --- a/lang/c/include/vpkppc/format/PAK.h +++ b/lang/c/include/vpkppc/format/PAK.h @@ -7,3 +7,6 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_pak_create(const char* path); // REQUIRES MANUAL FREE: vpkpp_close SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_pak_open(const char* path, vpkpp_entry_callback_t callback); + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_pak_guid(vpkpp_pack_file_handle_t handle); diff --git a/lang/c/include/vpkppc/format/PCK.h b/lang/c/include/vpkppc/format/PCK.h index 05259951c..e41cd0fe9 100644 --- a/lang/c/include/vpkppc/format/PCK.h +++ b/lang/c/include/vpkppc/format/PCK.h @@ -10,3 +10,6 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_pck_create_with_options(const char* // REQUIRES MANUAL FREE: vpkpp_close SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_pck_open(const char* path, vpkpp_entry_callback_t callback); + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_pck_guid(vpkpp_pack_file_handle_t handle); diff --git a/lang/c/include/vpkppc/format/VPK.h b/lang/c/include/vpkppc/format/VPK.h index acacb32ef..b347b2ffa 100644 --- a/lang/c/include/vpkppc/format/VPK.h +++ b/lang/c/include/vpkppc/format/VPK.h @@ -11,6 +11,9 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_vpk_create_with_options(const char* // REQUIRES MANUAL FREE: vpkpp_close SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_vpk_open(const char* path, vpkpp_entry_callback_t callback); +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_vpk_guid(vpkpp_pack_file_handle_t handle); + SOURCEPP_API bool vpkpp_vpk_generate_keypair_files(const char* path); SOURCEPP_API bool vpkpp_vpk_sign_from_file(vpkpp_pack_file_handle_t handle, const char* filename); diff --git a/lang/c/include/vpkppc/format/VPK_VTMB.h b/lang/c/include/vpkppc/format/VPK_VTMB.h index e89028970..852e05ffb 100644 --- a/lang/c/include/vpkppc/format/VPK_VTMB.h +++ b/lang/c/include/vpkppc/format/VPK_VTMB.h @@ -7,3 +7,6 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_vpk_vtmb_create(const char* path); // REQUIRES MANUAL FREE: vpkpp_close SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_vpk_vtmb_open(const char* path, vpkpp_entry_callback_t callback); + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_vpk_vtmb_guid(vpkpp_pack_file_handle_t handle); diff --git a/lang/c/include/vpkppc/format/WAD3.h b/lang/c/include/vpkppc/format/WAD3.h index 8747cf329..1dff4d676 100644 --- a/lang/c/include/vpkppc/format/WAD3.h +++ b/lang/c/include/vpkppc/format/WAD3.h @@ -7,3 +7,6 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_wad3_create(const char* path); // REQUIRES MANUAL FREE: vpkpp_close SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_wad3_open(const char* path, vpkpp_entry_callback_t callback); + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_wad3_guid(vpkpp_pack_file_handle_t handle); diff --git a/lang/c/include/vpkppc/format/ZIP.h b/lang/c/include/vpkppc/format/ZIP.h index 0b6e5beff..90ac7826b 100644 --- a/lang/c/include/vpkppc/format/ZIP.h +++ b/lang/c/include/vpkppc/format/ZIP.h @@ -7,3 +7,14 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_zip_create(const char* path); // REQUIRES MANUAL FREE: vpkpp_close SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_zip_open(const char* path, vpkpp_entry_callback_t callback); + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_zip_guid(vpkpp_pack_file_handle_t handle); + +SOURCEPP_API vpkpp_entry_compression_type_e vpkpp_zip_get_entry_compression_type(vpkpp_pack_file_handle_t handle, const char* path); + +SOURCEPP_API void vpkpp_zip_set_entry_compression_type(vpkpp_pack_file_handle_t handle, const char* path, vpkpp_entry_compression_type_e type); + +SOURCEPP_API int16_t vpkpp_zip_get_entry_compression_strength(vpkpp_pack_file_handle_t handle, const char* path); + +SOURCEPP_API void vpkpp_zip_set_entry_compression_strength(vpkpp_pack_file_handle_t handle, const char* path, int16_t strength); diff --git a/lang/c/src/vpkppc/Convert.cpp b/lang/c/src/vpkppc/Convert.cpp index c04b879b9..92b95fc64 100644 --- a/lang/c/src/vpkppc/Convert.cpp +++ b/lang/c/src/vpkppc/Convert.cpp @@ -14,6 +14,8 @@ Entry* Convert::entry(vpkpp_entry_handle_t handle) { BakeOptions Convert::optionsFromC(vpkpp_bake_options_t options) { return { + .zip_compressionTypeOverride = static_cast(options.zip_compressionTypeOverride), + .zip_compressionStrength = options.zip_compressionStrength, .gma_writeCRCs = static_cast(options.gma_writeCRCs), .vpk_generateMD5Entries = static_cast(options.vpk_generateMD5Entries), }; @@ -21,13 +23,17 @@ BakeOptions Convert::optionsFromC(vpkpp_bake_options_t options) { EntryOptions Convert::optionsFromC(vpkpp_entry_options_t options) { return { - .vpk_saveToDirectory = static_cast(options.vpk_saveToDirectory), + .zip_compressionType = static_cast(options.zip_compressionType), + .zip_compressionStrength = options.zip_compressionStrength, .vpk_preloadBytes = options.vpk_preloadBytes, + .vpk_saveToDirectory = static_cast(options.vpk_saveToDirectory), }; } vpkpp_bake_options_t Convert::optionsToC(BakeOptions options) { return { + .zip_compressionTypeOverride = static_cast(options.zip_compressionTypeOverride), + .zip_compressionStrength = options.zip_compressionStrength, .gma_writeCRCs = options.gma_writeCRCs, .vpk_generateMD5Entries = options.vpk_generateMD5Entries, }; @@ -35,7 +41,9 @@ vpkpp_bake_options_t Convert::optionsToC(BakeOptions options) { vpkpp_entry_options_t Convert::optionsToC(EntryOptions options) { return { - .vpk_saveToDirectory = options.vpk_saveToDirectory, + .zip_compressionType = static_cast(options.zip_compressionType), + .zip_compressionStrength = options.zip_compressionStrength, .vpk_preloadBytes = options.vpk_preloadBytes, + .vpk_saveToDirectory = options.vpk_saveToDirectory, }; } diff --git a/lang/c/src/vpkppc/PackFile.cpp b/lang/c/src/vpkppc/PackFile.cpp index ad9d0647c..1466f1266 100644 --- a/lang/c/src/vpkppc/PackFile.cpp +++ b/lang/c/src/vpkppc/PackFile.cpp @@ -28,10 +28,10 @@ SOURCEPP_API sourcepp_string_array_t vpkpp_get_openable_extensions() { return Convert::toStringArray(PackFile::getOpenableExtensions()); } -SOURCEPP_API vpkpp_pack_file_type_e vpkpp_get_type(vpkpp_pack_file_handle_t handle) { - SOURCEPP_EARLY_RETURN_VAL(handle, VPKPP_PACK_FILE_TYPE_UNKNOWN); +SOURCEPP_API sourcepp_string_t vpkpp_get_guid(vpkpp_pack_file_handle_t handle) { + SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); - return static_cast(Convert::packFile(handle)->getType()); + return Convert::toString(Convert::packFile(handle)->getGUID()); } SOURCEPP_API int vpkpp_has_entry_checksums(vpkpp_pack_file_handle_t handle) { diff --git a/lang/c/src/vpkppc/_vpkppc.cmake b/lang/c/src/vpkppc/_vpkppc.cmake index 73ae0a68b..c3e788947 100644 --- a/lang/c/src/vpkppc/_vpkppc.cmake +++ b/lang/c/src/vpkppc/_vpkppc.cmake @@ -1,6 +1,5 @@ add_pretty_parser(vpkpp C PRECOMPILED_HEADERS - "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/BSP.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/FPX.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/GCF.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/format/GMA.h" @@ -15,11 +14,9 @@ add_pretty_parser(vpkpp C "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/Entry.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/Options.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/PackFile.h" - "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/PackFileType.h" "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/vpkpp.h" SOURCES "${CMAKE_CURRENT_SOURCE_DIR}/lang/c/include/vpkppc/Convert.hpp" - "${CMAKE_CURRENT_LIST_DIR}/format/BSP.cpp" "${CMAKE_CURRENT_LIST_DIR}/format/FPX.cpp" "${CMAKE_CURRENT_LIST_DIR}/format/GCF.cpp" "${CMAKE_CURRENT_LIST_DIR}/format/GMA.cpp" diff --git a/lang/c/src/vpkppc/format/BSP.cpp b/lang/c/src/vpkppc/format/BSP.cpp deleted file mode 100644 index 28e1eceff..000000000 --- a/lang/c/src/vpkppc/format/BSP.cpp +++ /dev/null @@ -1,19 +0,0 @@ -#include - -#include - -#include - -using namespace vpkpp; - -SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_bsp_open(const char* path, vpkpp_entry_callback_t callback) { - SOURCEPP_EARLY_RETURN_VAL(path, nullptr); - - auto packFile = BSP::open(path, callback ? [callback](const std::string& path, const Entry& entry) { - callback(path.c_str(), const_cast(&entry)); - } : static_cast(nullptr)); - if (!packFile) { - return nullptr; - } - return packFile.release(); -} diff --git a/lang/c/src/vpkppc/format/FPX.cpp b/lang/c/src/vpkppc/format/FPX.cpp index fd3566c98..93bb3834c 100644 --- a/lang/c/src/vpkppc/format/FPX.cpp +++ b/lang/c/src/vpkppc/format/FPX.cpp @@ -2,6 +2,7 @@ #include +#include #include using namespace vpkpp; @@ -27,3 +28,10 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_fpx_open(const char* path, vpkpp_ent } return packFile.release(); } + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_fpx_guid(vpkpp_pack_file_handle_t handle) { + SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); + + return Convert::toString(FPX::GUID); +} diff --git a/lang/c/src/vpkppc/format/GCF.cpp b/lang/c/src/vpkppc/format/GCF.cpp index 7e88956a0..2b6eca98a 100644 --- a/lang/c/src/vpkppc/format/GCF.cpp +++ b/lang/c/src/vpkppc/format/GCF.cpp @@ -2,6 +2,7 @@ #include +#include #include using namespace vpkpp; @@ -17,3 +18,10 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_gcf_open(const char* path, vpkpp_ent } return packFile.release(); } + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_gcf_guid(vpkpp_pack_file_handle_t handle) { + SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); + + return Convert::toString(GCF::GUID); +} diff --git a/lang/c/src/vpkppc/format/GMA.cpp b/lang/c/src/vpkppc/format/GMA.cpp index 49dcb40d1..bf6bade8d 100644 --- a/lang/c/src/vpkppc/format/GMA.cpp +++ b/lang/c/src/vpkppc/format/GMA.cpp @@ -2,6 +2,7 @@ #include +#include #include using namespace vpkpp; @@ -17,3 +18,10 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_gma_open(const char* path, vpkpp_ent } return packFile.release(); } + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_gma_guid(vpkpp_pack_file_handle_t handle) { + SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); + + return Convert::toString(GMA::GUID); +} diff --git a/lang/c/src/vpkppc/format/ORE.cpp b/lang/c/src/vpkppc/format/ORE.cpp index 2c8f37333..57865b8a0 100644 --- a/lang/c/src/vpkppc/format/ORE.cpp +++ b/lang/c/src/vpkppc/format/ORE.cpp @@ -2,6 +2,7 @@ #include +#include #include using namespace vpkpp; @@ -27,3 +28,10 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_ore_open(const char* path, vpkpp_ent } return packFile.release(); } + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_ore_guid(vpkpp_pack_file_handle_t handle) { + SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); + + return Convert::toString(ORE::GUID); +} diff --git a/lang/c/src/vpkppc/format/PAK.cpp b/lang/c/src/vpkppc/format/PAK.cpp index b593a9b50..2898cede8 100644 --- a/lang/c/src/vpkppc/format/PAK.cpp +++ b/lang/c/src/vpkppc/format/PAK.cpp @@ -2,6 +2,7 @@ #include +#include #include using namespace vpkpp; @@ -27,3 +28,10 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_pak_open(const char* path, vpkpp_ent } return packFile.release(); } + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_pak_guid(vpkpp_pack_file_handle_t handle) { + SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); + + return Convert::toString(PAK::GUID); +} diff --git a/lang/c/src/vpkppc/format/PCK.cpp b/lang/c/src/vpkppc/format/PCK.cpp index 9e1b9cb37..c661de302 100644 --- a/lang/c/src/vpkppc/format/PCK.cpp +++ b/lang/c/src/vpkppc/format/PCK.cpp @@ -2,6 +2,7 @@ #include +#include #include using namespace vpkpp; @@ -37,3 +38,10 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_pck_open(const char* path, vpkpp_ent } return packFile.release(); } + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_pck_guid(vpkpp_pack_file_handle_t handle) { + SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); + + return Convert::toString(PCK::GUID); +} diff --git a/lang/c/src/vpkppc/format/VPK.cpp b/lang/c/src/vpkppc/format/VPK.cpp index 706fb7c03..68293b0dd 100644 --- a/lang/c/src/vpkppc/format/VPK.cpp +++ b/lang/c/src/vpkppc/format/VPK.cpp @@ -2,6 +2,7 @@ #include +#include #include #include @@ -39,6 +40,13 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_vpk_open(const char* path, vpkpp_ent return packFile.release(); } +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_vpk_guid(vpkpp_pack_file_handle_t handle) { + SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); + + return Convert::toString(VPK::GUID); +} + SOURCEPP_API bool vpkpp_vpk_generate_keypair_files(const char* path) { SOURCEPP_EARLY_RETURN_VAL(path, false); @@ -50,7 +58,7 @@ SOURCEPP_API bool vpkpp_vpk_sign_from_file(vpkpp_pack_file_handle_t handle, cons SOURCEPP_EARLY_RETURN_VAL(filename, false); auto* vpk = Convert::packFile(handle); - if (vpk->getType() != PackFileType::VPK) { + if (!vpk->isInstanceOf()) { return false; } return dynamic_cast(vpk)->sign(filename); @@ -64,7 +72,7 @@ SOURCEPP_API bool vpkpp_vpk_sign_from_mem(vpkpp_pack_file_handle_t handle, const SOURCEPP_EARLY_RETURN_VAL(publicKeyLen, false); auto* vpk = Convert::packFile(handle); - if (vpk->getType() != PackFileType::VPK) { + if (!vpk->isInstanceOf()) { return false; } return dynamic_cast(vpk)->sign( @@ -76,7 +84,7 @@ SOURCEPP_API uint32_t vpkpp_vpk_get_version(vpkpp_pack_file_handle_t handle) { SOURCEPP_EARLY_RETURN_VAL(handle, 0); auto* vpk = Convert::packFile(handle); - if (vpk->getType() != PackFileType::VPK) { + if (!vpk->isInstanceOf()) { return 0; } return dynamic_cast(vpk)->getVersion(); @@ -86,7 +94,7 @@ SOURCEPP_API void vpkpp_vpk_set_version(vpkpp_pack_file_handle_t handle, uint32_ SOURCEPP_EARLY_RETURN(handle); auto* vpk = Convert::packFile(handle); - if (vpk->getType() != PackFileType::VPK) { + if (!vpk->isInstanceOf()) { return; } dynamic_cast(vpk)->setVersion(version); @@ -96,7 +104,7 @@ SOURCEPP_API uint32_t vpkpp_vpk_get_chunk_size(vpkpp_pack_file_handle_t handle) SOURCEPP_EARLY_RETURN_VAL(handle, 0); auto* vpk = Convert::packFile(handle); - if (vpk->getType() != PackFileType::VPK) { + if (!vpk->isInstanceOf()) { return 0; } return dynamic_cast(vpk)->getChunkSize(); @@ -106,7 +114,7 @@ SOURCEPP_API void vpkpp_vpk_set_chunk_size(vpkpp_pack_file_handle_t handle, uint SOURCEPP_EARLY_RETURN(handle); auto* vpk = Convert::packFile(handle); - if (vpk->getType() != PackFileType::VPK) { + if (!vpk->isInstanceOf()) { return; } dynamic_cast(vpk)->setChunkSize(chunkSize); diff --git a/lang/c/src/vpkppc/format/VPK_VTMB.cpp b/lang/c/src/vpkppc/format/VPK_VTMB.cpp index c9d4df5d0..66095d833 100644 --- a/lang/c/src/vpkppc/format/VPK_VTMB.cpp +++ b/lang/c/src/vpkppc/format/VPK_VTMB.cpp @@ -2,6 +2,7 @@ #include +#include #include using namespace vpkpp; @@ -27,3 +28,10 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_vpk_vtmb_open(const char* path, vpkp } return packFile.release(); } + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_vpk_vtmb_guid(vpkpp_pack_file_handle_t handle) { + SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); + + return Convert::toString(VPK_VTMB::GUID); +} diff --git a/lang/c/src/vpkppc/format/WAD3.cpp b/lang/c/src/vpkppc/format/WAD3.cpp index f0d8b49d9..916f01471 100644 --- a/lang/c/src/vpkppc/format/WAD3.cpp +++ b/lang/c/src/vpkppc/format/WAD3.cpp @@ -2,6 +2,7 @@ #include +#include #include using namespace vpkpp; @@ -27,3 +28,10 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_wad3_open(const char* path, vpkpp_en } return packFile.release(); } + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_wad3_guid(vpkpp_pack_file_handle_t handle) { + SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); + + return Convert::toString(WAD3::GUID); +} diff --git a/lang/c/src/vpkppc/format/ZIP.cpp b/lang/c/src/vpkppc/format/ZIP.cpp index b967f2fe8..da96ae0ff 100644 --- a/lang/c/src/vpkppc/format/ZIP.cpp +++ b/lang/c/src/vpkppc/format/ZIP.cpp @@ -2,7 +2,9 @@ #include +#include #include +#include using namespace vpkpp; @@ -27,3 +29,54 @@ SOURCEPP_API vpkpp_pack_file_handle_t vpkpp_zip_open(const char* path, vpkpp_ent } return packFile.release(); } + +// REQUIRES MANUAL FREE: sourcepp_string_free +SOURCEPP_API sourcepp_string_t vpkpp_zip_guid(vpkpp_pack_file_handle_t handle) { + SOURCEPP_EARLY_RETURN_VAL(handle, SOURCEPP_STRING_INVALID); + + return Convert::toString(ZIP::GUID); +} + +SOURCEPP_API vpkpp_entry_compression_type_e vpkpp_zip_get_entry_compression_type(vpkpp_pack_file_handle_t handle, const char* path) { + SOURCEPP_EARLY_RETURN_VAL(handle, ENTRY_COMPRESSION_TYPE_NO_COMPRESS); + SOURCEPP_EARLY_RETURN_VAL(path, ENTRY_COMPRESSION_TYPE_NO_COMPRESS); + + auto* zip = Convert::packFile(handle); + if (!zip->isInstanceOf()) { + return ENTRY_COMPRESSION_TYPE_NO_COMPRESS; + } + return static_cast(dynamic_cast(zip)->getEntryCompressionType(path)); +} + +SOURCEPP_API void vpkpp_zip_set_entry_compression_type(vpkpp_pack_file_handle_t handle, const char* path, vpkpp_entry_compression_type_e type) { + SOURCEPP_EARLY_RETURN(handle); + SOURCEPP_EARLY_RETURN(path); + + auto* zip = Convert::packFile(handle); + if (!zip->isInstanceOf()) { + return; + } + dynamic_cast(zip)->setEntryCompressionType(path, static_cast(type)); +} + +SOURCEPP_API int16_t vpkpp_zip_get_entry_compression_strength(vpkpp_pack_file_handle_t handle, const char* path) { + SOURCEPP_EARLY_RETURN_VAL(handle, 0); + SOURCEPP_EARLY_RETURN_VAL(path, 0); + + auto* zip = Convert::packFile(handle); + if (!zip->isInstanceOf()) { + return 0; + } + return dynamic_cast(zip)->getEntryCompressionStrength(path); +} + +SOURCEPP_API void vpkpp_zip_set_entry_compression_strength(vpkpp_pack_file_handle_t handle, const char* path, int16_t strength) { + SOURCEPP_EARLY_RETURN(handle); + SOURCEPP_EARLY_RETURN(path); + + auto* zip = Convert::packFile(handle); + if (!zip->isInstanceOf()) { + return; + } + dynamic_cast(zip)->setEntryCompressionStrength(path, strength); +} diff --git a/lang/csharp/src/sourcepp/Buffer.cs.in b/lang/csharp/src/sourcepp/Buffer.cs.in index f368bc195..cb5e05c56 100644 --- a/lang/csharp/src/sourcepp/Buffer.cs.in +++ b/lang/csharp/src/sourcepp/Buffer.cs.in @@ -1,15 +1,25 @@ using System; using System.Runtime.InteropServices; -namespace ${TARGET} +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * + * DO NOT EDIT THIS FILE + * IT IS AUTOGENERATED + * THANK YOU + * + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ + +namespace ${TARGET}.sourcepp { internal static unsafe partial class Extern { - [DllImport("${TARGET}c")] - public static extern Buffer sourcepp_buffer_new(ulong size); + [LibraryImport("${TARGET}c", EntryPoint = "sourcepp_buffer_new")] + public static partial Buffer BufferNew(ulong size); - [DllImport("${TARGET}c")] - public static extern void sourcepp_buffer_free(Buffer* str); + [LibraryImport("${TARGET}c", EntryPoint = "sourcepp_buffer_free")] + public static partial void BufferFree(Buffer* str); } [StructLayout(LayoutKind.Sequential)] @@ -27,7 +37,7 @@ namespace ${TARGET} fixed (Buffer* bufferPtr = &buffer) { - Extern.sourcepp_buffer_free(bufferPtr); + Extern.BufferFree(bufferPtr); } return result; diff --git a/lang/csharp/src/sourcepp/String.cs.in b/lang/csharp/src/sourcepp/String.cs.in index 24be8dd34..08d6bf134 100644 --- a/lang/csharp/src/sourcepp/String.cs.in +++ b/lang/csharp/src/sourcepp/String.cs.in @@ -1,21 +1,31 @@ using System.Collections.Generic; using System.Runtime.InteropServices; -namespace ${TARGET} +/* + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + * + * DO NOT EDIT THIS FILE + * IT IS AUTOGENERATED + * THANK YOU + * + * !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! + */ + +namespace ${TARGET}.sourcepp { internal static unsafe partial class Extern { - [DllImport("${TARGET}c")] - public static extern String sourcepp_string_new(ulong size); + [LibraryImport("${TARGET}c", EntryPoint = "sourcepp_string_new")] + public static partial String StringNew(ulong size); - [DllImport("${TARGET}c")] - public static extern void sourcepp_string_free(String* str); + [LibraryImport("${TARGET}c", EntryPoint = "sourcepp_string_free")] + public static partial void StringFree(String* str); - [DllImport("${TARGET}c")] - public static extern StringArray sourcepp_string_array_new(ulong size); + [LibraryImport("${TARGET}c", EntryPoint = "sourcepp_string_array_new")] + public static partial StringArray StringArrayNew(ulong size); - [DllImport("${TARGET}c")] - public static extern void sourcepp_string_array_free(StringArray* array); + [LibraryImport("${TARGET}c", EntryPoint = "sourcepp_string_array_free")] + public static partial void StringArrayFree(StringArray* array); } [StructLayout(LayoutKind.Sequential)] @@ -40,7 +50,7 @@ namespace ${TARGET} fixed (String* strPtr = &str) { - Extern.sourcepp_string_free(strPtr); + Extern.StringFree(strPtr); } return result; @@ -57,7 +67,7 @@ namespace ${TARGET} fixed (StringArray* arrayPtr = &array) { - Extern.sourcepp_string_array_free(arrayPtr); + Extern.StringArrayFree(arrayPtr); } return strings; diff --git a/lang/csharp/src/vpkpp/Entry.cs b/lang/csharp/src/vpkpp/Entry.cs index 624c55ba3..1e29c5eb3 100644 --- a/lang/csharp/src/vpkpp/Entry.cs +++ b/lang/csharp/src/vpkpp/Entry.cs @@ -5,32 +5,35 @@ namespace vpkpp { internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern uint vpkpp_entry_get_flags(void* handle); + internal static unsafe partial class Entry + { + [LibraryImport("vpkppc", EntryPoint = "vpkpp_entry_get_flags")] + public static partial uint GetFlags(void* handle); - [DllImport("vpkppc")] - public static extern uint vpkpp_entry_get_archive_index(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_entry_get_archive_index")] + public static partial uint GetArchiveIndex(void* handle); - [DllImport("vpkppc")] - public static extern ulong vpkpp_entry_get_length(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_entry_get_length")] + public static partial ulong GetLength(void* handle); - [DllImport("vpkppc")] - public static extern ulong vpkpp_entry_get_compressed_length(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_entry_get_compressed_length")] + public static partial ulong GetCompressedLength(void* handle); - [DllImport("vpkppc")] - public static extern ulong vpkpp_entry_get_offset(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_entry_get_offset")] + public static partial ulong GetOffset(void* handle); - [DllImport("vpkppc")] - public static extern Buffer vpkpp_entry_get_extra_data(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_entry_get_extra_data")] + public static partial sourcepp.Buffer GetExtraData(void* handle); - [DllImport("vpkppc")] - public static extern uint vpkpp_entry_get_crc32(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_entry_get_crc32")] + public static partial uint GetCRC32(void* handle); - [DllImport("vpkppc")] - public static extern int vpkpp_entry_is_unbaked(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_entry_is_unbaked")] + public static partial int IsUnbaked(void* handle); - [DllImport("vpkppc")] - public static extern void vpkpp_entry_free(void** handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_entry_free")] + public static partial void Free(void** handle); + } } public class Entry @@ -49,7 +52,7 @@ internal unsafe Entry(void* handle, bool managed) { fixed (void** handlePtr = &Handle) { - Extern.vpkpp_entry_free(handlePtr); + Extern.Entry.Free(handlePtr); } } } @@ -61,7 +64,7 @@ public uint Flags { unsafe { - return Extern.vpkpp_entry_get_flags(Handle); + return Extern.Entry.GetFlags(Handle); } } } @@ -72,7 +75,7 @@ public uint ArchiveIndex { unsafe { - return Extern.vpkpp_entry_get_archive_index(Handle); + return Extern.Entry.GetArchiveIndex(Handle); } } } @@ -83,7 +86,7 @@ public ulong Length { unsafe { - return Extern.vpkpp_entry_get_length(Handle); + return Extern.Entry.GetLength(Handle); } } } @@ -94,7 +97,7 @@ public ulong CompressedLength { unsafe { - return Extern.vpkpp_entry_get_compressed_length(Handle); + return Extern.Entry.GetCompressedLength(Handle); } } } @@ -105,7 +108,7 @@ public ulong Offset { unsafe { - return Extern.vpkpp_entry_get_offset(Handle); + return Extern.Entry.GetOffset(Handle); } } } @@ -116,8 +119,8 @@ public byte[] ExtraData { unsafe { - var buffer = Extern.vpkpp_entry_get_extra_data(Handle); - return BufferUtils.ConvertToArrayAndDelete(ref buffer); + var buffer = Extern.Entry.GetExtraData(Handle); + return sourcepp.BufferUtils.ConvertToArrayAndDelete(ref buffer); } } } @@ -128,7 +131,7 @@ public uint CRC32 { unsafe { - return Extern.vpkpp_entry_get_crc32(Handle); + return Extern.Entry.GetCRC32(Handle); } } } @@ -139,7 +142,7 @@ public bool Unbaked { unsafe { - return Convert.ToBoolean(Extern.vpkpp_entry_is_unbaked(Handle)); + return Convert.ToBoolean(Extern.Entry.IsUnbaked(Handle)); } } } diff --git a/lang/csharp/src/vpkpp/Format/BSP.cs b/lang/csharp/src/vpkpp/Format/BSP.cs deleted file mode 100644 index 27e5b1efb..000000000 --- a/lang/csharp/src/vpkpp/Format/BSP.cs +++ /dev/null @@ -1,40 +0,0 @@ -using System; -using System.Runtime.InteropServices; - -namespace vpkpp.Format -{ - using EntryCallback = Action; - - internal static unsafe partial class Extern - { - [DllImport("vpkppc")] - public static extern void* vpkpp_bsp_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); - } - - public class BSP : PackFile - { - private protected unsafe BSP(void* handle) : base(handle) {} - - public new static BSP? Open(string path) - { - unsafe - { - var handle = Extern.vpkpp_bsp_open(path, 0); - return handle == null ? null : new BSP(handle); - } - } - - public new static BSP? Open(string path, EntryCallback callback) - { - unsafe - { - EntryCallbackNative callbackNative = (path, entry) => - { - callback(path, new Entry(entry, true)); - }; - var handle = Extern.vpkpp_bsp_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); - return handle == null ? null : new BSP(handle); - } - } - } -} diff --git a/lang/csharp/src/vpkpp/Format/FPX.cs b/lang/csharp/src/vpkpp/Format/FPX.cs index 97c549f16..8436aad04 100644 --- a/lang/csharp/src/vpkpp/Format/FPX.cs +++ b/lang/csharp/src/vpkpp/Format/FPX.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Runtime.InteropServices; namespace vpkpp.Format @@ -7,11 +7,17 @@ namespace vpkpp.Format internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern void* vpkpp_fpx_create([MarshalAs(UnmanagedType.LPStr)] string path); + internal static unsafe partial class FPX + { + [LibraryImport("vpkppc", EntryPoint = "vpkpp_fpx_create")] + public static partial void* Create([MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern void* vpkpp_fpx_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_fpx_open")] + public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_fpx_guid")] + public static partial sourcepp.String GUID(); + } } public class FPX : PackFile @@ -22,7 +28,7 @@ private protected unsafe FPX(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_fpx_create(path); + var handle = Extern.FPX.Create(path); return handle == null ? null : new FPX(handle); } } @@ -31,7 +37,7 @@ private protected unsafe FPX(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_fpx_open(path, 0); + var handle = Extern.FPX.Open(path, 0); return handle == null ? null : new FPX(handle); } } @@ -44,9 +50,21 @@ private protected unsafe FPX(void* handle) : base(handle) {} { callback(path, new Entry(entry, true)); }; - var handle = Extern.vpkpp_fpx_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); + var handle = Extern.FPX.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); return handle == null ? null : new FPX(handle); } } + + public static string GUID + { + get + { + unsafe + { + var str = Extern.FPX.GUID(); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); + } + } + } } } diff --git a/lang/csharp/src/vpkpp/Format/GCF.cs b/lang/csharp/src/vpkpp/Format/GCF.cs index 3a5a2fedd..8bf8ef99b 100644 --- a/lang/csharp/src/vpkpp/Format/GCF.cs +++ b/lang/csharp/src/vpkpp/Format/GCF.cs @@ -7,9 +7,15 @@ namespace vpkpp.Format internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern void* vpkpp_gcf_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); - } + internal static unsafe partial class GCF + { + [LibraryImport("vpkppc", EntryPoint = "vpkpp_gcf_open")] + public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_gcf_guid")] + public static partial sourcepp.String GUID(); + } + } public class GCF : PackFile { @@ -19,7 +25,7 @@ private protected unsafe GCF(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_gcf_open(path, 0); + var handle = Extern.GCF.Open(path, 0); return handle == null ? null : new GCF(handle); } } @@ -32,9 +38,21 @@ private protected unsafe GCF(void* handle) : base(handle) {} { callback(path, new Entry(entry, true)); }; - var handle = Extern.vpkpp_gcf_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); + var handle = Extern.GCF.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); return handle == null ? null : new GCF(handle); } } - } + + public static string GUID + { + get + { + unsafe + { + var str = Extern.GCF.GUID(); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); + } + } + } + } } diff --git a/lang/csharp/src/vpkpp/Format/GMA.cs b/lang/csharp/src/vpkpp/Format/GMA.cs index 4272fff93..7dd718d4d 100644 --- a/lang/csharp/src/vpkpp/Format/GMA.cs +++ b/lang/csharp/src/vpkpp/Format/GMA.cs @@ -7,9 +7,15 @@ namespace vpkpp.Format internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern void* vpkpp_gma_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); - } + internal static unsafe partial class GMA + { + [LibraryImport("vpkppc", EntryPoint = "vpkpp_gma_open")] + public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_gma_guid")] + public static partial sourcepp.String GUID(); + } + } public class GMA : PackFile { @@ -19,7 +25,7 @@ private protected unsafe GMA(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_gma_open(path, 0); + var handle = Extern.GMA.Open(path, 0); return handle == null ? null : new GMA(handle); } } @@ -32,9 +38,21 @@ private protected unsafe GMA(void* handle) : base(handle) {} { callback(path, new Entry(entry, true)); }; - var handle = Extern.vpkpp_gma_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); + var handle = Extern.GMA.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); return handle == null ? null : new GMA(handle); } } - } + + public static string GUID + { + get + { + unsafe + { + var str = Extern.GMA.GUID(); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); + } + } + } + } } diff --git a/lang/csharp/src/vpkpp/Format/ORE.cs b/lang/csharp/src/vpkpp/Format/ORE.cs index 79eb7ad85..6dab7f0fe 100644 --- a/lang/csharp/src/vpkpp/Format/ORE.cs +++ b/lang/csharp/src/vpkpp/Format/ORE.cs @@ -7,11 +7,17 @@ namespace vpkpp.Format internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern void* vpkpp_ore_create([MarshalAs(UnmanagedType.LPStr)] string path); + internal static unsafe partial class ORE + { + [LibraryImport("vpkppc", EntryPoint = "vpkpp_ore_create")] + public static partial void* Create([MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern void* vpkpp_ore_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_ore_open")] + public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_ore_guid")] + public static partial sourcepp.String GUID(); + } } public class ORE : PackFile @@ -22,7 +28,7 @@ private protected unsafe ORE(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_ore_create(path); + var handle = Extern.ORE.Create(path); return handle == null ? null : new ORE(handle); } } @@ -31,7 +37,7 @@ private protected unsafe ORE(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_ore_open(path, 0); + var handle = Extern.ORE.Open(path, 0); return handle == null ? null : new ORE(handle); } } @@ -44,9 +50,21 @@ private protected unsafe ORE(void* handle) : base(handle) {} { callback(path, new Entry(entry, true)); }; - var handle = Extern.vpkpp_ore_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); + var handle = Extern.ORE.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); return handle == null ? null : new ORE(handle); } } - } + + public static string GUID + { + get + { + unsafe + { + var str = Extern.ORE.GUID(); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); + } + } + } + } } diff --git a/lang/csharp/src/vpkpp/Format/PAK.cs b/lang/csharp/src/vpkpp/Format/PAK.cs index b5345b17d..5104e2cfb 100644 --- a/lang/csharp/src/vpkpp/Format/PAK.cs +++ b/lang/csharp/src/vpkpp/Format/PAK.cs @@ -7,11 +7,17 @@ namespace vpkpp.Format internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern void* vpkpp_pak_create([MarshalAs(UnmanagedType.LPStr)] string path); + internal static unsafe partial class PAK + { + [LibraryImport("vpkppc", EntryPoint = "vpkpp_pak_create")] + public static partial void* Create([MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern void* vpkpp_pak_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_pak_open")] + public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_pak_guid")] + public static partial sourcepp.String GUID(); + } } public class PAK : PackFile @@ -22,7 +28,7 @@ private protected unsafe PAK(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_pak_create(path); + var handle = Extern.PAK.Create(path); return handle == null ? null : new PAK(handle); } } @@ -31,7 +37,7 @@ private protected unsafe PAK(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_pak_open(path, 0); + var handle = Extern.PAK.Open(path, 0); return handle == null ? null : new PAK(handle); } } @@ -44,9 +50,21 @@ private protected unsafe PAK(void* handle) : base(handle) {} { callback(path, new Entry(entry, true)); }; - var handle = Extern.vpkpp_pak_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); + var handle = Extern.PAK.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); return handle == null ? null : new PAK(handle); } } - } + + public static string GUID + { + get + { + unsafe + { + var str = Extern.PAK.GUID(); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); + } + } + } + } } diff --git a/lang/csharp/src/vpkpp/Format/PCK.cs b/lang/csharp/src/vpkpp/Format/PCK.cs index af4c3e498..0a264e6b4 100644 --- a/lang/csharp/src/vpkpp/Format/PCK.cs +++ b/lang/csharp/src/vpkpp/Format/PCK.cs @@ -7,14 +7,20 @@ namespace vpkpp.Format internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern void* vpkpp_pck_create([MarshalAs(UnmanagedType.LPStr)] string path); + internal static unsafe partial class PCK + { + [LibraryImport("vpkppc", EntryPoint = "vpkpp_pck_create")] + public static partial void* Create([MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern void* vpkpp_pck_create_with_options([MarshalAs(UnmanagedType.LPStr)] string path, uint version, uint godotMajorVersion, uint godotMinorVersion, uint godotPatchVersion); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_pck_create_with_options")] + public static partial void* Create([MarshalAs(UnmanagedType.LPStr)] string path, uint version, uint godotMajorVersion, uint godotMinorVersion, uint godotPatchVersion); - [DllImport("vpkppc")] - public static extern void* vpkpp_pck_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_pck_open")] + public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_pck_guid")] + public static partial sourcepp.String GUID(); + } } public class PCK : PackFile @@ -25,7 +31,7 @@ private protected unsafe PCK(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_pck_create(path); + var handle = Extern.PCK.Create(path); return handle == null ? null : new PCK(handle); } } @@ -34,7 +40,7 @@ private protected unsafe PCK(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_pck_create_with_options(path, version, godotMajorVersion, godotMinorVersion, godotPatchVersion); + var handle = Extern.PCK.Create(path, version, godotMajorVersion, godotMinorVersion, godotPatchVersion); return handle == null ? null : new PCK(handle); } } @@ -43,7 +49,7 @@ private protected unsafe PCK(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_pck_open(path, 0); + var handle = Extern.PCK.Open(path, 0); return handle == null ? null : new PCK(handle); } } @@ -56,9 +62,21 @@ private protected unsafe PCK(void* handle) : base(handle) {} { callback(path, new Entry(entry, true)); }; - var handle = Extern.vpkpp_pck_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); + var handle = Extern.PCK.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); return handle == null ? null : new PCK(handle); } } - } + + public static string GUID + { + get + { + unsafe + { + var str = Extern.PCK.GUID(); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); + } + } + } + } } diff --git a/lang/csharp/src/vpkpp/Format/VPK.cs b/lang/csharp/src/vpkpp/Format/VPK.cs index df7cae969..347fcefc2 100644 --- a/lang/csharp/src/vpkpp/Format/VPK.cs +++ b/lang/csharp/src/vpkpp/Format/VPK.cs @@ -9,29 +9,35 @@ namespace vpkpp.Format internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern void* vpkpp_vpk_create([MarshalAs(UnmanagedType.LPStr)] string path); + internal static unsafe partial class VPK + { + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_create")] + public static partial void* Create([MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern void* vpkpp_vpk_create_with_options([MarshalAs(UnmanagedType.LPStr)] string path, uint version); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_create_with_options")] + public static partial void* Create([MarshalAs(UnmanagedType.LPStr)] string path, uint version); - [DllImport("vpkppc")] - public static extern void* vpkpp_vpk_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_open")] + public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); - [DllImport("vpkppc")] - public static extern byte vpkpp_vpk_generate_keypair_files([MarshalAs(UnmanagedType.LPStr)] string path); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_guid")] + public static partial sourcepp.String GUID(); - [DllImport("vpkppc")] - public static extern byte vpkpp_vpk_sign_from_file(void* handle, [MarshalAs(UnmanagedType.LPStr)] string filepath); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_generate_keypair_files")] + public static partial byte GenerateKeypairFiles([MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern byte vpkpp_vpk_sign_from_mem(void* handle, byte* privateKeyBuffer, ulong privateKeyLen, byte* publicKeyBuffer, ulong publicKeyLen); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_sign_from_file")] + public static partial byte Sign(void* handle, [MarshalAs(UnmanagedType.LPStr)] string filepath); - [DllImport("vpkppc")] - public static extern uint vpkpp_vpk_get_version(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_sign_from_mem")] + public static partial byte Sign(void* handle, byte* privateKeyBuffer, ulong privateKeyLen, byte* publicKeyBuffer, ulong publicKeyLen); - [DllImport("vpkppc")] - public static extern void vpkpp_vpk_set_version(void* handle, uint version); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_get_version")] + public static partial uint GetVersion(void* handle); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_set_version")] + public static partial void SetVersion(void* handle, uint version); + } } public class VPK : PackFile @@ -42,7 +48,7 @@ private unsafe VPK(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_vpk_create(path); + var handle = Extern.VPK.Create(path); return handle == null ? null : new VPK(handle); } } @@ -51,7 +57,7 @@ private unsafe VPK(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_vpk_create_with_options(path, version); + var handle = Extern.VPK.Create(path, version); return handle == null ? null : new VPK(handle); } } @@ -60,7 +66,7 @@ private unsafe VPK(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_vpk_open(path, 0); + var handle = Extern.VPK.Open(path, 0); return handle == null ? null : new VPK(handle); } } @@ -73,7 +79,7 @@ private unsafe VPK(void* handle) : base(handle) {} { callback(path, new Entry(entry, true)); }; - var handle = Extern.vpkpp_vpk_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); + var handle = Extern.VPK.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); return handle == null ? null : new VPK(handle); } } @@ -82,7 +88,7 @@ public static bool GenerateKeyPairFiles(string path) { unsafe { - return Convert.ToBoolean(Extern.vpkpp_vpk_generate_keypair_files(path)); + return Convert.ToBoolean(Extern.VPK.GenerateKeypairFiles(path)); } } @@ -90,7 +96,7 @@ public bool Sign(string filepath) { unsafe { - return Convert.ToBoolean(Extern.vpkpp_vpk_sign_from_file(Handle, filepath)); + return Convert.ToBoolean(Extern.VPK.Sign(Handle, filepath)); } } @@ -102,7 +108,7 @@ public bool Sign(byte[] privateKey, byte[] publicKey) { fixed (byte* publicKeyBufferPtr = publicKey) { - return Convert.ToBoolean(Extern.vpkpp_vpk_sign_from_mem(Handle, privateKeyBufferPtr, (ulong) privateKey.LongLength, publicKeyBufferPtr, (ulong) publicKey.LongLength)); + return Convert.ToBoolean(Extern.VPK.Sign(Handle, privateKeyBufferPtr, (ulong) privateKey.LongLength, publicKeyBufferPtr, (ulong) publicKey.LongLength)); } } } @@ -118,26 +124,38 @@ public bool Sign(IEnumerable privateKey, IEnumerable publicKey) { fixed (byte* publicKeyBufferPtr = publicKeyData) { - return Convert.ToBoolean(Extern.vpkpp_vpk_sign_from_mem(Handle, privateKeyBufferPtr, (ulong) privateKeyData.LongLength, publicKeyBufferPtr, (ulong) publicKeyData.LongLength)); + return Convert.ToBoolean(Extern.VPK.Sign(Handle, privateKeyBufferPtr, (ulong) privateKeyData.LongLength, publicKeyBufferPtr, (ulong) publicKeyData.LongLength)); } } } } - public uint Version + public static string GUID + { + get + { + unsafe + { + var str = Extern.VPK.GUID(); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); + } + } + } + + public uint Version { get { unsafe { - return Extern.vpkpp_vpk_get_version(Handle); + return Extern.VPK.GetVersion(Handle); } } set { unsafe { - Extern.vpkpp_vpk_set_version(Handle, Math.Clamp(value, 1, 2)); + Extern.VPK.SetVersion(Handle, Math.Clamp(value, 1, 2)); } } } diff --git a/lang/csharp/src/vpkpp/Format/VPK_VTMB.cs b/lang/csharp/src/vpkpp/Format/VPK_VTMB.cs index e90755db9..d11ae508e 100644 --- a/lang/csharp/src/vpkpp/Format/VPK_VTMB.cs +++ b/lang/csharp/src/vpkpp/Format/VPK_VTMB.cs @@ -7,11 +7,17 @@ namespace vpkpp.Format internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern void* vpkpp_vpk_vtmb_create([MarshalAs(UnmanagedType.LPStr)] string path); + internal static unsafe partial class VPK_VTMB + { + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_vtmb_create")] + public static partial void* Create([MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern void* vpkpp_vpk_vtmb_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_vtmb_open")] + public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_vpk_vtmb_guid")] + public static partial sourcepp.String GUID(); + } } public class VPK_VTMB : PackFile @@ -22,7 +28,7 @@ private protected unsafe VPK_VTMB(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_vpk_vtmb_create(path); + var handle = Extern.VPK_VTMB.Create(path); return handle == null ? null : new VPK_VTMB(handle); } } @@ -31,7 +37,7 @@ private protected unsafe VPK_VTMB(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_vpk_vtmb_open(path, 0); + var handle = Extern.VPK_VTMB.Open(path, 0); return handle == null ? null : new VPK_VTMB(handle); } } @@ -44,9 +50,21 @@ private protected unsafe VPK_VTMB(void* handle) : base(handle) {} { callback(path, new Entry(entry, true)); }; - var handle = Extern.vpkpp_vpk_vtmb_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); + var handle = Extern.VPK_VTMB.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); return handle == null ? null : new VPK_VTMB(handle); } } - } + + public static string GUID + { + get + { + unsafe + { + var str = Extern.VPK_VTMB.GUID(); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); + } + } + } + } } diff --git a/lang/csharp/src/vpkpp/Format/WAD3.cs b/lang/csharp/src/vpkpp/Format/WAD3.cs index 4cc69de25..445ec0af5 100644 --- a/lang/csharp/src/vpkpp/Format/WAD3.cs +++ b/lang/csharp/src/vpkpp/Format/WAD3.cs @@ -7,11 +7,17 @@ namespace vpkpp.Format internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern void* vpkpp_wad3_create([MarshalAs(UnmanagedType.LPStr)] string path); + internal static unsafe partial class WAD3 + { + [LibraryImport("vpkppc", EntryPoint = "vpkpp_wad3_create")] + public static partial void* Create([MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern void* vpkpp_wad3_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_wad3_open")] + public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_wad3_guid")] + public static partial sourcepp.String GUID(); + } } public class WAD3 : PackFile @@ -22,7 +28,7 @@ private protected unsafe WAD3(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_wad3_create(path); + var handle = Extern.WAD3.Create(path); return handle == null ? null : new WAD3(handle); } } @@ -31,7 +37,7 @@ private protected unsafe WAD3(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_wad3_open(path, 0); + var handle = Extern.WAD3.Open(path, 0); return handle == null ? null : new WAD3(handle); } } @@ -44,9 +50,21 @@ private protected unsafe WAD3(void* handle) : base(handle) {} { callback(path, new Entry(entry, true)); }; - var handle = Extern.vpkpp_wad3_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); + var handle = Extern.WAD3.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); return handle == null ? null : new WAD3(handle); } } - } + + public static string GUID + { + get + { + unsafe + { + var str = Extern.WAD3.GUID(); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); + } + } + } + } } diff --git a/lang/csharp/src/vpkpp/Format/ZIP.cs b/lang/csharp/src/vpkpp/Format/ZIP.cs index bef391528..3d8138b00 100644 --- a/lang/csharp/src/vpkpp/Format/ZIP.cs +++ b/lang/csharp/src/vpkpp/Format/ZIP.cs @@ -7,12 +7,30 @@ namespace vpkpp.Format internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern void* vpkpp_zip_create([MarshalAs(UnmanagedType.LPStr)] string path); + internal static unsafe partial class ZIP + { + [LibraryImport("vpkppc", EntryPoint = "vpkpp_zip_create")] + public static partial void* Create([MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern void* vpkpp_zip_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); - } + [LibraryImport("vpkppc", EntryPoint = "vpkpp_zip_open")] + public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_zip_guid")] + public static partial sourcepp.String GUID(); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_zip_get_entry_compression_type")] + public static partial int GetEntryCompressionType(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_zip_set_entry_compression_type")] + public static partial void SetEntryCompressionType(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path, int type); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_zip_get_entry_compression_strength")] + public static partial short GetEntryCompressionStrength(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path); + + [LibraryImport("vpkppc", EntryPoint = "vpkpp_zip_set_entry_compression_strength")] + public static partial void SetEntryCompressionStrength(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path, short strength); + } + } public class ZIP : PackFile { @@ -22,7 +40,7 @@ private protected unsafe ZIP(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_zip_create(path); + var handle = Extern.ZIP.Create(path); return handle == null ? null : new ZIP(handle); } } @@ -31,7 +49,7 @@ private protected unsafe ZIP(void* handle) : base(handle) {} { unsafe { - var handle = Extern.vpkpp_zip_open(path, 0); + var handle = Extern.ZIP.Open(path, 0); return handle == null ? null : new ZIP(handle); } } @@ -44,9 +62,53 @@ private protected unsafe ZIP(void* handle) : base(handle) {} { callback(path, new Entry(entry, true)); }; - var handle = Extern.vpkpp_zip_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); + var handle = Extern.ZIP.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); return handle == null ? null : new ZIP(handle); } } - } + + public EntryCompressionType GetEntryCompressionType(string path) + { + unsafe + { + return (EntryCompressionType)Extern.ZIP.GetEntryCompressionType(Handle, path); + } + } + + public void SetEntryCompressionType(string path, EntryCompressionType type) + { + unsafe + { + Extern.ZIP.SetEntryCompressionType(Handle, path, (int)type); + } + } + + public short GetEntryCompressionStrength(string path) + { + unsafe + { + return Extern.ZIP.GetEntryCompressionStrength(Handle, path); + } + } + + public void SetEntryCompressionStrength(string path, short strength) + { + unsafe + { + Extern.ZIP.SetEntryCompressionStrength(Handle, path, strength); + } + } + + public static string GUID + { + get + { + unsafe + { + var str = Extern.ZIP.GUID(); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); + } + } + } + } } diff --git a/lang/csharp/src/vpkpp/Options.cs b/lang/csharp/src/vpkpp/Options.cs index 0892c50c6..0e251f099 100644 --- a/lang/csharp/src/vpkpp/Options.cs +++ b/lang/csharp/src/vpkpp/Options.cs @@ -2,19 +2,32 @@ namespace vpkpp { + public enum EntryCompressionType : short + { + NO_OVERRIDE = -1, + NO_COMPRESS = 0, + DEFLATE = 8, + BZIP2 = 12, + LZMA = 14, + ZSTD = 93, + XZ = 95, + } + [StructLayout(LayoutKind.Sequential)] public struct BakeOptions { - public int gma_writeCRCs; - - public int vpk_generateMD5Entries; - } + public EntryCompressionType zip_compressionTypeOverride; + public short zip_compressionStrength; + public byte gma_writeCRCs; + public byte vpk_generateMD5Entries; + } [StructLayout(LayoutKind.Sequential)] public struct EntryOptions { - public int vpk_saveToDirectory; - - public uint vpk_preloadBytes; - } + public EntryCompressionType zip_compressionType; + public short zip_compressionStrength; + public ushort vpk_preloadBytes; + public byte vpk_saveToDirectory; + } } diff --git a/lang/csharp/src/vpkpp/PackFile.cs b/lang/csharp/src/vpkpp/PackFile.cs index 59e27f196..1964bcc31 100644 --- a/lang/csharp/src/vpkpp/PackFile.cs +++ b/lang/csharp/src/vpkpp/PackFile.cs @@ -19,134 +19,134 @@ namespace vpkpp internal static unsafe partial class Extern { - [DllImport("vpkppc")] - public static extern void* vpkpp_open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_open")] + public static partial void* Open([MarshalAs(UnmanagedType.LPStr)] string path, IntPtr callback); - [DllImport("vpkppc")] - public static extern StringArray vpkpp_get_openable_extensions(); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_get_openable_extensions")] + public static partial sourcepp.StringArray GetOpenableExtensions(); - [DllImport("vpkppc")] - public static extern PackFileType vpkpp_get_type(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_get_guid")] + public static partial sourcepp.String GetGUID(void* handle); - [DllImport("vpkppc")] - public static extern int vpkpp_has_entry_checksums(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_has_entry_checksums")] + public static partial int HasEntryChecksums(void* handle); - [DllImport("vpkppc")] - public static extern StringArray vpkpp_verify_entry_checksums(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_verify_entry_checksums")] + public static partial sourcepp.StringArray VerifyEntryChecksums(void* handle); - [DllImport("vpkppc")] - public static extern int vpkpp_has_pack_file_checksum(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_has_pack_file_checksum")] + public static partial int HasPackFileChecksum(void* handle); - [DllImport("vpkppc")] - public static extern int vpkpp_verify_pack_file_checksum(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_verify_pack_file_checksum")] + public static partial int VerifyPackFileChecksum(void* handle); - [DllImport("vpkppc")] - public static extern int vpkpp_has_pack_file_signature(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_has_pack_file_signature")] + public static partial int HasPackFileSignature(void* handle); - [DllImport("vpkppc")] - public static extern int vpkpp_verify_pack_file_signature(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_verify_pack_file_signature")] + public static partial int VerifyPackFileSignature(void* handle); - [DllImport("vpkppc")] - public static extern int vpkpp_is_case_sensitive(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_is_case_sensitive")] + public static partial int IsCaseSensitive(void* handle); - [DllImport("vpkppc")] - public static extern int vpkpp_has_entry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path, int includeUnbaked); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_has_entry")] + public static partial int HasEntry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path, int includeUnbaked); - [DllImport("vpkppc")] - public static extern void* vpkpp_find_entry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path, int includeUnbaked); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_find_entry")] + public static partial void* FindEntry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path, int includeUnbaked); - [DllImport("vpkppc")] - public static extern Buffer vpkpp_read_entry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_read_entry")] + public static partial sourcepp.Buffer ReadEntry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern String vpkpp_read_entry_text(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_read_entry_text")] + public static partial sourcepp.String ReadEntryText(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern int vpkpp_is_read_only(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_is_read_only")] + public static partial int IsReadOnly(void* handle); - [DllImport("vpkppc")] - public static extern void vpkpp_add_entry_from_file(void* handle, [MarshalAs(UnmanagedType.LPStr)] string entryPath, [MarshalAs(UnmanagedType.LPStr)] string filepath); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_add_entry_from_file")] + public static partial void AddEntryFromFile(void* handle, [MarshalAs(UnmanagedType.LPStr)] string entryPath, [MarshalAs(UnmanagedType.LPStr)] string filepath); - [DllImport("vpkppc")] - public static extern void vpkpp_add_entry_from_file_with_options(void* handle, [MarshalAs(UnmanagedType.LPStr)] string entryPath, [MarshalAs(UnmanagedType.LPStr)] string filepath, EntryOptions options); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_add_entry_from_file_with_options")] + public static partial void AddEntryFromFile(void* handle, [MarshalAs(UnmanagedType.LPStr)] string entryPath, [MarshalAs(UnmanagedType.LPStr)] string filepath, EntryOptions options); - [DllImport("vpkppc")] - public static extern void vpkpp_add_entry_from_mem(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path, byte* buffer, ulong bufferLen); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_add_entry_from_mem")] + public static partial void AddEntryFromMem(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path, byte* buffer, ulong bufferLen); - [DllImport("vpkppc")] - public static extern void vpkpp_add_entry_from_mem_with_options(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path, byte* buffer, ulong bufferLen, EntryOptions options); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_add_entry_from_mem_with_options")] + public static partial void AddEntryFromMem(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path, byte* buffer, ulong bufferLen, EntryOptions options); - [DllImport("vpkppc")] - public static extern void vpkpp_add_directory(void* handle, [MarshalAs(UnmanagedType.LPStr)] string entryBaseDir, [MarshalAs(UnmanagedType.LPStr)] string dir, IntPtr creation); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_add_directory")] + public static partial void AddDirectory(void* handle, [MarshalAs(UnmanagedType.LPStr)] string entryBaseDir, [MarshalAs(UnmanagedType.LPStr)] string dir, IntPtr creation); - [DllImport("vpkppc")] - public static extern void vpkpp_add_directory_with_options(void* handle, [MarshalAs(UnmanagedType.LPStr)] string entryBaseDir, [MarshalAs(UnmanagedType.LPStr)] string dir, EntryOptions options); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_add_directory_with_options")] + public static partial void AddDirectory(void* handle, [MarshalAs(UnmanagedType.LPStr)] string entryBaseDir, [MarshalAs(UnmanagedType.LPStr)] string dir, EntryOptions options); - [DllImport("vpkppc")] - public static extern int vpkpp_rename_entry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string oldPath, [MarshalAs(UnmanagedType.LPStr)] string newPath); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_rename_entry")] + public static partial int RenameEntry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string oldPath, [MarshalAs(UnmanagedType.LPStr)] string newPath); - [DllImport("vpkppc")] - public static extern int vpkpp_rename_directory(void* handle, [MarshalAs(UnmanagedType.LPStr)] string oldDir, [MarshalAs(UnmanagedType.LPStr)] string newDir); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_rename_directory")] + public static partial int RenameDirectory(void* handle, [MarshalAs(UnmanagedType.LPStr)] string oldDir, [MarshalAs(UnmanagedType.LPStr)] string newDir); - [DllImport("vpkppc")] - public static extern int vpkpp_remove_entry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_remove_entry")] + public static partial int RemoveEntry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string path); - [DllImport("vpkppc")] - public static extern ulong vpkpp_remove_directory(void* handle, [MarshalAs(UnmanagedType.LPStr)] string dirName); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_remove_directory")] + public static partial ulong RemoveDirectory(void* handle, [MarshalAs(UnmanagedType.LPStr)] string dirName); - [DllImport("vpkppc")] - public static extern int vpkpp_bake(void* handle, [MarshalAs(UnmanagedType.LPStr)] string outputDir, IntPtr callback); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_bake")] + public static partial int Bake(void* handle, [MarshalAs(UnmanagedType.LPStr)] string outputDir, IntPtr callback); - [DllImport("vpkppc")] - public static extern int vpkpp_bake_with_options(void* handle, [MarshalAs(UnmanagedType.LPStr)] string outputDir, BakeOptions options, IntPtr callback); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_bake_with_options")] + public static partial int Bake(void* handle, [MarshalAs(UnmanagedType.LPStr)] string outputDir, BakeOptions options, IntPtr callback); - [DllImport("vpkppc")] - public static extern int vpkpp_extract_entry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string entryPath, [MarshalAs(UnmanagedType.LPStr)] string filepath); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_extract_entry")] + public static partial int ExtractEntry(void* handle, [MarshalAs(UnmanagedType.LPStr)] string entryPath, [MarshalAs(UnmanagedType.LPStr)] string filepath); - [DllImport("vpkppc")] - public static extern int vpkpp_extract_directory(void* handle, [MarshalAs(UnmanagedType.LPStr)] string dir, [MarshalAs(UnmanagedType.LPStr)] string outputDir); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_extract_directory")] + public static partial int ExtractDirectory(void* handle, [MarshalAs(UnmanagedType.LPStr)] string dir, [MarshalAs(UnmanagedType.LPStr)] string outputDir); - [DllImport("vpkppc")] - public static extern int vpkpp_extract_all(void* handle, [MarshalAs(UnmanagedType.LPStr)] string outputDir, int createUnderPackFileDir); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_extract_all")] + public static partial int ExtractAll(void* handle, [MarshalAs(UnmanagedType.LPStr)] string outputDir, int createUnderPackFileDir); - [DllImport("vpkppc")] - public static extern int vpkpp_extract_all_if(void* handle, [MarshalAs(UnmanagedType.LPStr)] string outputDir, IntPtr predicate, int stripSharedDirs); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_extract_all_if")] + public static partial int ExtractAllIf(void* handle, [MarshalAs(UnmanagedType.LPStr)] string outputDir, IntPtr predicate, int stripSharedDirs); - [DllImport("vpkppc")] - public static extern ulong vpkpp_get_entry_count(void* handle, int includeUnbaked); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_get_entry_count")] + public static partial ulong GetEntryCount(void* handle, int includeUnbaked); - [DllImport("vpkppc")] - public static extern void vpkpp_run_for_all_entries(void* handle, IntPtr operation, int includeUnbaked); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_run_for_all_entries")] + public static partial void RunForAllEntries(void* handle, IntPtr operation, int includeUnbaked); - [DllImport("vpkppc")] - public static extern String vpkpp_get_filepath(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_get_filepath")] + public static partial sourcepp.String GetFilepath(void* handle); - [DllImport("vpkppc")] - public static extern String vpkpp_get_truncated_filepath(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_get_truncated_filepath")] + public static partial sourcepp.String GetTruncatedFilepath(void* handle); - [DllImport("vpkppc")] - public static extern String vpkpp_get_filename(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_get_filename")] + public static partial sourcepp.String GetFilename(void* handle); - [DllImport("vpkppc")] - public static extern String vpkpp_get_truncated_filename(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_get_truncated_filename")] + public static partial sourcepp.String GetTruncatedFilename(void* handle); - [DllImport("vpkppc")] - public static extern String vpkpp_get_filestem(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_get_filestem")] + public static partial sourcepp.String GetFilestem(void* handle); - [DllImport("vpkppc")] - public static extern String vpkpp_get_truncated_filestem(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_get_truncated_filestem")] + public static partial sourcepp.String GetTruncatedFilestem(void* handle); - [DllImport("vpkppc")] - public static extern Attribute vpkpp_get_supported_entry_attributes(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_get_supported_entry_attributes")] + public static partial Attribute GetSupportedEntryAttributes(void* handle); - [DllImport("vpkppc")] - public static extern String vpkpp_to_string(void* handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_to_string")] + public static partial sourcepp.String ToString(void* handle); - [DllImport("vpkppc")] - public static extern void vpkpp_close(void** handle); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_close")] + public static partial void Close(void** handle); - [DllImport("vpkppc")] - public static extern String vpkpp_escape_entry_path_for_write([MarshalAs(UnmanagedType.LPStr)] string path); + [LibraryImport("vpkppc", EntryPoint = "vpkpp_escape_entry_path_for_write")] + public static partial sourcepp.String EscapeEntryPathForWrite([MarshalAs(UnmanagedType.LPStr)] string path); } public class PackFile @@ -162,7 +162,7 @@ private protected unsafe PackFile(void* handle) { fixed (void** handlePtr = &Handle) { - Extern.vpkpp_close(handlePtr); + Extern.Close(handlePtr); } } } @@ -171,7 +171,7 @@ private protected unsafe PackFile(void* handle) { unsafe { - var handle = Extern.vpkpp_open(path, 0); + var handle = Extern.Open(path, 0); return handle == null ? null : new PackFile(handle); } } @@ -184,28 +184,28 @@ private protected unsafe PackFile(void* handle) { callback(path, new Entry(entry, true)); }; - var handle = Extern.vpkpp_open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); + var handle = Extern.Open(path, Marshal.GetFunctionPointerForDelegate(callbackNative)); return handle == null ? null : new PackFile(handle); } } public static string EscapeEntryPathForWrite(string path) { - var str = Extern.vpkpp_escape_entry_path_for_write(path); - return StringUtils.ConvertToStringAndDelete(ref str); + var str = Extern.EscapeEntryPathForWrite(path); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); } public static List GetSupportedFileTypes() { - var stringArray = Extern.vpkpp_get_openable_extensions(); - return StringUtils.ConvertToListAndDelete(ref stringArray); + var stringArray = Extern.GetOpenableExtensions(); + return sourcepp.StringUtils.ConvertToListAndDelete(ref stringArray); } public bool HasEntryChecksums() { unsafe { - return Convert.ToBoolean(Extern.vpkpp_has_entry_checksums(Handle)); + return Convert.ToBoolean(Extern.HasEntryChecksums(Handle)); } } @@ -213,8 +213,8 @@ public IEnumerable VerifyEntryChecksums() { unsafe { - var stringArray = Extern.vpkpp_verify_entry_checksums(Handle); - return StringUtils.ConvertToListAndDelete(ref stringArray); + var stringArray = Extern.VerifyEntryChecksums(Handle); + return sourcepp.StringUtils.ConvertToListAndDelete(ref stringArray); } } @@ -222,7 +222,7 @@ public bool HasPackFileChecksum() { unsafe { - return Convert.ToBoolean(Extern.vpkpp_has_pack_file_checksum(Handle)); + return Convert.ToBoolean(Extern.HasPackFileChecksum(Handle)); } } @@ -230,7 +230,7 @@ public bool VerifyPackFileChecksum() { unsafe { - return Convert.ToBoolean(Extern.vpkpp_verify_pack_file_checksum(Handle)); + return Convert.ToBoolean(Extern.VerifyPackFileChecksum(Handle)); } } @@ -238,7 +238,7 @@ public bool HasPackFileSignature() { unsafe { - return Convert.ToBoolean(Extern.vpkpp_has_pack_file_signature(Handle)); + return Convert.ToBoolean(Extern.HasPackFileSignature(Handle)); } } @@ -246,7 +246,7 @@ public bool VerifyPackFileSignature() { unsafe { - return Convert.ToBoolean(Extern.vpkpp_verify_pack_file_signature(Handle)); + return Convert.ToBoolean(Extern.VerifyPackFileSignature(Handle)); } } @@ -254,7 +254,7 @@ public bool HasEntry(string path, bool includeUnbaked = true) { unsafe { - return Convert.ToBoolean(Extern.vpkpp_has_entry(Handle, path, Convert.ToInt32(includeUnbaked))); + return Convert.ToBoolean(Extern.HasEntry(Handle, path, Convert.ToInt32(includeUnbaked))); } } @@ -262,7 +262,7 @@ public bool HasEntry(string path, bool includeUnbaked = true) { unsafe { - var entry = Extern.vpkpp_find_entry(Handle, path, Convert.ToInt32(includeUnbaked)); + var entry = Extern.FindEntry(Handle, path, Convert.ToInt32(includeUnbaked)); return entry == null ? null : new Entry(entry, false); } } @@ -271,8 +271,8 @@ public bool HasEntry(string path, bool includeUnbaked = true) { unsafe { - var buffer = Extern.vpkpp_read_entry(Handle, path); - return buffer.size < 0 ? null : BufferUtils.ConvertToArrayAndDelete(ref buffer); + var buffer = Extern.ReadEntry(Handle, path); + return buffer.size < 0 ? null : sourcepp.BufferUtils.ConvertToArrayAndDelete(ref buffer); } } @@ -280,8 +280,8 @@ public bool HasEntry(string path, bool includeUnbaked = true) { unsafe { - var str = Extern.vpkpp_read_entry_text(Handle, path); - return str.size < 0 ? null : StringUtils.ConvertToStringAndDelete(ref str); + var str = Extern.ReadEntryText(Handle, path); + return str.size < 0 ? null : sourcepp.StringUtils.ConvertToStringAndDelete(ref str); } } @@ -289,7 +289,7 @@ public void AddEntry(string entryPath, string filepath) { unsafe { - Extern.vpkpp_add_entry_from_file(Handle, entryPath, filepath); + Extern.AddEntryFromFile(Handle, entryPath, filepath); } } @@ -297,7 +297,7 @@ public void AddEntry(string entryPath, string filepath, EntryOptions options) { unsafe { - Extern.vpkpp_add_entry_from_file_with_options(Handle, entryPath, filepath, options); + Extern.AddEntryFromFile(Handle, entryPath, filepath, options); } } @@ -307,7 +307,7 @@ public void AddEntry(string path, byte[] buffer) { fixed (byte* bufferPtr = buffer) { - Extern.vpkpp_add_entry_from_mem(Handle, path, bufferPtr, (ulong) buffer.LongLength); + Extern.AddEntryFromMem(Handle, path, bufferPtr, (ulong) buffer.LongLength); } } } @@ -318,7 +318,7 @@ public void AddEntry(string path, byte[] buffer, EntryOptions options) { fixed (byte* bufferPtr = buffer) { - Extern.vpkpp_add_entry_from_mem_with_options(Handle, path, bufferPtr, (ulong) buffer.LongLength, options); + Extern.AddEntryFromMem(Handle, path, bufferPtr, (ulong) buffer.LongLength, options); } } } @@ -330,7 +330,7 @@ public void AddEntry(string path, IEnumerable buffer) var data = buffer.ToArray(); fixed (byte* bufferPtr = data) { - Extern.vpkpp_add_entry_from_mem(Handle, path, bufferPtr, (ulong)data.LongLength); + Extern.AddEntryFromMem(Handle, path, bufferPtr, (ulong)data.LongLength); } } } @@ -342,7 +342,7 @@ public void AddEntry(string path, IEnumerable buffer, EntryOptions options var data = buffer.ToArray(); fixed (byte* bufferPtr = data) { - Extern.vpkpp_add_entry_from_mem_with_options(Handle, path, bufferPtr, (ulong)data.LongLength, options); + Extern.AddEntryFromMem(Handle, path, bufferPtr, (ulong)data.LongLength, options); } } } @@ -351,7 +351,7 @@ public void AddDirectory(string entryBasePath, string dir) { unsafe { - Extern.vpkpp_add_directory(Handle, entryBasePath, dir, 0); + Extern.AddDirectory(Handle, entryBasePath, dir, 0); } } @@ -359,7 +359,7 @@ public void AddDirectory(string entryBasePath, string dir, EntryOptions options) { unsafe { - Extern.vpkpp_add_directory_with_options(Handle, entryBasePath, dir, options); + Extern.AddDirectory(Handle, entryBasePath, dir, options); } } @@ -371,7 +371,7 @@ public void AddDirectory(string entryBasePath, string dir, EntryCreation creatio { return creation(path); }; - Extern.vpkpp_add_directory(Handle, entryBasePath, dir, Marshal.GetFunctionPointerForDelegate(callbackNative)); + Extern.AddDirectory(Handle, entryBasePath, dir, Marshal.GetFunctionPointerForDelegate(callbackNative)); } } @@ -379,7 +379,7 @@ public bool RenameEntry(string oldPath, string newPath) { unsafe { - return Convert.ToBoolean(Extern.vpkpp_rename_entry(Handle, oldPath, newPath)); + return Convert.ToBoolean(Extern.RenameEntry(Handle, oldPath, newPath)); } } @@ -387,7 +387,7 @@ public bool RenameDirectory(string oldDir, string newDir) { unsafe { - return Convert.ToBoolean(Extern.vpkpp_rename_directory(Handle, oldDir, newDir)); + return Convert.ToBoolean(Extern.RenameDirectory(Handle, oldDir, newDir)); } } @@ -395,7 +395,7 @@ public bool RemoveEntry(string path) { unsafe { - return Convert.ToBoolean(Extern.vpkpp_remove_entry(Handle, path)); + return Convert.ToBoolean(Extern.RemoveEntry(Handle, path)); } } @@ -403,7 +403,7 @@ public ulong RemoveDirectory(string dirName) { unsafe { - return Extern.vpkpp_remove_directory(Handle, dirName); + return Extern.RemoveDirectory(Handle, dirName); } } @@ -411,7 +411,7 @@ public bool Bake(string outputDir) { unsafe { - return Convert.ToBoolean(Extern.vpkpp_bake(Handle, outputDir, 0)); + return Convert.ToBoolean(Extern.Bake(Handle, outputDir, 0)); } } @@ -423,7 +423,7 @@ public bool Bake(string outputDir, EntryCallback callback) { callback(path, new Entry(entry, true)); }; - return Convert.ToBoolean(Extern.vpkpp_bake(Handle, outputDir, Marshal.GetFunctionPointerForDelegate(callbackNative))); + return Convert.ToBoolean(Extern.Bake(Handle, outputDir, Marshal.GetFunctionPointerForDelegate(callbackNative))); } } @@ -431,7 +431,7 @@ public bool Bake(string outputDir, BakeOptions options) { unsafe { - return Convert.ToBoolean(Extern.vpkpp_bake_with_options(Handle, outputDir, options, 0)); + return Convert.ToBoolean(Extern.Bake(Handle, outputDir, options, 0)); } } @@ -443,7 +443,7 @@ public bool Bake(string outputDir, BakeOptions options, EntryCallback callback) { callback(path, new Entry(entry, true)); }; - return Convert.ToBoolean(Extern.vpkpp_bake_with_options(Handle, outputDir, options, Marshal.GetFunctionPointerForDelegate(callbackNative))); + return Convert.ToBoolean(Extern.Bake(Handle, outputDir, options, Marshal.GetFunctionPointerForDelegate(callbackNative))); } } @@ -451,7 +451,7 @@ public bool ExtractEntry(string entryPath, string filepath) { unsafe { - return Convert.ToBoolean(Extern.vpkpp_extract_entry(Handle, entryPath, filepath)); + return Convert.ToBoolean(Extern.ExtractEntry(Handle, entryPath, filepath)); } } @@ -459,7 +459,7 @@ public bool ExtractDirectory(string dir, string outputDir) { unsafe { - return Convert.ToBoolean(Extern.vpkpp_extract_directory(Handle, dir, outputDir)); + return Convert.ToBoolean(Extern.ExtractDirectory(Handle, dir, outputDir)); } } @@ -467,7 +467,7 @@ public bool ExtractAll(string outputDir, bool createUnderPackFileDir = true) { unsafe { - return Convert.ToBoolean(Extern.vpkpp_extract_all(Handle, outputDir, Convert.ToInt32(createUnderPackFileDir))); + return Convert.ToBoolean(Extern.ExtractAll(Handle, outputDir, Convert.ToInt32(createUnderPackFileDir))); } } @@ -479,7 +479,7 @@ public bool ExtractAll(string outputDir, EntryPredicate predicate, bool stripSha { return Convert.ToInt32(predicate(path, new Entry(entry, true))); }; - return Convert.ToBoolean(Extern.vpkpp_extract_all_if(Handle, outputDir, Marshal.GetFunctionPointerForDelegate(predicateNative), Convert.ToInt32(stripSharedDirs))); + return Convert.ToBoolean(Extern.ExtractAllIf(Handle, outputDir, Marshal.GetFunctionPointerForDelegate(predicateNative), Convert.ToInt32(stripSharedDirs))); } } @@ -487,7 +487,7 @@ public ulong GetEntryCount(bool includeUnbaked = true) { unsafe { - return Extern.vpkpp_get_entry_count(Handle, Convert.ToInt32(includeUnbaked)); + return Extern.GetEntryCount(Handle, Convert.ToInt32(includeUnbaked)); } } @@ -499,7 +499,7 @@ public void RunForAllEntries(EntryCallback operation, bool includeUnbaked = true { operation(path, new Entry(entry, true)); }; - Extern.vpkpp_run_for_all_entries(Handle, Marshal.GetFunctionPointerForDelegate(callbackNative), Convert.ToInt32(includeUnbaked)); + Extern.RunForAllEntries(Handle, Marshal.GetFunctionPointerForDelegate(callbackNative), Convert.ToInt32(includeUnbaked)); } } @@ -507,18 +507,19 @@ public override string ToString() { unsafe { - var str = Extern.vpkpp_to_string(Handle); - return StringUtils.ConvertToStringAndDelete(ref str); + var str = Extern.ToString(Handle); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); } } - public PackFileType Type + public string TypeGUID { get { unsafe { - return Extern.vpkpp_get_type(Handle); + var str = Extern.GetGUID(Handle); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); } } } @@ -529,7 +530,7 @@ public bool CaseSensitive { unsafe { - return Convert.ToBoolean(Extern.vpkpp_is_case_sensitive(Handle)); + return Convert.ToBoolean(Extern.IsCaseSensitive(Handle)); } } } @@ -540,7 +541,7 @@ public bool ReadOnly { unsafe { - return Convert.ToBoolean(Extern.vpkpp_is_read_only(Handle)); + return Convert.ToBoolean(Extern.IsReadOnly(Handle)); } } } @@ -551,8 +552,8 @@ public string FilePath { unsafe { - var str = Extern.vpkpp_get_filepath(Handle); - return StringUtils.ConvertToStringAndDelete(ref str); + var str = Extern.GetFilepath(Handle); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); } } } @@ -563,8 +564,8 @@ public string TruncatedFilePath { unsafe { - var str = Extern.vpkpp_get_truncated_filepath(Handle); - return StringUtils.ConvertToStringAndDelete(ref str); + var str = Extern.GetTruncatedFilepath(Handle); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); } } } @@ -575,8 +576,8 @@ public string FileName { unsafe { - var str = Extern.vpkpp_get_filename(Handle); - return StringUtils.ConvertToStringAndDelete(ref str); + var str = Extern.GetFilename(Handle); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); } } } @@ -587,8 +588,8 @@ public string TruncatedFileName { unsafe { - var str = Extern.vpkpp_get_truncated_filename(Handle); - return StringUtils.ConvertToStringAndDelete(ref str); + var str = Extern.GetTruncatedFilename(Handle); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); } } } @@ -599,8 +600,8 @@ public string FileStem { unsafe { - var str = Extern.vpkpp_get_filestem(Handle); - return StringUtils.ConvertToStringAndDelete(ref str); + var str = Extern.GetFilestem(Handle); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); } } } @@ -611,8 +612,8 @@ public string TruncatedFileStem { unsafe { - var str = Extern.vpkpp_get_truncated_filestem(Handle); - return StringUtils.ConvertToStringAndDelete(ref str); + var str = Extern.GetTruncatedFilestem(Handle); + return sourcepp.StringUtils.ConvertToStringAndDelete(ref str); } } } @@ -623,7 +624,7 @@ public Attribute SupportedEntryAttributes { unsafe { - return Extern.vpkpp_get_supported_entry_attributes(Handle); + return Extern.GetSupportedEntryAttributes(Handle); } } } diff --git a/lang/csharp/test/vpkpp.test/PackFileTest.cs b/lang/csharp/test/vpkpp.test/PackFileTest.cs index ad5598db1..1f72cb667 100644 --- a/lang/csharp/test/vpkpp.test/PackFileTest.cs +++ b/lang/csharp/test/vpkpp.test/PackFileTest.cs @@ -2,76 +2,70 @@ namespace vpkpp.test { - [TestClass] - public class PackFileTest - { - [TestMethod] - public void Open() - { - var vpk = PackFile.Open(BasePortalPath + "portal_pak_dir.vpk", (path, entry) => - { - Console.WriteLine(path); - }); - Assert.IsNotNull(vpk); - Assert.AreEqual(vpk.Type, PackFileType.VPK); + [TestClass] + public class PackFileTest + { + [TestMethod] + public void Open() + { + var vpk = PackFile.Open(BasePortalPath + "portal_pak_dir.vpk", (path, entry) => + { + Console.WriteLine(path); + }); + Assert.IsNotNull(vpk); + Assert.AreEqual(vpk.TypeGUID, Format.VPK.GUID); - Assert.IsFalse(vpk.CaseSensitive); + Assert.IsFalse(vpk.CaseSensitive); - var entry = vpk.FindEntry("materials/console/background1.vmt"); - Assert.IsNotNull(entry); - Assert.AreEqual(vpk.ReadEntryText("materials/console/background1.vmt"), "\"UnlitGeneric\"\r\n{\r\n\t\"$basetexture\" \"console/background1\"\r\n\t\"$vertexcolor\" 1\r\n\t\"$vertexalpha\" 1\r\n\t\"$ignorez\" 1\r\n\t\"$no_fullbright\" \"1\"\r\n\t\"$nolod\" \"1\"\r\n}"); + var entry = vpk.FindEntry("materials/console/background1.vmt"); + Assert.IsNotNull(entry); + Assert.AreEqual(vpk.ReadEntryText("materials/console/background1.vmt"), "\"UnlitGeneric\"\r\n{\r\n\t\"$basetexture\" \"console/background1\"\r\n\t\"$vertexcolor\" 1\r\n\t\"$vertexalpha\" 1\r\n\t\"$ignorez\" 1\r\n\t\"$no_fullbright\" \"1\"\r\n\t\"$nolod\" \"1\"\r\n}"); - Assert.IsFalse(vpk.ReadOnly); + Assert.IsFalse(vpk.ReadOnly); - Assert.AreEqual(vpk.GetEntryCount(), 3509u); + Assert.AreEqual(vpk.GetEntryCount(), 3509u); - Assert.AreEqual(vpk.FilePath, BasePortalPath + "portal_pak_dir.vpk"); - Assert.AreEqual(vpk.TruncatedFilePath, BasePortalPath + "portal_pak"); - Assert.AreEqual(vpk.FileName, "portal_pak_dir.vpk"); - Assert.AreEqual(vpk.TruncatedFileName, "portal_pak.vpk"); - Assert.AreEqual(vpk.FileStem, "portal_pak_dir"); - Assert.AreEqual(vpk.TruncatedFileStem, "portal_pak"); - Assert.AreEqual(vpk.SupportedEntryAttributes, Attribute.LENGTH | Attribute.VPK_PRELOADED_DATA | Attribute.ARCHIVE_INDEX | Attribute.CRC32); - Assert.AreEqual(vpk.ToString(), "portal_pak.vpk | Version v2"); - } + Assert.AreEqual(vpk.FilePath, BasePortalPath + "portal_pak_dir.vpk"); + Assert.AreEqual(vpk.TruncatedFilePath, BasePortalPath + "portal_pak"); + Assert.AreEqual(vpk.FileName, "portal_pak_dir.vpk"); + Assert.AreEqual(vpk.TruncatedFileName, "portal_pak.vpk"); + Assert.AreEqual(vpk.FileStem, "portal_pak_dir"); + Assert.AreEqual(vpk.TruncatedFileStem, "portal_pak"); + Assert.AreEqual(vpk.SupportedEntryAttributes, Attribute.LENGTH | Attribute.VPK_PRELOADED_DATA | Attribute.ARCHIVE_INDEX | Attribute.CRC32); + Assert.AreEqual(vpk.ToString(), "portal_pak.vpk | Version v2"); + } - [TestMethod] - public void VerifyChecksums() - { - var vpk = PackFile.Open(BasePortalPath + "portal_pak_dir.vpk"); - Assert.IsNotNull(vpk); - Assert.AreEqual(vpk.VerifyEntryChecksums().Count(), 0); - Assert.IsTrue(vpk.VerifyPackFileChecksum()); - } + [TestMethod] + public void VerifyChecksums() + { + var vpk = PackFile.Open(BasePortalPath + "portal_pak_dir.vpk"); + Assert.IsNotNull(vpk); + Assert.AreEqual(vpk.VerifyEntryChecksums().Count(), 0); + Assert.IsTrue(vpk.VerifyPackFileChecksum()); + } - [TestMethod] - public void GetSupportedFileTypes() - { - Assert.AreEqual(PackFile.GetSupportedFileTypes().Count, 12); - } + [TestMethod] + public void GetVPKVersion() + { + var vpk = Format.VPK.Open(BasePortalPath + "portal_pak_dir.vpk"); + Assert.IsNotNull(vpk); + Assert.AreEqual(vpk.Version, 2u); + } - [TestMethod] - public void GetVPKVersion() - { - var vpk = Format.VPK.Open(BasePortalPath + "portal_pak_dir.vpk"); - Assert.IsNotNull(vpk); - Assert.AreEqual(vpk.Version, 2u); - } - - private static string BasePortalPath - { - get - { - if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) - { - return @"D:\SteamLibrary\steamapps\common\Portal\portal\"; - } - if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) - { - return Environment.GetEnvironmentVariable("HOME") + "/.steam/steam/steamapps/common/Portal/portal/"; - } - throw new FileLoadException("Unable to find Steam install directory!"); - } - } - } + private static string BasePortalPath + { + get + { + if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) + { + return @"D:\SteamLibrary\steamapps\common\Portal\portal\"; + } + if (RuntimeInformation.IsOSPlatform(OSPlatform.Linux)) + { + return Environment.GetEnvironmentVariable("HOME") + "/.steam/steam/steamapps/common/Portal/portal/"; + } + throw new FileLoadException("Unable to find Steam install directory!"); + } + } + } } diff --git a/src/vpkpp/PackFile.cpp b/src/vpkpp/PackFile.cpp index a68ecbf79..17bacef6b 100644 --- a/src/vpkpp/PackFile.cpp +++ b/src/vpkpp/PackFile.cpp @@ -14,7 +14,6 @@ // Need to include these so the compiler will think the automatic registry // variables are important enough to initialize :3 (I love C++!) -#include #include #include #include @@ -143,10 +142,6 @@ std::vector PackFile::getOpenableExtensions() { return out; } -PackFileType PackFile::getType() const { - return this->type; -} - std::vector PackFile::verifyEntryChecksums() const { return {}; } diff --git a/src/vpkpp/_vpkpp.cmake b/src/vpkpp/_vpkpp.cmake index fd01fdf54..ec0f0d408 100644 --- a/src/vpkpp/_vpkpp.cmake +++ b/src/vpkpp/_vpkpp.cmake @@ -2,7 +2,6 @@ add_pretty_parser(vpkpp DEPS libzstd_static MINIZIP::minizip sourcepp_crypto sourcepp_parser sourcepp::bsppp sourcepp::kvpp DEPS_PUBLIC tsl::hat_trie PRECOMPILED_HEADERS - "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/BSP.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/FPX.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/GCF.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/format/GMA.h" @@ -17,10 +16,8 @@ add_pretty_parser(vpkpp "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/Entry.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/Options.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/PackFile.h" - "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/PackFileType.h" "${CMAKE_CURRENT_SOURCE_DIR}/include/vpkpp/vpkpp.h" SOURCES - "${CMAKE_CURRENT_LIST_DIR}/format/BSP.cpp" "${CMAKE_CURRENT_LIST_DIR}/format/FPX.cpp" "${CMAKE_CURRENT_LIST_DIR}/format/GCF.cpp" "${CMAKE_CURRENT_LIST_DIR}/format/GMA.cpp" diff --git a/src/vpkpp/format/BSP.cpp b/src/vpkpp/format/BSP.cpp deleted file mode 100644 index a0c11b928..000000000 --- a/src/vpkpp/format/BSP.cpp +++ /dev/null @@ -1,128 +0,0 @@ -#include - -#include - -#include -#include -#include -#include -#include -#include - -using namespace sourcepp; -using namespace vpkpp; - -using bsppp::BSPLump; - -BSP::BSP(const std::string& fullFilePath_) - : ZIP(fullFilePath_) - , tempPakLumpPath((std::filesystem::temp_directory_path() / (string::generateUUIDv4() + ".zip")).string()) { - this->type = PackFileType::BSP; -} - -BSP::~BSP() { - // Pull this in from the ZIP dtor, have to do it before deleting the file - this->closeZIP(); - std::filesystem::remove(this->tempPakLumpPath); -} - -std::unique_ptr BSP::open(const std::string& path, const EntryCallback& callback) { - if (!std::filesystem::exists(path)) { - // File does not exist - return nullptr; - } - - auto* bsp = new BSP{path}; - auto packFile = std::unique_ptr(bsp); - - { - bsppp::BSP reader{path}; - if (!reader) { - // File failed to load, or has an invalid signature - return nullptr; - } - - bsp->version = reader.getVersion(); - bsp->mapRevision = reader.getMapRevision(); - - if (auto pakFileLump = reader.readLump(BSPLump::PAKFILE)) { - // Extract the paklump to a temp file - FileStream writer{bsp->tempPakLumpPath, FileStream::OPT_TRUNCATE | FileStream::OPT_CREATE_IF_NONEXISTENT}; - writer.write(*pakFileLump); - } else { - // No paklump, create an empty zip - if (!ZIP::create(bsp->tempPakLumpPath)) { - return nullptr; - } - } - } - - if (!bsp->openZIP(bsp->tempPakLumpPath)) { - return nullptr; - } - - for (auto code = mz_zip_goto_first_entry(bsp->zipHandle); code == MZ_OK; code = mz_zip_goto_next_entry(bsp->zipHandle)) { - mz_zip_file* fileInfo = nullptr; - if (mz_zip_entry_get_info(bsp->zipHandle, &fileInfo)) { - return nullptr; - } - if (mz_zip_entry_is_dir(bsp->zipHandle) == MZ_OK) { - continue; - } - - auto entryPath = bsp->cleanEntryPath(fileInfo->filename); - - Entry entry = createNewEntry(); - entry.flags = fileInfo->compression_method; - entry.length = fileInfo->uncompressed_size; - entry.compressedLength = fileInfo->compressed_size; - - bsp->entries.emplace(entryPath, entry); - - if (callback) { - callback(entryPath, entry); - } - } - - return packFile; -} - -bool BSP::bake(const std::string& outputDir_, BakeOptions options, const EntryCallback& callback) { - // Get the proper file output folder - const std::string outputDir = this->getBakeOutputDir(outputDir_); - const std::string outputPath = outputDir + '/' + this->getFilename(); - - // If the output path is different, copy the entire BSP there - if (outputPath != this->fullFilePath) { - std::filesystem::copy_file(this->fullFilePath, outputPath, std::filesystem::copy_options::overwrite_existing); - PackFile::setFullFilePath(outputDir); - } - - // Use temp folder so we can read from the current ZIP - if (!this->bakeTempZip(this->tempZIPPath, options, callback)) { - return false; - } - this->mergeUnbakedEntries(); - - // Close the ZIP - this->closeZIP(); - - // Write the new lump - { - bsppp::BSP writer{this->fullFilePath}; - if (!writer) { - return false; - } - writer.writeLump(BSPLump::PAKFILE, fs::readFileBuffer(this->tempZIPPath), false); - } - - // Rename and reopen the ZIP - std::filesystem::rename(this->tempZIPPath, this->tempPakLumpPath); - return this->openZIP(this->tempPakLumpPath); -} - -BSP::operator std::string() const { - return PackFile::operator std::string() + - " | Version v" + std::to_string(this->version) + - " | Map Revision " + std::to_string(this->mapRevision); -} diff --git a/src/vpkpp/format/FPX.cpp b/src/vpkpp/format/FPX.cpp index 594a9a781..bff7adcd4 100644 --- a/src/vpkpp/format/FPX.cpp +++ b/src/vpkpp/format/FPX.cpp @@ -7,11 +7,6 @@ using namespace sourcepp; using namespace vpkpp; -FPX::FPX(const std::string& fullFilePath_) - : VPK(fullFilePath_) { - this->type = PackFileType::FPX; -} - std::unique_ptr FPX::create(const std::string& path) { { FileStream stream{path, FileStream::OPT_TRUNCATE | FileStream::OPT_CREATE_IF_NONEXISTENT}; diff --git a/src/vpkpp/format/GCF.cpp b/src/vpkpp/format/GCF.cpp index b1bacb5bd..efe36915d 100644 --- a/src/vpkpp/format/GCF.cpp +++ b/src/vpkpp/format/GCF.cpp @@ -10,11 +10,6 @@ using namespace sourcepp; using namespace vpkpp; -GCF::GCF(const std::string& fullFilePath_) - : PackFileReadOnly(fullFilePath_) { - this->type = PackFileType::GCF; -} - std::unique_ptr GCF::open(const std::string& path, const EntryCallback& callback) { // TODO: Add v5 and perhaps v4 support diff --git a/src/vpkpp/format/GMA.cpp b/src/vpkpp/format/GMA.cpp index 67bf35896..3f7e0821c 100644 --- a/src/vpkpp/format/GMA.cpp +++ b/src/vpkpp/format/GMA.cpp @@ -9,11 +9,6 @@ using namespace sourcepp; using namespace vpkpp; -GMA::GMA(const std::string& fullFilePath_) - : PackFile(fullFilePath_) { - this->type = PackFileType::GMA; -} - std::unique_ptr GMA::open(const std::string& path, const EntryCallback& callback) { if (!std::filesystem::exists(path)) { // File does not exist diff --git a/src/vpkpp/format/ORE.cpp b/src/vpkpp/format/ORE.cpp index d1f7fec41..0cb338f4d 100644 --- a/src/vpkpp/format/ORE.cpp +++ b/src/vpkpp/format/ORE.cpp @@ -7,11 +7,6 @@ using namespace sourcepp; using namespace vpkpp; -ORE::ORE(const std::string& fullFilePath_) - : PackFileReadOnly(fullFilePath_) { - this->type = PackFileType::ORE; -} - std::unique_ptr ORE::create(const std::string& path) { { FileStream stream{path, FileStream::OPT_TRUNCATE | FileStream::OPT_CREATE_IF_NONEXISTENT}; diff --git a/src/vpkpp/format/PAK.cpp b/src/vpkpp/format/PAK.cpp index a696879de..b50789d46 100644 --- a/src/vpkpp/format/PAK.cpp +++ b/src/vpkpp/format/PAK.cpp @@ -7,11 +7,6 @@ using namespace sourcepp; using namespace vpkpp; -PAK::PAK(const std::string& fullFilePath_) - : PackFile(fullFilePath_) { - this->type = PackFileType::PAK; -} - std::unique_ptr PAK::create(const std::string& path) { { FileStream stream{path, FileStream::OPT_TRUNCATE | FileStream::OPT_CREATE_IF_NONEXISTENT}; diff --git a/src/vpkpp/format/PCK.cpp b/src/vpkpp/format/PCK.cpp index 0c74a5b83..620d6c756 100644 --- a/src/vpkpp/format/PCK.cpp +++ b/src/vpkpp/format/PCK.cpp @@ -12,11 +12,6 @@ using namespace vpkpp; constexpr int PCK_DIRECTORY_STRING_PADDING = 4; constexpr int PCK_FILE_DATA_PADDING = 16; -PCK::PCK(const std::string& fullFilePath_) - : PackFile(fullFilePath_) { - this->type = PackFileType::PCK; -} - std::unique_ptr PCK::create(const std::string& path, uint32_t version, uint32_t godotMajorVersion, uint32_t godotMinorVersion, uint32_t godotPatchVersion) { if (version != 1 && version != 2) { return nullptr; diff --git a/src/vpkpp/format/VPK.cpp b/src/vpkpp/format/VPK.cpp index a5ea5ee80..a288772ba 100644 --- a/src/vpkpp/format/VPK.cpp +++ b/src/vpkpp/format/VPK.cpp @@ -44,16 +44,11 @@ std::string removeVPKAndOrDirSuffix(const std::string& path, bool isFPX) { } bool isFPX(const VPK* vpk) { - return vpk->getType() == PackFileType::FPX; + return vpk->isInstanceOf(); } } // namespace -VPK::VPK(const std::string& fullFilePath_) - : PackFile(fullFilePath_) { - this->type = PackFileType::VPK; -} - std::unique_ptr VPK::create(const std::string& path, uint32_t version) { if (version != 0 && version != 1 && version != 2 && version != 54) { return nullptr; @@ -443,7 +438,7 @@ void VPK::addEntryInternal(Entry& entry, const std::string& path, std::vector 0) { - const auto clampedPreloadBytes = std::clamp(options.vpk_preloadBytes, 0u, buffer.size() > VPK_MAX_PRELOAD_BYTES ? VPK_MAX_PRELOAD_BYTES : static_cast(buffer.size())); + const auto clampedPreloadBytes = std::clamp(options.vpk_preloadBytes, 0, buffer.size() > VPK_MAX_PRELOAD_BYTES ? VPK_MAX_PRELOAD_BYTES : static_cast(buffer.size())); entry.extraData.resize(clampedPreloadBytes); std::memcpy(entry.extraData.data(), buffer.data(), clampedPreloadBytes); buffer.erase(buffer.begin(), buffer.begin() + clampedPreloadBytes); diff --git a/src/vpkpp/format/VPK_VTMB.cpp b/src/vpkpp/format/VPK_VTMB.cpp index fac822986..5a34f156d 100644 --- a/src/vpkpp/format/VPK_VTMB.cpp +++ b/src/vpkpp/format/VPK_VTMB.cpp @@ -9,11 +9,6 @@ using namespace sourcepp; using namespace vpkpp; -VPK_VTMB::VPK_VTMB(const std::string& fullFilePath_) - : PackFile(fullFilePath_) { - this->type = PackFileType::VPK_VTMB; -} - std::unique_ptr VPK_VTMB::create(const std::string& path) { { FileStream stream{path, FileStream::OPT_TRUNCATE | FileStream::OPT_CREATE_IF_NONEXISTENT}; diff --git a/src/vpkpp/format/WAD3.cpp b/src/vpkpp/format/WAD3.cpp index 91525ff81..2e4797dcf 100644 --- a/src/vpkpp/format/WAD3.cpp +++ b/src/vpkpp/format/WAD3.cpp @@ -49,11 +49,6 @@ constexpr std::string_view k_FileTypeNames[] = { "font", }; -WAD3::WAD3(const std::string& fullFilePath_) - : PackFile(fullFilePath_) { - this->type = PackFileType::WAD3; -} - std::unique_ptr WAD3::create(const std::string& path) { FileStream stream{path, FileStream::OPT_TRUNCATE | FileStream::OPT_CREATE_IF_NONEXISTENT}; stream diff --git a/src/vpkpp/format/ZIP.cpp b/src/vpkpp/format/ZIP.cpp index 620d26bb9..fa8a23df8 100644 --- a/src/vpkpp/format/ZIP.cpp +++ b/src/vpkpp/format/ZIP.cpp @@ -20,9 +20,7 @@ using namespace vpkpp; ZIP::ZIP(const std::string& fullFilePath_) : PackFile(fullFilePath_) - , tempZIPPath((std::filesystem::temp_directory_path() / (string::generateUUIDv4() + ".zip")).string()) { - this->type = PackFileType::ZIP; -} + , tempZIPPath((std::filesystem::temp_directory_path() / (string::generateUUIDv4() + ".zip")).string()) {} ZIP::~ZIP() { this->closeZIP(); @@ -165,15 +163,15 @@ void ZIP::setEntryCompressionType(const std::string& path_, EntryCompressionType } } -uint16_t ZIP::getEntryCompressionStrength(const std::string& path_) const { +int16_t ZIP::getEntryCompressionStrength(const std::string& path_) const { const auto path = this->cleanEntryPath(path_); if (this->entries.count(path)) { - return static_cast(this->entries.at(path).flags & 0xffff); + return static_cast(this->entries.at(path).flags & 0xffff); } return 0; } -void ZIP::setEntryCompressionStrength(const std::string& path_, uint16_t strength) { +void ZIP::setEntryCompressionStrength(const std::string& path_, int16_t strength) { const auto path = this->cleanEntryPath(path_); if (this->entries.count(path)) { this->entries.at(path).flags = (this->entries.at(path).flags & 0xffff0000) | strength; diff --git a/src/vpkpp/format/example/ExamplePackFileImpl.cpp b/src/vpkpp/format/example/ExamplePackFileImpl.cpp index 470b47166..8e11bb5d1 100644 --- a/src/vpkpp/format/example/ExamplePackFileImpl.cpp +++ b/src/vpkpp/format/example/ExamplePackFileImpl.cpp @@ -8,12 +8,6 @@ using namespace sourcepp; using namespace vpkpp; -EXAMPLE::EXAMPLE(const std::string& fullFilePath_) - : PackFile(fullFilePath_) { - // Add a new type in the PackFileType enum for this file type, and set it here - this->type = PackFileType::UNKNOWN; -} - std::unique_ptr EXAMPLE::open(const std::string& path, const EntryCallback& callback) { // Check if the file exists if (!std::filesystem::exists(path)) { diff --git a/src/vpkpp/format/example/ExamplePackFileImpl.h b/src/vpkpp/format/example/ExamplePackFileImpl.h index a08649f44..b637dbb62 100644 --- a/src/vpkpp/format/example/ExamplePackFileImpl.h +++ b/src/vpkpp/format/example/ExamplePackFileImpl.h @@ -25,6 +25,14 @@ class EXAMPLE : public PackFile { // Always return a unique_ptr to PackFile so it has a uniform return type [[nodiscard]] static std::unique_ptr open(const std::string& path, const EntryCallback& callback = nullptr); + // Use a site like https://guidgenerator.com/ to generate a GUID - don't copypaste this one!!! + static constexpr inline std::string_view GUID = "9F389AF190E74D3DA472C5AA4B881F83"; + + // Necessary to identify the type of the pack file + [[nodiscard]] constexpr std::string_view getGUID() const noexcept override { + return EXAMPLE::GUID; + } + // [OPTIONAL] Implement this and return true if your file format is case-sensitive [[nodiscard]] constexpr bool isCaseSensitive() const noexcept override { return PackFile::isCaseSensitive(); @@ -47,7 +55,7 @@ class EXAMPLE : public PackFile { } protected: - explicit EXAMPLE(const std::string& fullFilePath_); + using PackFile::PackFile; // [WRITE] Adds a new entry from either a filename or a buffer // Again, if your type needs any new options specific to entries, add them to EntryOptions