From 6dc25b6403d24d302cfdd6b0bc70f36fd28eecb7 Mon Sep 17 00:00:00 2001 From: lumiscosity Date: Mon, 30 Sep 2024 21:03:55 +0200 Subject: [PATCH] patch saving, part 2 after 3 hours and checking like 5 libraries i finally found this obscure one with 3 stars on github made 6 months ago which does exactly what i wanted. we're saved! saving still doesn't work, but it's actually an isuue on my end this time; there seems to be something off about qt's regex parsing. i'll look into it later. --- .gitmodules | 3 --- CMakeLists.txt | 10 ++++---- src/changelogwidget.cpp | 53 +++++++++++++++++++++++------------------ src/changelogwidget.h | 4 ---- third_party/KZip | 1 + third_party/bit7z | 1 - third_party/zip | 1 + 7 files changed, 38 insertions(+), 35 deletions(-) create mode 160000 third_party/KZip delete mode 160000 third_party/bit7z create mode 160000 third_party/zip diff --git a/.gitmodules b/.gitmodules index da39826..6617474 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,6 +1,3 @@ -[submodule "third_party/bit7z"] - path = third_party/bit7z - url = https://github.com/rikyoz/bit7z [submodule "third_party/liblcf"] path = third_party/liblcf url = https://github.com/lumiscosity/liblcf diff --git a/CMakeLists.txt b/CMakeLists.txt index 33d70c9..62d59d2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,7 +6,7 @@ set(CMAKE_AUTOUIC ON) set(CMAKE_AUTOMOC ON) set(CMAKE_AUTORCC ON) -set(CMAKE_CXX_STANDARD 17) +set(CMAKE_CXX_STANDARD 20) set(CMAKE_CXX_STANDARD_REQUIRED ON) find_package(QT NAMES Qt6 REQUIRED COMPONENTS Widgets) @@ -24,8 +24,6 @@ else(USE_SYSTEM_LIBLCF) add_liblcf() endif(USE_SYSTEM_LIBLCF) -add_subdirectory(${CMAKE_SOURCE_DIR}/third_party/bit7z) - set(PROJECT_SOURCES src/main.cpp src/lcfops.h @@ -39,6 +37,11 @@ set(PROJECT_SOURCES src/changelogwidget.cpp src/changelogwidget.ui third_party/easyrpg_editor/dbstring.h + third_party/zip/3rdparty/miniz-3.0.2/miniz.h + third_party/zip/include/exceptions.hpp + third_party/zip/include/zip.hpp + third_party/zip/src/exceptions.cpp + third_party/zip/src/zip.cpp ) qt_add_executable(mossball @@ -49,7 +52,6 @@ qt_add_executable(mossball ) target_link_libraries(mossball PRIVATE Qt${QT_VERSION_MAJOR}::Widgets) -target_link_libraries(mossball PRIVATE bit7z) target_link_libraries(mossball PRIVATE lcf) diff --git a/src/changelogwidget.cpp b/src/changelogwidget.cpp index 1c3ec91..cabee7b 100644 --- a/src/changelogwidget.cpp +++ b/src/changelogwidget.cpp @@ -17,7 +17,9 @@ #include "changelogwidget.h" #include "ui_changelogwidget.h" -#include + +#include "../third_party/zip/include/exceptions.hpp" +#include "../third_party/zip/include/zip.hpp" #include #include @@ -27,7 +29,6 @@ ChangelogWidget::ChangelogWidget(QString work_dir, QWidget *parent) : work_dir(w ui->setupUi(this); QFont font = QFontDatabase::systemFont(QFontDatabase::FixedFont); ui->plainTextEdit->setFont(font); - } ChangelogWidget::~ChangelogWidget() { @@ -39,44 +40,50 @@ void ChangelogWidget::set_text(QString text) { } void ChangelogWidget::on_pushButton_clicked() { - QString out = QFileDialog::getSaveFileName(this, "Select save location", "", "7z Archive (*.7z)"); + QString out = QFileDialog::getSaveFileName(this, "Select save location", "", "Archive (*.zip)"); if (!out.isEmpty()) { - auto bytes = ui->plainTextEdit->toPlainText().toUtf8(); - std::vector c(bytes.constData(), bytes.constData() + bytes.size()); + auto c = ui->plainTextEdit->toPlainText().toStdString(); // create an archive from all the files and the changelog // i don't actually trust people to not remove stuff after the treeview step, so we treat the changelog as the file list instead // this does pose some annoyances with filenames, which can contain spaces, but we have a fallback + try { - using namespace bit7z; + minidocx::Zip z; + z.open(out.toStdString(), minidocx::Zip::OpenMode::Create); - #if defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__) - Bit7zLibrary lib("7z.dll"); - #else - Bit7zLibrary lib("7z.so"); - #endif - BitArchiveWriter archive{ lib, BitFormat::SevenZip }; QRegularExpression ex("^[^ ]* [^ ]*\[.*$"); QRegularExpression fileex("(?:\\S+\\s+){1}(.+?)(?:\(|$)"); for (QString i : ui->plainTextEdit->toPlainText().split("\n")) { - if (QStringList{"+", "-", "*"}.contains(i.first(1))) { - if (ex.match(i).hasMatch() && i.mid(2, 3) == "MAP" && i.contains("]")) { - archive.addFile(QString(work_dir + QString("/Map%1.lmu").arg(i.split("[")[0].split("]")[0])).toStdString()); - } else if (!ex.match(i).hasMatch() && i.split(" ").size() >= 2) { - archive.addFile(QString(work_dir + QString("/%1/%2").arg(i.split(" ")[1]).arg(fileex.match(i).captured())).toStdString()); + if (i.length() > 5) { + if (QStringList{"+", "*"}.contains(i.first(1))) { + auto temp1 = ex.match(i).hasMatch(); + qWarning()<= 2) { + z.addFileFromDisk(QString("%1/%2").arg(i.split(" ")[1]).arg(fileex.match(i).captured()).toStdString(), QString(work_dir + QString("/%1/%2").arg(i.split(" ")[1]).arg(fileex.match(i).captured())).toStdString()); + } } } } - archive.addFile(c, "changelog.txt"); - archive.addFile(work_dir.toStdString() + "/RPG_RT.lmt"); - archive.addFile(work_dir.toStdString() + "/RPG_RT.ldb"); - archive.compressTo(out.toStdString()); + z.addFileFromString("changelog.txt", c); + z.addFileFromDisk("/RPG_RT.lmt", work_dir.toStdString() + "/RPG_RT.lmt"); + z.addFileFromDisk("/RPG_RT.ldb", work_dir.toStdString() + "/RPG_RT.ldb"); + + z.close(); QMessageBox::information(this, "Success", "Patch compiled successfully."); this->close(); - } catch ( const bit7z::BitException& ex ) { - QMessageBox::critical(this, "Error", QString("An error occured when compiling: %1 (error code %2) \nEnsure that you haven't broken the changelog formatting and the the files detected are present in the work copy, then try again. In case of continued failure, please report the issue in Mossball's repository.").arg(ex.what()).arg(ex.code().value())); + + } + catch (const minidocx::exception& ex) { + QMessageBox::critical(this, "Error", QString("An error occured while compiling: %1 \nEnsure that you haven't broken the changelog formatting and the the files detected are present in the work copy, then try again. In case of continued failure, please report the issue in Mossball's repository.").arg(ex.what())); + return; } + + QMessageBox::information(this, "Success", "Patch compiled successfully."); + this->close(); } } diff --git a/src/changelogwidget.h b/src/changelogwidget.h index 3edc19d..8202fa9 100644 --- a/src/changelogwidget.h +++ b/src/changelogwidget.h @@ -30,12 +30,8 @@ class ChangelogWidget : public QWidget { explicit ChangelogWidget(QString work_dir, QWidget *parent = nullptr); ~ChangelogWidget(); void set_text(QString text); - - QStringList changecsv; - private slots: void on_pushButton_clicked(); - private: Ui::ChangelogWidget *ui; QString work_dir; diff --git a/third_party/KZip b/third_party/KZip new file mode 160000 index 0000000..31df0fb --- /dev/null +++ b/third_party/KZip @@ -0,0 +1 @@ +Subproject commit 31df0fbb848eacfccde01e0542b127a478cb45df diff --git a/third_party/bit7z b/third_party/bit7z deleted file mode 160000 index bec6a22..0000000 --- a/third_party/bit7z +++ /dev/null @@ -1 +0,0 @@ -Subproject commit bec6a2206ee4032c6a424b41ee39771e155f5ea9 diff --git a/third_party/zip b/third_party/zip new file mode 160000 index 0000000..8e657bf --- /dev/null +++ b/third_party/zip @@ -0,0 +1 @@ +Subproject commit 8e657bfa0aaaa797c717236fb978e38de97a8226