Skip to content

Commit

Permalink
Always compress baFO4dds and baSFdds. Never compress baTES3
Browse files Browse the repository at this point in the history
  • Loading branch information
Liderate committed Jul 1, 2024
1 parent 2ee77e4 commit 65a7124
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 6 deletions.
2 changes: 2 additions & 0 deletions src/ArchiveBuilderFactory.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <bsapacker/ArchiveBuilderFactory.h>

#include <bsapacker/GeneralArchiveBuilder.h>
#include <bsapacker/MorrowindArchiveBuilder.h>
#include <bsapacker/NullArchiveBuilder.h>
#include <bsapacker/TextureArchiveBuilder.h>
#include <bsapacker/TexturelessArchiveBuilder.h>
Expand Down Expand Up @@ -41,6 +42,7 @@ namespace BsaPacker
{
switch (archiveType) {
case baTES3:
return std::make_unique<MorrowindArchiveBuilder>(this->m_ArchiveBuilderHelper, modDto->Directory(), archiveType);
case baTES4:
case baFO3:
case baSSE:
Expand Down
79 changes: 79 additions & 0 deletions src/MorrowindArchiveBuilder.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#include <bsapacker/MorrowindArchiveBuilder.h>

#include <bsapacker/ArchiveBuilderHelper.h>
#include <QDirIterator>
#include <QApplication>
#include <QDebug>

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<libbsarch::bs_archive_auto>(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<libbsarch::bs_archive_auto> 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
4 changes: 2 additions & 2 deletions src/SettingsService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ namespace BsaPacker
const QList<MOBase::PluginSetting>& 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);
};

Expand Down
7 changes: 3 additions & 4 deletions src/TextureArchiveBuilder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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<bool>(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)
Expand Down
35 changes: 35 additions & 0 deletions src/bsapacker/MorrowindArchiveBuilder.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#ifndef MORROWINDARCHIVEBUILDER_H
#define MORROWINDARCHIVEBUILDER_H

#include "bsapacker_global.h"
#include <bsapacker/IArchiveBuilder.h>
#include <bsapacker/IArchiveBuilderHelper.h>
#include <QDir>

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<libbsarch::bs_archive_auto> 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<libbsarch::bs_archive_auto> m_Archive;
bool m_Cancelled;
QDir m_RootDirectory;
};
} // namespace BsaPacker

#endif // MORROWINDARCHIVEBUILDER_H

0 comments on commit 65a7124

Please sign in to comment.