forked from PurpleFez/modorganizer-bsapacker
-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Always compress baFO4dds and baSFdds. Never compress baTES3
- Loading branch information
Showing
5 changed files
with
121 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |