Podmiana LZ4 na ZSTD raw block. Podmiana CompressManager na ChunkManager
This commit is contained in:
parent
00d4b00209
commit
b3c317c914
10 changed files with 244 additions and 267 deletions
177
ChunkManager.cpp
Normal file
177
ChunkManager.cpp
Normal file
|
|
@ -0,0 +1,177 @@
|
||||||
|
#include "ChunkManager.h"
|
||||||
|
|
||||||
|
ChunkManager::ChunkManager(EncryptionManager& em)
|
||||||
|
:eman(em)
|
||||||
|
{ }
|
||||||
|
|
||||||
|
ChunkManager::~ChunkManager()
|
||||||
|
{ }
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Kompresja blokowa
|
||||||
|
//
|
||||||
|
// Dzielenie vectora na chunki dok³adnie po 128KB
|
||||||
|
// Kompresowanie chunków bez nag³ówka
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
std::vector<char> ChunkManager::chunked(const std::vector<char>& raw, const bool& encrypt)
|
||||||
|
{
|
||||||
|
//std::vector<BlockSize> blockSizes;
|
||||||
|
|
||||||
|
// Maksymalny rozmiar chunka
|
||||||
|
const size_t maxBlockSize = BLOCK_SIZE;
|
||||||
|
const size_t rawSize = raw.size();
|
||||||
|
|
||||||
|
uint16_t blockLen = 0;
|
||||||
|
uint32_t lastChunkRawSize;
|
||||||
|
std::vector<char> compressedBlocks;
|
||||||
|
for (size_t offset = 0; offset < rawSize; offset += maxBlockSize)
|
||||||
|
{
|
||||||
|
// Rozmiar chunka
|
||||||
|
const size_t chunkSize = std::min(maxBlockSize, rawSize - offset);
|
||||||
|
|
||||||
|
auto begin = raw.begin() + offset;
|
||||||
|
auto end = begin + chunkSize;
|
||||||
|
|
||||||
|
// Skopiuj fragment danych do chunka
|
||||||
|
std::vector<char> chunk(begin, end);
|
||||||
|
|
||||||
|
std::vector<char> outChunk = encrypt ? eman.encrypt(compress_data(chunk)) : compress_data(chunk);
|
||||||
|
|
||||||
|
uint32_t chs = chunk.size();
|
||||||
|
uint32_t zch = outChunk.size();
|
||||||
|
|
||||||
|
//addIntToVector<uint32_t>(compressedBlocks, chs);
|
||||||
|
lastChunkRawSize = chs;
|
||||||
|
addIntToVector<uint32_t>(compressedBlocks, zch);
|
||||||
|
compressedBlocks.insert(compressedBlocks.end(), outChunk.begin(), outChunk.end());
|
||||||
|
|
||||||
|
blockLen++;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<char> zip;
|
||||||
|
// Wstaw liczbê o iloœci bloków do vectora;
|
||||||
|
// Przekonpwertuj usigned int32 na ci¹g znkaów
|
||||||
|
// uint16_t blockLen = blockSizes .size();
|
||||||
|
addIntToVector<uint16_t>(zip, blockLen);
|
||||||
|
addIntToVector<uint32_t>(zip, maxBlockSize);
|
||||||
|
addIntToVector<uint32_t>(zip, lastChunkRawSize);
|
||||||
|
|
||||||
|
// Dodaj skompresowane dane
|
||||||
|
zip.insert(zip.end(), compressedBlocks.begin(), compressedBlocks.end());
|
||||||
|
|
||||||
|
return zip;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kompresja
|
||||||
|
std::vector<char> ChunkManager::compress_data(const std::vector<char>& input)
|
||||||
|
{
|
||||||
|
const int level = 3;
|
||||||
|
|
||||||
|
// Obs³uga pustego chunku: zwracamy pusty wynik (0 bajtów).
|
||||||
|
if (input.empty()) return {};
|
||||||
|
|
||||||
|
ZSTD_CCtx* cctx = ZSTD_createCCtx();
|
||||||
|
if (!cctx) {
|
||||||
|
std::cerr << "ZSTD_createCCtx failed\n";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ustawienia „bez ramek”
|
||||||
|
size_t rc = 0;
|
||||||
|
rc |= ZSTD_CCtx_setParameter(cctx, ZSTD_c_format, ZSTD_f_zstd1_magicless);
|
||||||
|
rc |= ZSTD_CCtx_setParameter(cctx, ZSTD_c_checksumFlag, 0);
|
||||||
|
rc |= ZSTD_CCtx_setParameter(cctx, ZSTD_c_contentSizeFlag, 0);
|
||||||
|
rc |= ZSTD_CCtx_setParameter(cctx, ZSTD_c_dictIDFlag, 0);
|
||||||
|
rc |= ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, level);
|
||||||
|
|
||||||
|
if (ZSTD_isError(rc)) {
|
||||||
|
std::cerr << "ZSTD_CCtx_setParameter error\n";
|
||||||
|
ZSTD_freeCCtx(cctx);
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
const size_t srcSize = input.size();
|
||||||
|
|
||||||
|
// Szacowanie rozmiaru skompresowanego vectoru
|
||||||
|
const size_t maxDst = ZSTD_compressBound(srcSize);
|
||||||
|
|
||||||
|
std::vector<char> out(maxDst);
|
||||||
|
|
||||||
|
// Faktyczna kompresja
|
||||||
|
size_t written = ZSTD_compress2(cctx, out.data(), maxDst,
|
||||||
|
input.data(), srcSize);
|
||||||
|
|
||||||
|
ZSTD_freeCCtx(cctx);
|
||||||
|
|
||||||
|
if (ZSTD_isError(written)) {
|
||||||
|
std::cerr << "ZSTD_compress2 error: " << ZSTD_getErrorName(written) << "\n";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
out.resize(written);
|
||||||
|
return out;
|
||||||
|
}
|
||||||
|
|
||||||
|
//////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Dekompresja blokowa
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
std::vector<char> ChunkManager::dechunked(const std::vector<char>& zip, const bool& encrypt)
|
||||||
|
{
|
||||||
|
size_t offset = 0;
|
||||||
|
const uint16_t chunkLen = getIntFromVector<uint16_t>(zip, offset);
|
||||||
|
const uint32_t chunkBeforeSize = getIntFromVector<uint32_t>(zip, offset);
|
||||||
|
const uint32_t chunkLastSize = getIntFromVector<uint32_t>(zip, offset);
|
||||||
|
|
||||||
|
std::vector<char> chunksString;
|
||||||
|
|
||||||
|
// Dekompresja bloków
|
||||||
|
for (size_t i = 0; i < chunkLen; ++i)
|
||||||
|
{
|
||||||
|
// Pobierz rozmiar chunków przed i po skompresowaniem
|
||||||
|
uint32_t chunkSize = i < chunkLen - 1 ? chunkBeforeSize : chunkLastSize;
|
||||||
|
uint32_t chunkZipSize = getIntFromVector<uint32_t>(zip, offset);
|
||||||
|
|
||||||
|
// Pobierz blok chunka
|
||||||
|
std::vector<char> inChunk(chunkZipSize);
|
||||||
|
std::memcpy(inChunk.data(), zip.data() + offset, chunkZipSize);
|
||||||
|
offset += chunkZipSize;
|
||||||
|
|
||||||
|
// Jeœli flaga encrypt jest aktywna najpierw zdeszyfruj blok
|
||||||
|
std::vector<char> zipChunk = encrypt ? eman.decrypt(inChunk) : std::move(inChunk);
|
||||||
|
|
||||||
|
// Zdeklarój pusty chunk
|
||||||
|
std::vector<char> chunk = decompress_data(zipChunk, chunkSize);
|
||||||
|
|
||||||
|
// Scal chunki
|
||||||
|
chunksString.insert(chunksString.end(), chunk.begin(), chunk.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
return chunksString;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dekompresja
|
||||||
|
std::vector<char> ChunkManager::decompress_data(const std::vector<char>& input, const size_t& expected)
|
||||||
|
{
|
||||||
|
ZSTD_DCtx* dctx = ZSTD_createDCtx();
|
||||||
|
size_t r = 0;
|
||||||
|
r |= ZSTD_DCtx_setParameter(dctx, ZSTD_d_format, ZSTD_f_zstd1_magicless);
|
||||||
|
if (ZSTD_isError(r))
|
||||||
|
{
|
||||||
|
std::cerr << "ZSTD_DCtx_setParameter error" << std::endl;
|
||||||
|
ZSTD_freeDCtx(dctx);
|
||||||
|
}
|
||||||
|
|
||||||
|
std::vector<char> output(expected);
|
||||||
|
|
||||||
|
size_t dsize = ZSTD_decompressDCtx(dctx, output.data(), expected, input.data(), input.size());
|
||||||
|
ZSTD_freeDCtx(dctx);
|
||||||
|
|
||||||
|
if (ZSTD_isError(dsize)) {
|
||||||
|
std::cerr << "ZSTD_decompressDCtx error: " << ZSTD_getErrorName(dsize) << "\n";
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
@ -7,6 +7,14 @@
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
#define ZSTD_STATIC_LINKING_ONLY
|
||||||
|
#include <zstd.h>
|
||||||
|
|
||||||
|
#if ZSTD_VERSION_NUMBER < 10400
|
||||||
|
#error "Wymagane zstd >= 1.4.0 dla ZSTD_c_format / ZSTD_f_zstd1_magicless"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
#include "EncryptionManager.h"
|
||||||
|
|
||||||
#define BLOCK_SIZE 131072 // 128KB
|
#define BLOCK_SIZE 131072 // 128KB
|
||||||
|
|
||||||
|
|
@ -16,19 +24,20 @@ struct BlockSize
|
||||||
uint32_t zip;
|
uint32_t zip;
|
||||||
};
|
};
|
||||||
|
|
||||||
class CompressingManager
|
class ChunkManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
CompressingManager();
|
ChunkManager(EncryptionManager& em);
|
||||||
~CompressingManager();
|
~ChunkManager();
|
||||||
|
|
||||||
// Kompresja danych
|
// Kompresja danych
|
||||||
std::vector<char> compress(const std::vector<char>&);
|
std::vector<char> chunked(const std::vector<char>&, const bool&);
|
||||||
|
|
||||||
// Dekompresja
|
// Dekompresja
|
||||||
std::vector<char> decompress(const std::vector<char>&);
|
std::vector<char> dechunked(const std::vector<char>&, const bool&);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
EncryptionManager eman;
|
||||||
std::vector<BlockSize> blockSizes;
|
std::vector<BlockSize> blockSizes;
|
||||||
|
|
||||||
// Przekonwertuj zmienn¹ na ci¹g na vector
|
// Przekonwertuj zmienn¹ na ci¹g na vector
|
||||||
|
|
@ -50,5 +59,11 @@ private:
|
||||||
|
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Kompresja
|
||||||
|
std::vector<char> compress_data(const std::vector<char>&);
|
||||||
|
|
||||||
|
// Dekompresja
|
||||||
|
std::vector<char> decompress_data(const std::vector<char>&, const size_t&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
@ -1,119 +0,0 @@
|
||||||
#include "CompressingManager.h"
|
|
||||||
|
|
||||||
CompressingManager::CompressingManager()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
CompressingManager::~CompressingManager()
|
|
||||||
{ }
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Kompresja blokowa
|
|
||||||
//
|
|
||||||
// Dzielenie vectora na chunki dok³adnie po 128KB
|
|
||||||
// Kompresowanie chunków bez nag³ówka
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
std::vector<char> CompressingManager::compress(const std::vector<char>& raw)
|
|
||||||
{
|
|
||||||
//std::vector<BlockSize> blockSizes;
|
|
||||||
|
|
||||||
// Maksymalny rozmiar chunka
|
|
||||||
const size_t maxBlockSize = BLOCK_SIZE;
|
|
||||||
const size_t rawSize = raw.size();
|
|
||||||
|
|
||||||
uint16_t blockLen = 0;
|
|
||||||
uint32_t lastChunkRawSize;
|
|
||||||
std::vector<char> compressedBlocks;
|
|
||||||
for (size_t offset = 0; offset < rawSize; offset += maxBlockSize)
|
|
||||||
{
|
|
||||||
// Rozmiar chunka
|
|
||||||
const size_t chunkSize = std::min(maxBlockSize, rawSize - offset);
|
|
||||||
|
|
||||||
auto begin = raw.begin() + offset;
|
|
||||||
auto end = begin + chunkSize;
|
|
||||||
|
|
||||||
// Skopiuj fragment danych do chunka
|
|
||||||
std::vector<char> chunk(begin, end);
|
|
||||||
|
|
||||||
// Obliczanie rozmiaru skompresowanego bloku
|
|
||||||
int maxZipChunkSize = LZ4_compressBound(chunkSize);
|
|
||||||
|
|
||||||
// Buffor wyjœciowy nadpisany skompresowanymi danymi
|
|
||||||
std::vector<char> zipChunk(maxZipChunkSize);
|
|
||||||
|
|
||||||
// Kompresja
|
|
||||||
int zipSize = LZ4_compress_default(chunk.data(), zipChunk.data(), chunkSize, maxZipChunkSize);
|
|
||||||
|
|
||||||
// Zmiana rozmiaru do faktycznego rozmiaru po kompresji
|
|
||||||
zipChunk.resize(zipSize);
|
|
||||||
|
|
||||||
uint32_t chs = chunk.size();
|
|
||||||
uint32_t zch = zipChunk.size();
|
|
||||||
|
|
||||||
//addIntToVector<uint32_t>(compressedBlocks, chs);
|
|
||||||
lastChunkRawSize = chs;
|
|
||||||
addIntToVector<uint32_t>(compressedBlocks, zch);
|
|
||||||
compressedBlocks.insert(compressedBlocks.end(), zipChunk.begin(), zipChunk.end());
|
|
||||||
|
|
||||||
blockLen++;
|
|
||||||
}
|
|
||||||
|
|
||||||
std::vector<char> zip;
|
|
||||||
// Wstaw liczbê o iloœci bloków do vectora;
|
|
||||||
// Przekonpwertuj usigned int32 na ci¹g znkaów
|
|
||||||
// uint16_t blockLen = blockSizes .size();
|
|
||||||
addIntToVector<uint16_t>(zip, blockLen);
|
|
||||||
addIntToVector<uint32_t>(zip, maxBlockSize);
|
|
||||||
addIntToVector<uint32_t>(zip, lastChunkRawSize);
|
|
||||||
|
|
||||||
// Dodaj skompresowane dane
|
|
||||||
zip.insert(zip.end(), compressedBlocks.begin(), compressedBlocks.end());
|
|
||||||
|
|
||||||
return zip;
|
|
||||||
}
|
|
||||||
|
|
||||||
//////////////////////////////////////////////////////////////
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Dekompresja blokowa
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
std::vector<char> CompressingManager::decompress(const std::vector<char>& zip)
|
|
||||||
{
|
|
||||||
size_t offset = 0;
|
|
||||||
const uint16_t chunkLen = getIntFromVector<uint16_t>(zip, offset);
|
|
||||||
const uint32_t chunkBeforeSize = getIntFromVector<uint32_t>(zip, offset);
|
|
||||||
const uint32_t chunkLastSize = getIntFromVector<uint32_t>(zip, offset);
|
|
||||||
|
|
||||||
std::vector<char> chunksString;
|
|
||||||
|
|
||||||
// Dekompresja bloków
|
|
||||||
for (size_t i = 0; i < chunkLen; ++i)
|
|
||||||
{
|
|
||||||
// Pobierz rozmiar chunków przed i po skompresowaniem
|
|
||||||
uint32_t chunkSize = i < chunkLen - 1 ? chunkBeforeSize : chunkLastSize;
|
|
||||||
uint32_t chunkZipSize = getIntFromVector<uint32_t>(zip, offset);
|
|
||||||
|
|
||||||
// Pobierz blok chunka
|
|
||||||
std::vector<char> zipChunk(chunkZipSize);
|
|
||||||
std::memcpy(zipChunk.data(), zip.data() + offset, chunkZipSize);
|
|
||||||
offset += chunkZipSize;
|
|
||||||
|
|
||||||
// Zdeklarój pusty chunk
|
|
||||||
std::vector<char> chunk(chunkSize);
|
|
||||||
|
|
||||||
// Dekompresja chunka
|
|
||||||
int sizeData = LZ4_decompress_safe(zipChunk.data(), chunk.data(), static_cast<int>(chunkZipSize), static_cast<int>(chunkSize));
|
|
||||||
|
|
||||||
if (sizeData < 0)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("LZ4 Decompressing Error");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Dostosowanie rozmiaru vectora po skompresowaniu
|
|
||||||
chunk.resize(sizeData);
|
|
||||||
|
|
||||||
// Scal chunki
|
|
||||||
chunksString.insert(chunksString.end(), chunk.begin(), chunk.end());
|
|
||||||
}
|
|
||||||
|
|
||||||
return chunksString;
|
|
||||||
}
|
|
||||||
128
CreateCargo.cpp
128
CreateCargo.cpp
|
|
@ -110,31 +110,28 @@ bool CreateCargo::GetFileList(const std::string& path)
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::string fileRef = RemoveStartPath(PathToUnixLike(tmpPath));
|
std::string fileRef = RemoveStartPath(PathToUnixLike(tmpPath));
|
||||||
if (CheckIgnorePath(tmpPath))
|
PathConf pc;
|
||||||
|
if (methodFlags > -1)
|
||||||
{
|
{
|
||||||
PathConf pc;
|
pc.path = PathToUnixLike(tmpPath);
|
||||||
if (methodFlags > -1)
|
pc.parameter = methodFlags;
|
||||||
|
filesPaths.push_back(pc);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
if (!FindOnTheList(ignoreList, fileRef) || !CheckFileExtension(fileRef, ignoreList))
|
||||||
{
|
{
|
||||||
pc.path = PathToUnixLike(tmpPath);
|
if (FindOnTheList(zipList, fileRef) || CheckFileExtension(fileRef, zipList))
|
||||||
pc.parameter = methodFlags;
|
|
||||||
filesPaths.push_back(pc);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (!FindOnTheList(ignoreList, fileRef) || !CheckFileExtension(fileRef, ignoreList))
|
|
||||||
{
|
{
|
||||||
if (FindOnTheList(zipList, fileRef) || CheckFileExtension(fileRef, zipList))
|
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? 3 : 1;
|
||||||
{
|
|
||||||
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? 3 : 1;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? 2 : 0;
|
|
||||||
}
|
|
||||||
pc.path = PathToUnixLike(tmpPath);
|
|
||||||
std::cout << pc.path << " - " << pc.parameter << std::endl;
|
|
||||||
filesPaths.push_back(pc);
|
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? 2 : 0;
|
||||||
|
}
|
||||||
|
pc.path = PathToUnixLike(tmpPath);
|
||||||
|
std::cout << pc.path << " - " << pc.parameter << std::endl;
|
||||||
|
filesPaths.push_back(pc);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -192,12 +189,12 @@ void CreateCargo::computingBytes(const int16_t& flag, std::vector<char>& input,
|
||||||
{
|
{
|
||||||
//Flaga aktywna sprawdza czy plik jest na liście. Jeśli jest to zwraca surowedane
|
//Flaga aktywna sprawdza czy plik jest na liście. Jeśli jest to zwraca surowedane
|
||||||
//Przeciwnie kompresuje dane
|
//Przeciwnie kompresuje dane
|
||||||
CompressingManager cm;
|
ChunkManager cm(crypt);
|
||||||
|
|
||||||
switch (flag)
|
switch (flag)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
output = cm.compress(input);
|
output = cm.chunked(input, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
|
@ -205,7 +202,7 @@ void CreateCargo::computingBytes(const int16_t& flag, std::vector<char>& input,
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
output = crypt.encrypt(cm.compress(input));
|
output = crypt.encrypt(cm.chunked(input, false));
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
@ -301,26 +298,6 @@ bool CreateCargo::FindOnTheList(const std::vector<std::string>& list, const std:
|
||||||
return it == list.end() ? false : true;
|
return it == list.end() ? false : true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Rozdzielanie paternu od œcie¿ki
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
void CreateCargo::ExtPatternAndPathDetection(const std::vector<std::string>& data, std::vector<std::string>& pattern, std::vector<std::string>& path)
|
|
||||||
{
|
|
||||||
for (const auto& d : data)
|
|
||||||
{
|
|
||||||
if (d.front() == '*')
|
|
||||||
{
|
|
||||||
std::string tmpPattern = d;
|
|
||||||
tmpPattern.erase(tmpPattern.begin());
|
|
||||||
pattern.push_back(UpperString(tmpPattern));
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
path.push_back(d);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Sprawdzanie rozszeżeń plików
|
// Sprawdzanie rozszeżeń plików
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -367,69 +344,6 @@ uint64_t CreateCargo::fnv64(const std::string& data)
|
||||||
return hash;
|
return hash;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Sprawdzanie czy plik znajduje siê na liœcie
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
bool CreateCargo::FilteringData(const std::string& path)
|
|
||||||
{
|
|
||||||
std::vector<std::string> cmPatterns;
|
|
||||||
std::vector<std::string> cmPaths;
|
|
||||||
|
|
||||||
// Rozdziel œcie¿ki i patterny na osobne listy
|
|
||||||
ExtPatternAndPathDetection(zipList, cmPatterns, cmPaths);
|
|
||||||
|
|
||||||
if (FindOnTheList(cmPatterns, ALL_FILE))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sprawd¿ czy istnieje plik o danym rozsze¿eniu
|
|
||||||
if (CheckFileExtension(path, cmPatterns))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// SprawdŸ czy instnieje dany plik w danej lokalizacji
|
|
||||||
if (FindOnTheList(cmPaths, path))
|
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Kasowanie z listy plików ignorow
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
bool CreateCargo::CheckIgnorePath(const std::string& path)
|
|
||||||
{
|
|
||||||
std::vector<std::string> igPatterns;
|
|
||||||
std::vector<std::string> igPaths;
|
|
||||||
|
|
||||||
ExtPatternAndPathDetection(ignoreList, igPatterns, igPaths);
|
|
||||||
|
|
||||||
// Sprawd¿ czy istnieje plik o danym rozsze¿eniu
|
|
||||||
if (CheckFileExtension(path, igPatterns))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Obrubka œcierzki
|
|
||||||
// Usuwanie katalogu root
|
|
||||||
std::string cleanPath = RemoveStartPath(path);
|
|
||||||
|
|
||||||
// Przekszta³cenie œcierzki na format unixowy
|
|
||||||
std::string unixPath = PathToUnixLike(cleanPath);
|
|
||||||
|
|
||||||
// SprawdŸ czy instnieje dany plik w danej lokalizacji
|
|
||||||
if (FindOnTheList(igPaths, unixPath))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Trworzenie archiwum
|
// Trworzenie archiwum
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -25,7 +25,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <lz4.h>
|
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
#include <utility>
|
#include <utility>
|
||||||
#include <memory>
|
#include <memory>
|
||||||
|
|
@ -34,7 +33,7 @@
|
||||||
#include <nlohmann/json.hpp>
|
#include <nlohmann/json.hpp>
|
||||||
|
|
||||||
#include "DataStruct.h"
|
#include "DataStruct.h"
|
||||||
#include "CompressingManager.h"
|
#include "ChunkManager.h"
|
||||||
#include "EncryptionManager.h"
|
#include "EncryptionManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -107,18 +106,12 @@ private:
|
||||||
// Przygotowanie nag³ówków i plików
|
// Przygotowanie nag³ówków i plików
|
||||||
std::vector<FilesTable> ComputingHeadFiles();
|
std::vector<FilesTable> ComputingHeadFiles();
|
||||||
|
|
||||||
// Sprawdzanie czy plik znajduje siê na liœcie
|
|
||||||
bool FilteringData(const std::string&);
|
|
||||||
|
|
||||||
// Wczytanie filtrów wyj¹tków
|
// Wczytanie filtrów wyj¹tków
|
||||||
void GetFilters(const std::string&);
|
void GetFilters(const std::string&);
|
||||||
|
|
||||||
// Sprawdza czy plik znajduje siê na liœcie
|
// Sprawdza czy plik znajduje siê na liœcie
|
||||||
void computingBytes(const int16_t&, std::vector<char>&, std::vector<char>&);
|
void computingBytes(const int16_t&, std::vector<char>&, std::vector<char>&);
|
||||||
|
|
||||||
// Kasowanie z listy plików ignorow
|
|
||||||
bool CheckIgnorePath(const std::string&);
|
|
||||||
|
|
||||||
// Sprawdzanie rozsze¿eñ plików
|
// Sprawdzanie rozsze¿eñ plików
|
||||||
bool CheckFileExtension(const std::string&, const std::vector<std::string>&);
|
bool CheckFileExtension(const std::string&, const std::vector<std::string>&);
|
||||||
|
|
||||||
|
|
@ -128,9 +121,6 @@ private:
|
||||||
// Wygenerój FNV-1a HASH
|
// Wygenerój FNV-1a HASH
|
||||||
uint64_t fnv64(const std::string& data);
|
uint64_t fnv64(const std::string& data);
|
||||||
|
|
||||||
// Rozdzielanie paternu od œcie¿ki
|
|
||||||
void ExtPatternAndPathDetection(const std::vector<std::string>&, std::vector<std::string>&, std::vector<std::string>&);
|
|
||||||
|
|
||||||
// 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&);
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -137,14 +137,14 @@ bool ExtractCargo::HashValid(const std::vector<char>& data, const uint64_t& crc)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Magiczna funkcja do dekompresji i deszyfracji danych
|
// Magiczna funkcja do dekompresji i deszyfracji danych
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void ExtractCargo::computingBytes(const std::vector<char>& input, std::vector<char>& output, const int8_t& flag)
|
void ExtractCargo::computingBytes(const std::vector<char>& input, std::vector<char>& output, const int16_t& flag)
|
||||||
{
|
{
|
||||||
CompressingManager cm;
|
CompressingManager cm(eman);
|
||||||
|
|
||||||
switch (flag)
|
switch (flag)
|
||||||
{
|
{
|
||||||
case 1:
|
case 1:
|
||||||
output = cm.decompress(input);
|
output = cm.decompress(input, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
|
|
@ -152,7 +152,7 @@ void ExtractCargo::computingBytes(const std::vector<char>& input, std::vector<ch
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
output = cm.decompress(eman.decrypt(input));
|
output = cm.decompress(input, false);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
|
|
|
||||||
|
|
@ -31,7 +31,7 @@
|
||||||
#include <xxhash.h>
|
#include <xxhash.h>
|
||||||
|
|
||||||
#include "DataStruct.h"
|
#include "DataStruct.h"
|
||||||
#include "CompressingManager.h"
|
#include "ChunkManager.h"
|
||||||
#include "EncryptionManager.h"
|
#include "EncryptionManager.h"
|
||||||
|
|
||||||
class ExtractCargo {
|
class ExtractCargo {
|
||||||
|
|
@ -76,6 +76,6 @@ private:
|
||||||
void CreateDirections(std::filesystem::path);
|
void CreateDirections(std::filesystem::path);
|
||||||
|
|
||||||
// Magiczna funkcja do dekompresji i deszyfracji danych
|
// Magiczna funkcja do dekompresji i deszyfracji danych
|
||||||
void computingBytes(const std::vector<char>&, std::vector<char>&, const int8_t&);
|
void computingBytes(const std::vector<char>&, std::vector<char>&, const int16_t&);
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
10
voidcmd.cpp
10
voidcmd.cpp
|
|
@ -40,11 +40,11 @@ void RenderHelp()
|
||||||
const std::string HelpInstruction =
|
const std::string HelpInstruction =
|
||||||
"pakcmd <parametr> <catalog> \n"
|
"pakcmd <parametr> <catalog> \n"
|
||||||
" \n"
|
" \n"
|
||||||
" \-c Compressing \n"
|
" -c Compressing \n"
|
||||||
" \-r Raw files \n"
|
" -r Raw files \n"
|
||||||
" \-e Encrypted \n"
|
" -e Encrypted \n"
|
||||||
" \-s Compressing and Encrypted \n"
|
" -s Compressing and Encrypted \n"
|
||||||
" \-f Pack the files according to the guidelines given in the \<directory\>.json \n"
|
" -f Pack the files according to the guidelines given in the <directory>.json \n"
|
||||||
" \n"
|
" \n"
|
||||||
"Extracting: \n"
|
"Extracting: \n"
|
||||||
" -x Extract files from the specified container \n"
|
" -x Extract files from the specified container \n"
|
||||||
|
|
|
||||||
|
|
@ -104,13 +104,13 @@
|
||||||
<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\json\include;3rd\lz4\include;3rd\xxhash\include</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>3rd\ftxui\include;3rd\libsodium\include;3rd\json\include;3rd\zstd\include;3rd\lz4\include;3rd\xxhash\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalLibraryDirectories>3rd\ftxui\Debug;3rd\lz4\lib;3rd\libsodium\lib\Debug</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>3rd\zstd\lib\Debug;3rd\ftxui\Debug;3rd\lz4\lib;3rd\libsodium\lib\Debug</AdditionalLibraryDirectories>
|
||||||
<AdditionalDependencies>liblz4_static.lib;ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib;libsodium.lib</AdditionalDependencies>
|
<AdditionalDependencies>liblz4_static.lib;ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib;libsodium.lib;zstd_static.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
|
@ -122,17 +122,17 @@
|
||||||
<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\json\include;3rd\lz4\include;</AdditionalIncludeDirectories>
|
<AdditionalIncludeDirectories>3rd\ftxui\include;3rd\libsodium\include;3rd\json\include;3rd\zstd\include;3rd\lz4\include;</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<AdditionalLibraryDirectories>3rd\libsodium\lib\Release;3rd\ftxui\Release;3rd\lz4\lib</AdditionalLibraryDirectories>
|
<AdditionalLibraryDirectories>3rd\zstd\lib\Release;3rd\libsodium\lib\Release;3rd\ftxui\Release;3rd\lz4\lib</AdditionalLibraryDirectories>
|
||||||
<AdditionalDependencies>liblz4_static.lib;ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib;libsodium.lib</AdditionalDependencies>
|
<AdditionalDependencies>liblz4_static.lib;ftxui-component.lib;ftxui-dom.lib;ftxui-screen.lib;libsodium.lib;zstd_static.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="CompressingManager.cpp" />
|
<ClCompile Include="ChunkManager.cpp" />
|
||||||
<ClCompile Include="CreateCargo.cpp" />
|
<ClCompile Include="CreateCargo.cpp" />
|
||||||
<ClCompile Include="EncryptionManager.cpp" />
|
<ClCompile Include="EncryptionManager.cpp" />
|
||||||
<ClCompile Include="ExtractCargo.cpp" />
|
<ClCompile Include="ExtractCargo.cpp" />
|
||||||
|
|
@ -141,7 +141,7 @@
|
||||||
<ClCompile Include="voidcmd.cpp" />
|
<ClCompile Include="voidcmd.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="CompressingManager.h" />
|
<ClInclude Include="ChunkManager.h" />
|
||||||
<ClInclude Include="CreateCargo.h" />
|
<ClInclude Include="CreateCargo.h" />
|
||||||
<ClInclude Include="DataStruct.h" />
|
<ClInclude Include="DataStruct.h" />
|
||||||
<ClInclude Include="EncryptionManager.h" />
|
<ClInclude Include="EncryptionManager.h" />
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@
|
||||||
<ClCompile Include="Interface.cpp">
|
<ClCompile Include="Interface.cpp">
|
||||||
<Filter>Pliki źródłowe</Filter>
|
<Filter>Pliki źródłowe</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="CompressingManager.cpp">
|
<ClCompile Include="ChunkManager.cpp">
|
||||||
<Filter>Pliki źródłowe</Filter>
|
<Filter>Pliki źródłowe</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<ClCompile Include="EncryptionManager.cpp">
|
<ClCompile Include="EncryptionManager.cpp">
|
||||||
|
|
@ -53,7 +53,7 @@
|
||||||
<ClInclude Include="Interface.h">
|
<ClInclude Include="Interface.h">
|
||||||
<Filter>Pliki nagłówkowe</Filter>
|
<Filter>Pliki nagłówkowe</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="CompressingManager.h">
|
<ClInclude Include="ChunkManager.h">
|
||||||
<Filter>Pliki nagłówkowe</Filter>
|
<Filter>Pliki nagłówkowe</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
<ClInclude Include="EncryptionManager.h">
|
<ClInclude Include="EncryptionManager.h">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue