Zmiana metody kompresji na chunkowanie, zmiana nazwy z Void Archive na expak
This commit is contained in:
parent
f6150b0d17
commit
aef8daae9b
15 changed files with 320 additions and 93 deletions
7
.gitignore
vendored
7
.gitignore
vendored
|
|
@ -361,3 +361,10 @@ MigrationBackup/
|
||||||
|
|
||||||
# Fody - auto-generated XML schema
|
# Fody - auto-generated XML schema
|
||||||
FodyWeavers.xsd
|
FodyWeavers.xsd
|
||||||
|
|
||||||
|
3rd/
|
||||||
|
test/
|
||||||
|
test2/
|
||||||
|
*.pak
|
||||||
|
expak/
|
||||||
|
x64/
|
||||||
121
CompressingManager.cpp
Normal file
121
CompressingManager.cpp
Normal file
|
|
@ -0,0 +1,121 @@
|
||||||
|
#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());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::cout << "FULL: " << chunksString.size() << std::endl;
|
||||||
|
|
||||||
|
return chunksString;
|
||||||
|
}
|
||||||
54
CompressingManager.h
Normal file
54
CompressingManager.h
Normal file
|
|
@ -0,0 +1,54 @@
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <cstdint>
|
||||||
|
#include <cstring>
|
||||||
|
#include <lz4.h>
|
||||||
|
#include <stdexcept>
|
||||||
|
#include <algorithm>
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
|
#define BLOCK_SIZE 131072 // 128KB
|
||||||
|
|
||||||
|
struct BlockSize
|
||||||
|
{
|
||||||
|
uint32_t raw;
|
||||||
|
uint32_t zip;
|
||||||
|
};
|
||||||
|
|
||||||
|
class CompressingManager
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
CompressingManager();
|
||||||
|
~CompressingManager();
|
||||||
|
|
||||||
|
// Kompresja danych
|
||||||
|
std::vector<char> compress(const std::vector<char>&);
|
||||||
|
|
||||||
|
// Dekompresja
|
||||||
|
std::vector<char> decompress(const std::vector<char>&);
|
||||||
|
|
||||||
|
private:
|
||||||
|
std::vector<BlockSize> blockSizes;
|
||||||
|
|
||||||
|
// Przekonwertuj zmienn¹ na ci¹g na vector
|
||||||
|
template <typename T>
|
||||||
|
void addIntToVector(std::vector<char>& vec, const T& val)
|
||||||
|
{
|
||||||
|
size_t tmpSize = vec.size();
|
||||||
|
vec.resize(tmpSize + sizeof(val));
|
||||||
|
std::memcpy(vec.data() + tmpSize, &val, sizeof(val));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pobierz zmienn¹ z vectora
|
||||||
|
template <typename T>
|
||||||
|
T getIntFromVector(const std::vector<char>& vec, size_t& offset)
|
||||||
|
{
|
||||||
|
T tmp{};
|
||||||
|
std::memcpy(&tmp, vec.data() + offset, sizeof(tmp));
|
||||||
|
offset += sizeof(tmp);
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
@ -157,48 +157,38 @@ CargoHead CreateCargo::CreateCargoHead(const uint32_t& filesLen, const uint64_t&
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Kompresowanie
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
std::vector<char> CreateCargo::Compressing(const std::vector<char>& raw)
|
|
||||||
{
|
|
||||||
int maxZipSize = LZ4_compressBound(raw.size());
|
|
||||||
std::vector<char> zip(maxZipSize);
|
|
||||||
int zipSize = LZ4_compress_default(raw.data(), zip.data(), raw.size(), maxZipSize);
|
|
||||||
zip.resize(zipSize);
|
|
||||||
|
|
||||||
return zip;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Sprawdza czy plik znajduje siê na liœcie
|
// Sprawdza czy plik znajduje siê na liœcie
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool CreateCargo::CheckFileOnTheList(const std::string& path, std::vector<char>& input, std::vector<char>& output)
|
uint8_t CreateCargo::CheckFileOnTheList(const std::string& path, std::vector<char>& input, std::vector<char>& output)
|
||||||
{
|
{
|
||||||
//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;
|
||||||
|
|
||||||
if (filteringFlag) {
|
if (filteringFlag) {
|
||||||
if (FilteringData(path))
|
if (FilteringData(path))
|
||||||
{
|
{
|
||||||
output = Compressing(input);
|
output = cm.compress(input);
|
||||||
return true;
|
return ZIP_FILE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
output = std::move(input);
|
output = std::move(input);
|
||||||
return false;
|
return RAW_FILE;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Flaga aktywna kompresuje dane
|
//Flaga aktywna kompresuje dane
|
||||||
if (compressingFlag)
|
if (compressingFlag)
|
||||||
{
|
{
|
||||||
output = Compressing(input);
|
|
||||||
return true;
|
output = cm.compress(input);
|
||||||
|
return ZIP_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
output = std::move(input);
|
output = std::move(input);
|
||||||
return false;
|
return RAW_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -238,15 +228,15 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
|
||||||
|
|
||||||
//Kompresjia
|
//Kompresjia
|
||||||
std::vector<char> zip;
|
std::vector<char> zip;
|
||||||
bool isZip = CheckFileOnTheList(path, buffor, zip);
|
uint8_t method = CheckFileOnTheList(path, buffor, zip);
|
||||||
|
|
||||||
FilesTable ft;
|
FilesTable ft;
|
||||||
ft.nameFile = path;
|
ft.nameFile = path;
|
||||||
ft.nameLen = path.length();
|
ft.nameLen = path.length();
|
||||||
|
ft.hashName = fnv32(path);
|
||||||
ft.offset = offset;
|
ft.offset = offset;
|
||||||
ft.size = zip.size();
|
ft.size = zip.size();
|
||||||
ft.rawSize = size;
|
ft.isZip = method;
|
||||||
ft.isZip = isZip;
|
|
||||||
ft.crc = crc;
|
ft.crc = crc;
|
||||||
|
|
||||||
cargo.write(reinterpret_cast<const char*>(zip.data()), zip.size());
|
cargo.write(reinterpret_cast<const char*>(zip.data()), zip.size());
|
||||||
|
|
@ -323,6 +313,24 @@ std::string CreateCargo::UpperString(std::string s) {
|
||||||
return s;
|
return s;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
// Wygenerój FNV-1a HASH
|
||||||
|
//-----------------------------------------------------------------------------
|
||||||
|
uint32_t CreateCargo::fnv32(const std::string& data)
|
||||||
|
{
|
||||||
|
const uint32_t fnvOffset = 2166136261u;
|
||||||
|
const uint32_t fnvPrime = 16777619u;
|
||||||
|
|
||||||
|
uint32_t hash = fnvOffset;
|
||||||
|
for (unsigned char c : data)
|
||||||
|
{
|
||||||
|
hash ^= c;
|
||||||
|
hash *= fnvPrime;
|
||||||
|
}
|
||||||
|
|
||||||
|
return hash;
|
||||||
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Sprawdzanie czy plik znajduje siê na liœcie
|
// Sprawdzanie czy plik znajduje siê na liœcie
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -412,9 +420,9 @@ bool CreateCargo::WriteCargo()
|
||||||
cargo.write(reinterpret_cast<const char*>(&head.nameLen), sizeof(head.nameLen));
|
cargo.write(reinterpret_cast<const char*>(&head.nameLen), sizeof(head.nameLen));
|
||||||
cargo.write(head.nameFile.data(), head.nameLen);
|
cargo.write(head.nameFile.data(), head.nameLen);
|
||||||
|
|
||||||
|
cargo.write(reinterpret_cast<const char*>(&head.hashName), sizeof(head.hashName));
|
||||||
cargo.write(reinterpret_cast<const char*>(&head.offset), sizeof(head.offset));
|
cargo.write(reinterpret_cast<const char*>(&head.offset), sizeof(head.offset));
|
||||||
cargo.write(reinterpret_cast<const char*>(&head.size), sizeof(head.size));
|
cargo.write(reinterpret_cast<const char*>(&head.size), sizeof(head.size));
|
||||||
cargo.write(reinterpret_cast<const char*>(&head.rawSize), sizeof(head.rawSize));
|
|
||||||
cargo.write(reinterpret_cast<const char*>(&head.crc), sizeof(head.crc));
|
cargo.write(reinterpret_cast<const char*>(&head.crc), sizeof(head.crc));
|
||||||
cargo.write(reinterpret_cast<const char*>(&head.isZip), sizeof(head.isZip));
|
cargo.write(reinterpret_cast<const char*>(&head.isZip), sizeof(head.isZip));
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,7 @@
|
||||||
#include "DataStruct.h"
|
#include "DataStruct.h"
|
||||||
#include "Txtpp.h"
|
#include "Txtpp.h"
|
||||||
#include "xxhash.h"
|
#include "xxhash.h"
|
||||||
|
#include "CompressingManager.h"
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -98,9 +99,6 @@ private:
|
||||||
// Tworzenie nag³owka pliku
|
// Tworzenie nag³owka pliku
|
||||||
CargoHead CreateCargoHead(const uint32_t&, const uint64_t&);
|
CargoHead CreateCargoHead(const uint32_t&, const uint64_t&);
|
||||||
|
|
||||||
// Kompresowanie
|
|
||||||
std::vector<char> Compressing(const std::vector<char>&);
|
|
||||||
|
|
||||||
// Przygotowanie nag³ówków i plików
|
// Przygotowanie nag³ówków i plików
|
||||||
std::vector<FilesTable> ComputingHeadFiles();
|
std::vector<FilesTable> ComputingHeadFiles();
|
||||||
|
|
||||||
|
|
@ -111,7 +109,7 @@ private:
|
||||||
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
|
||||||
bool CheckFileOnTheList(const std::string&, std::vector<char>&, std::vector<char>&);
|
uint8_t CheckFileOnTheList(const std::string&, std::vector<char>&, std::vector<char>&);
|
||||||
|
|
||||||
// Kasowanie z listy plików ignorow
|
// Kasowanie z listy plików ignorow
|
||||||
bool CheckIgnorePath(const std::string&);
|
bool CheckIgnorePath(const std::string&);
|
||||||
|
|
@ -122,6 +120,9 @@ private:
|
||||||
// Zamieñ ca³y ci¹g na du¿e litery
|
// Zamieñ ca³y ci¹g na du¿e litery
|
||||||
std::string UpperString(std::string);
|
std::string UpperString(std::string);
|
||||||
|
|
||||||
|
// Wygenerój FNV-1a HASH
|
||||||
|
uint32_t fnv32(const std::string& data);
|
||||||
|
|
||||||
// Rozdzielanie paternu od œcie¿ki
|
// Rozdzielanie paternu od œcie¿ki
|
||||||
void ExtPatternAndPathDetection(const std::vector<std::string>&, std::vector<std::string>&, std::vector<std::string>&);
|
void ExtPatternAndPathDetection(const std::vector<std::string>&, std::vector<std::string>&, std::vector<std::string>&);
|
||||||
|
|
||||||
|
|
|
||||||
24
DataStruct.h
24
DataStruct.h
|
|
@ -25,24 +25,32 @@
|
||||||
|
|
||||||
|
|
||||||
#define EXTENSION "pak"
|
#define EXTENSION "pak"
|
||||||
#define SIGNATURE "VoidFS"
|
#define SIGNATURE "XPAK"
|
||||||
|
|
||||||
#define VERSION 11
|
#define VERSION 100
|
||||||
|
|
||||||
|
|
||||||
//Prgoram title
|
//Prgoram title
|
||||||
#define PROGRAM_TITLE "Void Archive Tool"
|
#define PROGRAM_TITLE "eXtendet PAK"
|
||||||
#define PROGRAM_VERSION "v1.1"
|
#define PROGRAM_VERSION "v1.2"
|
||||||
#define PROGRAM_AUTHOR "Yanczi"
|
#define PROGRAM_AUTHOR "Yanczi"
|
||||||
#define PROGRAM_COMPILING "1 September 2025"
|
#define PROGRAM_COMPILING "28 September 2025"
|
||||||
#define PROGRAM_LICENSE "GNU LGPL v3"
|
#define PROGRAM_LICENSE "GNU LGPL v3"
|
||||||
|
|
||||||
|
//Limity
|
||||||
|
#define MAX_FILE_SIZE 2147483648 // 2GB
|
||||||
|
#define MAX_PAK_SIZE 8796093022208 // 8TB
|
||||||
|
|
||||||
|
// Metody zapisania pliku
|
||||||
|
#define RAW_FILE 0
|
||||||
|
#define ZIP_FILE 1
|
||||||
|
#define CRYPT_FILE 2
|
||||||
|
#define CRYPT_ZIP 3
|
||||||
|
|
||||||
struct CargoHead
|
struct CargoHead
|
||||||
{
|
{
|
||||||
std::string signature;
|
std::string signature;
|
||||||
uint8_t version;
|
uint16_t version;
|
||||||
uint32_t files;
|
uint32_t files;
|
||||||
uint64_t table;
|
uint64_t table;
|
||||||
};
|
};
|
||||||
|
|
@ -51,9 +59,9 @@ struct FilesTable
|
||||||
{
|
{
|
||||||
uint8_t nameLen;
|
uint8_t nameLen;
|
||||||
std::string nameFile;
|
std::string nameFile;
|
||||||
|
uint32_t hashName;
|
||||||
uint64_t offset;
|
uint64_t offset;
|
||||||
uint32_t size;
|
uint32_t size;
|
||||||
uint32_t rawSize;
|
|
||||||
uint64_t crc;
|
uint64_t crc;
|
||||||
bool isZip;
|
uint8_t isZip;
|
||||||
};
|
};
|
||||||
|
|
@ -78,8 +78,8 @@ bool ExtractCargo::Extract(const std::string& cFile)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool ExtractCargo::CheckCargoFile()
|
bool ExtractCargo::CheckCargoFile()
|
||||||
{
|
{
|
||||||
std::vector<char> magic(6);
|
std::vector<char> magic(signature.size());
|
||||||
uint8_t cargoVer = 0;
|
uint16_t cargoVer = 0;
|
||||||
|
|
||||||
if (!cargoFile.is_open())
|
if (!cargoFile.is_open())
|
||||||
{
|
{
|
||||||
|
|
@ -92,6 +92,8 @@ bool ExtractCargo::CheckCargoFile()
|
||||||
cargoFile.read(reinterpret_cast<char*>(&filesLen), sizeof(filesLen));
|
cargoFile.read(reinterpret_cast<char*>(&filesLen), sizeof(filesLen));
|
||||||
cargoFile.read(reinterpret_cast<char*>(&tablePosition), sizeof(tablePosition));
|
cargoFile.read(reinterpret_cast<char*>(&tablePosition), sizeof(tablePosition));
|
||||||
|
|
||||||
|
std::cout << std::string(magic.begin(), magic.end()) << std::endl;
|
||||||
|
|
||||||
if (std::string(magic.begin(), magic.end()) != signature)
|
if (std::string(magic.begin(), magic.end()) != signature)
|
||||||
{
|
{
|
||||||
std::cerr << "Error: Corrupted Cargo" << std::endl;
|
std::cerr << "Error: Corrupted Cargo" << std::endl;
|
||||||
|
|
@ -109,29 +111,6 @@ bool ExtractCargo::CheckCargoFile()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Dekomprezja danych
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
std::vector<char> ExtractCargo::DecompressingData(const std::vector<char>& zip, const uint32_t& estimatedSize)
|
|
||||||
{
|
|
||||||
std::vector<char> unzip(estimatedSize);
|
|
||||||
|
|
||||||
int sizeData = LZ4_decompress_safe(
|
|
||||||
zip.data(),
|
|
||||||
unzip.data(),
|
|
||||||
static_cast<int>(zip.size()),
|
|
||||||
static_cast<int>(estimatedSize)
|
|
||||||
);
|
|
||||||
|
|
||||||
if (sizeData < 0)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("LZ4 Decompressing Error");
|
|
||||||
}
|
|
||||||
unzip.resize(sizeData);
|
|
||||||
|
|
||||||
return unzip;
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Sprawdzanie sumy kontrolnej
|
// Sprawdzanie sumy kontrolnej
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -163,9 +142,9 @@ void ExtractCargo::LoadFilesTable()
|
||||||
cargoFile.read(nameBuffor.data(), fhTmp.nameLen);
|
cargoFile.read(nameBuffor.data(), fhTmp.nameLen);
|
||||||
fhTmp.nameFile = std::string(nameBuffor.begin(), nameBuffor.end());
|
fhTmp.nameFile = std::string(nameBuffor.begin(), nameBuffor.end());
|
||||||
|
|
||||||
|
cargoFile.read(reinterpret_cast<char*>(&fhTmp.hashName), sizeof(fhTmp.hashName));
|
||||||
cargoFile.read(reinterpret_cast<char*>(&fhTmp.offset), sizeof(fhTmp.offset));
|
cargoFile.read(reinterpret_cast<char*>(&fhTmp.offset), sizeof(fhTmp.offset));
|
||||||
cargoFile.read(reinterpret_cast<char*>(&fhTmp.size), sizeof(fhTmp.size));
|
cargoFile.read(reinterpret_cast<char*>(&fhTmp.size), sizeof(fhTmp.size));
|
||||||
cargoFile.read(reinterpret_cast<char*>(&fhTmp.rawSize), sizeof(fhTmp.rawSize));
|
|
||||||
cargoFile.read(reinterpret_cast<char*>(&fhTmp.crc), sizeof(fhTmp.crc));
|
cargoFile.read(reinterpret_cast<char*>(&fhTmp.crc), sizeof(fhTmp.crc));
|
||||||
cargoFile.read(reinterpret_cast<char*>(&fhTmp.isZip), sizeof(fhTmp.isZip));
|
cargoFile.read(reinterpret_cast<char*>(&fhTmp.isZip), sizeof(fhTmp.isZip));
|
||||||
|
|
||||||
|
|
@ -178,6 +157,8 @@ void ExtractCargo::LoadFilesTable()
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void ExtractCargo::ExtractingFilesFromCargo()
|
void ExtractCargo::ExtractingFilesFromCargo()
|
||||||
{
|
{
|
||||||
|
CompressingManager cm;
|
||||||
|
|
||||||
for (const auto& fh : filesHeads)
|
for (const auto& fh : filesHeads)
|
||||||
{
|
{
|
||||||
std::filesystem::path dir = cargoFileName.stem() / fh.nameFile;
|
std::filesystem::path dir = cargoFileName.stem() / fh.nameFile;
|
||||||
|
|
@ -189,7 +170,7 @@ void ExtractCargo::ExtractingFilesFromCargo()
|
||||||
|
|
||||||
cargoFile.read(buffor.data(), fh.size);
|
cargoFile.read(buffor.data(), fh.size);
|
||||||
|
|
||||||
std::vector<char> rawBuffor = fh.isZip ? DecompressingData(buffor, fh.rawSize) : buffor;
|
std::vector<char> rawBuffor = fh.isZip ? cm.decompress(buffor) : buffor;
|
||||||
|
|
||||||
if (!HashValid(rawBuffor, fh.crc))
|
if (!HashValid(rawBuffor, fh.crc))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,7 +22,6 @@
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <lz4.h>
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
|
@ -30,6 +29,7 @@
|
||||||
|
|
||||||
#include "DataStruct.h"
|
#include "DataStruct.h"
|
||||||
#include "xxhash.h"
|
#include "xxhash.h"
|
||||||
|
#include "CompressingManager.h"
|
||||||
|
|
||||||
class ExtractCargo {
|
class ExtractCargo {
|
||||||
public:
|
public:
|
||||||
|
|
@ -65,9 +65,6 @@ private:
|
||||||
// Pobieranie nag³ówków plików
|
// Pobieranie nag³ówków plików
|
||||||
void LoadFilesTable();
|
void LoadFilesTable();
|
||||||
|
|
||||||
// Dekomprezja danych
|
|
||||||
std::vector<char> DecompressingData(const std::vector<char>&, const uint32_t&);
|
|
||||||
|
|
||||||
// Sprawdzanie sumy kontrolnej
|
// Sprawdzanie sumy kontrolnej
|
||||||
bool HashValid(const std::vector<char>&, const uint64_t&);
|
bool HashValid(const std::vector<char>&, const uint64_t&);
|
||||||
|
|
||||||
|
|
|
||||||
26
Txtpp.h
26
Txtpp.h
|
|
@ -71,6 +71,32 @@ public:
|
||||||
return tmp;
|
return tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
T getValue(const std::string& key, const std::string& val)
|
||||||
|
{
|
||||||
|
std::vector<std::string> tmp;
|
||||||
|
Parse(key, tmp);
|
||||||
|
|
||||||
|
for (const auto& line : tmp)
|
||||||
|
{
|
||||||
|
std::string cleanLine = RemoveSpaces(line);
|
||||||
|
std::string t;
|
||||||
|
std::string v;
|
||||||
|
|
||||||
|
bool tv = false;
|
||||||
|
|
||||||
|
for (const char& c : cleanLine)
|
||||||
|
{
|
||||||
|
if (c != ":") {tv = true;}
|
||||||
|
|
||||||
|
if (!tv) { t += c; }
|
||||||
|
else { v += c; }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return tmp;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const char sectionStart = '{';
|
const char sectionStart = '{';
|
||||||
const char sectionEnd = '}';
|
const char sectionEnd = '}';
|
||||||
|
|
|
||||||
|
|
@ -60,7 +60,7 @@ bool ViewCargo::View(const std::string& path)
|
||||||
|
|
||||||
headElements.push_back(ftxui::text(" Zip ") | ftxui::bold);
|
headElements.push_back(ftxui::text(" Zip ") | ftxui::bold);
|
||||||
headElements.push_back(ftxui::text("Nazwa pliku") | ftxui::bold | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 56));
|
headElements.push_back(ftxui::text("Nazwa pliku") | ftxui::bold | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 56));
|
||||||
headElements.push_back(ftxui::text("CRC") | ftxui::bold | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 20));
|
headElements.push_back(ftxui::text("Hash Name") | ftxui::bold | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 20));
|
||||||
|
|
||||||
filesList.push_back(hbox(std::move(headElements)));
|
filesList.push_back(hbox(std::move(headElements)));
|
||||||
|
|
||||||
|
|
@ -80,7 +80,7 @@ bool ViewCargo::View(const std::string& path)
|
||||||
bool ViewCargo::CheckCargoFile(const std::string& path)
|
bool ViewCargo::CheckCargoFile(const std::string& path)
|
||||||
{
|
{
|
||||||
std::vector<char> magic(signature.length());
|
std::vector<char> magic(signature.length());
|
||||||
uint8_t cargoVer = 0;
|
uint16_t cargoVer = 0;
|
||||||
|
|
||||||
std::ifstream cargo(path, std::ios::binary);
|
std::ifstream cargo(path, std::ios::binary);
|
||||||
|
|
||||||
|
|
@ -139,14 +139,14 @@ void ViewCargo::GetFileList(const std::string& path)
|
||||||
cargo.read(nameBuffor.data(), fhTmp.nameLen);
|
cargo.read(nameBuffor.data(), fhTmp.nameLen);
|
||||||
fhTmp.nameFile = std::string(nameBuffor.begin(), nameBuffor.end());
|
fhTmp.nameFile = std::string(nameBuffor.begin(), nameBuffor.end());
|
||||||
|
|
||||||
|
cargo.read(reinterpret_cast<char*>(&fhTmp.hashName), sizeof(fhTmp.hashName));
|
||||||
cargo.read(reinterpret_cast<char*>(&fhTmp.offset), sizeof(fhTmp.offset));
|
cargo.read(reinterpret_cast<char*>(&fhTmp.offset), sizeof(fhTmp.offset));
|
||||||
cargo.read(reinterpret_cast<char*>(&fhTmp.size), sizeof(fhTmp.size));
|
cargo.read(reinterpret_cast<char*>(&fhTmp.size), sizeof(fhTmp.size));
|
||||||
cargo.read(reinterpret_cast<char*>(&fhTmp.rawSize), sizeof(fhTmp.rawSize));
|
|
||||||
cargo.read(reinterpret_cast<char*>(&fhTmp.crc), sizeof(fhTmp.crc));
|
cargo.read(reinterpret_cast<char*>(&fhTmp.crc), sizeof(fhTmp.crc));
|
||||||
cargo.read(reinterpret_cast<char*>(&fhTmp.isZip), sizeof(fhTmp.isZip));
|
cargo.read(reinterpret_cast<char*>(&fhTmp.isZip), sizeof(fhTmp.isZip));
|
||||||
|
|
||||||
//Tworzenie wierszy tabeli
|
//Tworzenie wierszy tabeli
|
||||||
CreateTableRow(fhTmp.nameFile, fhTmp.isZip, fhTmp.crc);
|
CreateTableRow(fhTmp.nameFile, fhTmp.isZip, fhTmp.hashName);
|
||||||
}
|
}
|
||||||
|
|
||||||
cargo.close();
|
cargo.close();
|
||||||
|
|
@ -155,7 +155,7 @@ void ViewCargo::GetFileList(const std::string& path)
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Generowanie wierszy do tabeli
|
// Generowanie wierszy do tabeli
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
void ViewCargo::CreateTableRow(std::string file, bool zip, uint64_t hash)
|
void ViewCargo::CreateTableRow(const std::string& file, const uint8_t& zip, const uint32_t& hash)
|
||||||
{
|
{
|
||||||
//Zamiania crc liczbowej na hex string
|
//Zamiania crc liczbowej na hex string
|
||||||
std::stringstream ss;
|
std::stringstream ss;
|
||||||
|
|
@ -166,13 +166,13 @@ void ViewCargo::CreateTableRow(std::string file, bool zip, uint64_t hash)
|
||||||
ftxui::Element eZip;
|
ftxui::Element eZip;
|
||||||
|
|
||||||
//Dodawanie check boxa czy plik jest spakowany czy nie
|
//Dodawanie check boxa czy plik jest spakowany czy nie
|
||||||
if (zip)
|
if (zip == 1)
|
||||||
{
|
{
|
||||||
eZip = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Green);
|
eZip = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
eZip = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::Red);
|
eZip = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
|
||||||
}
|
}
|
||||||
|
|
||||||
//Dodawanie komurek
|
//Dodawanie komurek
|
||||||
|
|
|
||||||
|
|
@ -39,7 +39,7 @@ public:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
const std::string signature;
|
const std::string signature;
|
||||||
const uint8_t version;
|
const uint16_t version;
|
||||||
|
|
||||||
uint32_t filesLen;
|
uint32_t filesLen;
|
||||||
uint64_t tablePos;
|
uint64_t tablePos;
|
||||||
|
|
@ -48,7 +48,7 @@ private:
|
||||||
bool CheckCargoFile(const std::string&);
|
bool CheckCargoFile(const std::string&);
|
||||||
void GetFileList(const std::string&);
|
void GetFileList(const std::string&);
|
||||||
void RenderList();
|
void RenderList();
|
||||||
void CreateTableRow(std::string, bool, uint64_t);
|
void CreateTableRow(const std::string&, const uint8_t&, const uint32_t&);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
25
voidcmd.cpp
25
voidcmd.cpp
|
|
@ -38,21 +38,30 @@ void RenderHelp()
|
||||||
{
|
{
|
||||||
const std::string HelpTitle = "< Manual >";
|
const std::string HelpTitle = "< Manual >";
|
||||||
const std::string HelpInstruction =
|
const std::string HelpInstruction =
|
||||||
"voidarchive <parametr> <plik & katalog> \n"
|
"pakcmd <parametr> <catalog> \n"
|
||||||
" \n"
|
" \n"
|
||||||
"COMPRESSION -c Pack and compress files from the specified directory \n"
|
" -c Pack and compress with LZ4 \n"
|
||||||
"PACKING -p Pack files from the specified directory \n"
|
" -p Pack files from the specified directory \n"
|
||||||
"FILTERING -f Pack the files according to the guidelines given in the <directory>.txt\n"
|
" -e Pack and encrypted from the specified directory \n"
|
||||||
"EXTRACTING -x Extract files from the specified container \n"
|
" -f Pack the files according to the guidelines given in the <directory>.txt \n"
|
||||||
"LISTING -ls List files stored in a container \n"
|
" \n"
|
||||||
|
"Extracting: \n"
|
||||||
|
" -x Extract files from the specified container \n"
|
||||||
|
" -ls List files stored in a container \n"
|
||||||
" \n"
|
" \n"
|
||||||
" \n"
|
" \n"
|
||||||
"<catalog>.txt \n"
|
"<catalog>.txt \n"
|
||||||
" \n"
|
" \n"
|
||||||
"Keys: \n"
|
"Keys: \n"
|
||||||
" \n"
|
" \n"
|
||||||
" {compress} - Compressing files -> /path/data/file.txt *.txt *.* - All files \n"
|
" {compress} - Compressing files \n"
|
||||||
" {ignore} - Ignoring concrete files -> /path/data/file.txt *.txt \n";
|
" {crypt} - Encrypted files with AES256 \n"
|
||||||
|
" {ignore} - Ignoring concrete files \n"
|
||||||
|
" \n"
|
||||||
|
" /path/to/file.ext - Concrete file \n"
|
||||||
|
" *.ext - All files with concrete extension \n"
|
||||||
|
" *.* - All files !NOT WORKING WITH {ignore} KEY! \n"
|
||||||
|
" \n";
|
||||||
|
|
||||||
Interface tui;
|
Interface tui;
|
||||||
tui.TextBorder(HelpTitle, HelpInstruction);
|
tui.TextBorder(HelpTitle, HelpInstruction);
|
||||||
|
|
|
||||||
|
|
@ -24,6 +24,7 @@
|
||||||
<ProjectGuid>{fc5a6d25-b824-4f4f-86c6-c2cc11d4f02b}</ProjectGuid>
|
<ProjectGuid>{fc5a6d25-b824-4f4f-86c6-c2cc11d4f02b}</ProjectGuid>
|
||||||
<RootNamespace>voidcmd</RootNamespace>
|
<RootNamespace>voidcmd</RootNamespace>
|
||||||
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
<WindowsTargetPlatformVersion>10.0</WindowsTargetPlatformVersion>
|
||||||
|
<ProjectName>expak</ProjectName>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">
|
||||||
|
|
@ -103,10 +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\lz4\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>3rd\lz4\lib</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>liblz4_static.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
|
||||||
|
|
@ -118,13 +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\lz4\include</AdditionalIncludeDirectories>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
<Link>
|
<Link>
|
||||||
<SubSystem>Console</SubSystem>
|
<SubSystem>Console</SubSystem>
|
||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
|
<AdditionalLibraryDirectories>3rd\lz4\lib</AdditionalLibraryDirectories>
|
||||||
|
<AdditionalDependencies>liblz4_static.lib</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClCompile Include="CompressingManager.cpp" />
|
||||||
<ClCompile Include="CreateCargo.cpp" />
|
<ClCompile Include="CreateCargo.cpp" />
|
||||||
<ClCompile Include="ExtractCargo.cpp" />
|
<ClCompile Include="ExtractCargo.cpp" />
|
||||||
<ClCompile Include="Interface.cpp" />
|
<ClCompile Include="Interface.cpp" />
|
||||||
|
|
@ -133,6 +141,7 @@
|
||||||
<ClCompile Include="xxhash.c" />
|
<ClCompile Include="xxhash.c" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
|
<ClInclude Include="CompressingManager.h" />
|
||||||
<ClInclude Include="CreateCargo.h" />
|
<ClInclude Include="CreateCargo.h" />
|
||||||
<ClInclude Include="DataStruct.h" />
|
<ClInclude Include="DataStruct.h" />
|
||||||
<ClInclude Include="ExtractCargo.h" />
|
<ClInclude Include="ExtractCargo.h" />
|
||||||
|
|
|
||||||
|
|
@ -33,6 +33,9 @@
|
||||||
<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">
|
||||||
|
<Filter>Pliki źródłowe</Filter>
|
||||||
|
</ClCompile>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="CreateCargo.h">
|
<ClInclude Include="CreateCargo.h">
|
||||||
|
|
@ -56,6 +59,9 @@
|
||||||
<ClInclude Include="Interface.h">
|
<ClInclude Include="Interface.h">
|
||||||
<Filter>Pliki nagłówkowe</Filter>
|
<Filter>Pliki nagłówkowe</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="CompressingManager.h">
|
||||||
|
<Filter>Pliki nagłówkowe</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="icon.ico">
|
<Image Include="icon.ico">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue