aboutsummaryrefslogtreecommitdiff
path: root/libs/bsa_extractor
diff options
context:
space:
mode:
Diffstat (limited to 'libs/bsa_extractor')
-rw-r--r--libs/bsa_extractor/.gitattributes7
-rw-r--r--libs/bsa_extractor/.github/workflows/build.yml20
-rw-r--r--libs/bsa_extractor/.gitignore5
-rw-r--r--libs/bsa_extractor/.pre-commit-config.yaml20
-rw-r--r--libs/bsa_extractor/CMakeLists.txt5
-rw-r--r--libs/bsa_extractor/CMakePresets.json52
-rw-r--r--libs/bsa_extractor/src/CMakeLists.txt13
-rw-r--r--libs/bsa_extractor/src/bsa_extractor_en.ts59
-rw-r--r--libs/bsa_extractor/src/bsaextractor.cpp140
-rw-r--r--libs/bsa_extractor/src/bsaextractor.h34
-rw-r--r--libs/bsa_extractor/vcpkg.json36
11 files changed, 391 insertions, 0 deletions
diff --git a/libs/bsa_extractor/.gitattributes b/libs/bsa_extractor/.gitattributes
new file mode 100644
index 0000000..f869712
--- /dev/null
+++ b/libs/bsa_extractor/.gitattributes
@@ -0,0 +1,7 @@
+# Set the default behavior, in case people don't have core.autocrlf set.
+* text=auto
+
+# Explicitly declare text files you want to always be normalized and converted
+# to native line endings on checkout.
+*.cpp text eol=crlf
+*.h text eol=crlf
diff --git a/libs/bsa_extractor/.github/workflows/build.yml b/libs/bsa_extractor/.github/workflows/build.yml
new file mode 100644
index 0000000..ea613a5
--- /dev/null
+++ b/libs/bsa_extractor/.github/workflows/build.yml
@@ -0,0 +1,20 @@
+name: Build BSA Extractor
+
+on:
+ push:
+ branches: [master]
+ pull_request:
+ types: [opened, synchronize, reopened]
+
+env:
+ VCPKG_BINARY_SOURCES: clear;x-azblob,${{ vars.AZ_BLOB_VCPKG_URL }},${{ secrets.AZ_BLOB_SAS }},readwrite
+
+jobs:
+ build:
+ runs-on: windows-2022
+ steps:
+ - name: Build BSA Extractor
+ id: build-bsa-extractor
+ uses: ModOrganizer2/build-with-mob-action
+ with:
+ mo2-dependencies: uibase bsatk
diff --git a/libs/bsa_extractor/.gitignore b/libs/bsa_extractor/.gitignore
new file mode 100644
index 0000000..cf71be7
--- /dev/null
+++ b/libs/bsa_extractor/.gitignore
@@ -0,0 +1,5 @@
+edit
+CMakeLists.txt.user
+/msbuild.log
+/*std*.log
+/*build
diff --git a/libs/bsa_extractor/.pre-commit-config.yaml b/libs/bsa_extractor/.pre-commit-config.yaml
new file mode 100644
index 0000000..fd69da3
--- /dev/null
+++ b/libs/bsa_extractor/.pre-commit-config.yaml
@@ -0,0 +1,20 @@
+repos:
+ - repo: https://github.com/pre-commit/pre-commit-hooks
+ rev: v6.0.0
+ hooks:
+ - id: trailing-whitespace
+ - id: end-of-file-fixer
+ - id: check-merge-conflict
+ - id: check-case-conflict
+ # - repo: https://github.com/pre-commit/mirrors-clang-format
+ # rev: v19.1.5
+ # hooks:
+ # - id: clang-format
+ # 'types_or': [c++, c]
+
+ci:
+ autofix_commit_msg: "[pre-commit.ci] Auto fixes from pre-commit.com hooks."
+ autofix_prs: true
+ autoupdate_commit_msg: "[pre-commit.ci] Pre-commit autoupdate."
+ autoupdate_schedule: quarterly
+ submodules: false
diff --git a/libs/bsa_extractor/CMakeLists.txt b/libs/bsa_extractor/CMakeLists.txt
new file mode 100644
index 0000000..154e97a
--- /dev/null
+++ b/libs/bsa_extractor/CMakeLists.txt
@@ -0,0 +1,5 @@
+cmake_minimum_required(VERSION 3.16)
+
+project(bsa_extractor)
+
+add_subdirectory(src)
diff --git a/libs/bsa_extractor/CMakePresets.json b/libs/bsa_extractor/CMakePresets.json
new file mode 100644
index 0000000..023baf5
--- /dev/null
+++ b/libs/bsa_extractor/CMakePresets.json
@@ -0,0 +1,52 @@
+{
+ "configurePresets": [
+ {
+ "errors": {
+ "deprecated": true
+ },
+ "hidden": true,
+ "name": "cmake-dev",
+ "warnings": {
+ "deprecated": true,
+ "dev": true
+ }
+ },
+ {
+ "cacheVariables": {
+ "VCPKG_MANIFEST_NO_DEFAULT_FEATURES": {
+ "type": "BOOL",
+ "value": "ON"
+ }
+ },
+ "toolchainFile": "$env{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake",
+ "hidden": true,
+ "name": "vcpkg"
+ },
+ {
+ "binaryDir": "${sourceDir}/vsbuild",
+ "architecture": {
+ "strategy": "set",
+ "value": "x64"
+ },
+ "cacheVariables": {
+ "CMAKE_CXX_FLAGS": "/EHsc /MP /W4",
+ "VCPKG_TARGET_TRIPLET": {
+ "type": "STRING",
+ "value": "x64-windows-static-md"
+ }
+ },
+ "generator": "Visual Studio 17 2022",
+ "inherits": ["cmake-dev", "vcpkg"],
+ "name": "vs2022-windows",
+ "toolset": "v143"
+ }
+ ],
+ "buildPresets": [
+ {
+ "name": "vs2022-windows",
+ "resolvePackageReferences": "on",
+ "configurePreset": "vs2022-windows"
+ }
+ ],
+ "version": 4
+}
diff --git a/libs/bsa_extractor/src/CMakeLists.txt b/libs/bsa_extractor/src/CMakeLists.txt
new file mode 100644
index 0000000..3a027c5
--- /dev/null
+++ b/libs/bsa_extractor/src/CMakeLists.txt
@@ -0,0 +1,13 @@
+cmake_minimum_required(VERSION 3.16)
+
+file(GLOB bsa_extractor_SOURCES CONFIGURE_DEPENDS
+ ${CMAKE_CURRENT_SOURCE_DIR}/*.cpp
+ ${CMAKE_CURRENT_SOURCE_DIR}/*.h
+ ${CMAKE_CURRENT_SOURCE_DIR}/*.ui
+ ${CMAKE_CURRENT_SOURCE_DIR}/*.qrc
+)
+
+add_library(bsa_extractor SHARED ${bsa_extractor_SOURCES})
+mo2_configure_plugin(bsa_extractor NO_SOURCES WARNINGS OFF)
+target_link_libraries(bsa_extractor PRIVATE mo2::uibase mo2::bsatk)
+mo2_install_plugin(bsa_extractor)
diff --git a/libs/bsa_extractor/src/bsa_extractor_en.ts b/libs/bsa_extractor/src/bsa_extractor_en.ts
new file mode 100644
index 0000000..7f27449
--- /dev/null
+++ b/libs/bsa_extractor/src/bsa_extractor_en.ts
@@ -0,0 +1,59 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE TS>
+<TS version="2.1" language="en_US">
+<context>
+ <name>BsaExtractor</name>
+ <message>
+ <location filename="bsaextractor.cpp" line="42"/>
+ <source>BSA Extractor</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="bsaextractor.cpp" line="53"/>
+ <source>Offers a dialog during installation of a mod to unpack all its BSAs</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="bsaextractor.cpp" line="87"/>
+ <source>invalid mod name</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="bsaextractor.cpp" line="88"/>
+ <source>BSA extraction doesn&apos;t work on mods that have the same name as a non-MO mod.Please remove the mod then reinstall with a different name.</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="bsaextractor.cpp" line="96"/>
+ <source>Extract BSA</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="bsaextractor.cpp" line="97"/>
+ <source>This mod contains at least one BSA. Do you want to unpack it?
+(If you don&apos;t know about BSAs, just select no)</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="bsaextractor.cpp" line="101"/>
+ <source>Remove extracted archives</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="bsaextractor.cpp" line="102"/>
+ <source>Do you wish to remove BSAs after extraction completed?
+</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="bsaextractor.cpp" line="108"/>
+ <source>failed to read %1: %2</source>
+ <translation type="unfinished"></translation>
+ </message>
+ <message>
+ <location filename="bsaextractor.cpp" line="124"/>
+ <source>This archive contains invalid hashes. Some files may be broken.</source>
+ <translation type="unfinished"></translation>
+ </message>
+</context>
+</TS>
diff --git a/libs/bsa_extractor/src/bsaextractor.cpp b/libs/bsa_extractor/src/bsaextractor.cpp
new file mode 100644
index 0000000..305edca
--- /dev/null
+++ b/libs/bsa_extractor/src/bsaextractor.cpp
@@ -0,0 +1,140 @@
+#include "bsaextractor.h"
+
+#include <uibase/iplugingame.h>
+#include <uibase/imodlist.h>
+#include <uibase/versioninfo.h>
+#include <uibase/imodinterface.h>
+#include <uibase/questionboxmemory.h>
+#include <uibase/report.h>
+
+#include <bsatk/bsaarchive.h>
+
+#include <QDir>
+#include <QFileInfoList>
+#include <QCoreApplication>
+#include <QMessageBox>
+#include <QtPlugin>
+
+#include <functional>
+
+using namespace MOBase;
+
+
+BsaExtractor::BsaExtractor()
+ : m_Organizer(nullptr)
+{
+}
+
+bool BsaExtractor::init(MOBase::IOrganizer *moInfo)
+{
+ m_Organizer = moInfo;
+ moInfo->modList()->onModInstalled([this](auto* mod) { modInstalledHandler(mod); });
+ return true;
+}
+
+QString BsaExtractor::name() const
+{
+ return "BSA Extractor";
+}
+
+QString BsaExtractor::localizedName() const
+{
+ return tr("BSA Extractor");
+}
+
+
+QString BsaExtractor::author() const
+{
+ return "Tannin & MO2 Team";
+}
+
+QString BsaExtractor::description() const
+{
+ return tr("Offers a dialog during installation of a mod to unpack all its BSAs");
+}
+
+VersionInfo BsaExtractor::version() const
+{
+ return VersionInfo(1, 5, 0, VersionInfo::RELEASE_FINAL);
+}
+
+QList<PluginSetting> BsaExtractor::settings() const
+{
+ return {
+ PluginSetting("only_alternate_source", "only trigger bsa extraction for alternate game sources", true)
+ };
+}
+
+
+bool BsaExtractor::extractProgress(QProgressDialog &progress, int percentage, std::string fileName)
+{
+ progress.setLabelText(fileName.c_str());
+ progress.setValue(percentage);
+ qApp->processEvents();
+ return !progress.wasCanceled();
+}
+
+
+void BsaExtractor::modInstalledHandler(IModInterface *mod)
+{
+
+ if (m_Organizer->pluginSetting(name(), "only_alternate_source").toBool() &&
+ !(m_Organizer->modList()->state(mod->name()) & IModList::STATE_ALTERNATE)) {
+ return;
+ }
+
+ if (QFileInfo(mod->absolutePath()) == QFileInfo(m_Organizer->managedGame()->dataDirectory().absolutePath())) {
+ QMessageBox::information(nullptr, tr("invalid mod name"),
+ tr("BSA extraction doesn't work on mods that have the same name as a non-MO mod."
+ "Please remove the mod then reinstall with a different name."));
+ return;
+ }
+ QDir dir(mod->absolutePath());
+
+ QFileInfoList archives = dir.entryInfoList(QStringList({ "*.bsa", "*.ba2" }));
+ if (archives.length() != 0 &&
+ (QuestionBoxMemory::query(nullptr, "unpackBSA", tr("Extract BSA"),
+ tr("This mod contains at least one BSA. Do you want to unpack it?\n"
+ "(If you don't know about BSAs, just select no)"),
+ QDialogButtonBox::Yes | QDialogButtonBox::No, QDialogButtonBox::No) == QDialogButtonBox::Yes)) {
+
+ bool removeBSAs = (QuestionBoxMemory::query(nullptr, "removeUnpackedBSA", tr("Remove extracted archives"),
+ tr("Do you wish to remove BSAs after extraction completed?\n"),
+ QDialogButtonBox::Yes | QDialogButtonBox::No, QDialogButtonBox::No) == QDialogButtonBox::Yes);
+ foreach (QFileInfo archiveInfo, archives) {
+ BSA::Archive archive;
+ BSA::EErrorCode result = archive.read(archiveInfo.absoluteFilePath().toLocal8Bit().constData(), true);
+ if ((result != BSA::ERROR_NONE) && (result != BSA::ERROR_INVALIDHASHES)) {
+ reportError(tr("failed to read %1: %2").arg(archiveInfo.fileName()).arg(result));
+ return;
+ }
+
+ QProgressDialog progress(nullptr);
+ progress.setMaximum(100);
+ progress.setValue(0);
+ progress.show();
+
+ archive.extractAll(mod->absolutePath().toLocal8Bit().constData(),
+ [this, &progress](int value, std::string filename) {
+ return extractProgress(progress, value, filename);
+ },
+ false);
+
+ if (result == BSA::ERROR_INVALIDHASHES) {
+ reportError(tr("This archive contains invalid hashes. Some files may be broken."));
+ }
+
+ archive.close();
+
+ if (removeBSAs) {
+ if (!QFile::remove(archiveInfo.absoluteFilePath())) {
+ qCritical("failed to remove archive %s", archiveInfo.absoluteFilePath().toUtf8().constData());
+ }
+ }
+ }
+ }
+}
+
+#if QT_VERSION < QT_VERSION_CHECK(5,0,0)
+Q_EXPORT_PLUGIN2(bsaextractor, BsaExtractor)
+#endif
diff --git a/libs/bsa_extractor/src/bsaextractor.h b/libs/bsa_extractor/src/bsaextractor.h
new file mode 100644
index 0000000..09631ff
--- /dev/null
+++ b/libs/bsa_extractor/src/bsaextractor.h
@@ -0,0 +1,34 @@
+#ifndef BSAEXTRACTOR_H
+#define BSAEXTRACTOR_H
+
+#include <QProgressDialog>
+
+#include <uibase/iplugin.h>
+
+class BsaExtractor : public QObject, public MOBase::IPlugin
+{
+ Q_OBJECT
+ Q_INTERFACES(MOBase::IPlugin)
+#if QT_VERSION >= QT_VERSION_CHECK(5,0,0)
+ Q_PLUGIN_METADATA(IID "org.tannin.BSAExtractor")
+#endif
+
+public:
+ BsaExtractor();
+
+ virtual bool init(MOBase::IOrganizer *moInfo) override;
+ virtual QString name() const override;
+ virtual QString localizedName() const override;
+ virtual QString author() const override;
+ virtual QString description() const override;
+ virtual MOBase::VersionInfo version() const override;
+ virtual QList<MOBase::PluginSetting> settings() const override;
+
+private:
+ void modInstalledHandler(MOBase::IModInterface *mod);
+ bool extractProgress(QProgressDialog &progress, int percentage, std::string fileName);
+private:
+ MOBase::IOrganizer *m_Organizer;
+};
+
+#endif // BSAEXTRACTOR_H
diff --git a/libs/bsa_extractor/vcpkg.json b/libs/bsa_extractor/vcpkg.json
new file mode 100644
index 0000000..9ff119d
--- /dev/null
+++ b/libs/bsa_extractor/vcpkg.json
@@ -0,0 +1,36 @@
+{
+ "dependencies": [
+ "mo2-dds-header",
+ "boost-thread",
+ "boost-interprocess",
+ "zlib",
+ "lz4"
+ ],
+ "features": {
+ "standalone": {
+ "description": "Build Standalone.",
+ "dependencies": ["mo2-cmake"]
+ }
+ },
+ "vcpkg-configuration": {
+ "default-registry": {
+ "kind": "git",
+ "repository": "https://github.com/Microsoft/vcpkg",
+ "baseline": "294f76666c3000630d828703e675814c05a4fd43"
+ },
+ "registries": [
+ {
+ "kind": "git",
+ "repository": "https://github.com/Microsoft/vcpkg",
+ "baseline": "294f76666c3000630d828703e675814c05a4fd43",
+ "packages": ["boost*", "boost-*"]
+ },
+ {
+ "kind": "git",
+ "repository": "https://github.com/ModOrganizer2/vcpkg-registry",
+ "baseline": "8beb2e0efa9c17dd6d17bb05288dd1e40727f673",
+ "packages": ["mo2-*"]
+ }
+ ]
+ }
+}