Skip to content

Commit

Permalink
Merge branch 'async-refactor'
Browse files Browse the repository at this point in the history
  • Loading branch information
MF committed Feb 8, 2020
2 parents 30775ca + f26af98 commit a763e8f
Show file tree
Hide file tree
Showing 54 changed files with 333 additions and 189 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ add_library(${PROJ_NAME} SHARED
src/BsaPackerWorker.cpp
src/ModDtoProcessService.h
src/NexusId.h
src/QBSArchiveAuto.h

src/ArchiveAutoService.cpp
src/ArchiveBuildDirector.cpp
Expand All @@ -84,6 +85,7 @@ add_library(${PROJ_NAME} SHARED
src/OblivionDummyPluginService.cpp
src/PackerDialog.cpp
src/PackerDialogFactory.cpp
src/QBSArchiveAuto.cpp
src/SettingsService.cpp
src/SkyrimDummyPluginService.cpp
src/SkyrimSEDummyPluginService.cpp
Expand Down
15 changes: 1 addition & 14 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
version: 1.0.{build}
skip_branch_with_pr: true
image: Visual Studio 2019
environment:
WEBHOOK_URL:
secure: gOKbXaZM9ImtMD5XrYITvdyZUW/az082G9OIN1EC1Vbg57wBaeLhi49uGjxPw5GVujHku6kxN6ab89zhbS5GVeluR76GM83IbKV4Sh7udXzoYZZdg6YudtYHzdhCgUeiedpswbuczTq9ceIkkfSEWZuh/lMAAVVwvcGsJAnoPFw=
build:
parallel: true
build_script:
- cmd: >-
git clone --depth=1 --branch=%APPVEYOR_REPO_BRANCH% https://github.com/ModOrganizer2/modorganizer-umbrella.git c:\projects\modorganizer-umbrella 2> $null
git clone --depth=1 --branch=master https://github.com/ModOrganizer2/modorganizer-umbrella.git c:\projects\modorganizer-umbrella 2> $null
mkdir c:\projects\modorganizer-build -type directory
Expand All @@ -22,13 +19,3 @@ artifacts:
name: bsa_packer_pdb
- path: build\bsa_packer.lib
name: bsa_packer_lib
on_success:
- ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER
- ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1
- ps: ./send.ps1 success $env:WEBHOOK_URL
on_failure:
- ps: Set-Location -Path $env:APPVEYOR_BUILD_FOLDER
- ps: Push-AppveyorArtifact ${env:APPVEYOR_BUILD_FOLDER}\stdout.log
- ps: Push-AppveyorArtifact ${env:APPVEYOR_BUILD_FOLDER}\stderr.log
- ps: Invoke-RestMethod https://raw.githubusercontent.com/DiscordHooks/appveyor-discord-webhook/master/send.ps1 -o send.ps1
- ps: ./send.ps1 failure $env:WEBHOOK_URL
2 changes: 1 addition & 1 deletion include/bsapacker/ArchiveAutoService.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace BsaPacker
ArchiveAutoService(ArchiveAutoService&&) = default;
ArchiveAutoService& operator=(ArchiveAutoService&&) = default;

void CreateBSA(libbsarch::bs_archive_auto* archive, const QString& archiveName) const override;
void CreateBSA(QBSArchiveAuto* archive, const std::string& archiveName) const override;
};
} // namespace BsaPacker

Expand Down
11 changes: 8 additions & 3 deletions include/bsapacker/ArchiveBuildDirector.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,27 @@
#include <bsapacker/IArchiveBuilder.h>
#include <bsapacker/ISettingsService.h>

#include <QProgressDialog>
#include <QFutureWatcher>

namespace BsaPacker
{
class ArchiveBuildDirector
{
public:
explicit ArchiveBuildDirector(IArchiveBuilder* archiveFileBuildService);
explicit ArchiveBuildDirector(IArchiveBuilder* archiveBuilder);
~ArchiveBuildDirector() = default;
ArchiveBuildDirector(const ArchiveBuildDirector&) = default;
ArchiveBuildDirector& operator=(const ArchiveBuildDirector&) = default;
ArchiveBuildDirector(ArchiveBuildDirector&&) = default;
ArchiveBuildDirector& operator=(ArchiveBuildDirector&&) = default;

void Construct();
uint32_t Construct();

private:
IArchiveBuilder* m_ArchiveFileBuildService = nullptr;
IArchiveBuilder* m_ArchiveBuilder = nullptr;
QFutureWatcher<void> futureWatcher;
QProgressDialog dialog;
};
} // namespace BsaPacker

Expand Down
4 changes: 2 additions & 2 deletions include/bsapacker/GeneralArchiveBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace BsaPacker

