diff --git a/ChunkManager.cpp b/ChunkManager.cpp index 6da9cc4..25b8065 100644 --- a/ChunkManager.cpp +++ b/ChunkManager.cpp @@ -82,10 +82,6 @@ std::vector ChunkManager::dechunked(const std::vector& zip, const bo const uint32_t chunkBeforeSize = getIntFromVector(zip, offset); const uint32_t chunkLastSize = getIntFromVector(zip, offset); - std::cout << "Q: " << chunkLen << std::endl; - std::cout << "C: " << chunkBeforeSize << std::endl; - std::cout << "L: " << chunkBeforeSize << std::endl; - std::vector chunksString; // Dekompresja bloków diff --git a/CreateCargo.cpp b/CreateCargo.cpp index b1b97a9..50dc8f9 100644 --- a/CreateCargo.cpp +++ b/CreateCargo.cpp @@ -24,12 +24,10 @@ CreateCargo::CreateCargo() , extension(EXTENSION) , version(VERSION) , methodFlags(0) - , xxhState(XXH64_createState()) , offset(0) , hppKey(false) { // TODO Auto-generated constructor stub - XXH64_reset(xxhState, 0); } CreateCargo::~CreateCargo() { @@ -243,8 +241,6 @@ std::vector CreateCargo::ComputingHeadFiles() std::string path = PathToUnixLike(RemoveStartPath(file.path)); std::ifstream f(file.path, std::ios::binary | std::ios::ate); - std::cout << path << std::endl; - //Obliczanie rozmiaru pliku size_t size = f.tellg(); f.seekg(0, std::ios::beg); @@ -255,105 +251,32 @@ std::vector CreateCargo::ComputingHeadFiles() } else { - XXH64_reset(xxhState, 0); - //Wczytanie pliku do pamięci - std::vector buffer(CHUNK_STREAM_256MB); - - uint64_t sizeFile = 0; - - const uint32_t chunkBlockSize = CHUNK_BLOCK_SIZE; - const uint32_t quantity = (size + chunkBlockSize) / chunkBlockSize; - const uint32_t lastChunkSize = size - (chunkBlockSize * (quantity - 1)); - - // Jeśli jest ustawiona flaga inna niż RAW - // Dodaj do kontenera konfigurację chunków - if (file.parameter != FILE_FLAG_RAW) - { - std::cout << "CHUNK PARAM" << std::endl; - cargo.write(reinterpret_cast(&quantity), sizeof(quantity)); - cargo.write(reinterpret_cast(&chunkBlockSize), sizeof(chunkBlockSize)); - cargo.write(reinterpret_cast(&lastChunkSize), sizeof(lastChunkSize)); - sizeFile = sizeof(quantity) + sizeof(chunkBlockSize) + sizeof(lastChunkSize); - } - - // Strumieniowanie danych - while (f.read(buffer.data(), CHUNK_STREAM_256MB) || f.gcount() > 0) - { - const int bufferSize = f.gcount(); - buffer.resize(bufferSize); - - // Aktualizacja XXH64 - XXH64_update(xxhState, buffer.data(), buffer.size()); - - if (file.parameter == FILE_FLAG_RAW) - { - // Zapisywanie strumienia do kontenera - cargo.write(reinterpret_cast(buffer.data()), buffer.size()); - sizeFile += bufferSize; - } - else - { - for (uint32_t ofs = 0; ofs < bufferSize; ofs += chunkBlockSize) - { - // Rozmiar chunka - const uint32_t chunkSize = std::min(chunkBlockSize, bufferSize - ofs); - - auto begin = buffer.begin() + ofs; - auto end = begin + chunkSize; - - // Skopiuj fragment danych do chunka - std::vector chunk(begin, end); - - std::vector outChunk; - - // Przetwórz chunki i przetwórz - if ((file.parameter & FILE_FLAG_COMPRESS) == FILE_FLAG_COMPRESS) - { - // Zaszyfruj i skompresuj lub tylko skompresuj - outChunk = (file.parameter & FILE_FLAG_ENCRYPT) == FILE_FLAG_ENCRYPT ? - eman.encrypt(cman.compress(chunk)) : cman.compress(chunk); - } - else - { - // Zaszyfruj lub skopiuj - outChunk = (file.parameter & FILE_FLAG_ENCRYPT) == FILE_FLAG_ENCRYPT ? - eman.encrypt(cman.compress(chunk)) : cman.compress(chunk); - } - - const uint32_t outSize = outChunk.size(); - - cargo.write(reinterpret_cast(&outSize), sizeof(outSize)); - sizeFile += sizeof(outSize); - - cargo.write(reinterpret_cast(outChunk.data()), outChunk.size()); - sizeFile += outSize; - } - std::cout << "SIZE: " << sizeFile << std::endl; - } - } - + std::vector buffer(size); + f.read(buffer.data(), size); f.close(); //Tworzenie hashu CRC - //const uint64_t crc = XXH64(buffer.data(), buffer.size(), 0); + const uint64_t crc = XXH64(buffer.data(), buffer.size(), 0); //Kompresjia - //std::vector pakBuffer; - //computingBytes(file.parameter, buffer, pakBuffer); + std::vector pakBuffer; + computingBytes(file.parameter, buffer, pakBuffer); + + std::cout << static_cast(file.parameter) << std::endl; FilesTable ft; ft.nameFile = path; ft.nameLen = path.length(); ft.offset = offset; - ft.size = sizeFile; + ft.size = pakBuffer.size(); ft.flag = file.parameter; - ft.crc = XXH64_digest(xxhState); + ft.crc = crc; - //cargo.write(reinterpret_cast(pakBuffer.data()), pakBuffer.size()); + cargo.write(reinterpret_cast(pakBuffer.data()), pakBuffer.size()); filesTable.push_back(ft); - offset += sizeFile; + offset += pakBuffer.size(); } } diff --git a/CreateCargo.h b/CreateCargo.h index e31b3e6..a870d6d 100644 --- a/CreateCargo.h +++ b/CreateCargo.h @@ -35,7 +35,6 @@ #include "DataStruct.h" #include "ChunkManager.h" #include "EncryptionManager.h" -#include "CompressionManager.h" #define KEY_ZIP "compress" // Pliki do skompresowania @@ -66,8 +65,6 @@ private: uint8_t methodFlags; - XXH64_state_t* xxhState; - std::string catalogPath; std::string tempFile; @@ -76,7 +73,6 @@ private: std::vector filesList; EncryptionManager eman; - CompressionManager cman; bool hppKey; // listy wyjątków diff --git a/DataStruct.h b/DataStruct.h index 5a17980..c4113c6 100644 --- a/DataStruct.h +++ b/DataStruct.h @@ -34,9 +34,6 @@ #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 diff --git a/ExtractCargo.cpp b/ExtractCargo.cpp index c59d8d8..6006138 100644 --- a/ExtractCargo.cpp +++ b/ExtractCargo.cpp @@ -22,6 +22,7 @@ ExtractCargo::ExtractCargo() :filesLen(0) , tablePosition(0) + , filesHeadsOffset(0) , version(VERSION) , signature(SIGNATURE) { @@ -97,15 +98,18 @@ bool ExtractCargo::CheckCargoFile() } cargoFile.read(magic.data(), magic.size()); + + // Pobierz pozycję tablicy plików i jej rozmiar + cargoFile.read(reinterpret_cast(&tablePosition), sizeof(tablePosition)); + cargoFile.read(reinterpret_cast(&filesLen), sizeof(filesLen)); + if (std::string(magic.begin(), magic.end()) != signature) { std::cerr << "Error: Corrupted Cargo" << std::endl; return false; } - // Pobierz pozycję tablicy plików i jej rozmiar - cargoFile.read(reinterpret_cast(&tablePosition), sizeof(tablePosition)); - cargoFile.read(reinterpret_cast(&filesLen), sizeof(filesLen)); + filesHeadsOffset = signature.length() + sizeof(cargoVer) + sizeof(filesLen); return true; } @@ -175,9 +179,6 @@ void ExtractCargo::LoadFilesTable() cargoFile.read(reinterpret_cast(&fhTmp.crc), sizeof(fhTmp.crc)); cargoFile.read(reinterpret_cast(&fhTmp.flag), sizeof(fhTmp.flag)); - std::cout << tablePosition << std::endl; - std::cout << "Size: " << fhTmp.size << std::endl; - filesHeads.push_back(fhTmp); } } @@ -193,7 +194,6 @@ void ExtractCargo::ExtractingFilesFromCargo() CreateDirections(dir); std::ofstream file(dir, std::ios::binary); - std::cout << fh.size << std::endl; cargoFile.seekg(fh.offset); std::vector buffor(fh.size); diff --git a/ExtractCargo.h b/ExtractCargo.h index 9ee7e1f..e5cc23c 100644 --- a/ExtractCargo.h +++ b/ExtractCargo.h @@ -47,6 +47,7 @@ private: uint32_t filesLen; uint64_t tablePosition; + int filesHeadsOffset; const int8_t version; const std::string signature; diff --git a/voidcmd.vcxproj b/voidcmd.vcxproj index 49f706f..dcc841e 100644 --- a/voidcmd.vcxproj +++ b/voidcmd.vcxproj @@ -103,7 +103,7 @@ true _DEBUG;_CONSOLE;%(PreprocessorDefinitions);SODIUM_STATIC true - stdcpp20 + stdcpp17 3rd\libsodium\include;3rd\json\include;3rd\zstd\include;3rd\xxhash\include