diff --git a/CreateCargo.cpp b/CreateCargo.cpp index adbddf5..b1b97a9 100644 --- a/CreateCargo.cpp +++ b/CreateCargo.cpp @@ -20,8 +20,8 @@ #include "CreateCargo.h" CreateCargo::CreateCargo() - : signature(fl::sigpak) - , extension(fl::extpak) + : signature(SIGNATURE) + , extension(EXTENSION) , 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 + "." + signature; + cargoFile = path + "." + extension; 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 == flag::enc || flag == flag::ezd || encList.size() > 0) + if (flag == FILE_FLAG_ENCRYPT || flag == FILE_FLAG_ZIPENC || encList.size() > 0) { eman.saveKey(catalogPath, hppKey); } @@ -185,13 +185,42 @@ CargoHead CreateCargo::CreateCargoHead(const uint32_t& filesLen, const uint64_t& { CargoHead ch; - ch.signature = fl::sigpak; + ch.signature = signature; 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 //----------------------------------------------------------------------------- @@ -220,26 +249,26 @@ std::vector CreateCargo::ComputingHeadFiles() size_t size = f.tellg(); f.seekg(0, std::ios::beg); - if (size > ds::maxFileSize) + if (size > MAX_FILE_SIZE) { - std::cerr << path << " is too large. It exceeds " << ds::maxFileSize / 1024 / 1024 / 1024 << "GB!" << std::endl; + std::cerr << path << " is too large. It exceeds " << MAX_FILE_SIZE / 1024 / 1024 / 1024 << "GB!" << std::endl; } else { XXH64_reset(xxhState, 0); //Wczytanie pliku do pamięci - std::vector buffer(ds::chunk_stream); + std::vector buffer(CHUNK_STREAM_256MB); uint64_t sizeFile = 0; - const uint32_t chunkBlockSize = ds::block_size; + const uint32_t chunkBlockSize = CHUNK_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 != flag::raw) + if (file.parameter != FILE_FLAG_RAW) { std::cout << "CHUNK PARAM" << std::endl; cargo.write(reinterpret_cast(&quantity), sizeof(quantity)); @@ -249,7 +278,7 @@ std::vector CreateCargo::ComputingHeadFiles() } // Strumieniowanie danych - while (f.read(buffer.data(), ds::chunk_stream) || f.gcount() > 0) + while (f.read(buffer.data(), CHUNK_STREAM_256MB) || f.gcount() > 0) { const int bufferSize = f.gcount(); buffer.resize(bufferSize); @@ -257,7 +286,7 @@ std::vector CreateCargo::ComputingHeadFiles() // Aktualizacja XXH64 XXH64_update(xxhState, buffer.data(), buffer.size()); - if (file.parameter == flag::raw) + if (file.parameter == FILE_FLAG_RAW) { // Zapisywanie strumienia do kontenera cargo.write(reinterpret_cast(buffer.data()), buffer.size()); @@ -279,16 +308,16 @@ std::vector CreateCargo::ComputingHeadFiles() std::vector outChunk; // Przetwórz chunki i przetwórz - if ((file.parameter & flag::zip) == flag::zip) + if ((file.parameter & FILE_FLAG_COMPRESS) == FILE_FLAG_COMPRESS) { // Zaszyfruj i skompresuj lub tylko skompresuj - outChunk = (file.parameter & flag::enc) == flag::enc ? + outChunk = (file.parameter & FILE_FLAG_ENCRYPT) == FILE_FLAG_ENCRYPT ? eman.encrypt(cman.compress(chunk)) : cman.compress(chunk); } else { // Zaszyfruj lub skopiuj - outChunk = (file.parameter & flag::enc) == flag::enc ? + outChunk = (file.parameter & FILE_FLAG_ENCRYPT) == FILE_FLAG_ENCRYPT ? eman.encrypt(cman.compress(chunk)) : cman.compress(chunk); } @@ -344,25 +373,24 @@ 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::enc)) + if (jslist.contains(KEY_ENCRYPT)) { - encList = jslist[key::enc].get>(); + encList = jslist[KEY_ENCRYPT].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>(); } - // Flaga tworzenia klucza jako plik nagłówka c++ - hppKey = jslist.value(key::hpp, false); + hppKey = jslist.value("keyhpp", false); } //----------------------------------------------------------------------------- diff --git a/CreateCargo.h b/CreateCargo.h index 3879779..e31b3e6 100644 --- a/CreateCargo.h +++ b/CreateCargo.h @@ -45,17 +45,6 @@ #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; @@ -124,6 +113,9 @@ 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 af4da80..5a17980 100644 --- a/DataStruct.h +++ b/DataStruct.h @@ -44,6 +44,7 @@ #define FILE_FLAG_FILTERING 0xAB + //Prgoram title #define PROGRAM_TITLE "eXtendet PAK" #define PROGRAM_VERSION "v0.5" @@ -51,39 +52,9 @@ #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"; - - inline constexpr std::string_view extpak = "pak"; - inline constexpr std::string_view extkey = "key"; -} - -// Size -namespace ds -{ - // Chunki streamowania - inline constexpr int chunk_stream = 268435456; // 256MB - - // 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; // 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; -} +//Limity +#define MAX_FILE_SIZE 8589934592 // 8GB +#define MAX_PAK_SIZE 8796093022208 // 8TB struct CargoHead { diff --git a/ExtractCargo.cpp b/ExtractCargo.cpp index 83f53a5..c59d8d8 100644 --- a/ExtractCargo.cpp +++ b/ExtractCargo.cpp @@ -22,11 +22,11 @@ ExtractCargo::ExtractCargo() :filesLen(0) , tablePosition(0) - , xxhState(XXH64_createState()) + , version(VERSION) , signature(SIGNATURE) { // TODO Auto-generated constructor stub - XXH64_reset(xxhState, 0); + } ExtractCargo::~ExtractCargo() diff --git a/ExtractCargo.h b/ExtractCargo.h index 3cab45c..9ee7e1f 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 eb20331..1ba9020 100644 --- a/voidcmd.cpp +++ b/voidcmd.cpp @@ -82,7 +82,17 @@ static bool EmptyPath(std::string path) int main(int argc, char* argv[]) { std::string path = ""; - std::cout << PROGRAM_VERSION << " Release " << PROGRAM_COMPILING << std::endl; + 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 << "Author: " << PROGRAM_AUTHOR << std::endl; std::cout << "License: " << PROGRAM_LICENSE << "\n" << std::endl;