Skip to content

Commit a763e8f

Browse files
author
MF
committed
Merge branch 'async-refactor'
2 parents 30775ca + f26af98 commit a763e8f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+333
-189
lines changed

CMakeLists.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,7 @@ add_library(${PROJ_NAME} SHARED
5959
src/BsaPackerWorker.cpp
6060
src/ModDtoProcessService.h
6161
src/NexusId.h
62+
src/QBSArchiveAuto.h
6263

6364
src/ArchiveAutoService.cpp
6465
src/ArchiveBuildDirector.cpp
@@ -84,6 +85,7 @@ add_library(${PROJ_NAME} SHARED
8485
src/OblivionDummyPluginService.cpp
8586
src/PackerDialog.cpp
8687
src/PackerDialogFactory.cpp
88+
src/QBSArchiveAuto.cpp
8789
src/SettingsService.cpp
8890
src/SkyrimDummyPluginService.cpp
8991
src/SkyrimSEDummyPluginService.cpp

appveyor.yml

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,11 @@
11
version: 1.0.{build}
22
skip_branch_with_pr: true
33
image: Visual Studio 2019
4-
environment:
5-
WEBHOOK_URL:
6-
secure: gOKbXaZM9ImtMD5XrYITvdyZUW/az082G9OIN1EC1Vbg57wBaeLhi49uGjxPw5GVujHku6kxN6ab89zhbS5GVeluR76GM83IbKV4Sh7udXzoYZZdg6YudtYHzdhCgUeiedpswbuczTq9ceIkkfSEWZuh/lMAAVVwvcGsJAnoPFw=
74
build:
85
parallel: true
96
build_script:
107
- cmd: >-
11-
git clone --depth=1 --branch=%APPVEYOR_REPO_BRANCH% https://github.com/ModOrganizer2/modorganizer-umbrella.git c:\projects\modorganizer-umbrella 2> $null
8+
git clone --depth=1 --branch=master https://github.com/ModOrganizer2/modorganizer-umbrella.git c:\projects\modorganizer-umbrella 2> $null
129
1310
mkdir c:\projects\modorganizer-build -type directory
1411
@@ -22,13 +19,3 @@ artifacts:
2219
name: bsa_packer_pdb
2320
- path: build\bsa_packer.lib
2421
name: bsa_packer_lib
25-
on_success:
26-
- ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER
27-
- ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1
28-
- ps: ./send.ps1 success $env:WEBHOOK_URL
29-
on_failure:
30-
- ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER
31-
- ps: Push-AppveyorArtifact ${env:APPVEYOR_BUILD_FOLDER}\stdout.log
32-
- ps: Push-AppveyorArtifact ${env:APPVEYOR_BUILD_FOLDER}\stderr.log
33-
- ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1
34-
- ps: ./send.ps1 failure $env:WEBHOOK_URL

include/bsapacker/ArchiveAutoService.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ namespace BsaPacker
1515
ArchiveAutoService(ArchiveAutoService&&) = default;
1616
ArchiveAutoService& operator=(ArchiveAutoService&&) = default;
1717

18-
void CreateBSA(libbsarch::bs_archive_auto* archive, const QString& archiveName) const override;
18+
void CreateBSA(QBSArchiveAuto* archive, const std::string& archiveName) const override;
1919
};
2020
} // namespace BsaPacker
2121

include/bsapacker/ArchiveBuildDirector.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,22 +4,27 @@
44
#include <bsapacker/IArchiveBuilder.h>
55
#include <bsapacker/ISettingsService.h>
66

