Przerobiona metoda tworzenia kontenerów. Błędnie dobiera opcje
This commit is contained in:
parent
69089cd2f9
commit
1392b5bbe0
6 changed files with 97 additions and 63 deletions
116
CreateCargo.cpp
116
CreateCargo.cpp
|
|
@ -20,11 +20,10 @@
|
||||||
#include "CreateCargo.h"
|
#include "CreateCargo.h"
|
||||||
|
|
||||||
CreateCargo::CreateCargo()
|
CreateCargo::CreateCargo()
|
||||||
:compressingFlag(false)
|
: signature(SIGNATURE)
|
||||||
, filteringFlag(false)
|
|
||||||
, signature(SIGNATURE)
|
|
||||||
, extension(EXTENSION)
|
, extension(EXTENSION)
|
||||||
, version(VERSION)
|
, version(VERSION)
|
||||||
|
, methodFlags(0)
|
||||||
, offset(0)
|
, offset(0)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
|
|
@ -38,12 +37,11 @@ CreateCargo::~CreateCargo() {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Punk wejścia do tworzenia archivum
|
// 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;
|
cargoFile = path + "." + extension;
|
||||||
catalogPath = path;
|
catalogPath = path;
|
||||||
compressingFlag = compress;
|
methodFlags = flag;
|
||||||
filteringFlag = filters;
|
|
||||||
|
|
||||||
//Sprawdzanie pakowanego kontentu
|
//Sprawdzanie pakowanego kontentu
|
||||||
if (!std::filesystem::is_directory(path))
|
if (!std::filesystem::is_directory(path))
|
||||||
|
|
@ -58,18 +56,6 @@ bool CreateCargo::Create(const std::string& path, bool compress, bool filters)
|
||||||
return false;
|
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
|
//Pobieranie listy plików do spakowania
|
||||||
std::cout << "Creating a file list..." << std::endl;
|
std::cout << "Creating a file list..." << std::endl;
|
||||||
if (!GetFileList(path))
|
if (!GetFileList(path))
|
||||||
|
|
@ -78,6 +64,18 @@ bool CreateCargo::Create(const std::string& path, bool compress, bool filters)
|
||||||
return false;
|
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
|
// Utworzenie kontenera
|
||||||
cargo.open(cargoFile, std::ios::binary);
|
cargo.open(cargoFile, std::ios::binary);
|
||||||
|
|
||||||
|
|
@ -166,31 +164,30 @@ uint8_t CreateCargo::CheckFileOnTheList(const std::string& path, std::vector<cha
|
||||||
//Przeciwnie kompresuje dane
|
//Przeciwnie kompresuje dane
|
||||||
CompressingManager cm;
|
CompressingManager cm;
|
||||||
|
|
||||||
if (filteringFlag) {
|
// Kompresja
|
||||||
if (FilteringData(path))
|
if (methodFlags == 1)
|
||||||
{
|
|
||||||
output = cm.compress(input);
|
|
||||||
return ZIP_FILE;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
//output = std::move(input);
|
|
||||||
output = crypt.encrypt(input);
|
|
||||||
return RAW_FILE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//Flaga aktywna kompresuje dane
|
|
||||||
if (compressingFlag)
|
|
||||||
{
|
{
|
||||||
|
|
||||||
output = cm.compress(input);
|
output = cm.compress(input);
|
||||||
return ZIP_FILE;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
//output = std::move(input);
|
// Szyfrowanie
|
||||||
output = crypt.encrypt(input);
|
if (methodFlags == 2)
|
||||||
return RAW_FILE;
|
{
|
||||||
|
output = crypt.encrypt(input);
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kompresja i szyfrowanie
|
||||||
|
if (methodFlags == 3)
|
||||||
|
{
|
||||||
|
output = crypt.encrypt(cm.compress(input));
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Zwraca surowe dane
|
||||||
|
output = std::move(input);
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -256,15 +253,46 @@ void CreateCargo::GetFilters(const std::string& filterFile)
|
||||||
{
|
{
|
||||||
std::cout << "Downloading the exception list" << std::endl;
|
std::cout << "Downloading the exception list" << std::endl;
|
||||||
|
|
||||||
Txtpp ff(filterFile);
|
std::ifstream file(filterFile);
|
||||||
|
nlohmann::json jslist;
|
||||||
|
file >> jslist;
|
||||||
|
file.close();
|
||||||
|
|
||||||
// Lista plików do skompresowania
|
// Lista plików do skompresowania
|
||||||
zipList = ff.Get(KEY_ZIP);
|
std::vector<std::string> zip = jslist[KEY_ZIP].get<std::vector<std::string>>();
|
||||||
|
|
||||||
|
// Lista plików do zaszyfrowania
|
||||||
|
std::vector<std::string> enc = jslist[KEY_ENCRYPT].get<std::vector<std::string>>();
|
||||||
|
|
||||||
// Lista plików do pominięcia
|
// Lista plików do pominięcia
|
||||||
ignoreList = ff.Get(KEY_IGNORE);
|
std::vector<std::string> ignore = jslist[KEY_IGNORE].get<std::vector<std::string>>();
|
||||||
|
|
||||||
ff.Close();
|
PrepareList(zip, enc, ignore);
|
||||||
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Przygotuj listê plików do spakowania
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
void CreateCargo::PrepareList(const std::vector<std::string>& zip, const std::vector<std::string>& enc, const std::vector<std::string>& 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();
|
cargo.close();
|
||||||
|
|
||||||
// Zapisywanie klucza szyfrującego
|
// Zapisywanie klucza szyfrującego
|
||||||
crypt.saveKey(catalogPath);
|
//crypt.saveKey(catalogPath);
|
||||||
|
|
||||||
std::cout << "The container was successfully created! " << cargoFile << std::endl;
|
std::cout << "The container was successfully created! " << cargoFile << std::endl;
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,6 +31,7 @@
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <xxhash.h>
|
#include <xxhash.h>
|
||||||
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include "DataStruct.h"
|
#include "DataStruct.h"
|
||||||
#include "Txtpp.h"
|
#include "Txtpp.h"
|
||||||
|
|
@ -45,14 +46,14 @@
|
||||||
#define KEY_ZIP "COMPRESS" // Pliki do skompresowania
|
#define KEY_ZIP "COMPRESS" // Pliki do skompresowania
|
||||||
#define KEY_RAW "RAW" // Pliki które maj¹ pozostaæ w oryginalnej formie
|
#define KEY_RAW "RAW" // Pliki które maj¹ pozostaæ w oryginalnej formie
|
||||||
#define KEY_IGNORE "IGNORE" // Pliki pominiête przy pakowaniu
|
#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
|
#define ALL_FILE ".*" // Wszystkie pliki
|
||||||
|
|
||||||
struct MethodFlags
|
struct PathConf
|
||||||
{
|
{
|
||||||
bool compressing = false;
|
std::string path;
|
||||||
bool encryption = false;
|
int8_t parameter;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CreateCargo {
|
class CreateCargo {
|
||||||
|
|
@ -61,16 +62,14 @@ public:
|
||||||
virtual ~CreateCargo();
|
virtual ~CreateCargo();
|
||||||
|
|
||||||
// Punk wejœcia do tworzenia archivum
|
// Punk wejœcia do tworzenia archivum
|
||||||
bool Create(const std::string&, bool, bool);
|
bool Create(const std::string&, int8_t);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool compressingFlag;
|
|
||||||
bool filteringFlag;
|
|
||||||
const std::string signature;
|
const std::string signature;
|
||||||
const std::string extension;
|
const std::string extension;
|
||||||
const uint8_t version;
|
const uint8_t version;
|
||||||
|
|
||||||
MethodFlags methodFlags;
|
int8_t methodFlags;
|
||||||
|
|
||||||
|
|
||||||
std::string catalogPath;
|
std::string catalogPath;
|
||||||
|
|
@ -85,6 +84,9 @@ private:
|
||||||
std::vector<std::string> ignoreList;
|
std::vector<std::string> ignoreList;
|
||||||
std::vector<std::string> zipList;
|
std::vector<std::string> zipList;
|
||||||
|
|
||||||
|
// G³ówna lista plików z parametrami
|
||||||
|
std::vector<PathConf> filesPaths;
|
||||||
|
|
||||||
|
|
||||||
std::ofstream cargo;
|
std::ofstream cargo;
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
|
|
@ -135,5 +137,8 @@ private:
|
||||||
|
|
||||||
// ZnajdŸ wskazany element na liœcie
|
// ZnajdŸ wskazany element na liœcie
|
||||||
bool FindOnTheList(const std::vector<std::string>&, const std::string&);
|
bool FindOnTheList(const std::vector<std::string>&, const std::string&);
|
||||||
|
|
||||||
|
// Przygotuj listê plików do spakowania
|
||||||
|
void PrepareList(const std::vector<std::string>&, const std::vector<std::string>&, const std::vector<std::string>&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -31,10 +31,11 @@
|
||||||
|
|
||||||
enum StoreMethod
|
enum StoreMethod
|
||||||
{
|
{
|
||||||
RAW,
|
FILTERING = -1,
|
||||||
LZ4,
|
RAW = 0,
|
||||||
CHACHA20,
|
COMPRESS = 1,
|
||||||
LZ4_CHACHA20
|
ENCRYPT = 2,
|
||||||
|
COMPRESSxENCRYPT = 3
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -60,8 +60,8 @@ bool ExtractCargo::Extract(const std::string& cFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Wczytaj klucz deszyfrujšcy
|
// Wczytaj klucz deszyfrujšcy
|
||||||
std::filesystem::path kdir = cargoFileName.stem();
|
//std::filesystem::path kdir = cargoFileName.stem();
|
||||||
eman.loadKey(kdir.string());
|
//eman.loadKey(kdir.string());
|
||||||
|
|
||||||
//Otwieranie kontenera
|
//Otwieranie kontenera
|
||||||
cargoFile.open(cargoFileName, std::ios::binary);
|
cargoFile.open(cargoFileName, std::ios::binary);
|
||||||
|
|
|
||||||
|
|
@ -111,7 +111,7 @@ int main(int argc, char* argv[]) {
|
||||||
|
|
||||||
if (!EmptyPath(path)) { return 1; }
|
if (!EmptyPath(path)) { return 1; }
|
||||||
|
|
||||||
if (!cargo.Create(path, true, false))
|
if (!cargo.Create(path, 1))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -121,7 +121,7 @@ int main(int argc, char* argv[]) {
|
||||||
if (arg == "-p" && i + 1 < argc)
|
if (arg == "-p" && i + 1 < argc)
|
||||||
{
|
{
|
||||||
path = argv[i + 1];
|
path = argv[i + 1];
|
||||||
if (!cargo.Create(path, false, false))
|
if (!cargo.Create(path, 0))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
@ -132,7 +132,7 @@ int main(int argc, char* argv[]) {
|
||||||
{
|
{
|
||||||
path = argv[i + 1];
|
path = argv[i + 1];
|
||||||
if (!EmptyPath(path)) { return 1; }
|
if (!EmptyPath(path)) { return 1; }
|
||||||
if (!cargo.Create(path, false, true))
|
if (!cargo.Create(path, -1))
|
||||||
{
|
{
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -104,7 +104,7 @@
|
||||||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
<AdditionalIncludeDirectories>3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include;3rd\xxhash\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>3rd\ftxui\include;3rd\libsodium\include;3rd\json\include;3rd\lz4\include;3rd\xxhash\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
|
@ -122,7 +122,7 @@
|
||||||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||||
<ConformanceMode>true</ConformanceMode>
|
<ConformanceMode>true</ConformanceMode>
|
||||||
<LanguageStandard>stdcpp17</LanguageStandard>
|
<LanguageStandard>stdcpp17</LanguageStandard>
|
||||||
<AdditionalIncludeDirectories>3rd\ftxui\include;3rd\libsodium\include;3rd\lz4\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>3rd\ftxui\include;3rd\libsodium\include;3rd\json\include;3rd\lz4\include;</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue