From 65a7124d3c4827df62c9534e9b7d4639e6a12179 Mon Sep 17 00:00:00 2001 From: RJ Date: Mon, 1 Jul 2024 18:30:58 -0400 Subject: [PATCH] Always compress baFO4dds and baSFdds. Never compress baTES3 --- src/ArchiveBuilderFactory.cpp | 2 + src/MorrowindArchiveBuilder.cpp | 79 +++++++++++++++++++++++++ src/SettingsService.cpp | 4 +- src/TextureArchiveBuilder.cpp | 7 +-- src/bsapacker/MorrowindArchiveBuilder.h | 35 +++++++++++ 5 files changed, 121 insertions(+), 6 deletions(-) create mode 100644 src/MorrowindArchiveBuilder.cpp create mode 100644 src/bsapacker/MorrowindArchiveBuilder.h diff --git a/src/ArchiveBuilderFactory.cpp b/src/ArchiveBuilderFactory.cpp index fc72695..5b07ba4 100644 --- a/src/ArchiveBuilderFactory.cpp +++ b/src/ArchiveBuilderFactory.cpp @@ -1,6 +1,7 @@ #include #include +#include #include #include #include @@ -41,6 +42,7 @@ namespace BsaPacker { switch (archiveType) { case baTES3: + return std::make_unique(this->m_ArchiveBuilderHelper, modDto->Directory(), archiveType); case baTES4: case baFO3: case baSSE: diff --git a/src/MorrowindArchiveBuilder.cpp b/src/MorrowindArchiveBuilder.cpp new file mode 100644 index 0000000..ada9b40 --- /dev/null +++ b/src/MorrowindArchiveBuilder.cpp @@ -0,0 +1,79 @@ +#include + +#include +#include +#include +#include + +using namespace libbsarch; + +namespace BsaPacker +{ + MorrowindArchiveBuilder::MorrowindArchiveBuilder(const IArchiveBuilderHelper* archiveBuilderHelper, const QDir& rootDir, const bsa_archive_type_t& type) + : m_ArchiveBuilderHelper(archiveBuilderHelper), m_RootDirectory(rootDir) + { + this->m_Cancelled = false; + this->m_Archive = std::make_unique(type); + } + + uint32_t MorrowindArchiveBuilder::setFiles() + { + uint32_t incompressibleFiles = 0; + int count = 0; + const auto& dirString = (this->m_RootDirectory.path() + '/').toStdWString(); + const auto& rootDirFiles = this->m_ArchiveBuilderHelper->getRootDirectoryFilenames(dirString); + qDebug() << "root is: " << m_RootDirectory.path() + '/'; + + QDirIterator iterator(this->m_RootDirectory.absolutePath(), QDir::Files, QDirIterator::Subdirectories); + while (iterator.hasNext()) { + QApplication::processEvents(); + + if (this->m_Cancelled) { + this->m_Archive.reset(); + return 0; + } + + const QString& filepath = iterator.next(); + const bool ignored = this->m_ArchiveBuilderHelper->isFileIgnorable(filepath.toStdWString(), rootDirFiles); + + Q_EMIT this->valueChanged(++count); + if (ignored) { + continue; + } + + ++incompressibleFiles; + auto fileBlob = disk_blob( + dirString, + filepath.toStdWString()); + this->m_Archive->add_file_from_disk(fileBlob); + qDebug() << "file is: " << filepath; + } + this->m_Archive->set_compressed(false); + return incompressibleFiles; + } + + void MorrowindArchiveBuilder::setShareData(const bool value) + { + this->m_Archive->set_share_data(value); + } + + std::unique_ptr MorrowindArchiveBuilder::getArchive() + { + return std::move(this->m_Archive); + } + + uint32_t MorrowindArchiveBuilder::getFileCount() const + { + return this->m_ArchiveBuilderHelper->getFileCount(this->m_RootDirectory.path().toStdWString()); + } + + QString MorrowindArchiveBuilder::getRootPath() const + { + return this->m_RootDirectory.path(); + } + + void MorrowindArchiveBuilder::cancel() + { + this->m_Cancelled = true; + } +} // namespace BsaPacker diff --git a/src/SettingsService.cpp b/src/SettingsService.cpp index 40175fa..6ad8839 100644 --- a/src/SettingsService.cpp +++ b/src/SettingsService.cpp @@ -11,8 +11,8 @@ namespace BsaPacker const QList& SettingsService::PluginSettings = { MOBase::PluginSetting(SettingsService::SETTING_HIDE_LOOSE_ASSETS, QObject::tr("After creating the archive, set loose assets to hidden."), false), MOBase::PluginSetting(SettingsService::SETTING_CREATE_PLUGINS, QObject::tr("Create a dummy plugin to load the archive if one does not exist."), false), - MOBase::PluginSetting(SettingsService::SETTING_BLACKLISTED_FILES, QObject::tr("Specify a semi-colon seperated list of file extensions to ignore when packing."), ".txt;.hkx;.xml;.ini;.bk2"), - MOBase::PluginSetting(SettingsService::SETTING_COMPRESS_ARCHIVES, QObject::tr("Compress archives if they do not contain incompressible files."), true) + MOBase::PluginSetting(SettingsService::SETTING_BLACKLISTED_FILES, QObject::tr("Specify a semi-colon separated list of file extensions to ignore when packing."), ".txt;.hkx;.xml;.ini;.bk2"), + MOBase::PluginSetting(SettingsService::SETTING_COMPRESS_ARCHIVES, QObject::tr("Compress archives if they do not contain incompressible files. Texture archives for Fallout 4 and Starfield will always be compressed. Morrowind archives will never be compressed."), true) //MOBase::PluginSetting(SettingsService::SETTING_SPLIT_ARCHIVES, QObject::tr("Automatically create multiple archives if they exceed the size limit."), false); }; diff --git a/src/TextureArchiveBuilder.cpp b/src/TextureArchiveBuilder.cpp index a05232e..77bb40b 100644 --- a/src/TextureArchiveBuilder.cpp +++ b/src/TextureArchiveBuilder.cpp @@ -19,7 +19,6 @@ namespace BsaPacker uint32_t TextureArchiveBuilder::setFiles() { - uint32_t incompressibleFiles = 0; uint32_t compressibleFiles = 0; int count = 0; const auto& dirString = (this->m_RootDirectory.path() + '/').toStdWString(); @@ -43,16 +42,16 @@ namespace BsaPacker continue; } - this->m_ArchiveBuilderHelper->isIncompressible(filepath.toStdWString()) ? ++incompressibleFiles : ++compressibleFiles; + ++compressibleFiles; auto fileBlob = disk_blob( dirString, filepath.toStdWString()); this->m_Archive->add_file_from_disk(fileBlob); qDebug() << "file is: " << filepath; } - this->m_Archive->set_compressed(!static_cast(incompressibleFiles)); + this->m_Archive->set_compressed(true); this->m_Archive->set_dds_callback(TextureArchiveBuilder::DDSCallback, this->getRootPath().toStdWString()); - return incompressibleFiles + compressibleFiles; + return compressibleFiles; } void TextureArchiveBuilder::setShareData(const bool value) diff --git a/src/bsapacker/MorrowindArchiveBuilder.h b/src/bsapacker/MorrowindArchiveBuilder.h new file mode 100644 index 0000000..baf4b92 --- /dev/null +++ b/src/bsapacker/MorrowindArchiveBuilder.h @@ -0,0 +1,35 @@ +#ifndef MORROWINDARCHIVEBUILDER_H +#define MORROWINDARCHIVEBUILDER_H + +#include "bsapacker_global.h" +#include +#include +#include + +namespace BsaPacker +{ + class BSAPACKER_EXPORT MorrowindArchiveBuilder : public IArchiveBuilder + { + Q_OBJECT + Q_INTERFACES(BsaPacker::IEmitsValueChanged) + + public: + MorrowindArchiveBuilder(const IArchiveBuilderHelper* archiveBuilderHelper, const QDir& rootDir, const bsa_archive_type_t& type); + uint32_t setFiles() override; + void setShareData(bool value) override; + [[nodiscard]] std::unique_ptr getArchive() override; + [[nodiscard]] uint32_t getFileCount() const override; + [[nodiscard]] QString getRootPath() const override; + + public Q_SLOTS: + void cancel() override; + + private: + const IArchiveBuilderHelper* m_ArchiveBuilderHelper = nullptr; + std::unique_ptr m_Archive; + bool m_Cancelled; + QDir m_RootDirectory; + }; +} // namespace BsaPacker + +#endif // MORROWINDARCHIVEBUILDER_H