Usunięto TUI, Zmieniono strukturę PAK... agan, Rezygnacja z FNV hash jako referencji, Zmieana wartości flag na maski
This commit is contained in:
parent
a84a69cbd6
commit
91aaa279ec
16 changed files with 86 additions and 575 deletions
113
ViewCargo.cpp
113
ViewCargo.cpp
|
|
@ -20,14 +20,7 @@
|
|||
#include "ViewCargo.h"
|
||||
|
||||
ViewCargo::ViewCargo()
|
||||
:signature(SIGNATURE)
|
||||
, version(VERSION)
|
||||
, filesLen(0)
|
||||
, tablePos(0)
|
||||
{
|
||||
std::vector<std::string> header = {"Comress", "Encrypt", "Path", "RefHASH"};
|
||||
list.push_back(header);
|
||||
}
|
||||
{}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Wywoływanie
|
||||
|
|
@ -49,26 +42,24 @@ bool ViewCargo::View(const std::string& path)
|
|||
}
|
||||
|
||||
//Sprawdź czy kontener jest prawidłowy
|
||||
if (!CheckCargoFile(path))
|
||||
if (!ViewFiles(path))
|
||||
{
|
||||
std::cerr << "Nie prawidlowa struktura kontenera Void" << std::endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
//Pobieranie listy plików
|
||||
GetFileList(path);
|
||||
|
||||
//Renderowanie listy plików
|
||||
RenderList();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Sprawdzenie poprawności kontenera
|
||||
//-----------------------------------------------------------------------------
|
||||
bool ViewCargo::CheckCargoFile(const std::string& path)
|
||||
bool ViewCargo::ViewFiles(const std::string& path)
|
||||
{
|
||||
uint64_t tabPos = 0;
|
||||
uint32_t tabSize = 0;
|
||||
|
||||
const std::string signature = SIGNATURE;
|
||||
std::vector<char> magic(signature.length());
|
||||
int8_t cargoVer = 0;
|
||||
|
||||
|
|
@ -81,15 +72,14 @@ bool ViewCargo::CheckCargoFile(const std::string& path)
|
|||
}
|
||||
|
||||
//---------------------------------------------------------------
|
||||
// Odczytywanie pierwszych 11 bajtów nag³ówka pliku
|
||||
// 6 pierwszych to sygnatura
|
||||
// 1 wersja kontenera
|
||||
// 4 iloœæ plików w kontenerze
|
||||
// Odczytywanie pierwszych 16 bajtów nag³ówka pliku
|
||||
// 4 Sygnatura kontenera XPAK
|
||||
// 8 Offset tablicy plików
|
||||
// 4 Rozmiar tablicy plików
|
||||
//---------------------------------------------------------------
|
||||
cargo.read(magic.data(), magic.size());
|
||||
cargo.read(reinterpret_cast<char*>(&cargoVer), sizeof(cargoVer));
|
||||
cargo.read(reinterpret_cast<char*>(&filesLen), sizeof(filesLen));
|
||||
cargo.read(reinterpret_cast<char*>(&tablePos), sizeof(tablePos));
|
||||
cargo.read(reinterpret_cast<char*>(&tabPos), sizeof(tabPos));
|
||||
cargo.read(reinterpret_cast<char*>(&tabSize), sizeof(tabSize));
|
||||
|
||||
//Sprawdź czy kontener ma poprawną sygnature
|
||||
if (std::string(magic.begin(), magic.end()) != signature)
|
||||
|
|
@ -99,28 +89,13 @@ bool ViewCargo::CheckCargoFile(const std::string& path)
|
|||
return false;
|
||||
}
|
||||
|
||||
//SprawdŸ spójnoœæ wersji kontenera
|
||||
if (cargoVer != version)
|
||||
{
|
||||
std::cerr << "Error: Wrong cargo version" << std::endl;
|
||||
cargo.close();
|
||||
return false;
|
||||
}
|
||||
std::cout << "ZIP" << " " << "ENC" << " " << "Path" << std::endl;
|
||||
|
||||
cargo.close();
|
||||
// Przeskocz do tablicy plików
|
||||
cargo.seekg(tabPos);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Pobieranie listy plików z kontenera
|
||||
//-----------------------------------------------------------------------------
|
||||
void ViewCargo::GetFileList(const std::string& path)
|
||||
{
|
||||
std::ifstream cargo(path, std::ios::binary);
|
||||
cargo.seekg(tablePos);
|
||||
|
||||
for (uint32_t i = 0; i < filesLen; ++i)
|
||||
// Za³aduj dane o plikach
|
||||
for (uint32_t i = 0; i < tabSize; ++i)
|
||||
{
|
||||
FilesTable fhTmp;
|
||||
cargo.read(reinterpret_cast<char*>(&fhTmp.nameLen), sizeof(fhTmp.nameLen));
|
||||
|
|
@ -129,74 +104,50 @@ void ViewCargo::GetFileList(const std::string& path)
|
|||
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.flag), sizeof(fhTmp.flag));
|
||||
|
||||
//Tworzenie wierszy tabeli
|
||||
CreateTableRow(fhTmp.nameFile, fhTmp.flag, fhTmp.hashName);
|
||||
ShowFile(fhTmp.nameFile, fhTmp.flag);
|
||||
}
|
||||
|
||||
cargo.close();
|
||||
tui.table(list);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Generowanie wierszy do tabeli
|
||||
//-----------------------------------------------------------------------------
|
||||
void ViewCargo::CreateTableRow(const std::string& file, const uint8_t& flag, const uint64_t& hash)
|
||||
void ViewCargo::ShowFile(const std::string& file, const uint8_t& flag)
|
||||
{
|
||||
//Zamiania crc liczbowej na hex string
|
||||
std::stringstream ss;
|
||||
ss << "0x" << std::hex << std::uppercase << hash;
|
||||
|
||||
//Lista
|
||||
std::vector<std::string> tmpList = { "[ ]", "[ ]", file, ss.str() };
|
||||
|
||||
std::vector<ftxui::Element> cell;
|
||||
|
||||
ftxui::Element eZip;
|
||||
ftxui::Element eEnc;
|
||||
std::string compresedCheck = "[ ]";
|
||||
std::string encryptedCheck = "[ ]";
|
||||
|
||||
// Ustawianie checkboxów
|
||||
switch (flag)
|
||||
{
|
||||
case FILE_FLAG_COMPRESS:
|
||||
//eZip = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
|
||||
//eEnc = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
|
||||
tmpList[0] = "[x]";
|
||||
compresedCheck = "[x]";
|
||||
break;
|
||||
|
||||
case FILE_FLAG_ENCRYPT:
|
||||
tmpList[1] = "[x]";
|
||||
encryptedCheck = "[x]";
|
||||
break;
|
||||
|
||||
case FILE_FLAG_ZIPENC:
|
||||
tmpList[0] = "[x]";
|
||||
tmpList[1] = "[x]";
|
||||
compresedCheck = "[x]";
|
||||
encryptedCheck = "[x]";
|
||||
break;
|
||||
|
||||
default:
|
||||
tmpList[0] = "[ ]";
|
||||
tmpList[1] = "[ ]";
|
||||
compresedCheck = "[ ]";
|
||||
encryptedCheck = "[ ]";
|
||||
break;
|
||||
}
|
||||
|
||||
//Dodanie wiersza do listy
|
||||
list.push_back(tmpList);
|
||||
}
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
// Renderowanie listy plików
|
||||
//-----------------------------------------------------------------------------
|
||||
void ViewCargo::RenderList()
|
||||
{
|
||||
//Dodawanie wierszy do kolumn
|
||||
ftxui::Element table = ftxui::vbox(std::move(filesList));
|
||||
|
||||
auto screen = ftxui::Screen::Create(ftxui::Dimension::Fit(table));
|
||||
ftxui::Render(screen, table);
|
||||
screen.Print();
|
||||
// Wyœwietlanie
|
||||
std::cout << compresedCheck << " " << encryptedCheck << " " << file << std::endl;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue