From 1487f760b007d2d5cfa458c1cc53313737d7a43d Mon Sep 17 00:00:00 2001 From: WerWolv Date: Mon, 21 Feb 2022 22:47:56 +0100 Subject: [PATCH] build: Bundle files from the ImHex-Patterns repo with the installation --- CMakeLists.txt | 3 +++ cmake/build_helpers.cmake | 19 +++++++++++++++++++ lib/libimhex/source/helpers/paths.cpp | 10 +++++----- 3 files changed, 27 insertions(+), 5 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index d5b885740..67b73983a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,3 +35,6 @@ add_subdirectory(tests EXCLUDE_FROM_ALL) # Configure packaging createPackage() + +# Download and install all current files from the ImHex-Patterns repo +downloadImHexPatternsFiles() \ No newline at end of file diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index 9bb80c2e1..b2f850ae9 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -1,3 +1,5 @@ +include(FetchContent) + macro(addVersionDefines) if (IS_DIRECTORY "${CMAKE_SOURCE_DIR}/.git") # Get the current working branch @@ -279,3 +281,20 @@ macro(detectBadClone) endif() endforeach () endmacro() + + +function(downloadImHexPatternsFiles) + FetchContent_Declare( + imhex_patterns + GIT_REPOSITORY https://github.com/WerWolv/ImHex-Patterns.git + GIT_TAG master + ) + + FetchContent_Populate(imhex_patterns) + + set(PATTERNS_FOLDERS_TO_INSTALL constants encodings includes patterns yara magic) + foreach (FOLDER ${PATTERNS_FOLDERS_TO_INSTALL}) + install(DIRECTORY "${imhex_patterns_SOURCE_DIR}/${FOLDER}" DESTINATION "./") + endforeach() + +endfunction() \ No newline at end of file diff --git a/lib/libimhex/source/helpers/paths.cpp b/lib/libimhex/source/helpers/paths.cpp index 2b84b703d..4de17fbd0 100644 --- a/lib/libimhex/source/helpers/paths.cpp +++ b/lib/libimhex/source/helpers/paths.cpp @@ -59,7 +59,7 @@ namespace hex { CoTaskMemFree(wAppDataPath); } - std::vector paths = { parentDir, appDataDir / "imhex" }; + std::vector paths = { appDataDir / "imhex", parentDir }; switch (path) { case ImHexPath::Patterns: @@ -128,7 +128,7 @@ namespace hex { // Get path to special directories const fs::path applicationSupportDir(getMacApplicationSupportDirectoryPath()); - std::vector paths = { exePath, applicationSupportDir }; + std::vector paths = { applicationSupportDir, exePath }; switch (path) { case ImHexPath::Patterns: @@ -179,9 +179,6 @@ namespace hex { for (auto &dir : dataDirs) dir = dir / "imhex"; - if (!exePath.empty()) - dataDirs.emplace(dataDirs.begin(), fs::path(exePath.data()).parent_path()); - switch (path) { case ImHexPath::Patterns: addUserDirs(dataDirs); @@ -226,6 +223,9 @@ namespace hex { default: __builtin_unreachable(); } + + if (!exePath.empty()) + dataDirs.emplace(dataDirs.begin(), fs::path(exePath.data()).parent_path()); #endif if (!listNonExisting) {