Merge branch 'Wywołanie_i/o' of https://git.yanczi.eu/yanczi/VoidArchive into Wywołanie_i/o

This commit is contained in:
yanczi 2025-11-27 15:54:16 +01:00
commit f7d429e1d2
10 changed files with 132 additions and 95 deletions

View file

@ -243,32 +243,40 @@ std::vector<FilesTable> CreateCargo::ComputingHeadFiles()
size_t size = f.tellg(); size_t size = f.tellg();
f.seekg(0, std::ios::beg); f.seekg(0, std::ios::beg);
//Wczytanie pliku do pamiêci if (size > MAX_FILE_SIZE)
std::vector<char> buffer(size); {
f.read(buffer.data(), size); std::cerr << path << " is too large. It exceeds 2GB!" << std::endl;
f.close(); }
else
{
//Wczytanie pliku do pamiêci
std::vector<char> buffer(size);
f.read(buffer.data(), size);
f.close();
//Tworzenie hashu CRC //Tworzenie hashu CRC
const uint64_t crc = XXH64(buffer.data(), buffer.size(), VERSION); const uint64_t crc = XXH64(buffer.data(), buffer.size(), VERSION);
//Kompresjia //Kompresjia
std::vector<char> pakBuffer; std::vector<char> pakBuffer;
computingBytes(file.parameter, buffer, pakBuffer); computingBytes(file.parameter, buffer, pakBuffer);
FilesTable ft; FilesTable ft;
ft.nameFile = path; ft.nameFile = path;
ft.nameLen = path.length(); ft.nameLen = path.length();
ft.hashName = fnv64(path); ft.hashName = fnv64(path);
ft.offset = offset; ft.offset = offset;
ft.size = pakBuffer.size(); ft.size = pakBuffer.size();
ft.flag = file.parameter; ft.flag = file.parameter;
ft.crc = crc; ft.crc = crc;
cargo.write(reinterpret_cast<const char*>(pakBuffer.data()), pakBuffer.size()); cargo.write(reinterpret_cast<const char*>(pakBuffer.data()), pakBuffer.size());
filesTable.push_back(ft); filesTable.push_back(ft);
offset += pakBuffer.size(); offset += pakBuffer.size();
}
} }
return filesTable; return filesTable;
} }

View file

@ -87,6 +87,9 @@ private:
std::ofstream cargo; std::ofstream cargo;
uint64_t offset; uint64_t offset;
// Progress
std::atomic<uint64_t> progress;
// Tworzenie listy plików do spakowania // Tworzenie listy plików do spakowania

View file

@ -70,7 +70,7 @@ struct FilesTable
std::string nameFile; std::string nameFile;
uint64_t hashName; uint64_t hashName;
uint64_t offset; uint64_t offset;
uint32_t size; uint64_t size;
uint64_t crc; uint64_t crc;
int16_t flag; int16_t flag;
}; };

View file

