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"
|
||||
|
||||
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<cha
|
|||
//Przeciwnie kompresuje dane
|
||||
CompressingManager cm;
|
||||
|
||||
if (filteringFlag) {
|
||||
if (FilteringData(path))
|
||||
{
|
||||
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)
|
||||
// Kompresja
|
||||
if (methodFlags == 1)
|
||||
{
|
||||
|
||||
output = cm.compress(input);
|
||||
return ZIP_FILE;
|
||||
return 1;
|
||||
}
|
||||
|
||||
//output = std::move(input);
|
||||
output = crypt.encrypt(input);
|
||||
return RAW_FILE;
|
||||
// Szyfrowanie
|
||||
if (methodFlags == 2)
|
||||
{
|
||||
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;
|
||||
|
||||
Txtpp ff(filterFile);
|
||||
std::ifstream file(filterFile);
|
||||
nlohmann::json jslist;
|
||||
file >> jslist;
|
||||
file.close();
|
||||
|
||||
// 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
|
||||
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();
|
||||
|
||||
// Zapisywanie klucza szyfrującego
|
||||
crypt.saveKey(catalogPath);
|
||||
//crypt.saveKey(catalogPath);
|
||||
|
||||
std::cout << "The container was successfully created! " << cargoFile << std::endl;
|
||||
|
||||
|
|
|
|||
|
|
@ -31,6 +31,7 @@
|
|||
#include <memory>
|
||||
#include <string>
|
||||
#include <xxhash.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#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<std::string> ignoreList;
|
||||
std::vector<std::string> zipList;
|
||||
|
||||
// G³ówna lista plików z parametrami
|
||||
std::vector<PathConf> filesPaths;
|
||||
|
||||
|
||||
std::ofstream cargo;
|
||||
uint64_t offset;
|
||||
|
|
@ -135,5 +137,8 @@ private:
|
|||
|
||||
// ZnajdŸ wskazany element na liœcie
|
||||
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
|
||||
{
|
||||
RAW,
|
||||
LZ4,
|
||||
CHACHA20,
|
||||
LZ4_CHACHA20
|
||||
FILTERING = -1,
|
||||
RAW = 0,
|
||||
COMPRESS = 1,
|
||||
ENCRYPT = 2,
|
||||
COMPRESSxENCRYPT = 3
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@
|
|||
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<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>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
|
@ -122,7 +122,7 @@
|
|||
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
|
||||
<ConformanceMode>true</ConformanceMode>
|
||||
<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>
|
||||
<Link>
|
||||
<SubSystem>Console</SubSystem>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue