Skip to content

Commit

Permalink
build: Always extract magic file database
Browse files Browse the repository at this point in the history
  • Loading branch information
WerWolv committed Dec 28, 2023
1 parent b64bb3b commit 03dc26d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 14 deletions.
2 changes: 1 addition & 1 deletion plugins/builtin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
35 changes: 22 additions & 13 deletions plugins/builtin/source/content/file_extraction.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
constexpr static std::array<std::pair<std::string_view, bool>, 2> Paths = {
{
{ "auto_extract", false },
{ "always_auto_extract", true }
}
};

wolv::io::File file(path, wolv::io::File::Mode::Create);
if (!file.isValid())
continue;
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;

auto data = romfs::get(romfsPath).span<u8>();
file.writeBuffer(data.data(), data.size());
wolv::io::File file(path, wolv::io::File::Mode::Create);
if (!file.isValid())
continue;

if (file.getSize() == data.size())
break;
}
auto data = romfs::get(romfsPath).span<u8>();
file.writeBuffer(data.data(), data.size());

if (file.getSize() == data.size())
break;
}

}
}
}

Expand Down

0 comments on commit 03dc26d

Please sign in to comment.