7+
#include <QProgressDialog>
8+
#include <QFutureWatcher>
9+
710
namespace BsaPacker
811
{
912
class ArchiveBuildDirector
1013
{
1114
public:
12-
explicit ArchiveBuildDirector(IArchiveBuilder* archiveFileBuildService);
15+
explicit ArchiveBuildDirector(IArchiveBuilder* archiveBuilder);
1316
~ArchiveBuildDirector() = default;
1417
ArchiveBuildDirector(const ArchiveBuildDirector&) = default;
1518
ArchiveBuildDirector& operator=(const ArchiveBuildDirector&) = default;
1619
ArchiveBuildDirector(ArchiveBuildDirector&&) = default;
1720
ArchiveBuildDirector& operator=(ArchiveBuildDirector&&) = default;
1821

19-
void Construct();
22+
uint32_t Construct();
2023

2124
private:
22-
IArchiveBuilder* m_ArchiveFileBuildService = nullptr;
25+
IArchiveBuilder* m_ArchiveBuilder = nullptr;
26+
QFutureWatcher<void> futureWatcher;
27+
QProgressDialog dialog;
2328
};
2429
} // namespace BsaPacker
2530

include/bsapacker/GeneralArchiveBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace BsaPacker
2121

2222
uint32_t setFiles() override;
2323
void setShareData(bool value) override;
24-
[[nodiscard]] std::unique_ptr<libbsarch::bs_archive_auto> getArchive() override;
24+
[[nodiscard]] std::unique_ptr<QBSArchiveAuto> getArchive() override;
2525
[[nodiscard]] uint32_t getFileCount() const override;
2626
[[nodiscard]] QString getRootPath() const override;
2727

@@ -30,7 +30,7 @@ namespace BsaPacker
3030

3131
private:
3232
const IArchiveBuilderHelper* m_ArchiveBuilderHelper = nullptr;
33-
std::unique_ptr<libbsarch::bs_archive_auto> m_Archive;
33+
std::unique_ptr<QBSArchiveAuto> m_Archive;
3434
bool m_Cancelled;
3535
QDir m_RootDirectory;
3636
};

include/bsapacker/IArchiveAutoService.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
#ifndef IARCHIVEAUTOSERVICE_H
22
#define IARCHIVEAUTOSERVICE_H
33

4-
#include <bs_archive_auto.hpp>
5-
#include <QString>
4+
//#include <bs_archive_auto.hpp>
5+
#include "src/QBSArchiveAuto.h"
6+
#include <string>
67

78
namespace BsaPacker
89
{
910
class IArchiveAutoService
1011
{
1112
public:
1213
virtual ~IArchiveAutoService() = default;
13-
virtual void CreateBSA(libbsarch::bs_archive_auto*, const QString&) const = 0;
14+
virtual void CreateBSA(QBSArchiveAuto*, const std::string&) const = 0;
1415
};
1516
} // namespace BsaPacker
1617

include/bsapacker/IArchiveBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#define IARCHIVEBUILDER_H
33

44
#include <bsapacker/IEmitsValueChanged.h>
5-
#include <bs_archive_auto.hpp>
5+
#include "src/QBSArchiveAuto.h"
66

77
namespace BsaPacker
88
{
@@ -15,7 +15,7 @@ namespace BsaPacker
1515
virtual ~IArchiveBuilder() = default;
1616
virtual uint32_t setFiles() = 0;
1717
virtual void setShareData(bool) = 0;
18-
[[nodiscard]] virtual std::unique_ptr<libbsarch::bs_archive_auto> getArchive() = 0;
18+
[[nodiscard]] virtual std::unique_ptr<QBSArchiveAuto> getArchive() = 0;
1919
[[nodiscard]] virtual uint32_t getFileCount() const = 0;
2020
[[nodiscard]] virtual QString getRootPath() const = 0;
2121
};

include/bsapacker/IArchiveNameService.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ namespace BsaPacker
1010
{
1111
public:
1212
virtual ~IArchiveNameService() = default;
13-
virtual QString GetFileExtension() const = 0;
14-
virtual QString GetArchiveFullPath(bsa_archive_type_t, const IModDto*) const = 0;
13+
virtual std::string GetFileExtension() const = 0;
14+
virtual std::string GetArchiveFullPath(bsa_archive_type_t, const IModDto*) const = 0;
15+
virtual std::string GetArchiveFullPathPartial(bsa_archive_type_t, const IModDto*) const = 0;
1516
};
1617
} // namespace BsaPacker
1718

