From 03dc26d2d41ac6f28edfca8d50a19b3b8f1ea5d4 Mon Sep 17 00:00:00 2001 From: WerWolv Date: Thu, 28 Dec 2023 19:24:56 +0100 Subject: [PATCH] build: Always extract magic file database --- plugins/builtin/CMakeLists.txt | 2 +- .../source/content/file_extraction.cpp | 39 ++++++++++++------- 2 files changed, 25 insertions(+), 16 deletions(-) diff --git a/plugins/builtin/CMakeLists.txt b/plugins/builtin/CMakeLists.txt index a7cda908b..3f4887e27 100644 --- a/plugins/builtin/CMakeLists.txt +++ b/plugins/builtin/CMakeLists.txt @@ -4,7 +4,7 @@ include(ImHexPlugin) find_file(DEFAULT_MAGIC_FILE_PATH magic.mgc HINTS ${MAGIC_INCLUDE_DIRS}/../share/misc) if (DEFAULT_MAGIC_FILE_PATH) - add_romfs_resource(${DEFAULT_MAGIC_FILE_PATH} auto_extract/magic/magic.mgc) + add_romfs_resource(${DEFAULT_MAGIC_FILE_PATH} always_auto_extract/magic/magic.mgc) endif () add_imhex_plugin( diff --git a/plugins/builtin/source/content/file_extraction.cpp b/plugins/builtin/source/content/file_extraction.cpp index 501157cc8..4961f1df8 100644 --- a/plugins/builtin/source/content/file_extraction.cpp +++ b/plugins/builtin/source/content/file_extraction.cpp @@ -6,23 +6,32 @@ namespace hex::plugin::builtin { void extractBundledFiles() { - for (const auto &romfsPath : romfs::list("auto_extract")) { - for (const auto &imhexPath : fs::getDataPaths()) { - const auto path = imhexPath / std::fs::relative(romfsPath, "auto_extract"); - if (wolv::io::fs::exists(path)) - continue; - - wolv::io::File file(path, wolv::io::File::Mode::Create); - if (!file.isValid()) - continue; - - auto data = romfs::get(romfsPath).span(); - file.writeBuffer(data.data(), data.size()); - - if (file.getSize() == data.size()) - break; + constexpr static std::array, 2> Paths = { + { + { "auto_extract", false }, + { "always_auto_extract", true } } + }; + for (const auto [extractFolder, alwaysExtract] : Paths) { + for (const auto &romfsPath : romfs::list(extractFolder)) { + for (const auto &imhexPath : fs::getDataPaths()) { + const auto path = imhexPath / std::fs::relative(romfsPath, extractFolder); + if (!alwaysExtract && wolv::io::fs::exists(path)) + continue; + + wolv::io::File file(path, wolv::io::File::Mode::Create); + if (!file.isValid()) + continue; + + auto data = romfs::get(romfsPath).span(); + file.writeBuffer(data.data(), data.size()); + + if (file.getSize() == data.size()) + break; + } + + } } }