Compare commits
No commits in common. "master" and "streaming" have entirely different histories.
9 changed files with 63 additions and 31 deletions
|
|
@ -23,6 +23,9 @@ CompressionManager::CompressionManager()
|
||||||
:cctx(ZSTD_createCCtx())
|
:cctx(ZSTD_createCCtx())
|
||||||
,dctx(ZSTD_createDCtx())
|
,dctx(ZSTD_createDCtx())
|
||||||
{
|
{
|
||||||
|
// Tu ustawienia pod kompresjê
|
||||||
|
const int level = COMPRESSION_LEVEL;
|
||||||
|
|
||||||
// Ustawienia frameless
|
// Ustawienia frameless
|
||||||
size_t rc = 0;
|
size_t rc = 0;
|
||||||
|
|
||||||
|
|
@ -39,7 +42,7 @@ CompressionManager::CompressionManager()
|
||||||
rc |= ZSTD_CCtx_setParameter(cctx, ZSTD_c_dictIDFlag, 0);
|
rc |= ZSTD_CCtx_setParameter(cctx, ZSTD_c_dictIDFlag, 0);
|
||||||
|
|
||||||
// Ustawia poziom kompresji
|
// Ustawia poziom kompresji
|
||||||
rc |= ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, zstd::compression_level);
|
rc |= ZSTD_CCtx_setParameter(cctx, ZSTD_c_compressionLevel, level);
|
||||||
|
|
||||||
if (ZSTD_isError(rc)) {
|
if (ZSTD_isError(rc)) {
|
||||||
std::cerr << "ZSTD_CCtx_setParameter error" << std::endl;
|
std::cerr << "ZSTD_CCtx_setParameter error" << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -30,10 +30,7 @@
|
||||||
#error "Wymagane zstd >= 1.4.0 dla ZSTD_c_format / ZSTD_f_zstd1_magicless"
|
#error "Wymagane zstd >= 1.4.0 dla ZSTD_c_format / ZSTD_f_zstd1_magicless"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
namespace zstd
|
#define COMPRESSION_LEVEL 3
|
||||||
{
|
|
||||||
inline constexpr short compression_level = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
class CompressionManager
|
class CompressionManager
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@
|
||||||
CreateCargo::CreateCargo()
|
CreateCargo::CreateCargo()
|
||||||
: signature(fl::sigpak)
|
: signature(fl::sigpak)
|
||||||
, extension(fl::extpak)
|
, extension(fl::extpak)
|
||||||
|
, version(VERSION)
|
||||||
, methodFlags(0)
|
, methodFlags(0)
|
||||||
, xxhState(XXH64_createState())
|
, xxhState(XXH64_createState())
|
||||||
, offset(0)
|
, offset(0)
|
||||||
|
|
@ -132,11 +133,11 @@ bool CreateCargo::GetFileList(const std::string& path)
|
||||||
{
|
{
|
||||||
if (FindOnTheList(zipList, fileRef) || CheckFileExtension(fileRef, zipList))
|
if (FindOnTheList(zipList, fileRef) || CheckFileExtension(fileRef, zipList))
|
||||||
{
|
{
|
||||||
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? flag::ezd : flag::zip;
|
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? FILE_FLAG_ZIPENC : FILE_FLAG_COMPRESS;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? flag::enc : flag::raw;
|
pc.parameter = FindOnTheList(encList, fileRef) || CheckFileExtension(fileRef, encList) ? FILE_FLAG_ENCRYPT : FILE_FLAG_RAW;
|
||||||
}
|
}
|
||||||
pc.path = PathToUnixLike(tmpPath);
|
pc.path = PathToUnixLike(tmpPath);
|
||||||
std::cout << pc.path << " - " << pc.parameter << std::endl;
|
std::cout << pc.path << " - " << pc.parameter << std::endl;
|
||||||
|
|
|
||||||
|
|
@ -72,6 +72,7 @@ public:
|
||||||
private:
|
private:
|
||||||
const std::string signature;
|
const std::string signature;
|
||||||
const std::string extension;
|
const std::string extension;
|
||||||
|
const signed char version;
|
||||||
|
|
||||||
uint8_t methodFlags;
|
uint8_t methodFlags;
|
||||||
|
|
||||||
|
|
|
||||||
36
DataStruct.h
36
DataStruct.h
|
|
@ -22,15 +22,37 @@
|
||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
namespace ui
|
#define EXTENSION "pak"
|
||||||
{
|
#define SIGNATURE "XPAK"
|
||||||
inline constexpr std::string_view title = "exPak";
|
|
||||||
inline constexpr std::string_view ver = "0.5";
|
#define SIGNATURE_KEY_FILE "XKEY"
|
||||||
}
|
|
||||||
|
#define VERSION 0x03
|
||||||
|
|
||||||
|
// WielkoϾ pojedynczego bloku strumienia
|
||||||
|
#define CHUNK_STREAM_512KB 524288 // 512KB
|
||||||
|
#define CHUNK_STREAM_16MB 16777216 // 16MB
|
||||||
|
#define CHUNK_STREAM_256MB 268435456 // 256MB
|
||||||
|
|
||||||
|
// Rozmiar pojedynczego bloku
|
||||||
|
#define CHUNK_BLOCK_SIZE 131072 // 128KB
|
||||||
|
|
||||||
|
#define FILE_FLAG_RAW 0x00
|
||||||
|
#define FILE_FLAG_COMPRESS 0x0F
|
||||||
|
#define FILE_FLAG_ENCRYPT 0xF0
|
||||||
|
#define FILE_FLAG_ZIPENC 0xFF
|
||||||
|
|
||||||
|
#define FILE_FLAG_FILTERING 0xAB
|
||||||
|
|
||||||
|
//Prgoram title
|
||||||
|
#define PROGRAM_TITLE "eXtendet PAK"
|
||||||
|
#define PROGRAM_VERSION "v0.5"
|
||||||
|
#define PROGRAM_AUTHOR "Yanczi"
|
||||||
|
#define PROGRAM_COMPILING "19 December 2025"
|
||||||
|
#define PROGRAM_LICENSE "GNU LGPL v3"
|
||||||
|
|
||||||
// Pliki
|
// Pliki
|
||||||
namespace fl
|
namespace fl {
|
||||||
{
|
|
||||||
inline constexpr std::string_view sigpak = "XPAK";
|
inline constexpr std::string_view sigpak = "XPAK";
|
||||||
inline constexpr std::string_view sigkey = "XKEY";
|
inline constexpr std::string_view sigkey = "XKEY";
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -67,6 +67,9 @@ void EncryptionManager::generateKeys()
|
||||||
|
|
||||||
void EncryptionManager::saveKey(const std::string& path, bool hpp)
|
void EncryptionManager::saveKey(const std::string& path, bool hpp)
|
||||||
{
|
{
|
||||||
|
const std::string sig = SIGNATURE_KEY_FILE;
|
||||||
|
const int8_t ver = VERSION;
|
||||||
|
|
||||||
// Wygeneruj time stamp
|
// Wygeneruj time stamp
|
||||||
std::time_t now = std::time(nullptr);
|
std::time_t now = std::time(nullptr);
|
||||||
const int time = static_cast<int>(now);
|
const int time = static_cast<int>(now);
|
||||||
|
|
@ -75,13 +78,14 @@ void EncryptionManager::saveKey(const std::string& path, bool hpp)
|
||||||
std::vector<char> keyVec(reinterpret_cast<const char*>(key.data()),
|
std::vector<char> keyVec(reinterpret_cast<const char*>(key.data()),
|
||||||
reinterpret_cast<const char*>(key.data()) + key.size());
|
reinterpret_cast<const char*>(key.data()) + key.size());
|
||||||
|
|
||||||
const uint64_t crcKey = XXH64(keyVec.data(), keyVec.size(), 0);
|
const uint64_t crcKey = XXH64(keyVec.data(), keyVec.size(), VERSION);
|
||||||
|
|
||||||
// Zapisz ten œmietnik do pliku KEY
|
// Zapisz ten œmietnik do pliku KEY
|
||||||
std::ofstream file(path + ".key", std::ios::binary);
|
std::ofstream file(path + ".key", std::ios::binary);
|
||||||
if (!file) { std::cout << "Failed to save encryption key to file" << std::endl; }
|
if (!file) { std::cout << "Failed to save encryption key to file" << std::endl; }
|
||||||
|
|
||||||
file.write(fl::sigkey.data(), fl::sigkey.length());
|
file.write(sig.data(), sig.length());
|
||||||
|
file.write(reinterpret_cast<const char*>(&ver), sizeof(ver));
|
||||||
file.write(reinterpret_cast<const char*>(&time), sizeof(time));
|
file.write(reinterpret_cast<const char*>(&time), sizeof(time));
|
||||||
file.write(reinterpret_cast<const char*>(keyVec.data()), keyVec.size());
|
file.write(reinterpret_cast<const char*>(keyVec.data()), keyVec.size());
|
||||||
file.write(reinterpret_cast<const char*>(&crcKey), sizeof(crcKey));
|
file.write(reinterpret_cast<const char*>(&crcKey), sizeof(crcKey));
|
||||||
|
|
@ -98,7 +102,7 @@ void EncryptionManager::saveCppHeadFile(const std::string& path)
|
||||||
|
|
||||||
std::ofstream file(path + ".hpp");
|
std::ofstream file(path + ".hpp");
|
||||||
|
|
||||||
file << "// Plik wygenerowany przez " << ui::title << " " << ui::ver << std::endl;
|
file << "// Plik wygenerowany przez " << PROGRAM_TITLE << " " << PROGRAM_VERSION << std::endl;
|
||||||
file << std::endl;
|
file << std::endl;
|
||||||
file << std::endl;
|
file << std::endl;
|
||||||
file << "#pragma once" << std::endl;
|
file << "#pragma once" << std::endl;
|
||||||
|
|
@ -133,15 +137,18 @@ std::string EncryptionManager::toHex(const unsigned char* data, size_t len)
|
||||||
void EncryptionManager::loadKey(const std::string& path)
|
void EncryptionManager::loadKey(const std::string& path)
|
||||||
{
|
{
|
||||||
std::ifstream file(path + ".key", std::ios::binary);
|
std::ifstream file(path + ".key", std::ios::binary);
|
||||||
std::vector<char> sig(fl::sigkey.size());
|
|
||||||
|
const std::string signature = SIGNATURE_KEY_FILE;
|
||||||
|
std::vector<char> sig(signature.size());
|
||||||
int8_t ver;
|
int8_t ver;
|
||||||
int time;
|
int time;
|
||||||
|
|
||||||
// Wczytaj
|
// Wczytaj
|
||||||
file.read(sig.data(), sig.size());
|
file.read(sig.data(), sig.size());
|
||||||
|
file.read(reinterpret_cast<char*>(&ver), sizeof(ver));
|
||||||
|
|
||||||
// SprawdŸ czy plik klucza jest poprawny
|
// SprawdŸ czy plik klucza jest poprawny
|
||||||
if (std::string(sig.begin(), sig.end()) != fl::sigkey)
|
if (std::string(sig.begin(), sig.end()) != signature || ver != VERSION)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid key file!");
|
throw std::runtime_error("Invalid key file!");
|
||||||
}
|
}
|
||||||
|
|
@ -154,7 +161,7 @@ void EncryptionManager::loadKey(const std::string& path)
|
||||||
file.read(reinterpret_cast<char*>(&crcKey), sizeof(crcKey));
|
file.read(reinterpret_cast<char*>(&crcKey), sizeof(crcKey));
|
||||||
|
|
||||||
// SprawdŸ integralnoœæ klucza
|
// SprawdŸ integralnoœæ klucza
|
||||||
if (XXH64(keyVec.data(), keyVec.size(), 0) != crcKey)
|
if (XXH64(keyVec.data(), keyVec.size(), VERSION) != crcKey)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Key integrity error!");
|
throw std::runtime_error("Key integrity error!");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -23,7 +23,7 @@ ExtractCargo::ExtractCargo()
|
||||||
:filesLen(0)
|
:filesLen(0)
|
||||||
, tablePosition(0)
|
, tablePosition(0)
|
||||||
, xxhState(XXH64_createState())
|
, xxhState(XXH64_createState())
|
||||||
, signature(fl::sigpak)
|
, signature(SIGNATURE)
|
||||||
{
|
{
|
||||||
// TODO Auto-generated constructor stub
|
// TODO Auto-generated constructor stub
|
||||||
XXH64_reset(xxhState, 0);
|
XXH64_reset(xxhState, 0);
|
||||||
|
|
|
||||||
|
|
@ -59,7 +59,8 @@ bool ViewCargo::ViewFiles(const std::string& path)
|
||||||
uint64_t tabPos = 0;
|
uint64_t tabPos = 0;
|
||||||
uint32_t tabSize = 0;
|
uint32_t tabSize = 0;
|
||||||
|
|
||||||
std::vector<char> magic(fl::sigpak.length());
|
const std::string signature = SIGNATURE;
|
||||||
|
std::vector<char> magic(signature.length());
|
||||||
int8_t cargoVer = 0;
|
int8_t cargoVer = 0;
|
||||||
|
|
||||||
std::ifstream cargo(path, std::ios::binary);
|
std::ifstream cargo(path, std::ios::binary);
|
||||||
|
|
@ -81,7 +82,7 @@ bool ViewCargo::ViewFiles(const std::string& path)
|
||||||
cargo.read(reinterpret_cast<char*>(&tabSize), sizeof(tabSize));
|
cargo.read(reinterpret_cast<char*>(&tabSize), sizeof(tabSize));
|
||||||
|
|
||||||
//SprawdŸ czy kontener ma poprawn¹ sygnature
|
//SprawdŸ czy kontener ma poprawn¹ sygnature
|
||||||
if (std::string(magic.begin(), magic.end()) != fl::sigpak)
|
if (std::string(magic.begin(), magic.end()) != signature)
|
||||||
{
|
{
|
||||||
std::cerr << "Error: Corrupted Cargo" << std::endl;
|
std::cerr << "Error: Corrupted Cargo" << std::endl;
|
||||||
cargo.close();
|
cargo.close();
|
||||||
|
|
@ -128,15 +129,15 @@ void ViewCargo::ShowFile(const std::string& file, const uint8_t& flag)
|
||||||
// Ustawianie checkboxów
|
// Ustawianie checkboxów
|
||||||
switch (flag)
|
switch (flag)
|
||||||
{
|
{
|
||||||
case flag::zip:
|
case FILE_FLAG_COMPRESS:
|
||||||
compresedCheck = "[x]";
|
compresedCheck = "[x]";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case flag::enc:
|
case FILE_FLAG_ENCRYPT:
|
||||||
encryptedCheck = "[x]";
|
encryptedCheck = "[x]";
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case flag::ezd:
|
case FILE_FLAG_ZIPENC:
|
||||||
compresedCheck = "[x]";
|
compresedCheck = "[x]";
|
||||||
encryptedCheck = "[x]";
|
encryptedCheck = "[x]";
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
10
voidcmd.cpp
10
voidcmd.cpp
|
|
@ -80,16 +80,16 @@ static bool EmptyPath(std::string path)
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
std::cout << ui::title << std::endl << "ver. " << ui::ver << std::endl;
|
std::string path = "";
|
||||||
std::cout << "Author: Yanczi" << std::endl;
|
|
||||||
std::cout << "License: GNU LGPL v3" << "\n" << std::endl;
|
std::cout << PROGRAM_VERSION << " Release " << PROGRAM_COMPILING << std::endl;
|
||||||
|
std::cout << "Author: " << PROGRAM_AUTHOR << std::endl;
|
||||||
|
std::cout << "License: " << PROGRAM_LICENSE << "\n" << std::endl;
|
||||||
|
|
||||||
CreateCargo cargo;
|
CreateCargo cargo;
|
||||||
ExtractCargo extract;
|
ExtractCargo extract;
|
||||||
ViewCargo viewCargo;
|
ViewCargo viewCargo;
|
||||||
|
|
||||||
std::string path = "";
|
|
||||||
|
|
||||||
for (int i = 0; i < argc; ++i)
|
for (int i = 0; i < argc; ++i)
|
||||||
{
|
{
|
||||||
std::string arg = argv[i];
|
std::string arg = argv[i];
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue