diff --git a/CreateCargo.cpp b/CreateCargo.cpp index 35c6a2b..cac09a2 100644 --- a/CreateCargo.cpp +++ b/CreateCargo.cpp @@ -20,11 +20,10 @@ #include "CreateCargo.h" CreateCargo::CreateCargo() - :compressingFlag(false) - , filteringFlag(false) - , signature(SIGNATURE) + : signature(SIGNATURE) , extension(EXTENSION) , version(VERSION) + , methodFlags(0) , offset(0) { // TODO Auto-generated constructor stub @@ -38,12 +37,11 @@ CreateCargo::~CreateCargo() { //----------------------------------------------------------------------------- // Punk wejścia do tworzenia archivum //----------------------------------------------------------------------------- -bool CreateCargo::Create(const std::string& path, bool compress, bool filters) +bool CreateCargo::Create(const std::string& path, int8_t flag) { cargoFile = path + "." + extension; catalogPath = path; - compressingFlag = compress; - filteringFlag = filters; + methodFlags = flag; //Sprawdzanie pakowanego kontentu if (!std::filesystem::is_directory(path)) @@ -58,18 +56,6 @@ bool CreateCargo::Create(const std::string& path, bool compress, bool filters) return false; } - // Pobieranie listy plików wyjątków - if (filters) - { - std::string filterFile = path + ".txt"; - if (!std::filesystem::exists(filterFile)) - { - std::cerr << "Error: Missing " << filterFile << " file!" << std::endl; - return false; - } - GetFilters(filterFile); - } - //Pobieranie listy plików do spakowania std::cout << "Creating a file list..." << std::endl; if (!GetFileList(path)) @@ -78,6 +64,18 @@ bool CreateCargo::Create(const std::string& path, bool compress, bool filters) return false; } + // Pobieranie listy plików wyjątków + if (flag == -1) + { + std::string filterFile = path + ".json"; + if (!std::filesystem::exists(filterFile)) + { + std::cerr << "Error: Missing " << filterFile << " file!" << std::endl; + return false; + } + GetFilters(filterFile); + } + // Utworzenie kontenera cargo.open(cargoFile, std::ios::binary); @@ -166,31 +164,30 @@ uint8_t CreateCargo::CheckFileOnTheList(const std::string& path, std::vector> jslist; + file.close(); // Lista plików do skompresowania - zipList = ff.Get(KEY_ZIP); + std::vector zip = jslist[KEY_ZIP].get>(); + + // Lista plików do zaszyfrowania + std::vector enc = jslist[KEY_ENCRYPT].get>(); // Lista plików do pominięcia - ignoreList = ff.Get(KEY_IGNORE); + std::vector ignore = jslist[KEY_IGNORE].get>(); - ff.Close(); + PrepareList(zip, enc, ignore); +} + +//----------------------------------------------------------------------------- +// Przygotuj listę plików do spakowania +//----------------------------------------------------------------------------- +void CreateCargo::PrepareList(const std::vector& zip, const std::vector& enc, const std::vector& ignore) +{ + PathConf pc; + + for (const auto& item : filesList) + { + if (!FindOnTheList(ignore, item)) + { + if (FindOnTheList(zip, item)) + { + pc.parameter = FindOnTheList(enc, item) ? 3 : 1; + } + else + { + pc.parameter = FindOnTheList(enc, item) ? 2 : 0; + } + pc.path = item; + filesPaths.push_back(pc); + } + } } @@ -444,7 +472,7 @@ bool CreateCargo::WriteCargo() cargo.close(); // Zapisywanie klucza szyfrującego - crypt.saveKey(catalogPath); + //crypt.saveKey(catalogPath); std::cout << "The container was successfully created! " << cargoFile << std::endl; diff --git a/CreateCargo.h b/CreateCargo.h index 12a9c36..ab2d93b 100644 --- a/CreateCargo.h +++ b/CreateCargo.h @@ -31,6 +31,7 @@ #include #include #include +#include #include "DataStruct.h" #include "Txtpp.h" @@ -45,14 +46,14 @@ #define KEY_ZIP "COMPRESS" // Pliki do skompresowania #define KEY_RAW "RAW" // Pliki które mają pozostać w oryginalnej formie #define KEY_IGNORE "IGNORE" // Pliki pominięte przy pakowaniu -#define KEY_CRYPT "CRYPT" // Plili które mają być zaszyfrowane +#define KEY_ENCRYPT "ENCRYPT" // Plili które mają być zaszyfrowane #define ALL_FILE ".*" // Wszystkie pliki -struct MethodFlags +struct PathConf { - bool compressing = false; - bool encryption = false; + std::string path; + int8_t parameter; }; class CreateCargo { @@ -61,16 +62,14 @@ public: virtual ~CreateCargo(); // Punk wejścia do tworzenia archivum - bool Create(const std::string&, bool, bool); + bool Create(const std::string&, int8_t); private: - bool compressingFlag; - bool filteringFlag; const std::string signature; const std::string extension; const uint8_t version; - MethodFlags methodFlags; + int8_t methodFlags; std::string catalogPath; @@ -85,6 +84,9 @@ private: std::vector ignoreList; std::vector zipList; + // Główna lista plików z parametrami + std::vector filesPaths; + std::ofstream cargo; uint64_t offset; @@ -135,5 +137,8 @@ private: // Znajdź wskazany element na liście bool FindOnTheList(const std::vector&, const std::string&); + + // Przygotuj listę plików do spakowania + void PrepareList(const std::vector&, const std::vector&, const std::vector&); }; diff --git a/DataStruct.h b/DataStruct.h index 158d1b6..8136b69 100644 --- a/DataStruct.h +++ b/DataStruct.h @@ -31,10 +31,11 @@ enum StoreMethod { - RAW, - LZ4, - CHACHA20, - LZ4_CHACHA20 + FILTERING = -1, + RAW = 0, + COMPRESS = 1, + ENCRYPT = 2, + COMPRESSxENCRYPT = 3 }; diff --git a/ExtractCargo.cpp b/ExtractCargo.cpp index 23edcd3..fbbfeb8 100644 --- a/ExtractCargo.cpp +++ b/ExtractCargo.cpp @@ -60,8 +60,8 @@ bool ExtractCargo::Extract(const std::string& cFile) } // Wczytaj klucz deszyfrujący - std::filesystem::path kdir = cargoFileName.stem(); - eman.loadKey(kdir.string()); + //std::filesystem::path kdir = cargoFileName.stem(); + //eman.loadKey(kdir.string()); //Otwieranie kontenera cargoFile.open(cargoFileName, std::ios::binary); diff --git a/voidcmd.cpp b/voidcmd.cpp index ba2147b..5908996 100644 --- a/voidcmd.cpp +++ b/voidcmd.cpp @@ -111,7 +111,7 @@ int main(int argc, char* argv[]) { if (!EmptyPath(path)) { return 1; } - if (!cargo.Create(path, true, false)) + if (!cargo.Create(path, 1)) { return 1; } @@ -121,7 +121,7 @@ int main(int argc, char* argv[]) { if (arg == "-p" && i + 1 < argc) { path = argv[i + 1]; - if (!cargo.Create(path, false, false)) + if (!cargo.Create(path, 0)) { return 1; } @@ -132,7 +132,7 @@ int main(int argc, char* argv[]) { { path = argv[i + 1]; if (!EmptyPath(path)) { return 1; } - if (!cargo.Create(path, false, true)) + if (!cargo.Create(path, -1)) { return 1; } diff --git a/voidcmd.vcxproj b/voidcmd.vcxproj index 0d62872..d0fe1d7 100644 --- a/voidcmd.vcxproj +++ b/voidcmd.vcxproj @@ -104,7 +104,7 @@ _DEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpp17 - 3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include;3rd\xxhash\include + 3rd\ftxui\include;3rd\libsodium\include;3rd\json\include;3rd\lz4\include;3rd\xxhash\include Console @@ -122,7 +122,7 @@ NDEBUG;_CONSOLE;%(PreprocessorDefinitions) true stdcpp17 - 3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include + 3rd\ftxui\include;3rd\libsodium\include;3rd\json\include;3rd\lz4\include; Console