From 608e382095a723eb800d2f3838d9cf884d72da33 Mon Sep 17 00:00:00 2001 From: yanczi Date: Sun, 21 Dec 2025 11:49:30 +0100 Subject: [PATCH 1/2] Podmiana makr na globalne zmienne statyczne. Create cargo zmodyfikowane --- CreateCargo.cpp | 74 +++++++++++++++--------------------------------- CreateCargo.h | 14 +++++++-- DataStruct.h | 29 ++++++++++++++++--- ExtractCargo.cpp | 4 +-- ExtractCargo.h | 2 +- voidcmd.cpp | 12 +------- 6 files changed, 63 insertions(+), 72 deletions(-) diff --git a/CreateCargo.cpp b/CreateCargo.cpp index b1b97a9..adbddf5 100644 --- a/CreateCargo.cpp +++ b/CreateCargo.cpp @@ -20,8 +20,8 @@ #include "CreateCargo.h" CreateCargo::CreateCargo() - : signature(SIGNATURE) - , extension(EXTENSION) + : signature(fl::sigpak) + , extension(fl::extpak) , version(VERSION) , methodFlags(0) , xxhState(XXH64_createState()) @@ -42,7 +42,7 @@ CreateCargo::~CreateCargo() { //----------------------------------------------------------------------------- bool CreateCargo::Create(const std::string& path, const uint8_t& flag) { - cargoFile = path + "." + extension; + cargoFile = path + "." + signature; catalogPath = path; methodFlags = flag; @@ -90,7 +90,7 @@ bool CreateCargo::Create(const std::string& path, const uint8_t& flag) } // Zapisywanie klucza szyfrującego - if (flag == FILE_FLAG_ENCRYPT || flag == FILE_FLAG_ZIPENC || encList.size() > 0) + if (flag == flag::enc || flag == flag::ezd || encList.size() > 0) { eman.saveKey(catalogPath, hppKey); } @@ -185,42 +185,13 @@ CargoHead CreateCargo::CreateCargoHead(const uint32_t& filesLen, const uint64_t& { CargoHead ch; - ch.signature = signature; + ch.signature = fl::sigpak; ch.table = table; ch.files = filesLen; return ch; } -//----------------------------------------------------------------------------- -// Sprawdza czy plik znajduje się na liście -//----------------------------------------------------------------------------- -void CreateCargo::computingBytes(const uint8_t& flag, std::vector& input, std::vector& output) -{ - //Flaga aktywna sprawdza czy plik jest na liście. Jeśli jest to zwraca surowedane - //Przeciwnie kompresuje dane - ChunkManager cm(eman); - - switch (flag) - { - case FILE_FLAG_COMPRESS: - output = cm.chunked(input, true, false); - break; - - case FILE_FLAG_ENCRYPT: - output = cm.chunked(input, false, true); - break; - - case FILE_FLAG_ZIPENC: - output = cm.chunked(input, true, true); - break; - - default: - output = std::move(input); - break; - } -} - //----------------------------------------------------------------------------- // Przygotowanie nagłówków i plików //----------------------------------------------------------------------------- @@ -249,26 +220,26 @@ std::vector CreateCargo::ComputingHeadFiles() size_t size = f.tellg(); f.seekg(0, std::ios::beg); - if (size > MAX_FILE_SIZE) + if (size > ds::maxFileSize) { - std::cerr << path << " is too large. It exceeds " << MAX_FILE_SIZE / 1024 / 1024 / 1024 << "GB!" << std::endl; + std::cerr << path << " is too large. It exceeds " << ds::maxFileSize / 1024 / 1024 / 1024 << "GB!" << std::endl; } else { XXH64_reset(xxhState, 0); //Wczytanie pliku do pamięci - std::vector buffer(CHUNK_STREAM_256MB); + std::vector buffer(ds::chunk_stream); uint64_t sizeFile = 0; - const uint32_t chunkBlockSize = CHUNK_BLOCK_SIZE; + const uint32_t chunkBlockSize = ds::block_size; const uint32_t quantity = (size + chunkBlockSize) / chunkBlockSize; const uint32_t lastChunkSize = size - (chunkBlockSize * (quantity - 1)); // Jeśli jest ustawiona flaga inna niż RAW // Dodaj do kontenera konfigurację chunków - if (file.parameter != FILE_FLAG_RAW) + if (file.parameter != flag::raw) { std::cout << "CHUNK PARAM" << std::endl; cargo.write(reinterpret_cast(&quantity), sizeof(quantity)); @@ -278,7 +249,7 @@ std::vector CreateCargo::ComputingHeadFiles() } // Strumieniowanie danych - while (f.read(buffer.data(), CHUNK_STREAM_256MB) || f.gcount() > 0) + while (f.read(buffer.data(), ds::chunk_stream) || f.gcount() > 0) { const int bufferSize = f.gcount(); buffer.resize(bufferSize); @@ -286,7 +257,7 @@ std::vector CreateCargo::ComputingHeadFiles() // Aktualizacja XXH64 XXH64_update(xxhState, buffer.data(), buffer.size()); - if (file.parameter == FILE_FLAG_RAW) + if (file.parameter == flag::raw) { // Zapisywanie strumienia do kontenera cargo.write(reinterpret_cast(buffer.data()), buffer.size()); @@ -308,16 +279,16 @@ std::vector CreateCargo::ComputingHeadFiles() std::vector outChunk; // Przetwórz chunki i przetwórz - if ((file.parameter & FILE_FLAG_COMPRESS) == FILE_FLAG_COMPRESS) + if ((file.parameter & flag::zip) == flag::zip) { // Zaszyfruj i skompresuj lub tylko skompresuj - outChunk = (file.parameter & FILE_FLAG_ENCRYPT) == FILE_FLAG_ENCRYPT ? + outChunk = (file.parameter & flag::enc) == flag::enc ? eman.encrypt(cman.compress(chunk)) : cman.compress(chunk); } else { // Zaszyfruj lub skopiuj - outChunk = (file.parameter & FILE_FLAG_ENCRYPT) == FILE_FLAG_ENCRYPT ? + outChunk = (file.parameter & flag::enc) == flag::enc ? eman.encrypt(cman.compress(chunk)) : cman.compress(chunk); } @@ -373,24 +344,25 @@ void CreateCargo::GetFilters(const std::string& filterFile) file.close(); // Lista plików do skompresowania - if (jslist.contains(KEY_ZIP)) + if (jslist.contains(key::zip)) { - zipList = jslist[KEY_ZIP].get>(); + zipList = jslist[key::zip].get>(); } // Lista plików do zaszyfrowania - if (jslist.contains(KEY_ENCRYPT)) + if (jslist.contains(key::enc)) { - encList = jslist[KEY_ENCRYPT].get>(); + encList = jslist[key::enc].get>(); } // Lista plików do pominięcia - if (jslist.contains(KEY_IGNORE)) + if (jslist.contains(key::ignore)) { - ignoreList = jslist[KEY_IGNORE].get>(); + ignoreList = jslist[key::ignore].get>(); } - hppKey = jslist.value("keyhpp", false); + // Flaga tworzenia klucza jako plik nagłówka c++ + hppKey = jslist.value(key::hpp, false); } //----------------------------------------------------------------------------- diff --git a/CreateCargo.h b/CreateCargo.h index e31b3e6..3879779 100644 --- a/CreateCargo.h +++ b/CreateCargo.h @@ -45,6 +45,17 @@ #define ALL_FILE ".*" // Wszystkie pliki +namespace key +{ + inline constexpr std::string_view zip = "compress"; + inline constexpr std::string_view raw = "raw"; + inline constexpr std::string_view enc = "encrypt"; + inline constexpr std::string_view ignore = "ignore"; + inline constexpr std::string_view all = ".*"; + + inline constexpr std::string_view hpp = "keyhpp"; +} + struct PathConf { std::string path; @@ -113,9 +124,6 @@ private: // Wczytanie filtrów wyjątków void GetFilters(const std::string&); - // Sprawdza czy plik znajduje się na liście - void computingBytes(const uint8_t&, std::vector&, std::vector&); - // Sprawdzanie rozszeżeń plików bool CheckFileExtension(const std::string&, const std::vector&); diff --git a/DataStruct.h b/DataStruct.h index 5a17980..9f3c655 100644 --- a/DataStruct.h +++ b/DataStruct.h @@ -44,7 +44,6 @@ #define FILE_FLAG_FILTERING 0xAB - //Prgoram title #define PROGRAM_TITLE "eXtendet PAK" #define PROGRAM_VERSION "v0.5" @@ -52,9 +51,31 @@ #define PROGRAM_COMPILING "19 December 2025" #define PROGRAM_LICENSE "GNU LGPL v3" -//Limity -#define MAX_FILE_SIZE 8589934592 // 8GB -#define MAX_PAK_SIZE 8796093022208 // 8TB +namespace fl { + inline constexpr std::string_view sigpak = "XPAK"; + inline constexpr std::string_view sigkey = "XKEY"; + + inline constexpr std::string_view extpak = "pak"; + inline constexpr std::string_view extkey = "key"; +} + +namespace ds +{ + inline constexpr int chunk_stream = 268435456; + inline constexpr int block_size = 131072; + + inline constexpr int maxFileSize = 8589934592; +} + +namespace flag +{ + inline constexpr uint8_t raw = 0x00; + inline constexpr uint8_t zip = 0x0F; + inline constexpr uint8_t enc = 0xF0; + inline constexpr uint8_t ezd = 0xFF; + + inline constexpr uint8_t filter = 0xAB; +} struct CargoHead { diff --git a/ExtractCargo.cpp b/ExtractCargo.cpp index c59d8d8..83f53a5 100644 --- a/ExtractCargo.cpp +++ b/ExtractCargo.cpp @@ -22,11 +22,11 @@ ExtractCargo::ExtractCargo() :filesLen(0) , tablePosition(0) - , version(VERSION) + , xxhState(XXH64_createState()) , signature(SIGNATURE) { // TODO Auto-generated constructor stub - + XXH64_reset(xxhState, 0); } ExtractCargo::~ExtractCargo() diff --git a/ExtractCargo.h b/ExtractCargo.h index 9ee7e1f..3cab45c 100644 --- a/ExtractCargo.h +++ b/ExtractCargo.h @@ -47,8 +47,8 @@ private: uint32_t filesLen; uint64_t tablePosition; + XXH64_state_t* xxhState; - const int8_t version; const std::string signature; std::vector filesHeads; diff --git a/voidcmd.cpp b/voidcmd.cpp index 1ba9020..eb20331 100644 --- a/voidcmd.cpp +++ b/voidcmd.cpp @@ -82,17 +82,7 @@ static bool EmptyPath(std::string path) int main(int argc, char* argv[]) { std::string path = ""; - std::cout << - " 8888888b. d8888 888 d8P \n" - " 888 Y88b d88888 888 d8P \n" - " 888 888 d88P888 888 d8P \n" - " .d88b. 888 888 888 d88P d88P 888 888d88K \n" - "d8P Y8b `Y8bd8P' 8888888P\" d88P 888 8888888b \n" - "88888888 X88K 888 d88P 888 888 Y88b \n" - "Y8b. .d8\"\"8b. 888 d8888888888 888 Y88b \n" - " \"Y8888 888 888 888 d88P 888 888 Y88b\n" - << std::endl; - std::cout << "\n" << PROGRAM_VERSION << " Release " << PROGRAM_COMPILING << std::endl; + std::cout << PROGRAM_VERSION << " Release " << PROGRAM_COMPILING << std::endl; std::cout << "Author: " << PROGRAM_AUTHOR << std::endl; std::cout << "License: " << PROGRAM_LICENSE << "\n" << std::endl; From c2bdcfe2b9e781662ef5d883128cd5cf8d4326f5 Mon Sep 17 00:00:00 2001 From: yanczi Date: Sun, 21 Dec 2025 11:54:10 +0100 Subject: [PATCH 2/2] Komentarze --- DataStruct.h | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/DataStruct.h b/DataStruct.h index 9f3c655..af4da80 100644 --- a/DataStruct.h +++ b/DataStruct.h @@ -51,6 +51,7 @@ #define PROGRAM_COMPILING "19 December 2025" #define PROGRAM_LICENSE "GNU LGPL v3" +// Pliki namespace fl { inline constexpr std::string_view sigpak = "XPAK"; inline constexpr std::string_view sigkey = "XKEY"; @@ -59,21 +60,28 @@ namespace fl { inline constexpr std::string_view extkey = "key"; } +// Size namespace ds { - inline constexpr int chunk_stream = 268435456; - inline constexpr int block_size = 131072; + // Chunki streamowania + inline constexpr int chunk_stream = 268435456; // 256MB - inline constexpr int maxFileSize = 8589934592; + // Blok chunków + inline constexpr int block_size = 131072; // 128KB + + // Maksymalny rozmiar pliku do spakowania + inline constexpr int maxFileSize = 8589934592; // 8GB } +// Flagi namespace flag { - inline constexpr uint8_t raw = 0x00; - inline constexpr uint8_t zip = 0x0F; - inline constexpr uint8_t enc = 0xF0; - inline constexpr uint8_t ezd = 0xFF; + inline constexpr uint8_t raw = 0x00; // Surowy plik + inline constexpr uint8_t zip = 0x0F; // Kompresja + inline constexpr uint8_t enc = 0xF0; // Szyfrowanie + inline constexpr uint8_t ezd = 0xFF; // Kompresja z szyfrowaniem + // Flaga do aktywacji filtra zdefiniowanego w json inline constexpr uint8_t filter = 0xAB; }