From 8402ce1b65a2c445545d6731133283ca65a4b0e3 Mon Sep 17 00:00:00 2001 From: yanczi Date: Fri, 7 Nov 2025 16:38:19 +0100 Subject: [PATCH] =?UTF-8?q?Przeprawiona=20klasa=20tworzenia=20kontener?= =?UTF-8?q?=C3=B3w.=20Dodano=20funkcj=C4=99=20kt=C3=B3ra=20wygodnie=20dobi?= =?UTF-8?q?era=20odpowiednie=20dzia=C5=82anie=20dla=20danych?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- CreateCargo.cpp | 35 ++++++++-------- ExtractCargo.cpp | 30 ++++++++++++- ExtractCargo.h | 3 ++ {test3 => testx}/herrsher-of-the-void.png | Bin {test3 => testx}/mus_honkai_space.ogg | Bin {test3 => testx}/text_file.txt | 0 voidcmd.cpp | 49 +++++++++++++++------- 7 files changed, 84 insertions(+), 33 deletions(-) rename {test3 => testx}/herrsher-of-the-void.png (100%) rename {test3 => testx}/mus_honkai_space.ogg (100%) rename {test3 => testx}/text_file.txt (100%) diff --git a/CreateCargo.cpp b/CreateCargo.cpp index 0a426e5..5df0889 100644 --- a/CreateCargo.cpp +++ b/CreateCargo.cpp @@ -90,6 +90,12 @@ bool CreateCargo::Create(const std::string& path, int8_t flag) return false; } + // Zapisywanie klucza szyfrującego + if (flag == 2 || flag == 3) + { + crypt.saveKey(catalogPath); + } + return true; } @@ -171,30 +177,28 @@ void CreateCargo::computingBytes(const int8_t& flag, std::vector& input, s //Przeciwnie kompresuje dane CompressingManager cm; - // Kompresja - if (flag == 1) + switch (flag) { + case 1: std::cout << "COMPRESSING" << std::endl; output = cm.compress(input); - } + break; - // Szyfrowanie - if (flag == 2) - { + case 2: std::cout << "ENCRYPTION" << std::endl; output = crypt.encrypt(input); - } + break; - // Kompresja i szyfrowanie - if (flag == 3) - { + case 3: std::cout << "ZIP ENC" << std::endl; output = crypt.encrypt(cm.compress(input)); - } + break; - // Zwraca surowe dane - std::cout << "RAW" << std::endl; - output = std::move(input); + default: + std::cout << "RAW" << std::endl; + output = std::move(input); + break; + } } //----------------------------------------------------------------------------- @@ -478,9 +482,6 @@ bool CreateCargo::WriteCargo() cargo.close(); - // Zapisywanie klucza szyfrującego - //crypt.saveKey(catalogPath); - std::cout << "The container was successfully created! " << cargoFile << std::endl; return true; diff --git a/ExtractCargo.cpp b/ExtractCargo.cpp index bf4743b..6389f8f 100644 --- a/ExtractCargo.cpp +++ b/ExtractCargo.cpp @@ -132,6 +132,33 @@ bool ExtractCargo::HashValid(const std::vector& data, const uint64_t& crc) return true; } +//----------------------------------------------------------------------------- +// Magiczna funkcja do dekompresji i deszyfracji danych +//----------------------------------------------------------------------------- +void ExtractCargo::computingBytes(const std::vector& input, std::vector& output, const int8_t& flag) +{ + CompressingManager cm; + + switch (flag) + { + case 1: + output = cm.decompress(input); + break; + + case 2: + output = eman.decrypt(input); + break; + + case 3: + output = cm.decompress(eman.decrypt(input)); + break; + + default: + output = std::move(input); + break; + } +} + //----------------------------------------------------------------------------- // Pobieranie nagłówków plików //----------------------------------------------------------------------------- @@ -180,7 +207,8 @@ void ExtractCargo::ExtractingFilesFromCargo() cargoFile.read(buffor.data(), fh.size); - std::vector rawBuffor = fh.flag ? cm.decompress(buffor) : buffor; + std::vector rawBuffor; + computingBytes(buffor, rawBuffor, fh.size); if (!HashValid(rawBuffor, fh.crc)) { diff --git a/ExtractCargo.h b/ExtractCargo.h index 164a0fc..7107634 100644 --- a/ExtractCargo.h +++ b/ExtractCargo.h @@ -75,4 +75,7 @@ private: // Utwórz katalog void CreateDirections(std::filesystem::path); + // Magiczna funkcja do dekompresji i deszyfracji danych + void computingBytes(const std::vector&, std::vector&, const int8_t&); + }; diff --git a/test3/herrsher-of-the-void.png b/testx/herrsher-of-the-void.png similarity index 100% rename from test3/herrsher-of-the-void.png rename to testx/herrsher-of-the-void.png diff --git a/test3/mus_honkai_space.ogg b/testx/mus_honkai_space.ogg similarity index 100% rename from test3/mus_honkai_space.ogg rename to testx/mus_honkai_space.ogg diff --git a/test3/text_file.txt b/testx/text_file.txt similarity index 100% rename from test3/text_file.txt rename to testx/text_file.txt diff --git a/voidcmd.cpp b/voidcmd.cpp index 5908996..6fae4ef 100644 --- a/voidcmd.cpp +++ b/voidcmd.cpp @@ -40,33 +40,32 @@ void RenderHelp() const std::string HelpInstruction = "pakcmd \n" " \n" - " -c Pack and compress with LZ4 \n" - " -p Pack files from the specified directory \n" - " -e Pack and encrypted from the specified directory \n" - " -f Pack the files according to the guidelines given in the .txt \n" - " -s Pack and encrypted \n" - " -cs Pack and compress \n" + " \-c Compressing \n" + " \-r Raw files \n" + " \-e Encrypted \n" + " \-s Compressing and Encrypted \n" + " \-f Pack the files according to the guidelines given in the \.json \n" " \n" "Extracting: \n" " -x Extract files from the specified container \n" + " \n" + "Others: \n" " -ls List files stored in a container \n" " \n" - " \n" - ".txt \n" + ".json \n" " \n" "Keys: \n" " \n" - " {compress} - Compressing files \n" - " {crypt} - Encrypted files with ChaCha20 \n" + " {compress} - Compressing files \n" + " {crypt} - Encrypted files \n" " {ignore} - Ignoring concrete files \n" " \n" " /path/to/file.ext - Concrete file \n" " *.ext - All files with concrete extension \n" - " *.* - All files !NOT WORKING WITH {ignore} KEY! \n" - " \n"; + " *.* - All files !NOT WORKING WITH {ignore} KEY! \n"; - Interface tui; - tui.TextBorder(HelpTitle, HelpInstruction); + //Interface tui; + //tui.TextBorder(HelpTitle, HelpInstruction); } bool EmptyPath(std::string path) @@ -118,7 +117,7 @@ int main(int argc, char* argv[]) { i++; } - if (arg == "-p" && i + 1 < argc) + if (arg == "-r" && i + 1 < argc) { path = argv[i + 1]; if (!cargo.Create(path, 0)) @@ -128,6 +127,26 @@ int main(int argc, char* argv[]) { i++; } + if (arg == "-e" && i + 1 < argc) + { + path = argv[i + 1]; + if (!cargo.Create(path, 2)) + { + return 1; + } + i++; + } + + if (arg == "-s" && i + 1 < argc) + { + path = argv[i + 1]; + if (!cargo.Create(path, 3)) + { + return 1; + } + i++; + } + if (arg == "-f" && i + 1 < argc) { path = argv[i + 1];