impr: Bundle default magic file with application

This commit is contained in:
WerWolv
2023-10-29 19:43:40 +01:00
parent 80ca6bf177
commit c444ad9280
8 changed files with 100 additions and 14 deletions

View File

@@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.16)
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)
endif ()
add_imhex_plugin(
NAME
builtin
@@ -36,6 +41,7 @@ add_imhex_plugin(
source/content/file_handlers.cpp
source/content/project.cpp
source/content/achievements.cpp
source/content/file_extraction.cpp
source/content/providers/file_provider.cpp
source/content/providers/gdb_provider.cpp

View File

@@ -0,0 +1,26 @@
#include <hex/helpers/fs.hpp>
#include <wolv/io/file.hpp>
#include <romfs/romfs.hpp>
namespace hex::plugin::builtin {
void extractBundledFiles() {
for (const auto &romfsPath : romfs::list("auto_extract")) {
for (const auto &imhexPath : fs::getDataPaths()) {
wolv::io::File file(imhexPath, wolv::io::File::Mode::Create);
if (!file.isValid())
continue;
auto data = romfs::get(romfsPath).span<u8>();
file.writeBuffer(data.data(), data.size());
if (file.getSize() == data.size())
break;
}
}
}
}

View File

@@ -47,6 +47,8 @@ namespace hex::plugin::builtin {
void handleBorderlessWindowMode();
void extractBundledFiles();
}
IMHEX_PLUGIN_SUBCOMMANDS() {
@@ -107,6 +109,8 @@ IMHEX_PLUGIN_SETUP("Built-in", "WerWolv", "Default ImHex functionality") {
registerMainMenuEntries();
handleBorderlessWindowMode();
extractBundledFiles();
}
// This is the default plugin