Compare commits
3 commits
93296a1f6e
...
9593f98ae6
| Author | SHA1 | Date | |
|---|---|---|---|
| 9593f98ae6 | |||
|
|
c2bdcfe2b9 | ||
|
|
608e382095 |
6 changed files with 71 additions and 72 deletions
|
|
@ -20,8 +20,8 @@
|
||||||
#include "CreateCargo.h"
|
#include "CreateCargo.h"
|
||||||
|
|
||||||
CreateCargo::CreateCargo()
|
CreateCargo::CreateCargo()
|
||||||
: signature(SIGNATURE)
|
: signature(fl::sigpak)
|
||||||
, extension(EXTENSION)
|
, extension(fl::extpak)
|
||||||
, version(VERSION)
|
, version(VERSION)
|
||||||
, methodFlags(0)
|
, methodFlags(0)
|
||||||
, xxhState(XXH64_createState())
|
, xxhState(XXH64_createState())
|
||||||
|
|
@ -42,7 +42,7 @@ CreateCargo::~CreateCargo() {
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
bool CreateCargo::Create(const std::string& path, const uint8_t& flag)
|
bool CreateCargo::Create(const std::string& path, const uint8_t& flag)
|
||||||
{
|
{
|
||||||
cargoFile = path + "." + extension;
|
cargoFile = path + "." + signature;
|
||||||
catalogPath = path;
|
catalogPath = path;
|
||||||
methodFlags = flag;
|
methodFlags = flag;
|
||||||
|
|
||||||
|
|
@ -90,7 +90,7 @@ bool CreateCargo::Create(const std::string& path, const uint8_t& flag)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Zapisywanie klucza szyfrującego
|
// Zapisywanie klucza szyfrującego
|
||||||
if (flag == FILE_FLAG_ENCRYPT || flag == FILE_FLAG_ZIPENC || encList.size() > 0)
|
if (flag == flag::enc || flag == flag::ezd || encList.size() > 0)
|
||||||
{
|
{
|
||||||
eman.saveKey(catalogPath, hppKey);
|
eman.saveKey(catalogPath, hppKey);
|
||||||
}
|
}
|
||||||
|
|
@ -185,42 +185,13 @@ CargoHead CreateCargo::CreateCargoHead(const uint32_t& filesLen, const uint64_t&
|
||||||
{
|
{
|
||||||
CargoHead ch;
|
CargoHead ch;
|
||||||
|
|
||||||
ch.signature = signature;
|
ch.signature = fl::sigpak;
|
||||||
ch.table = table;
|
ch.table = table;
|
||||||
ch.files = filesLen;
|
ch.files = filesLen;
|
||||||
|
|
||||||
return ch;
|
return ch;
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
// Sprawdza czy plik znajduje siê na liœcie
|
|
||||||
//-----------------------------------------------------------------------------
|
|
||||||
void CreateCargo::computingBytes(const uint8_t& flag, std::vector<char>& input, std::vector<char>& output)
|
|
||||||
{
|
|
||||||
//Flaga aktywna sprawdza czy plik jest na liœcie. Jeœli jest to zwraca surowedane
|
|
||||||
//Przeciwnie kompresuje dane
|
|
||||||
ChunkManager cm(eman);
|
|
||||||
|
|
||||||
switch (flag)
|
|
||||||
{
|
|
||||||
case FILE_FLAG_COMPRESS:
|
|
||||||
output = cm.chunked(input, true, false);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FILE_FLAG_ENCRYPT:
|
|
||||||
output = cm.chunked(input, false, true);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case FILE_FLAG_ZIPENC:
|
|
||||||
output = cm.chunked(input, true, true);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
output = std::move(input);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
// Przygotowanie nagłówków i plików
|
// Przygotowanie nagłówków i plików
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
@ -249,26 +220,26 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
|
||||||
size_t size = f.tellg();
|
size_t size = f.tellg();
|
||||||
f.seekg(0, std::ios::beg);
|
f.seekg(0, std::ios::beg);
|
||||||
|
|
||||||
if (size > MAX_FILE_SIZE)
|
if (size > ds::maxFileSize)
|
||||||
{
|
{
|
||||||
std::cerr << path << " is too large. It exceeds " << MAX_FILE_SIZE / 1024 / 1024 / 1024 << "GB!" << std::endl;
|
std::cerr << path << " is too large. It exceeds " << ds::maxFileSize / 1024 / 1024 / 1024 << "GB!" << std::endl;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
XXH64_reset(xxhState, 0);
|
XXH64_reset(xxhState, 0);
|
||||||
|
|
||||||
//Wczytanie pliku do pamięci
|
//Wczytanie pliku do pamięci
|
||||||
std::vector<char> buffer(CHUNK_STREAM_256MB);
|
std::vector<char> buffer(ds::chunk_stream);
|
||||||
|
|
||||||
uint64_t sizeFile = 0;
|
uint64_t sizeFile = 0;
|
||||||
|
|
||||||
const uint32_t chunkBlockSize = CHUNK_BLOCK_SIZE;
|
const uint32_t chunkBlockSize = ds::block_size;
|
||||||
const uint32_t quantity = (size + chunkBlockSize) / chunkBlockSize;
|
const uint32_t quantity = (size + chunkBlockSize) / chunkBlockSize;
|
||||||
const uint32_t lastChunkSize = size - (chunkBlockSize * (quantity - 1));
|
const uint32_t lastChunkSize = size - (chunkBlockSize * (quantity - 1));
|
||||||
|
|
||||||
// Jeśli jest ustawiona flaga inna niż RAW
|
// Jeśli jest ustawiona flaga inna niż RAW
|
||||||
// Dodaj do kontenera konfigurację chunków
|
// Dodaj do kontenera konfigurację chunków
|
||||||
if (file.parameter != FILE_FLAG_RAW)
|
if (file.parameter != flag::raw)
|
||||||
{
|
{
|
||||||
std::cout << "CHUNK PARAM" << std::endl;
|
std::cout << "CHUNK PARAM" << std::endl;
|
||||||
cargo.write(reinterpret_cast<const char*>(&quantity), sizeof(quantity));
|
cargo.write(reinterpret_cast<const char*>(&quantity), sizeof(quantity));
|
||||||
|
|
@ -278,7 +249,7 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
|
||||||
}
|
}
|
||||||
|
|
||||||
// Strumieniowanie danych
|
// Strumieniowanie danych
|
||||||
while (f.read(buffer.data(), CHUNK_STREAM_256MB) || f.gcount() > 0)
|
while (f.read(buffer.data(), ds::chunk_stream) || f.gcount() > 0)
|
||||||
{
|
{
|
||||||
const int bufferSize = f.gcount();
|
const int bufferSize = f.gcount();
|
||||||
buffer.resize(bufferSize);
|
buffer.resize(bufferSize);
|
||||||
|
|
@ -286,7 +257,7 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
|
||||||
// Aktualizacja XXH64
|
// Aktualizacja XXH64
|
||||||
XXH64_update(xxhState, buffer.data(), buffer.size());
|
XXH64_update(xxhState, buffer.data(), buffer.size());
|
||||||
|
|
||||||
if (file.parameter == FILE_FLAG_RAW)
|
if (file.parameter == flag::raw)
|
||||||
{
|
{
|
||||||
// Zapisywanie strumienia do kontenera
|
// Zapisywanie strumienia do kontenera
|
||||||
cargo.write(reinterpret_cast<const char*>(buffer.data()), buffer.size());
|
cargo.write(reinterpret_cast<const char*>(buffer.data()), buffer.size());
|
||||||
|
|
@ -308,16 +279,16 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
|
||||||
std::vector<char> outChunk;
|
std::vector<char> outChunk;
|
||||||
|
|
||||||
// Przetwórz chunki i przetwórz
|
// Przetwórz chunki i przetwórz
|
||||||
if ((file.parameter & FILE_FLAG_COMPRESS) == FILE_FLAG_COMPRESS)
|
if ((file.parameter & flag::zip) == flag::zip)
|
||||||
{
|
{
|
||||||
// Zaszyfruj i skompresuj lub tylko skompresuj
|
// Zaszyfruj i skompresuj lub tylko skompresuj
|
||||||
outChunk = (file.parameter & FILE_FLAG_ENCRYPT) == FILE_FLAG_ENCRYPT ?
|
outChunk = (file.parameter & flag::enc) == flag::enc ?
|
||||||
eman.encrypt(cman.compress(chunk)) : cman.compress(chunk);
|
eman.encrypt(cman.compress(chunk)) : cman.compress(chunk);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
// Zaszyfruj lub skopiuj
|
// Zaszyfruj lub skopiuj
|
||||||
outChunk = (file.parameter & FILE_FLAG_ENCRYPT) == FILE_FLAG_ENCRYPT ?
|
outChunk = (file.parameter & flag::enc) == flag::enc ?
|
||||||
eman.encrypt(cman.compress(chunk)) : cman.compress(chunk);
|
eman.encrypt(cman.compress(chunk)) : cman.compress(chunk);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -373,24 +344,25 @@ void CreateCargo::GetFilters(const std::string& filterFile)
|
||||||
file.close();
|
file.close();
|
||||||
|
|
||||||
// Lista plików do skompresowania
|
// Lista plików do skompresowania
|
||||||
if (jslist.contains(KEY_ZIP))
|
if (jslist.contains(key::zip))
|
||||||
{
|
{
|
||||||
zipList = jslist[KEY_ZIP].get<std::vector<std::string>>();
|
zipList = jslist[key::zip].get<std::vector<std::string>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lista plików do zaszyfrowania
|
// Lista plików do zaszyfrowania
|
||||||
if (jslist.contains(KEY_ENCRYPT))
|
if (jslist.contains(key::enc))
|
||||||
{
|
{
|
||||||
encList = jslist[KEY_ENCRYPT].get<std::vector<std::string>>();
|
encList = jslist[key::enc].get<std::vector<std::string>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Lista plików do pominięcia
|
// Lista plików do pominięcia
|
||||||
if (jslist.contains(KEY_IGNORE))
|
if (jslist.contains(key::ignore))
|
||||||
{
|
{
|
||||||
ignoreList = jslist[KEY_IGNORE].get<std::vector<std::string>>();
|
ignoreList = jslist[key::ignore].get<std::vector<std::string>>();
|
||||||
}
|
}
|
||||||
|
|
||||||
hppKey = jslist.value("keyhpp", false);
|
// Flaga tworzenia klucza jako plik nag³ówka c++
|
||||||
|
hppKey = jslist.value(key::hpp, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
//-----------------------------------------------------------------------------
|
//-----------------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -45,6 +45,17 @@
|
||||||
|
|
||||||
#define ALL_FILE ".*" // Wszystkie pliki
|
#define ALL_FILE ".*" // Wszystkie pliki
|
||||||
|
|
||||||
|
namespace key
|
||||||
|
{
|
||||||
|
inline constexpr std::string_view zip = "compress";
|
||||||
|
inline constexpr std::string_view raw = "raw";
|
||||||
|
inline constexpr std::string_view enc = "encrypt";
|
||||||
|
inline constexpr std::string_view ignore = "ignore";
|
||||||
|
inline constexpr std::string_view all = ".*";
|
||||||
|
|
||||||
|
inline constexpr std::string_view hpp = "keyhpp";
|
||||||
|
}
|
||||||
|
|
||||||
struct PathConf
|
struct PathConf
|
||||||
{
|
{
|
||||||
std::string path;
|
std::string path;
|
||||||
|
|
@ -113,9 +124,6 @@ private:
|
||||||
// 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
|
|
||||||
void computingBytes(const uint8_t&, std::vector<char>&, std::vector<char>&);
|
|
||||||
|
|
||||||
// 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>&);
|
||||||
|
|
||||||
|
|
|
||||||
37
DataStruct.h
37
DataStruct.h
|
|
@ -44,7 +44,6 @@
|
||||||
|
|
||||||
#define FILE_FLAG_FILTERING 0xAB
|
#define FILE_FLAG_FILTERING 0xAB
|
||||||
|
|
||||||
|
|
||||||
//Prgoram title
|
//Prgoram title
|
||||||
#define PROGRAM_TITLE "eXtendet PAK"
|
#define PROGRAM_TITLE "eXtendet PAK"
|
||||||
#define PROGRAM_VERSION "v0.5"
|
#define PROGRAM_VERSION "v0.5"
|
||||||
|
|
@ -52,9 +51,39 @@
|
||||||
#define PROGRAM_COMPILING "19 December 2025"
|
#define PROGRAM_COMPILING "19 December 2025"
|
||||||
#define PROGRAM_LICENSE "GNU LGPL v3"
|
#define PROGRAM_LICENSE "GNU LGPL v3"
|
||||||
|
|
||||||
//Limity
|
// Pliki
|
||||||
#define MAX_FILE_SIZE 8589934592 // 8GB
|
namespace fl {
|
||||||
#define MAX_PAK_SIZE 8796093022208 // 8TB
|
inline constexpr std::string_view sigpak = "XPAK";
|
||||||
|
inline constexpr std::string_view sigkey = "XKEY";
|
||||||
|
|
||||||
|
inline constexpr std::string_view extpak = "pak";
|
||||||
|
inline constexpr std::string_view extkey = "key";
|
||||||
|
}
|
||||||
|
|
||||||
|
// Size
|
||||||
|
namespace ds
|
||||||
|
{
|
||||||
|
// Chunki streamowania
|
||||||
|
inline constexpr int chunk_stream = 268435456; // 256MB
|
||||||
|
|
||||||
|
// Blok chunków
|
||||||
|
inline constexpr int block_size = 131072; // 128KB
|
||||||
|
|
||||||
|
// Maksymalny rozmiar pliku do spakowania
|
||||||
|
inline constexpr int maxFileSize = 8589934592; // 8GB
|
||||||
|
}
|
||||||
|
|
||||||
|
// Flagi
|
||||||
|
namespace flag
|
||||||
|
{
|
||||||
|
inline constexpr uint8_t raw = 0x00; // Surowy plik
|
||||||
|
inline constexpr uint8_t zip = 0x0F; // Kompresja
|
||||||
|
inline constexpr uint8_t enc = 0xF0; // Szyfrowanie
|
||||||
|
inline constexpr uint8_t ezd = 0xFF; // Kompresja z szyfrowaniem
|
||||||
|
|
||||||
|
// Flaga do aktywacji filtra zdefiniowanego w json
|
||||||
|
inline constexpr uint8_t filter = 0xAB;
|
||||||
|
}
|
||||||
|
|
||||||
struct CargoHead
|
struct CargoHead
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,11 +22,11 @@
|
||||||
ExtractCargo::ExtractCargo()
|
ExtractCargo::ExtractCargo()
|
||||||
:filesLen(0)
|
:filesLen(0)
|
||||||
, tablePosition(0)
|
, tablePosition(0)
|
||||||
, version(VERSION)
|
, xxhState(XXH64_createState())
|
||||||
, signature(SIGNATURE)
|
, signature(SIGNATURE)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
|
XXH64_reset(xxhState, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
ExtractCargo::~ExtractCargo()
|
ExtractCargo::~ExtractCargo()
|
||||||
|
|
|
||||||
|
|
@ -47,8 +47,8 @@ private:
|
||||||
|
|
||||||
uint32_t filesLen;
|
uint32_t filesLen;
|
||||||
uint64_t tablePosition;
|
uint64_t tablePosition;
|
||||||
|
XXH64_state_t* xxhState;
|
||||||
|
|
||||||
const int8_t version;
|
|
||||||
const std::string signature;
|
const std::string signature;
|
||||||
|
|
||||||
std::vector<FilesTable> filesHeads;
|
std::vector<FilesTable> filesHeads;
|
||||||
|
|
|
||||||
12
voidcmd.cpp
12
voidcmd.cpp
|
|
@ -82,17 +82,7 @@ static bool EmptyPath(std::string path)
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
std::string path = "";
|
std::string path = "";
|
||||||
|
|
||||||
std::cout <<
|
std::cout << PROGRAM_VERSION << " Release " << PROGRAM_COMPILING << std::endl;
|
||||||
" 8888888b. d8888 888 d8P \n"
|
|
||||||
" 888 Y88b d88888 888 d8P \n"
|
|
||||||
" 888 888 d88P888 888 d8P \n"
|
|
||||||
" .d88b. 888 888 888 d88P d88P 888 888d88K \n"
|
|
||||||
"d8P Y8b `Y8bd8P' 8888888P\" d88P 888 8888888b \n"
|
|
||||||
"88888888 X88K 888 d88P 888 888 Y88b \n"
|
|
||||||
"Y8b. .d8\"\"8b. 888 d8888888888 888 Y88b \n"
|
|
||||||
" \"Y8888 888 888 888 d88P 888 888 Y88b\n"
|
|
||||||
<< std::endl;
|
|
||||||
std::cout << "\n" << PROGRAM_VERSION << " Release " << PROGRAM_COMPILING << std::endl;
|
|
||||||
std::cout << "Author: " << PROGRAM_AUTHOR << std::endl;
|
std::cout << "Author: " << PROGRAM_AUTHOR << std::endl;
|
||||||
std::cout << "License: " << PROGRAM_LICENSE << "\n" << std::endl;
|
std::cout << "License: " << PROGRAM_LICENSE << "\n" << std::endl;
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue