Skip to content

Commit

Permalink
improve error handling, part 1
Browse files Browse the repository at this point in the history
  • Loading branch information
lumiscosity committed Nov 2, 2024
1 parent d1fdcda commit 2f7c9b0
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 34 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
build/*
builds/*
CMakeLists.txt.user
third_party/bit7z/*
third_party/liblcf/*
Expand Down
14 changes: 12 additions & 2 deletions src/changelogwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,20 @@ void ChangelogWidget::on_pushButton_clicked() {
if (QStringList{"+", "*"}.contains(i.first(1))) {
if (ex.match(i).hasMatch() && i.mid(2, 3) == "MAP" && i.contains("]")) {
// map
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());
QString map_string = QString("Map%1.lmu").arg(i.split("[")[1].split("]")[0]);
try {
z.addFileFromDisk(map_string.toStdString(), QString(work_dir + map_string).toStdString());
} catch (const minidocx::io_error& ex) {
QMessageBox::warning(this, "Warning", QString("Could not include file %1 in the zip file! It is already in the changelog. Add the file to the archive manually.").arg(map_string));
}
} else if (!ex.match(i).hasMatch() && i.split(" ").size() >= 2) {
// file
z.addFileFromDisk(QString("%1/%2").arg(i.split(" ")[1]).arg(fileex.match(i).captured(1)).toStdString(), QString(work_dir + QString("/%1/%2").arg(i.split(" ")[1]).arg(fileex.match(i).captured(1))).toStdString());
QString file_string = QString("%1/%2").arg(i.split(" ")[1]).arg(fileex.match(i).captured(1));
try {
z.addFileFromDisk(file_string.toStdString(), QString(work_dir + file_string).toStdString());
} catch (const minidocx::io_error& ex) {
QMessageBox::warning(this, "Warning", QString("Could not include file %1 in the zip file! It is already in the changelog. Add the file to the archive manually.").arg(file_string));
}
}
}
}
Expand Down
72 changes: 40 additions & 32 deletions src/pickerwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
#include <QCryptographicHash>
#include <QDirIterator>
#include <QTreeWidgetItem>
#include <qmessagebox.h>

PickerWidget::PickerWidget(QWidget *parent) : QDialog(parent), ui(new Ui::PickerWidget) {
ui->setupUi(this);
Expand Down Expand Up @@ -182,6 +183,9 @@ void PickerWidget::gendiff(QString orig_path, QString work_path) {
// shared. only add them if the files actually differ
QFileInfo a(orig_path + "/" + i);
QFileInfo b(work_path + "/" + i);
if (!a.isFile() || !b.isFile()) {
break;
}
if (a.lastModified() != b.lastModified()){
shared.push_back(i);
}
Expand Down Expand Up @@ -248,38 +252,42 @@ void PickerWidget::gendiff(QString orig_path, QString work_path) {
}
ui->treeWidget->sortItems(0, Qt::SortOrder::AscendingOrder);
// get ldb data
std::unique_ptr<lcf::rpg::Database> orig_db = lcf::LDB_Reader::Load((orig_path + "/RPG_RT.ldb").toStdString());
std::unique_ptr<lcf::rpg::Database> work_db = lcf::LDB_Reader::Load((work_path + "/RPG_RT.ldb").toStdString());
// troops
dbdiff(orig_db->troops, work_db->troops, "Troop");
// tilesets
dbdiff(orig_db->chipsets, work_db->chipsets, "Tileset");
// terrains
dbdiff(orig_db->terrains, work_db->terrains, "Terrain");
// states
dbdiff(orig_db->states, work_db->states, "State");
// skills
dbdiff(orig_db->skills, work_db->skills, "Skill");
// items
dbdiff(orig_db->items, work_db->items, "Item");
// enemies
dbdiff(orig_db->classes, work_db->classes, "Enemy");
// elements
dbdiff(orig_db->attributes, work_db->attributes, "Element");
// classes
dbdiff(orig_db->classes, work_db->classes, "Class");
// animation2 (battler animation)
dbdiff(orig_db->battleranimations, work_db->battleranimations, "BattlerAnim");
// animations
dbdiff(orig_db->animations, work_db->animations, "Animation");
// actors
dbdiff(orig_db->actors, work_db->actors, "Actor");
// variables
dbdiff(orig_db->variables, work_db->variables, "V");
// switches
dbdiff(orig_db->switches, work_db->switches, "S");
// CEs
dbdiff(orig_db->commonevents, work_db->commonevents, "CE");
std::unique_ptr<lcf::rpg::Database> orig_db = lcf::LDB_Reader::Load((orig_path + "/RPG_RT.ldb").toStdString(), "UTF-8");
std::unique_ptr<lcf::rpg::Database> work_db = lcf::LDB_Reader::Load((work_path + "/RPG_RT.ldb").toStdString(), "UTF-8");
if (orig_db == nullptr | work_db == nullptr) {
QMessageBox::warning(this, "Warning", "Could not read the database files! Database info will have to be included manually.");
} else {
// troops
dbdiff(orig_db->troops, work_db->troops, "Troop");
// tilesets
dbdiff(orig_db->chipsets, work_db->chipsets, "Tileset");
// terrains
dbdiff(orig_db->terrains, work_db->terrains, "Terrain");
// states
dbdiff(orig_db->states, work_db->states, "State");
// skills
dbdiff(orig_db->skills, work_db->skills, "Skill");
// items
dbdiff(orig_db->items, work_db->items, "Item");
// enemies
dbdiff(orig_db->classes, work_db->classes, "Enemy");
// elements
dbdiff(orig_db->attributes, work_db->attributes, "Element");
// classes
dbdiff(orig_db->classes, work_db->classes, "Class");
// animation2 (battler animation)
dbdiff(orig_db->battleranimations, work_db->battleranimations, "BattlerAnim");
// animations
dbdiff(orig_db->animations, work_db->animations, "Animation");
// actors
dbdiff(orig_db->actors, work_db->actors, "Actor");
// variables
dbdiff(orig_db->variables, work_db->variables, "V");
// switches
dbdiff(orig_db->switches, work_db->switches, "S");
// CEs
dbdiff(orig_db->commonevents, work_db->commonevents, "CE");
}

// yoink the maps and put them up top
for (auto &i: ui->treeWidget->findItems("", Qt::MatchExactly, 1)) {
Expand Down

0 comments on commit 2f7c9b0

Please sign in to comment.