@ -1,37 +0,0 @@
/*
* This file is part of VoidArchiveTool.
*
* Copyright (C) 2025 Yanczi
*
* Void Archive Toolis free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Interface.h"
Interface::Interface() {
// TODO Auto-generated constructor stub
}
Interface::~Interface() {
// TODO Auto-generated destructor stub
}
void Interface::TextBorder(const std::string& title, const std::string& text)
{
auto element = ftxui::window(ftxui::text(title), ftxui::paragraphAlignLeft(text));
auto screen = ftxui::Screen::Create(ftxui::Dimension::Fit(element));
ftxui::Render(screen, element);
screen.Print();
}

71
Tui.cpp Normal file
View file

@ -0,0 +1,71 @@
/*
* This file is part of VoidArchiveTool.
*
* Copyright (C) 2025 Yanczi
*
* Void Archive Toolis free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
#include "Tui.h"
Tui::Tui() {
// TODO Auto-generated constructor stub
}
Tui::~Tui() {
// TODO Auto-generated destructor stub
}
void Tui::TextBorder(const std::string& title, const std::string& text)
{
auto element = ftxui::window(ftxui::text(title), ftxui::paragraphAlignLeft(text));
auto screen = ftxui::Screen::Create(ftxui::Dimension::Fit(element));
ftxui::Render(screen, element);
screen.Print();
}
void Tui::table(const std::vector<std::vector<std::string>>& data)
{
ftxui::Table table(data);
// Styl ogólny tabeli (ramki)
table.SelectAll().Border(ftxui::LIGHT);
// Oddzielenie nag³ówka od danych podwójn¹ lini¹
table.SelectRow(0).Border(ftxui::LIGHT);
table.SelectRow(0).Decorate(ftxui::bold); // Pogrubienie nag³ówka
table.SelectRow(0).SeparatorVertical(ftxui::LIGHT);
table.SelectRow(0).Border(ftxui::LIGHT);
table.SelectColumn(0).DecorateCells(ftxui::center);
table.SelectColumn(1).DecorateCells(ftxui::center);
table.SelectColumn(2).DecorateCells([](ftxui::Element e) {
return e | ftxui::flex;
});
table.SelectColumn(3).DecorateCells(ftxui::center);
table.SelectColumn(0).BorderRight(ftxui::LIGHT);
table.SelectColumn(1).BorderRight(ftxui::LIGHT);
table.SelectColumn(2).BorderRight(ftxui::LIGHT);
auto document = table.Render();
auto screen = ftxui::Screen::Create(ftxui::Dimension::Full(), ftxui::Dimension::Fit(document));
ftxui::Render(screen, document);
screen.Print();
}

View file

@ -20,14 +20,15 @@
#pragma once #pragma once
#include <ftxui/dom/elements.hpp> #include <ftxui/dom/elements.hpp>
#include <ftxui/dom/table.hpp>
#include <ftxui/screen/screen.hpp> #include <ftxui/screen/screen.hpp>
#include <string> #include <string>
class Interface { class Tui {
public: public:
Interface(); Tui();
virtual ~Interface(); virtual ~Tui();
void TextBorder(const std::string&, const std::string&); void TextBorder(const std::string&, const std::string&);
void table(const std::vector<std::vector<std::string>>&);
}; };

View file

@ -25,8 +25,8 @@ ViewCargo::ViewCargo()
, filesLen(0) , filesLen(0)
, tablePos(0) , tablePos(0)
{ {
// TODO Auto-generated constructor stub std::vector<std::string> header = {"Comress", "Encrypt", "Path", "RefHASH"};
list.push_back(header);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -55,17 +55,6 @@ bool ViewCargo::View(const std::string& path)
return false; return false;
} }
//Table Header
std::vector<ftxui::Element> headElements;
headElements.push_back(ftxui::text(" Compressed ") | ftxui::bold);
headElements.push_back(ftxui::text(" Encrypted ") | ftxui::bold);
headElements.push_back(ftxui::text("Nazwa pliku") | ftxui::bold | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 56));
headElements.push_back(ftxui::text("Hash Name") | ftxui::bold | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 20));
filesList.push_back(hbox(std::move(headElements)));
//Pobieranie listy plików //Pobieranie listy plików
GetFileList(path); GetFileList(path);
@ -151,6 +140,7 @@ void ViewCargo::GetFileList(const std::string& path)
} }
cargo.close(); cargo.close();
tui.table(list);
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -162,6 +152,9 @@ void ViewCargo::CreateTableRow(const std::string& file, const uint8_t& zip, cons
std::stringstream ss; std::stringstream ss;
ss << "0x" << std::hex << std::uppercase << hash; ss << "0x" << std::hex << std::uppercase << hash;
//Lista
std::vector<std::string> tmpList = { "[ ]", "[ ]", file, ss.str() };
std::vector<ftxui::Element> cell; std::vector<ftxui::Element> cell;
ftxui::Element eZip; ftxui::Element eZip;
@ -171,34 +164,28 @@ void ViewCargo::CreateTableRow(const std::string& file, const uint8_t& zip, cons
switch (zip) switch (zip)
{ {
case 1: case 1:
eZip = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan); //eZip = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
eEnc = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White); //eEnc = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
tmpList[0] = "[x]";
break; break;
case 2: case 2:
eZip = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White); tmpList[1] = "[x]";
eEnc = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
break; break;
case 3: case 3:
eZip = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan); tmpList[0] = "[x]";
eEnc = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan); tmpList[1] = "[x]";
break; break;
default: default:
eZip = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White); tmpList[0] = "[ ]";
eEnc = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White); tmpList[1] = "[ ]";
break; break;
} }
//Dodawanie komurek //Dodanie wiersza do listy
cell.push_back(eZip); list.push_back(tmpList);
cell.push_back(eEnc | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 7));
cell.push_back(ftxui::text(file) | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 56));
cell.push_back(ftxui::text(ss.str()) | ftxui::size(ftxui::WIDTH, ftxui::EQUAL, 20));
//Konwersja komurek na wiersz
filesList.push_back(ftxui::hbox(std::move(cell)));
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------

View file

@ -27,8 +27,10 @@
#include <sstream> #include <sstream>
#include <ftxui/dom/elements.hpp> #include <ftxui/dom/elements.hpp>
#include <ftxui/screen/screen.hpp> #include <ftxui/screen/screen.hpp>
#include <ftxui/dom/table.hpp>
#include "DataStruct.h" #include "DataStruct.h"
#include "Tui.h"
class ViewCargo { class ViewCargo {
public: public:
@ -38,12 +40,14 @@ public:
bool View(const std::string&); bool View(const std::string&);
private: private:
Tui tui;
const std::string signature; const std::string signature;
const uint16_t version; const uint16_t version;
uint32_t filesLen; uint32_t filesLen;
uint64_t tablePos; uint64_t tablePos;
std::vector<ftxui::Element> filesList; std::vector<ftxui::Element> filesList;
std::vector<std::vector<std::string>> list;
bool CheckCargoFile(const std::string&); bool CheckCargoFile(const std::string&);
void GetFileList(const std::string&); void GetFileList(const std::string&);

View file

@ -32,7 +32,7 @@
#include "CreateCargo.h" #include "CreateCargo.h"
#include "ExtractCargo.h" #include "ExtractCargo.h"
#include "ViewCargo.h" #include "ViewCargo.h"
#include "Interface.h" #include "Tui.h"
void RenderHelp() void RenderHelp()
{ {

View file

@ -137,7 +137,7 @@
<ClCompile Include="CreateCargo.cpp" /> <ClCompile Include="CreateCargo.cpp" />
<ClCompile Include="EncryptionManager.cpp" /> <ClCompile Include="EncryptionManager.cpp" />
<ClCompile Include="ExtractCargo.cpp" /> <ClCompile Include="ExtractCargo.cpp" />
<ClCompile Include="Interface.cpp" /> <ClCompile Include="Tui.cpp" />
<ClCompile Include="ViewCargo.cpp" /> <ClCompile Include="ViewCargo.cpp" />
<ClCompile Include="voidcmd.cpp" /> <ClCompile Include="voidcmd.cpp" />
</ItemGroup> </ItemGroup>
@ -148,7 +148,7 @@
<ClInclude Include="DataStruct.h" /> <ClInclude Include="DataStruct.h" />
<ClInclude Include="EncryptionManager.h" /> <ClInclude Include="EncryptionManager.h" />
<ClInclude Include="ExtractCargo.h" /> <ClInclude Include="ExtractCargo.h" />
<ClInclude Include="Interface.h" /> <ClInclude Include="Tui.h" />
<ClInclude Include="ViewCargo.h" /> <ClInclude Include="ViewCargo.h" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>