Mnieniono hash FNV-1a z 32b na 64b, String ścieżki do pliku przeniesiono na dół rekordu tablicy
This commit is contained in:
parent
4dbe684cd7
commit
942f94e1f0
8 changed files with 31 additions and 29 deletions
|
|
@ -233,7 +233,7 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
|
|||
FilesTable ft;
|
||||
ft.nameFile = path;
|
||||
ft.nameLen = path.length();
|
||||
ft.hashName = fnv32(path);
|
||||
ft.hashName = fnv64(path);
|
||||
ft.offset = offset;
|
||||
ft.size = zip.size();
|
||||
ft.isZip = method;
|
||||
|
|
@ -316,12 +316,12 @@ std::string CreateCargo::UpperString(std::string s) {
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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 uint32_t fnvPrime = 16777619u;
|
||||
const uint64_t fnvOffset = 14695981039346656037u;
|
||||
const uint64_t fnvPrime = 1099511628211u;
|
||||
|
||||
uint32_t hash = fnvOffset;
|
||||
uint64_t hash = fnvOffset;
|
||||
for (unsigned char c : data)
|
||||
{
|
||||
hash ^= c;
|
||||
|
|
@ -416,15 +416,16 @@ bool CreateCargo::WriteCargo()
|
|||
|
||||
for (const auto& head : filesHead)
|
||||
{
|
||||
// Œcie¿ka do plików
|
||||
cargo.write(reinterpret_cast<const char*>(&head.nameLen), sizeof(head.nameLen));
|
||||
cargo.write(head.nameFile.data(), head.nameLen);
|
||||
|
||||
// Tablica pliku
|
||||
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.size), sizeof(head.size));
|
||||
cargo.write(reinterpret_cast<const char*>(&head.crc), sizeof(head.crc));
|
||||
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
|
||||
|
|
|
|||
|
|
@ -29,6 +29,7 @@
|
|||
#include <stdexcept>
|
||||
#include <utility>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
#include "DataStruct.h"
|
||||
#include "Txtpp.h"
|
||||
|
|
@ -48,8 +49,6 @@
|
|||
#define ALL_FILE ".*" // Wszystkie pliki
|
||||
|
||||
|
||||
|
||||
|
||||
class CreateCargo {
|
||||
public:
|
||||
CreateCargo();
|
||||
|
|
@ -121,7 +120,7 @@ private:
|
|||
std::string UpperString(std::string);
|
||||
|
||||
// Wygenerój FNV-1a HASH
|
||||
uint32_t fnv32(const std::string& data);
|
||||
uint64_t fnv64(const std::string& data);
|
||||
|
||||
// Rozdzielanie paternu od œcie¿ki
|
||||
void ExtPatternAndPathDetection(const std::vector<std::string>&, std::vector<std::string>&, std::vector<std::string>&);
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ struct FilesTable
|
|||
{
|
||||
uint8_t nameLen;
|
||||
std::string nameFile;
|
||||
uint32_t hashName;
|
||||
uint64_t hashName;
|
||||
uint64_t offset;
|
||||
uint32_t size;
|
||||
uint64_t crc;
|
||||
|
|
|
|||
|
|
@ -136,17 +136,17 @@ void ExtractCargo::LoadFilesTable()
|
|||
for (uint32_t i = 0; i < filesLen; ++i)
|
||||
{
|
||||
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));
|
||||
|
||||
std::vector<char> nameBuffor(fhTmp.nameLen);
|
||||
cargoFile.read(nameBuffor.data(), fhTmp.nameLen);
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,6 +26,8 @@
|
|||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include <sstream>
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
#include "DataStruct.h"
|
||||
#include "xxhash.h"
|
||||
|
|
|
|||
|
|
@ -133,18 +133,18 @@ void ViewCargo::GetFileList(const std::string& path)
|
|||
for (uint32_t i = 0; i < filesLen; ++i)
|
||||
{
|
||||
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.offset), sizeof(fhTmp.offset));
|
||||
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.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
|
||||
CreateTableRow(fhTmp.nameFile, fhTmp.isZip, fhTmp.hashName);
|
||||
}
|
||||
|
|
@ -155,7 +155,7 @@ void ViewCargo::GetFileList(const std::string& path)
|
|||
//-----------------------------------------------------------------------------
|
||||
// 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
|
||||
std::stringstream ss;
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ private:
|
|||
bool CheckCargoFile(const std::string&);
|
||||
void GetFileList(const std::string&);
|
||||
void RenderList();
|
||||
void CreateTableRow(const std::string&, const uint8_t&, const uint32_t&);
|
||||
void CreateTableRow(const std::string&, const uint8_t&, const uint64_t&);
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -86,10 +86,10 @@ int main(int argc, char* argv[]) {
|
|||
" 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"
|
||||
"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"
|
||||
"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;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue