From 3525ebda98401c04d9884a71ef5b38c4abfef612 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Wed, 11 Oct 2023 01:16:49 -0500 Subject: [PATCH 1/3] Thread BSA writing - Show progress dialog - Prevent UI lockup TODO: Prevent dialog from being closed by Esc --- src/ArchiveAutoService.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/ArchiveAutoService.cpp b/src/ArchiveAutoService.cpp index 0c27315..6320885 100644 --- a/src/ArchiveAutoService.cpp +++ b/src/ArchiveAutoService.cpp @@ -1,11 +1,30 @@ #include +#include +#include +#include namespace BsaPacker { bool ArchiveAutoService::CreateBSA(libbsarch::bs_archive_auto* archive, const QString& archiveName, const bsa_archive_type_e type) const { try { - archive->save_to_disk(archiveName.toStdString()); + QProgressDialog savingDialog; + savingDialog.setWindowFlags(savingDialog.windowFlags() & ~Qt::WindowCloseButtonHint); + savingDialog.setWindowTitle(QObject::tr("Writing Archive")); + savingDialog.setCancelButton(0); + QLabel text; + text.setText(QObject::tr("Writing %1").arg(archiveName)); + savingDialog.setLabel(&text); + savingDialog.setRange(0, 0); + savingDialog.show(); + auto future = QtConcurrent::run([this, archive, archiveName]() { + archive->save_to_disk(archiveName.toStdString()); + }); + while (!future.isFinished()) + { + QCoreApplication::processEvents(); + } + savingDialog.hide(); } catch (std::exception e) { return false; From de1f19b5bdf4f38671904d1f3e8190d90647df21 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Wed, 11 Oct 2023 20:35:28 -0500 Subject: [PATCH 2/3] Move try/catch to thread and return result --- src/ArchiveAutoService.cpp | 40 +++++++++++++++++++------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/ArchiveAutoService.cpp b/src/ArchiveAutoService.cpp index 6320885..37ec93f 100644 --- a/src/ArchiveAutoService.cpp +++ b/src/ArchiveAutoService.cpp @@ -7,28 +7,28 @@ namespace BsaPacker { bool ArchiveAutoService::CreateBSA(libbsarch::bs_archive_auto* archive, const QString& archiveName, const bsa_archive_type_e type) const { - try { - QProgressDialog savingDialog; - savingDialog.setWindowFlags(savingDialog.windowFlags() & ~Qt::WindowCloseButtonHint); - savingDialog.setWindowTitle(QObject::tr("Writing Archive")); - savingDialog.setCancelButton(0); - QLabel text; - text.setText(QObject::tr("Writing %1").arg(archiveName)); - savingDialog.setLabel(&text); - savingDialog.setRange(0, 0); - savingDialog.show(); - auto future = QtConcurrent::run([this, archive, archiveName]() { + QProgressDialog savingDialog; + savingDialog.setWindowFlags(savingDialog.windowFlags() & ~Qt::WindowCloseButtonHint); + savingDialog.setWindowTitle(QObject::tr("Writing Archive")); + savingDialog.setCancelButton(0); + QLabel text; + text.setText(QObject::tr("Writing %1").arg(archiveName)); + savingDialog.setLabel(&text); + savingDialog.setRange(0, 0); + savingDialog.show(); + auto future = QtConcurrent::run([=]() -> bool { + try { archive->save_to_disk(archiveName.toStdString()); - }); - while (!future.isFinished()) - { - QCoreApplication::processEvents(); + } catch (std::exception e) { + return false; } - savingDialog.hide(); + return true; + }); + while (!future.isFinished()) + { + QCoreApplication::processEvents(); } - catch (std::exception e) { - return false; - } - return true; + savingDialog.hide(); + return future.result(); } } // namespace BsaPacker From 10d23dac41059a16b2b630b1f4d492ca9751e1e6 Mon Sep 17 00:00:00 2001 From: Jeremy Rimpo Date: Tue, 17 Oct 2023 01:07:16 -0500 Subject: [PATCH 3/3] Use light flag and ESL extension for SF --- src/StarfieldDummyPluginService.cpp | 2 +- src/StarfieldDummyPluginService.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/StarfieldDummyPluginService.cpp b/src/StarfieldDummyPluginService.cpp index a04e974..2357a7e 100644 --- a/src/StarfieldDummyPluginService.cpp +++ b/src/StarfieldDummyPluginService.cpp @@ -18,7 +18,7 @@ namespace BsaPacker { return false; } - const std::string& absoluteFileName = fileNameNoExtension.toStdString() + ".esp"; + const std::string& absoluteFileName = fileNameNoExtension.toStdString() + ".esl"; return this->m_FileWriterService->Write(absoluteFileName, reinterpret_cast(StarfieldDummyPluginService::RAW_STARFIELD), sizeof(StarfieldDummyPluginService::RAW_STARFIELD)); diff --git a/src/StarfieldDummyPluginService.h b/src/StarfieldDummyPluginService.h index b0de50a..dfa48a1 100644 --- a/src/StarfieldDummyPluginService.h +++ b/src/StarfieldDummyPluginService.h @@ -18,7 +18,7 @@ namespace BsaPacker const QString& archiveNameBase) const override; static constexpr unsigned char RAW_STARFIELD[] = { - 0x54, 0x45, 0x53, 0x34, 0x19, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x00, + 0x54, 0x45, 0x53, 0x34, 0x19, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2B, 0x02, 0x00, 0x00, 0x48, 0x45, 0x44, 0x52, 0x0C, 0x00, 0x8F, 0xC2, 0x75, 0x3F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x00, 0x43, 0x4E, 0x41, 0x4D, 0x01, 0x00,