include/bsapacker/IDummyPluginLogic.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,16 @@
11
#ifndef IDUMMYPLUGINLOGIC_H
22
#define IDUMMYPLUGINLOGIC_H
33

4-
#include <QString>
5-
#include <array>
4+
#include <string>
65

76
namespace BsaPacker
87
{
98
class IDummyPluginLogic
109
{
1110
public:
1211
virtual ~IDummyPluginLogic() = default;
13-
[[nodiscard]] virtual bool canCreateDummyESP(const QString& fileNameNoExtension) const = 0;
14-
[[nodiscard]] virtual bool canCreateDummyESL(const QString& fileNameNoExtension) const = 0;
12+
[[nodiscard]] virtual bool canCreateDummyESP(const std::string& fileNameNoExtension) const = 0;
13+
[[nodiscard]] virtual bool canCreateDummyESL(const std::string& fileNameNoExtension) const = 0;
1514
};
1615
}
1716

include/bsapacker/IDummyPluginService.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
#ifndef IDUMMYPLUGINSERVICE_H
22
#define IDUMMYPLUGINSERVICE_H
33

4-
#include <QString>
4+
#include <string>
55

66
namespace BsaPacker
77
{
88
class IDummyPluginService
99
{
1010
public:
1111
virtual ~IDummyPluginService() = default;
12-
virtual bool CreatePlugin(const QString& modPath,
13-
const QString& archiveNameBase) const = 0;
12+
virtual bool CreatePlugin(const std::string& modPath, const std::string& archiveNameBase) const = 0;
1413
};
1514
}
1615

include/bsapacker/IDummyPluginServiceFactory.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#define IDUMMYPLUGINSERVICEFACTORY_H
33

44
#include <bsapacker/IDummyPluginService.h>
5+
#include <memory>
56

