mirror of
https://github.com/ModOrganizer2/modorganizer-bsapacker.git
synced 2026-07-27 14:06:14 -07:00
Merge pull request #31 from ModOrganizer2/write_thread
Thread BSA writing
This commit is contained in:
@@ -1,15 +1,34 @@
|
||||
#include <bsapacker/ArchiveAutoService.h>
|
||||
#include <QProgressDialog>
|
||||
#include <QtConcurrent>
|
||||
#include <QLabel>
|
||||
|
||||
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([=]() -> bool {
|
||||
try {
|
||||
archive->save_to_disk(archiveName.toStdString());
|
||||
} catch (std::exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
while (!future.isFinished())
|
||||
{
|
||||
QCoreApplication::processEvents();
|
||||
}
|
||||
catch (std::exception e) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
savingDialog.hide();
|
||||
return future.result();
|
||||
}
|
||||
} // namespace BsaPacker
|
||||
|
||||
@@ -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<const char*>(StarfieldDummyPluginService::RAW_STARFIELD),
|
||||
sizeof(StarfieldDummyPluginService::RAW_STARFIELD));
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user