uint32_t setFiles() override;
void setShareData(bool value) override;
[[nodiscard]] std::unique_ptr<libbsarch::bs_archive_auto> getArchive() override;
[[nodiscard]] std::unique_ptr<QBSArchiveAuto> getArchive() override;
[[nodiscard]] uint32_t getFileCount() const override;
[[nodiscard]] QString getRootPath() const override;

Expand All @@ -30,7 +30,7 @@ namespace BsaPacker

private:
const IArchiveBuilderHelper* m_ArchiveBuilderHelper = nullptr;
std::unique_ptr<libbsarch::bs_archive_auto> m_Archive;
std::unique_ptr<QBSArchiveAuto> m_Archive;
bool m_Cancelled;
QDir m_RootDirectory;
};
Expand Down
7 changes: 4 additions & 3 deletions include/bsapacker/IArchiveAutoService.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
#ifndef IARCHIVEAUTOSERVICE_H
#define IARCHIVEAUTOSERVICE_H

#include <bs_archive_auto.hpp>
#include <QString>
//#include <bs_archive_auto.hpp>
#include "src/QBSArchiveAuto.h"
#include <string>

namespace BsaPacker
{
class IArchiveAutoService
{
public:
virtual ~IArchiveAutoService() = default;
virtual void CreateBSA(libbsarch::bs_archive_auto*, const QString&) const = 0;
virtual void CreateBSA(QBSArchiveAuto*, const std::string&) const = 0;
};
} // namespace BsaPacker

Expand Down
4 changes: 2 additions & 2 deletions include/bsapacker/IArchiveBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#define IARCHIVEBUILDER_H

#include <bsapacker/IEmitsValueChanged.h>
#include <bs_archive_auto.hpp>
#include "src/QBSArchiveAuto.h"

namespace BsaPacker
{
Expand All @@ -15,7 +15,7 @@ namespace BsaPacker
virtual ~IArchiveBuilder() = default;
virtual uint32_t setFiles() = 0;
virtual void setShareData(bool) = 0;
[[nodiscard]] virtual std::unique_ptr<libbsarch::bs_archive_auto> getArchive() = 0;
[[nodiscard]] virtual std::unique_ptr<QBSArchiveAuto> getArchive() = 0;
[[nodiscard]] virtual uint32_t getFileCount() const = 0;
[[nodiscard]] virtual QString getRootPath() const = 0;
};
Expand Down
5 changes: 3 additions & 2 deletions include/bsapacker/IArchiveNameService.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ namespace BsaPacker
{
public:
virtual ~IArchiveNameService() = default;
virtual QString GetFileExtension() const = 0;
virtual QString GetArchiveFullPath(bsa_archive_type_t, const IModDto*) const = 0;
virtual std::string GetFileExtension() const = 0;
virtual std::string GetArchiveFullPath(bsa_archive_type_t, const IModDto*) const = 0;
virtual std::string GetArchiveFullPathPartial(bsa_archive_type_t, const IModDto*) const = 0;
};
} // namespace BsaPacker

Expand Down
7 changes: 3 additions & 4 deletions include/bsapacker/IDummyPluginLogic.h
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
#ifndef IDUMMYPLUGINLOGIC_H
#define IDUMMYPLUGINLOGIC_H

#include <QString>
#include <array>
#include <string>

namespace BsaPacker
{
class IDummyPluginLogic
{
public:
virtual ~IDummyPluginLogic() = default;
[[nodiscard]] virtual bool canCreateDummyESP(const QString& fileNameNoExtension) const = 0;
[[nodiscard]] virtual bool canCreateDummyESL(const QString& fileNameNoExtension) const = 0;
[[nodiscard]] virtual bool canCreateDummyESP(const std::string& fileNameNoExtension) const = 0;
[[nodiscard]] virtual bool canCreateDummyESL(const std::string& fileNameNoExtension) const = 0;
};
}

Expand Down
5 changes: 2 additions & 3 deletions include/bsapacker/IDummyPluginService.h
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#ifndef IDUMMYPLUGINSERVICE_H
#define IDUMMYPLUGINSERVICE_H

#include <QString>
#include <string>

namespace BsaPacker
{
class IDummyPluginService
{
public:
virtual ~IDummyPluginService() = default;
virtual bool CreatePlugin(const QString& modPath,
const QString& archiveNameBase) const = 0;
virtual bool CreatePlugin(const std::string& modPath, const std::string& archiveNameBase) const = 0;
};
}

Expand Down
1 change: 1 addition & 0 deletions include/bsapacker/IDummyPluginServiceFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define IDUMMYPLUGINSERVICEFACTORY_H