67
namespace BsaPacker
78
{

include/bsapacker/IHideLooseAssetService.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
#ifndef IHIDELOOSEASSETSERVICE_H
22
#define IHIDELOOSEASSETSERVICE_H
33

4-
#include <QDir>
4+
#include <string>
55

66
namespace BsaPacker
77
{
88
class IHideLooseAssetService
99
{
1010
public:
1111
virtual ~IHideLooseAssetService() = default;
12-
virtual bool HideLooseAssets(const QDir& modDirectory) const = 0;
12+
virtual bool HideLooseAssets(const std::string& modDirectory) const = 0;
1313
};
1414
}
1515

include/bsapacker/IModDto.h

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
#ifndef IMODDTO_H
22
#define IMODDTO_H
33

4-
#include <QString>
4+
#include <string>
55

66
namespace BsaPacker
77
{
88
class IModDto
99
{
1010
public:
1111
virtual ~IModDto() = default;
12-
[[nodiscard]] virtual QString ArchiveExtension() const = 0;
13-
[[nodiscard]] virtual QString ArchiveName() const = 0;
14-
[[nodiscard]] virtual QString Directory() const = 0;
15-
[[nodiscard]] virtual QString ModForename() const = 0;
12+
[[nodiscard]] virtual std::string ArchiveExtension() const = 0;
13+
[[nodiscard]] virtual std::string ArchiveName() const = 0;
14+
[[nodiscard]] virtual std::string Directory() const = 0;
15+
[[nodiscard]] virtual std::string ModForename() const = 0;
1616
[[nodiscard]] virtual int NexusId() const = 0;
1717
};
1818
} // namespace BsaPacker

include/bsapacker/NullArchiveBuilder.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ namespace BsaPacker
1616

1717
uint32_t setFiles() override;
1818
void setShareData(bool) override;
19-
[[nodiscard]] std::unique_ptr<libbsarch::bs_archive_auto> getArchive() override;
19+
[[nodiscard]] std::unique_ptr<QBSArchiveAuto> getArchive() override;
2020
[[nodiscard]] uint32_t getFileCount() const override;
2121
[[nodiscard]] QString getRootPath() const override;
2222

include/bsapacker/TextureArchiveBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace BsaPacker
2121

2222
uint32_t setFiles() override;
2323
void setShareData(bool) override;
24-
[[nodiscard]] std::unique_ptr<libbsarch::bs_archive_auto> getArchive() override;
24+
[[nodiscard]] std::unique_ptr<QBSArchiveAuto> getArchive() override;
2525
[[nodiscard]] uint32_t getFileCount() const override;
2626
[[nodiscard]] QString getRootPath() const override;
2727

@@ -30,7 +30,7 @@ namespace BsaPacker
3030

3131
private:
3232
const IArchiveBuilderHelper* m_ArchiveBuilderHelper = nullptr;
33-
std::unique_ptr<libbsarch::bs_archive_auto> m_Archive;
33+
std::unique_ptr<QBSArchiveAuto> m_Archive;
3434
bool m_Cancelled;
3535
QDir m_RootDirectory;
3636

include/bsapacker/TexturelessArchiveBuilder.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ namespace BsaPacker
2121

2222
uint32_t setFiles() override;
2323
void setShareData(bool) override;
24-
[[nodiscard]] std::unique_ptr<libbsarch::bs_archive_auto> getArchive() override;
24+
[[nodiscard]] std::unique_ptr<QBSArchiveAuto> getArchive() override;
2525
[[nodiscard]] uint32_t getFileCount() const override;
2626
[[nodiscard]] QString getRootPath() const override;
2727

@@ -30,7 +30,7 @@ namespace BsaPacker
3030

3131
private:
3232
const IArchiveBuilderHelper* m_ArchiveBuilderHelper = nullptr;
33-
std::unique_ptr<libbsarch::bs_archive_auto> m_Archive;
33+
std::unique_ptr<QBSArchiveAuto> m_Archive;
3434
bool m_Cancelled;
3535
QDir m_RootDirectory;
3636
};

src/ArchiveAutoService.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
#include <bsapacker/ArchiveAutoService.h>
22

3+
#include <QDebug>
4+
35
namespace BsaPacker
46
{
5-
void ArchiveAutoService::CreateBSA(libbsarch::bs_archive_auto* archive, const QString& archiveName) const
7+
void ArchiveAutoService::CreateBSA(QBSArchiveAuto* archive, const std::string& archiveName) const
68
{
7-
archive->save_to_disk(archiveName.toStdString());
9+
qDebug() << "Saving archive " + QString::fromStdString(archiveName) + " to disk";
10+
archive->save_to_disk(archiveName);
11+
qDebug() << "Finished writing archive " + QString::fromStdString(archiveName) + " to disk";
812
}
913
} // namespace BsaPacker

src/ArchiveBuildDirector.cpp

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,36 @@
11
#include <bsapacker/ArchiveBuildDirector.h>
22

3-
#include <QProgressDialog>
3+
#include <QtConcurrent/QtConcurrentRun>
4+
5+
#include <QDebug>
46

57
namespace BsaPacker
68
{
79
ArchiveBuildDirector::ArchiveBuildDirector(
8-
IArchiveBuilder* archiveFileBuildService)
9-
: m_ArchiveFileBuildService(archiveFileBuildService)
10+
IArchiveBuilder* archiveBuilder) :
11+
m_ArchiveBuilder(archiveBuilder),
12+
dialog("Finding and marking files for archival", "Cancel", 0, this->m_ArchiveBuilder->getFileCount())
1013
{
14+
QObject::connect(&futureWatcher, &QFutureWatcher<void>::finished, &dialog, &QProgressDialog::reset);
15+
QObject::connect(&dialog, &QProgressDialog::canceled, this->m_ArchiveBuilder, &IArchiveBuilder::cancel);
16+
QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressRangeChanged, &dialog, &QProgressDialog::setRange);
17+
QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressValueChanged, &dialog, &QProgressDialog::setValue);
1118
}
1219

