Skip to content

Commit

Permalink
feat(modmanager): add attribute to ModFolder for skipping existing ar…
Browse files Browse the repository at this point in the history
…chives
  • Loading branch information
mklokocka committed Aug 13, 2024
1 parent ca012d3 commit d59f4c1
Show file tree
Hide file tree
Showing 5 changed files with 23 additions and 2 deletions.
Binary file added data/modfolder_ignore_existing.7z
Binary file not shown.
3 changes: 2 additions & 1 deletion include/btu/modmanager/mod_folder.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class ModFolder
using enum ModFolderIteratorBase::ArchiveTooLargeAction;
using enum ModFolderIteratorBase::ArchiveTooLargeState;

explicit ModFolder(Path directory, bsa::Settings bsa_settings);
explicit ModFolder(Path directory, bsa::Settings bsa_settings, bool ignore_existing_archives = false);

/// Get the size of the folder, including files in archives.
/// Utility function, equivalent to iterate() and counting the files.
Expand All @@ -102,6 +102,7 @@ class ModFolder
private:
Path dir_;
bsa::Settings bsa_settings_;
bool ignore_existing_archives_;
common::ThreadPool thread_pool_;
};
} // namespace btu::modmanager
6 changes: 5 additions & 1 deletion src/modmanager/mod_folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,10 @@

namespace btu::modmanager {

ModFolder::ModFolder(Path directory, bsa::Settings bsa_settings)
ModFolder::ModFolder(Path directory, bsa::Settings bsa_settings, bool ignore_existing_archives)
: dir_(std::move(directory))
, bsa_settings_(BTU_MOV(bsa_settings))
, ignore_existing_archives_(ignore_existing_archives)
, thread_pool_(common::make_thread_pool())
{
}
Expand Down Expand Up @@ -274,6 +275,9 @@ void ModFolder::transform(ModFolderTransformer &transformer) noexcept
if (transformer.stop_requested())
return;

if (is_arch(file_path) && ignore_existing_archives_)
continue;

futs.push_back(thread_pool_.submit_task([this, &file_path, &is_arch, &transformer] {
if (is_arch(file_path)) [[unlikely]]
transform_archive_file(file_path, transformer, bsa_settings_, thread_pool_);
Expand Down
1 change: 1 addition & 0 deletions tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ acquire_test("decompress")
acquire_test("esp")
acquire_test("make_transparent_alpha")
acquire_test("modfolder_transform")
acquire_test("modfolder_ignore_existing")
acquire_test("optimize")
acquire_test("nif_optimize")
acquire_test("resize")
Expand Down
15 changes: 15 additions & 0 deletions tests/modmanager/mod_folder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,21 @@ TEST_CASE("ModFolder transform", "[src]")
CHECK(btu::common::compare_directories(dir / "output", dir / "expected"));
}

TEST_CASE("ModFolder ignore existing", "[src]")
{
const Path dir = "modfolder_ignore_existing";
// operate on copy
btu::fs::remove_all(dir / "output");
btu::fs::copy(dir / "input", dir / "output");

auto mf = btu::modmanager::ModFolder(dir / "output", btu::bsa::Settings::get(btu::Game::SSE), true);

Transformer transformer;
mf.transform(transformer);

CHECK(btu::common::compare_directories(dir / "output", dir / "expected"));
}

TEST_CASE("ModFolder size", "[src]")
{
const Path dir = "modfolder";
Expand Down

0 comments on commit d59f4c1

Please sign in to comment.