diff --git a/CreateCargo.cpp b/CreateCargo.cpp index 845a915..bad0dc7 100644 --- a/CreateCargo.cpp +++ b/CreateCargo.cpp @@ -243,32 +243,40 @@ std::vector CreateCargo::ComputingHeadFiles() size_t size = f.tellg(); f.seekg(0, std::ios::beg); - //Wczytanie pliku do pamięci - std::vector 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 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 pakBuffer; - computingBytes(file.parameter, buffer, pakBuffer); + //Kompresjia + std::vector 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(pakBuffer.data()), pakBuffer.size()); + cargo.write(reinterpret_cast(pakBuffer.data()), pakBuffer.size()); - filesTable.push_back(ft); - offset += pakBuffer.size(); + filesTable.push_back(ft); + offset += pakBuffer.size(); + } } + return filesTable; } diff --git a/CreateCargo.h b/CreateCargo.h index e11d253..ddbb0cf 100644 --- a/CreateCargo.h +++ b/CreateCargo.h @@ -87,6 +87,9 @@ private: std::ofstream cargo; uint64_t offset; + // Progress + std::atomic progress; + // Tworzenie listy plików do spakowania diff --git a/DataStruct.h b/DataStruct.h index d941faf..db9318a 100644 --- a/DataStruct.h +++ b/DataStruct.h @@ -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; }; \ No newline at end of file diff --git a/Interface.cpp b/Interface.cpp deleted file mode 100644 index aff711b..0000000 --- a/Interface.cpp +++ /dev/null @@ -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 . - */ - -#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(); -} \ No newline at end of file diff --git a/Tui.cpp b/Tui.cpp new file mode 100644 index 0000000..eff5894 --- /dev/null +++ b/Tui.cpp @@ -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 . + */ + +#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>& 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(); +} \ No newline at end of file diff --git a/Interface.h b/Tui.h similarity index 87% rename from Interface.h rename to Tui.h index 5523efd..d3b7b99 100644 --- a/Interface.h +++ b/Tui.h @@ -20,14 +20,15 @@ #pragma once #include +#include #include #include -class Interface { +class Tui { public: - Interface(); - virtual ~Interface(); + Tui(); + virtual ~Tui(); void TextBorder(const std::string&, const std::string&); -}; - + void table(const std::vector>&); +}; \ No newline at end of file diff --git a/ViewCargo.cpp b/ViewCargo.cpp index 6eafe9c..d5a0df2 100644 --- a/ViewCargo.cpp +++ b/ViewCargo.cpp @@ -25,8 +25,8 @@ ViewCargo::ViewCargo() , filesLen(0) , tablePos(0) { - // TODO Auto-generated constructor stub - + std::vector 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 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 tmpList = { "[ ]", "[ ]", file, ss.str() }; + std::vector 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); } //----------------------------------------------------------------------------- diff --git a/ViewCargo.h b/ViewCargo.h index bdfb7f8..1ab452e 100644 --- a/ViewCargo.h +++ b/ViewCargo.h @@ -27,8 +27,10 @@ #include #include #include +#include #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 filesList; + std::vector> list; bool CheckCargoFile(const std::string&); void GetFileList(const std::string&); diff --git a/voidcmd.cpp b/voidcmd.cpp index c719bae..35e3644 100644 --- a/voidcmd.cpp +++ b/voidcmd.cpp @@ -32,7 +32,7 @@ #include "CreateCargo.h" #include "ExtractCargo.h" #include "ViewCargo.h" -#include "Interface.h" +#include "Tui.h" void RenderHelp() { diff --git a/voidcmd.vcxproj b/voidcmd.vcxproj index 523f5b0..119342f 100644 --- a/voidcmd.vcxproj +++ b/voidcmd.vcxproj @@ -137,7 +137,7 @@ - + @@ -148,7 +148,7 @@ - +