aboutsummaryrefslogtreecommitdiff
path: root/libs/bsapacker/src/GeneralArchiveBuilder.cpp
diff options
context:
space:
mode:
authorSulfurNitride <SulfurNitride@users.noreply.github.com>2026-02-11 02:37:39 -0600
committerSulfurNitride <SulfurNitride@users.noreply.github.com>2026-02-11 02:37:39 -0600
commit7ee008e150bc5bcf76082d726f719ee0fdfda982 (patch)
tree27fb39be241fdb5ac2734c574de678977d1856d0 /libs/bsapacker/src/GeneralArchiveBuilder.cpp
Fluorine Manager: full Linux port of Mod Organizer 2
Complete native Linux port with FUSE-based virtual filesystem, Proton/umu-run integration, and Flatpak packaging. Key features: - FUSE VFS replacing Windows USVFS (in-process + standalone helper for Flatpak) - Proton/GE-Proton/umu-run launcher with env var forwarding - Flatpak support (sandbox-aware VFS, NXM handler, umu-run) - Wine prefix management UI - Case-insensitive path resolution for Linux filesystems - QSettings-safe INI handling (avoids Bethesda INI corruption) - Portable instance support with auto-generated launcher scripts Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Diffstat (limited to 'libs/bsapacker/src/GeneralArchiveBuilder.cpp')
-rw-r--r--libs/bsapacker/src/GeneralArchiveBuilder.cpp97
1 files changed, 97 insertions, 0 deletions
diff --git a/libs/bsapacker/src/GeneralArchiveBuilder.cpp b/libs/bsapacker/src/GeneralArchiveBuilder.cpp
new file mode 100644
index 0000000..aaf93c7
--- /dev/null
+++ b/libs/bsapacker/src/GeneralArchiveBuilder.cpp
@@ -0,0 +1,97 @@
+#include <bsapacker/GeneralArchiveBuilder.h>
+
+#include <bsapacker/ArchiveBuilderHelper.h>
+#include <QDirIterator>
+#include <QApplication>
+#include <QDebug>
+
+using namespace libbsarch;
+
+namespace BsaPacker
+{
+ // 2 GiB limit. This does not consider size after compression or share data
+ const qint64 GeneralArchiveBuilder::SIZE_LIMIT = (qint64)1024 * 1024 * 1024 * 2;
+
+ GeneralArchiveBuilder::GeneralArchiveBuilder(const IArchiveBuilderHelper* archiveBuilderHelper, const QDir& rootDir, const bsa_archive_type_t& type)
+ : m_ArchiveBuilderHelper(archiveBuilderHelper), m_RootDirectory(rootDir), m_ArchiveType(type)
+ {
+ this->m_Cancelled = false;
+ this->m_Archives.emplace_back(std::make_unique<libbsarch::bs_archive_auto>(this->m_ArchiveType));
+ }
+
+ uint32_t GeneralArchiveBuilder::setFiles()
+ {
+ uint32_t incompressibleFiles = 0;
+ uint32_t compressibleFiles = 0;
+ int count = 0;
+ qint64 currentSize = 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) {
+ for (auto& archive : this->m_Archives) {
+ archive.reset();
+ }
+ return 0;
+ }
+
+ const QFileInfo& fileInfo = iterator.nextFileInfo();
+ const QString& filepath = fileInfo.absoluteFilePath();
+ const bool ignored = this->m_ArchiveBuilderHelper->isFileIgnorable(filepath.toStdWString(), rootDirFiles);
+
+ Q_EMIT this->valueChanged(++count);
+ if (ignored) {
+ continue;
+ }
+
+ currentSize += fileInfo.size();
+ if (currentSize > SIZE_LIMIT) {
+ currentSize = fileInfo.size();
+ this->m_Archives.back()->set_compressed(!static_cast<bool>(incompressibleFiles));
+ incompressibleFiles = 0;
+ compressibleFiles = 0;
+ this->m_Archives.emplace_back(std::make_unique<libbsarch::bs_archive_auto>(this->m_ArchiveType));
+ this->setShareData(true);
+ }
+
+ this->m_ArchiveBuilderHelper->isIncompressible(filepath.toStdWString()) ? ++incompressibleFiles : ++compressibleFiles;
+ auto fileBlob = disk_blob(
+ dirString,
+ filepath.toStdWString());
+ this->m_Archives.back()->add_file_from_disk(fileBlob);
+ qDebug() << "file is: " << filepath;
+ }
+ this->m_Archives.back()->set_compressed(!static_cast<bool>(incompressibleFiles));
+ return incompressibleFiles + compressibleFiles;
+ }
+
+ void GeneralArchiveBuilder::setShareData(const bool value)
+ {
+ this->m_Archives.back()->set_share_data(value);
+ }
+
+ std::vector<std::unique_ptr<libbsarch::bs_archive_auto>> GeneralArchiveBuilder::getArchives()
+ {
+ return std::move(this->m_Archives);
+ }
+
+ uint32_t GeneralArchiveBuilder::getFileCount() const
+ {
+ return this->m_ArchiveBuilderHelper->getFileCount(this->m_RootDirectory.path().toStdWString());
+ }
+
+ QString GeneralArchiveBuilder::getRootPath() const
+ {
+ return this->m_RootDirectory.path();
+ }
+
+ void GeneralArchiveBuilder::cancel()
+ {
+ this->m_Cancelled = true;
+ }
+} // namespace BsaPacker