#include <bsapacker/IDummyPluginService.h>
#include <memory>

namespace BsaPacker
{
Expand Down
4 changes: 2 additions & 2 deletions include/bsapacker/IHideLooseAssetService.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#ifndef IHIDELOOSEASSETSERVICE_H
#define IHIDELOOSEASSETSERVICE_H

#include <QDir>
#include <string>

namespace BsaPacker
{
class IHideLooseAssetService
{
public:
virtual ~IHideLooseAssetService() = default;
virtual bool HideLooseAssets(const QDir& modDirectory) const = 0;
virtual bool HideLooseAssets(const std::string& modDirectory) const = 0;
};
}

Expand Down
10 changes: 5 additions & 5 deletions include/bsapacker/IModDto.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
#ifndef IMODDTO_H
#define IMODDTO_H

#include <QString>
#include <string>

namespace BsaPacker
{
class IModDto
{
public:
virtual ~IModDto() = default;
[[nodiscard]] virtual QString ArchiveExtension() const = 0;
[[nodiscard]] virtual QString ArchiveName() const = 0;
[[nodiscard]] virtual QString Directory() const = 0;
[[nodiscard]] virtual QString ModForename() const = 0;
[[nodiscard]] virtual std::string ArchiveExtension() const = 0;
[[nodiscard]] virtual std::string ArchiveName() const = 0;
[[nodiscard]] virtual std::string Directory() const = 0;
[[nodiscard]] virtual std::string ModForename() const = 0;
[[nodiscard]] virtual int NexusId() const = 0;
};
} // namespace BsaPacker
Expand Down
2 changes: 1 addition & 1 deletion include/bsapacker/NullArchiveBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace BsaPacker

uint32_t setFiles() override;
void setShareData(bool) override;
[[nodiscard]] std::unique_ptr<libbsarch::bs_archive_auto> getArchive() override;
[[nodiscard]] std::unique_ptr<QBSArchiveAuto> getArchive() override;
[[nodiscard]] uint32_t getFileCount() const override;
[[nodiscard]] QString getRootPath() const override;

Expand Down
4 changes: 2 additions & 2 deletions include/bsapacker/TextureArchiveBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace BsaPacker

uint32_t setFiles() override;
void setShareData(bool) override;
[[nodiscard]] std::unique_ptr<libbsarch::bs_archive_auto> getArchive() override;
[[nodiscard]] std::unique_ptr<QBSArchiveAuto> getArchive() override;
[[nodiscard]] uint32_t getFileCount() const override;
[[nodiscard]] QString getRootPath() const override;

Expand All @@ -30,7 +30,7 @@ namespace BsaPacker

private:
const IArchiveBuilderHelper* m_ArchiveBuilderHelper = nullptr;
std::unique_ptr<libbsarch::bs_archive_auto> m_Archive;
std::unique_ptr<QBSArchiveAuto> m_Archive;
bool m_Cancelled;
QDir m_RootDirectory;

Expand Down
4 changes: 2 additions & 2 deletions include/bsapacker/TexturelessArchiveBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ namespace BsaPacker

uint32_t setFiles() override;
void setShareData(bool) override;
[[nodiscard]] std::unique_ptr<libbsarch::bs_archive_auto> getArchive() override;
[[nodiscard]] std::unique_ptr<QBSArchiveAuto> getArchive() override;
[[nodiscard]] uint32_t getFileCount() const override;
[[nodiscard]] QString getRootPath() const override;

Expand All @@ -30,7 +30,7 @@ namespace BsaPacker

private:
const IArchiveBuilderHelper* m_ArchiveBuilderHelper = nullptr;
std::unique_ptr<libbsarch::bs_archive_auto> m_Archive;
std::unique_ptr<QBSArchiveAuto> m_Archive;
bool m_Cancelled;
QDir m_RootDirectory;
};
Expand Down
8 changes: 6 additions & 2 deletions src/ArchiveAutoService.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include <bsapacker/ArchiveAutoService.h>

#include <QDebug>

namespace BsaPacker
{
void ArchiveAutoService::CreateBSA(libbsarch::bs_archive_auto* archive, const QString& archiveName) const
void ArchiveAutoService::CreateBSA(QBSArchiveAuto* archive, const std::string& archiveName) const
{
archive->save_to_disk(archiveName.toStdString());
qDebug() << "Saving archive " + QString::fromStdString(archiveName) + " to disk";
archive->save_to_disk(archiveName);
qDebug() << "Finished writing archive " + QString::fromStdString(archiveName) + " to disk";
}
} // namespace BsaPacker
38 changes: 24 additions & 14 deletions src/ArchiveBuildDirector.cpp
Original file line number Diff line number Diff line change
@@ -1,26 +1,36 @@
#include <bsapacker/ArchiveBuildDirector.h>

