Wywołanie_i/o #8

Merged
yanczi merged 2 commits from Wywołanie_i/o into master 2025-11-25 18:07:33 +01:00
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();
f.seekg(0, std::ios::beg);
//Wczytanie pliku do pamiêci
std::vector<char> buffer(size);
f.read(buffer.data(), size);
f.close();
if (size > MAX_FILE_SIZE)
{
std::cerr << path << " is too large. It exceeds 2GB!" << std::endl;
}
else
{
//Wczytanie pliku do pamiêci
std::vector<char> buffer(size);
f.read(buffer.data(), size);
f.close();
//Tworzenie hashu CRC
const uint64_t crc = XXH64(buffer.data(), buffer.size(), VERSION);
//Tworzenie hashu CRC
const uint64_t crc = XXH64(buffer.data(), buffer.size(), VERSION);
//Kompresjia
std::vector<char> pakBuffer;
computingBytes(file.parameter, buffer, pakBuffer);
//Kompresjia
std::vector<char> pakBuffer;
computingBytes(file.parameter, buffer, pakBuffer);
FilesTable ft;
ft.nameFile = path;
ft.nameLen = path.length();
ft.hashName = fnv64(path);
ft.offset = offset;
ft.size = pakBuffer.size();
ft.flag = file.parameter;
ft.crc = crc;
FilesTable ft;
ft.nameFile = path;
ft.nameLen = path.length();
ft.hashName = fnv64(path);
ft.offset = offset;
ft.size = pakBuffer.size();
ft.flag = file.parameter;
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);
offset += pakBuffer.size();
filesTable.push_back(ft);
offset += pakBuffer.size();
}
}
return filesTable;
}

View file

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

View file

@ -70,7 +70,7 @@ struct FilesTable
std::string nameFile;
uint64_t hashName;
uint64_t offset;
uint32_t size;
uint64_t size;
uint64_t crc;
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
#include <ftxui/dom/elements.hpp>
#include <ftxui/dom/table.hpp>
#include <ftxui/screen/screen.hpp>
#include <string>
class Interface {
class Tui {
public:
Interface();
virtual ~Interface();
Tui();
virtual ~Tui();
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)
, 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;
}
//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
GetFileList(path);
@ -151,6 +140,7 @@ void ViewCargo::GetFileList(const std::string& path)
}
cargo.close();
tui.table(list);
}
//-----------------------------------------------------------------------------
@ -162,6 +152,9 @@ void ViewCargo::CreateTableRow(const std::string& file, const uint8_t& zip, cons
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;
@ -171,34 +164,28 @@ void ViewCargo::CreateTableRow(const std::string& file, const uint8_t& zip, cons
switch (zip)
{
case 1:
eZip = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
eEnc = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
//eZip = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
//eEnc = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
tmpList[0] = "[x]";
break;
case 2:
eZip = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
eEnc = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
tmpList[1] = "[x]";
break;
case 3:
eZip = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
eEnc = ftxui::text(" [x] ") | ftxui::color(ftxui::Color::Cyan);
tmpList[0] = "[x]";
tmpList[1] = "[x]";
break;
default:
eZip = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
eEnc = ftxui::text(" [ ] ") | ftxui::color(ftxui::Color::White);
tmpList[0] = "[ ]";
tmpList[1] = "[ ]";
break;
}
//Dodawanie komurek
cell.push_back(eZip);
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)));
//Dodanie wiersza do listy
list.push_back(tmpList);
}
//-----------------------------------------------------------------------------

View file

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

View file

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

View file

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