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;
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue