Mnieniono hash FNV-1a z 32b na 64b, String ścieżki do pliku przeniesiono na dół rekordu tablicy

This commit is contained in:
yanczi 2025-10-02 15:44:14 +02:00
parent 4dbe684cd7
commit 942f94e1f0
8 changed files with 31 additions and 29 deletions

View file

@ -233,7 +233,7 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
FilesTable ft; FilesTable ft;
ft.nameFile = path; ft.nameFile = path;
ft.nameLen = path.length(); ft.nameLen = path.length();
ft.hashName = fnv32(path); ft.hashName = fnv64(path);
ft.offset = offset; ft.offset = offset;
ft.size = zip.size(); ft.size = zip.size();
ft.isZip = method; ft.isZip = method;
@ -316,12 +316,12 @@ std::string CreateCargo::UpperString(std::string s) {
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Wygenerój FNV-1a HASH // Wygenerój FNV-1a HASH
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
uint32_t CreateCargo::fnv32(const std::string& data) uint64_t CreateCargo::fnv64(const std::string& data)
{ {
const uint32_t fnvOffset = 2166136261u; const uint64_t fnvOffset = 14695981039346656037u;
const uint32_t fnvPrime = 16777619u; const uint64_t fnvPrime = 1099511628211u;
uint32_t hash = fnvOffset; uint64_t hash = fnvOffset;
for (unsigned char c : data) for (unsigned char c : data)
{ {
hash ^= c; hash ^= c;
@ -416,15 +416,16 @@ bool CreateCargo::WriteCargo()
for (const auto& head : filesHead) for (const auto& head : filesHead)
{ {
// Œcie¿ka do plików // Tablica pliku
cargo.write(reinterpret_cast<const char*>(&head.nameLen), sizeof(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.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.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));
// Œcie¿ka do plików
cargo.write(reinterpret_cast<const char*>(&head.nameLen), sizeof(head.nameLen));
cargo.write(head.nameFile.data(), head.nameLen);
} }
//Cofnij siê na pocz¹tek pliku //Cofnij siê na pocz¹tek pliku

View file

@ -29,6 +29,7 @@
#include <stdexcept> #include <stdexcept>
#include <utility> #include <utility>
#include <memory> #include <memory>
#include <string>
#include "DataStruct.h" #include "DataStruct.h"
#include "Txtpp.h" #include "Txtpp.h"
@ -48,8 +49,6 @@
#define ALL_FILE ".*" // Wszystkie pliki #define ALL_FILE ".*" // Wszystkie pliki
class CreateCargo { class CreateCargo {
public: public:
CreateCargo(); CreateCargo();
@ -121,7 +120,7 @@ private:
std::string UpperString(std::string); std::string UpperString(std::string);
// Wygenerój FNV-1a HASH // Wygenerój FNV-1a HASH
uint32_t fnv32(const std::string& data); uint64_t fnv64(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>&);

View file

@ -59,7 +59,7 @@ struct FilesTable
{ {
uint8_t nameLen; uint8_t nameLen;
std::string nameFile; std::string nameFile;
uint32_t hashName; uint64_t hashName;
uint64_t offset; uint64_t offset;
uint32_t size; uint32_t size;
uint64_t crc; uint64_t crc;

View file

@ -136,17 +136,17 @@ void ExtractCargo::LoadFilesTable()
for (uint32_t i = 0; i < filesLen; ++i) for (uint32_t i = 0; i < filesLen; ++i)
{ {
FilesTable fhTmp; FilesTable fhTmp;
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.size), sizeof(fhTmp.size));
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.nameLen), sizeof(fhTmp.nameLen)); cargoFile.read(reinterpret_cast<char*>(&fhTmp.nameLen), sizeof(fhTmp.nameLen));
std::vector<char> nameBuffor(fhTmp.nameLen); std::vector<char> nameBuffor(fhTmp.nameLen);
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.size), sizeof(fhTmp.size));
cargoFile.read(reinterpret_cast<char*>(&fhTmp.crc), sizeof(fhTmp.crc));
cargoFile.read(reinterpret_cast<char*>(&fhTmp.isZip), sizeof(fhTmp.isZip));
filesHeads.push_back(fhTmp); filesHeads.push_back(fhTmp);
} }

View file

@ -26,6 +26,8 @@
#include <algorithm> #include <algorithm>
#include <stdexcept> #include <stdexcept>
#include <sstream> #include <sstream>
#include <cstdint>
#include <string>
#include "DataStruct.h" #include "DataStruct.h"
#include "xxhash.h" #include "xxhash.h"

View file

@ -133,18 +133,18 @@ void ViewCargo::GetFileList(const std::string& path)
for (uint32_t i = 0; i < filesLen; ++i) for (uint32_t i = 0; i < filesLen; ++i)
{ {
FilesTable fhTmp; FilesTable fhTmp;
cargo.read(reinterpret_cast<char*>(&fhTmp.nameLen), sizeof(fhTmp.nameLen));
std::vector<char> nameBuffor(fhTmp.nameLen);
cargo.read(nameBuffor.data(), fhTmp.nameLen);
fhTmp.nameFile = std::string(nameBuffor.begin(), nameBuffor.end());
cargo.read(reinterpret_cast<char*>(&fhTmp.hashName), sizeof(fhTmp.hashName)); 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.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));
cargo.read(reinterpret_cast<char*>(&fhTmp.nameLen), sizeof(fhTmp.nameLen));
std::vector<char> nameBuffor(fhTmp.nameLen);
cargo.read(nameBuffor.data(), fhTmp.nameLen);
fhTmp.nameFile = std::string(nameBuffor.begin(), nameBuffor.end());
//Tworzenie wierszy tabeli //Tworzenie wierszy tabeli
CreateTableRow(fhTmp.nameFile, fhTmp.isZip, fhTmp.hashName); CreateTableRow(fhTmp.nameFile, fhTmp.isZip, fhTmp.hashName);
} }
@ -155,7 +155,7 @@ void ViewCargo::GetFileList(const std::string& path)
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// Generowanie wierszy do tabeli // Generowanie wierszy do tabeli
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
void ViewCargo::CreateTableRow(const std::string& file, const uint8_t& zip, const uint32_t& hash) void ViewCargo::CreateTableRow(const std::string& file, const uint8_t& zip, const uint64_t& hash)
{ {
//Zamiania crc liczbowej na hex string //Zamiania crc liczbowej na hex string
std::stringstream ss; std::stringstream ss;

View file

@ -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(const std::string&, const uint8_t&, const uint32_t&); void CreateTableRow(const std::string&, const uint8_t&, const uint64_t&);
}; };

View file

@ -86,10 +86,10 @@ int main(int argc, char* argv[]) {
" 888 Y88b d88888 888 d8P \n" " 888 Y88b d88888 888 d8P \n"
" 888 888 d88P888 888 d8P \n" " 888 888 d88P888 888 d8P \n"
" .d88b. 888 888 888 d88P d88P 888 888d88K \n" " .d88b. 888 888 888 d88P d88P 888 888d88K \n"
"d8P Y8b `Y8bd8P' 8888888P' d88P 888 8888888b \n" "d8P Y8b `Y8bd8P' 8888888P\" d88P 888 8888888b \n"
"88888888 X88K 888 d88P 888 888 Y88b \n" "88888888 X88K 888 d88P 888 888 Y88b \n"
"Y8b. .d8''8b. 888 d8888888888 888 Y88b \n" "Y8b. .d8\"\"8b. 888 d8888888888 888 Y88b \n"
" 'Y8888 888 888 888 d88P 888 888 Y88b\n" " \"Y8888 888 888 888 d88P 888 888 Y88b\n"
<< std::endl; << std::endl;
std::cout << "\n" << PROGRAM_VERSION << " Release " << PROGRAM_COMPILING << 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;