Skip to content

Commit

Permalink
patch saving, part 2
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lumiscosity committed Sep 30, 2024
1 parent 4f74f5e commit 6dc25b6
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 35 deletions.
3 changes: 0 additions & 3 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -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
10 changes: 6 additions & 4 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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)


Expand Down
53 changes: 30 additions & 23 deletions src/changelogwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@

#include "changelogwidget.h"
#include "ui_changelogwidget.h"
#include <bit7z/bitarchivewriter.hpp>

#include "../third_party/zip/include/exceptions.hpp"
#include "../third_party/zip/include/zip.hpp"

#include <QFileDialog>
#include <QMessageBox>
Expand All @@ -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() {
Expand All @@ -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<unsigned char> 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()<<temp1;
if (ex.match(i).hasMatch() && i.mid(2, 3) == "MAP" && i.contains("]")) {
z.addFileFromDisk(QString("Map%1.lmu").arg(i.split("[")[1].split("]")[0]).toStdString(), QString(work_dir + QString("/Map%1.lmu").arg(i.split("[")[1].split("]")[0])).toStdString());
} else if (!ex.match(i).hasMatch() && i.split(" ").size() >= 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();
}
}

4 changes: 0 additions & 4 deletions src/changelogwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions third_party/KZip
Submodule KZip added at 31df0f
1 change: 0 additions & 1 deletion third_party/bit7z
Submodule bit7z deleted from bec6a2
1 change: 1 addition & 0 deletions third_party/zip
Submodule zip added at 8e657b

0 comments on commit 6dc25b6

Please sign in to comment.