13-
void ArchiveBuildDirector::Construct()
20+
uint32_t ArchiveBuildDirector::Construct()
1421
{
15-
QProgressDialog dialog("Adding to archive",
16-
"Abort",
17-
0,
18-
static_cast<int>(this->m_ArchiveFileBuildService->getFileCount()));
19-
QObject::connect(&dialog, &QProgressDialog::canceled, this->m_ArchiveFileBuildService, &IArchiveBuilder::cancel);
20-
QObject::connect(this->m_ArchiveFileBuildService, SIGNAL(valueChanged(int)), &dialog, SLOT(setValue(int)));
21-
dialog.show();
22-
this->m_ArchiveFileBuildService->setShareData(true);
23-
this->m_ArchiveFileBuildService->setFiles();
24-
dialog.close();
22+
qDebug() << this->m_ArchiveBuilder->getFileCount() << "files in directory";
23+
//QObject::connect(this->m_ArchiveBuilder, &IArchiveBuilder::valueChanged, &dialog, &QProgressDialog::setValue);
24+
qDebug() << "Beginning async marking operation";
25+
this->m_ArchiveBuilder->setShareData(true);
26+
QFuture<uint32_t> future = QtConcurrent::run(this->m_ArchiveBuilder, &IArchiveBuilder::setFiles);
27+
futureWatcher.setFuture(future);
28+
qDebug() << "Progress dialog imminent";
29+
dialog.exec();
30+
qDebug() << "Waiting for marking to complete";
31+
future.waitForFinished();
32+
auto result = future.result();
33+
qDebug() << "Result obtained:" << result << "files marked";
34+
return result;
2535
}
2636
} // namespace BsaPacker

src/ArchiveBuilderFactory.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include <bsapacker/TextureArchiveBuilder.h>
66
#include <bsapacker/TexturelessArchiveBuilder.h>
77
#include "NexusId.h"
8+
#include <string>
89

910
namespace BsaPacker
1011
{
@@ -35,16 +36,17 @@ namespace BsaPacker
3536

3637
std::unique_ptr<IArchiveBuilder> ArchiveBuilderFactory::Create(const bsa_archive_type_t archiveType, const IModDto* modDto) const
3738
{
39+
const QDir& directory = QDir(QString::fromStdString(modDto->Directory()));
3840
switch (archiveType) {
3941
case baTES3:
4042
case baTES4:
4143
case baFO3:
4244
case baSSE:
43-
return std::make_unique<GeneralArchiveBuilder>(this->m_ArchiveBuilderHelper, modDto->Directory(), archiveType);
45+
return std::make_unique<GeneralArchiveBuilder>(this->m_ArchiveBuilderHelper, directory, archiveType);
4446
case baFO4:
45-
return std::make_unique<TexturelessArchiveBuilder>(this->m_ArchiveBuilderHelper, modDto->Directory(), archiveType);
47+
return std::make_unique<TexturelessArchiveBuilder>(this->m_ArchiveBuilderHelper, directory, archiveType);
4648
case baFO4dds:
47-
return std::make_unique<TextureArchiveBuilder>(this->m_ArchiveBuilderHelper, modDto->Directory(), archiveType);
49+
return std::make_unique<TextureArchiveBuilder>(this->m_ArchiveBuilderHelper, directory, archiveType);
4850
case baNone:
4951
default:
5052
return std::make_unique<NullArchiveBuilder>();

src/ArchiveBuilderHelper.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ namespace BsaPacker
1313
: m_SettingsService(settingsService)
1414
{
1515
}
16+
1617
uint32_t ArchiveBuilderHelper::getFileCount(const QDir& rootDirectory) const
1718
{
1819
QDirIterator it(rootDirectory, QDirIterator::Subdirectories);

0 commit comments

Comments
 (0)