#include <QProgressDialog>
#include <QtConcurrent/QtConcurrentRun>

#include <QDebug>

namespace BsaPacker
{
ArchiveBuildDirector::ArchiveBuildDirector(
IArchiveBuilder* archiveFileBuildService)
: m_ArchiveFileBuildService(archiveFileBuildService)
IArchiveBuilder* archiveBuilder) :
m_ArchiveBuilder(archiveBuilder),
dialog("Finding and marking files for archival", "Cancel", 0, this->m_ArchiveBuilder->getFileCount())
{
QObject::connect(&futureWatcher, &QFutureWatcher<void>::finished, &dialog, &QProgressDialog::reset);
QObject::connect(&dialog, &QProgressDialog::canceled, this->m_ArchiveBuilder, &IArchiveBuilder::cancel);
QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressRangeChanged, &dialog, &QProgressDialog::setRange);
QObject::connect(&futureWatcher, &QFutureWatcher<void>::progressValueChanged, &dialog, &QProgressDialog::setValue);
}

void ArchiveBuildDirector::Construct()
uint32_t ArchiveBuildDirector::Construct()
{
QProgressDialog dialog("Adding to archive",
"Abort",
0,
static_cast<int>(this->m_ArchiveFileBuildService->getFileCount()));
QObject::connect(&dialog, &QProgressDialog::canceled, this->m_ArchiveFileBuildService, &IArchiveBuilder::cancel);
QObject::connect(this->m_ArchiveFileBuildService, SIGNAL(valueChanged(int)), &dialog, SLOT(setValue(int)));
dialog.show();
this->m_ArchiveFileBuildService->setShareData(true);
this->m_ArchiveFileBuildService->setFiles();
dialog.close();
qDebug() << this->m_ArchiveBuilder->getFileCount() << "files in directory";
//QObject::connect(this->m_ArchiveBuilder, &IArchiveBuilder::valueChanged, &dialog, &QProgressDialog::setValue);
qDebug() << "Beginning async marking operation";
this->m_ArchiveBuilder->setShareData(true);
QFuture<uint32_t> future = QtConcurrent::run(this->m_ArchiveBuilder, &IArchiveBuilder::setFiles);
futureWatcher.setFuture(future);
qDebug() << "Progress dialog imminent";
dialog.exec();
qDebug() << "Waiting for marking to complete";
future.waitForFinished();
auto result = future.result();
qDebug() << "Result obtained:" << result << "files marked";
return result;
}
} // namespace BsaPacker
8 changes: 5 additions & 3 deletions src/ArchiveBuilderFactory.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <bsapacker/TextureArchiveBuilder.h>
#include <bsapacker/TexturelessArchiveBuilder.h>
#include "NexusId.h"
#include <string>

namespace BsaPacker
{
Expand Down Expand Up @@ -35,16 +36,17 @@ namespace BsaPacker

std::unique_ptr<IArchiveBuilder> ArchiveBuilderFactory::Create(const bsa_archive_type_t archiveType, const IModDto* modDto) const
{
const QDir& directory = QDir(QString::fromStdString(modDto->Directory()));
switch (archiveType) {
case baTES3:
case baTES4:
case baFO3:
case baSSE:
return std::make_unique<GeneralArchiveBuilder>(this->m_ArchiveBuilderHelper, modDto->Directory(), archiveType);
return std::make_unique<GeneralArchiveBuilder>(this->m_ArchiveBuilderHelper, directory, archiveType);
case baFO4:
return std::make_unique<TexturelessArchiveBuilder>(this->m_ArchiveBuilderHelper, modDto->Directory(), archiveType);
return std::make_unique<TexturelessArchiveBuilder>(this->m_ArchiveBuilderHelper, directory, archiveType);
case baFO4dds:
return std::make_unique<TextureArchiveBuilder>(this->m_ArchiveBuilderHelper, modDto->Directory(), archiveType);
return std::make_unique<TextureArchiveBuilder>(this->m_ArchiveBuilderHelper, directory, archiveType);
case baNone:
default:
return std::make_unique<NullArchiveBuilder>();
Expand Down
1 change: 1 addition & 0 deletions src/ArchiveBuilderHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ namespace BsaPacker
: m_SettingsService(settingsService)
{
}

uint32_t ArchiveBuilderHelper::getFileCount(const QDir& rootDirectory) const
{
QDirIterator it(rootDirectory, QDirIterator::Subdirectories);
Expand Down
Loading

0 comments on commit a763e8f

Please sign in to comment.