diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 3d6a890ca..4ac2e2da3 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -570,6 +570,8 @@ jobs: # Fedora cmake build (in imhex.spec) - name: 📦 Build RPM + env: + QA_RPATHS: 18 run: | fedpkg --path $GITHUB_WORKSPACE --release ${{ matrix.mock_release }} mockbuild --enable-network -N --root $GITHUB_WORKSPACE/mock.cfg extra_args -- -v diff --git a/cmake/build_helpers.cmake b/cmake/build_helpers.cmake index 073a4bac1..d29a1bdb8 100644 --- a/cmake/build_helpers.cmake +++ b/cmake/build_helpers.cmake @@ -14,47 +14,6 @@ macro(addDefines) message(FATAL_ERROR "IMHEX_VERSION is not defined") endif () - if (DEFINED IMHEX_COMMIT_HASH_LONG AND DEFINED IMHEX_COMMIT_HASH_SHORT AND DEFINED IMHEX_COMMIT_BRANCH) - add_compile_definitions( - GIT_COMMIT_HASH_LONG="${IMHEX_COMMIT_HASH_LONG}" - GIT_COMMIT_HASH_SHORT="${IMHEX_COMMIT_HASH_SHORT}" - GIT_BRANCH="${IMHEX_COMMIT_BRANCH}" - ) - else() - # Get the current working branch - execute_process( - COMMAND git rev-parse --abbrev-ref HEAD - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_BRANCH - OUTPUT_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE RESULT_BRANCH - ) - - # Get the latest abbreviated commit hash of the working branch - execute_process( - COMMAND git log -1 --format=%h --abbrev=7 - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_COMMIT_HASH_SHORT - OUTPUT_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE RESULT_HASH_SHORT - ) - - execute_process( - COMMAND git log -1 --format=%H - WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} - OUTPUT_VARIABLE GIT_COMMIT_HASH_LONG - OUTPUT_STRIP_TRAILING_WHITESPACE - RESULT_VARIABLE RESULT_HASH_LONG - ) - - if (RESULT_BRANCH EQUAL 0 AND RESULT_HASH_LONG EQUAL 0 AND RESULT_HASH_SHORT EQUAL 0) - add_compile_definitions( - GIT_COMMIT_HASH_SHORT="${GIT_COMMIT_HASH_SHORT}" - GIT_COMMIT_HASH_LONG="${GIT_COMMIT_HASH_LONG}" - GIT_BRANCH="${GIT_BRANCH}") - endif () - endif () - set(CMAKE_RC_FLAGS "${CMAKE_RC_FLAGS} -DPROJECT_VERSION_MAJOR=${PROJECT_VERSION_MAJOR} -DPROJECT_VERSION_MINOR=${PROJECT_VERSION_MINOR} -DPROJECT_VERSION_PATCH=${PROJECT_VERSION_PATCH} ") set(IMHEX_VERSION_STRING ${IMHEX_VERSION}) @@ -71,10 +30,16 @@ macro(addDefines) set(IMHEX_VERSION_STRING ${IMHEX_VERSION_STRING}-MinSizeRel) add_compile_definitions(NDEBUG) endif () - - add_compile_definitions(IMHEX_VERSION="${IMHEX_VERSION_STRING}") endmacro() +function(addDefineToSource SOURCE DEFINE) + set_property( + SOURCE ${SOURCE} + APPEND + PROPERTY COMPILE_DEFINITIONS "${DEFINE}" + ) +endfunction() + # Detect current OS / System macro(detectOS) if (WIN32) @@ -164,7 +129,7 @@ macro(configurePackingResources) set(MACOSX_BUNDLE_INFO_PLIST "${CMAKE_CURRENT_SOURCE_DIR}/resources/dist/macos/Info.plist.in") set(MACOSX_BUNDLE_BUNDLE_VERSION "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}.${PROJECT_VERSION_PATCH}") set(MACOSX_BUNDLE_GUI_IDENTIFIER "net.WerWolv.ImHex") - set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_VERSION}-${GIT_COMMIT_HASH_SHORT}") + set(MACOSX_BUNDLE_LONG_VERSION_STRING "${PROJECT_VERSION}-${IMHEX_COMMIT_HASH_SHORT}") set(MACOSX_BUNDLE_SHORT_VERSION_STRING "${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}") string(TIMESTAMP CURR_YEAR "%Y") diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index 6ae15bdba..0bbb42957 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -71,3 +71,44 @@ endif () target_link_libraries(libimhex PRIVATE ${FMT_LIBRARIES}) target_link_libraries(libimhex PUBLIC dl imgui ${NFD_LIBRARIES} magic ${CAPSTONE_LIBRARIES} LLVMDemangle microtar ${NLOHMANN_JSON_LIBRARIES} ${YARA_LIBRARIES} ${LIBCURL_LIBRARIES} ${MBEDTLS_LIBRARIES} ${LIBBACKTRACE_LIBRARIES} libpl libpl-gen ${MINIAUDIO_LIBRARIES} libwolv-utils libwolv-io libwolv-hash libwolv-net libwolv-containers) + + +if (DEFINED IMHEX_COMMIT_HASH_LONG AND DEFINED IMHEX_COMMIT_HASH_SHORT AND DEFINED IMHEX_COMMIT_BRANCH) + set(GIT_COMMIT_HASH_LONG "${IMHEX_COMMIT_HASH_LONG}") + set(GIT_COMMIT_HASH_SHORT "${IMHEX_COMMIT_HASH_SHORT}") + set(GIT_BRANCH "${IMHEX_COMMIT_BRANCH}") +else() + # Get the current working branch + execute_process( + COMMAND git rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_BRANCH + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RESULT_BRANCH + ) + + # Get the latest abbreviated commit hash of the working branch + execute_process( + COMMAND git log -1 --format=%h --abbrev=7 + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH_SHORT + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RESULT_HASH_SHORT + ) + + execute_process( + COMMAND git log -1 --format=%H + WORKING_DIRECTORY ${CMAKE_SOURCE_DIR} + OUTPUT_VARIABLE GIT_COMMIT_HASH_LONG + OUTPUT_STRIP_TRAILING_WHITESPACE + RESULT_VARIABLE RESULT_HASH_LONG + ) +endif () + +if ((NOT GIT_COMMIT_HASH_SHORT STREQUAL "") AND (NOT GIT_COMMIT_HASH_LONG STREQUAL "") AND (NOT GIT_BRANCH STREQUAL "")) + addDefineToSource(source/api/imhex_api.cpp "GIT_COMMIT_HASH_SHORT=\"${GIT_COMMIT_HASH_SHORT}\"") + addDefineToSource(source/api/imhex_api.cpp "GIT_COMMIT_HASH_LONG=\"${GIT_COMMIT_HASH_LONG}\"") + addDefineToSource(source/api/imhex_api.cpp "GIT_BRANCH=\"${GIT_BRANCH}\"") +endif () + +addDefineToSource(source/api/imhex_api.cpp "IMHEX_VERSION=\"${IMHEX_VERSION_STRING}\"") \ No newline at end of file diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index 2fb9a7d65..eb8e3603e 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -507,11 +507,42 @@ namespace hex { */ bool isPortableVersion(); + /** + * @brief Gets the current Operating System name + * @return Operating System name + */ std::string getOSName(); + /** + * @brief Gets the current Operating System version + * @return Operating System version + */ std::string getOSVersion(); + /** + * @brief Gets the current CPU architecture + * @return CPU architecture + */ std::string getArchitecture(); + + /** + * @brief Gets the current ImHex version + * @return ImHex version + */ + std::string getImHexVersion(); + + /** + * @brief Gets the current git commit hash + * @param longHash Whether to return the full hash or the shortened version + * @return Git commit hash + */ + std::string getCommitHash(bool longHash = false); + + /** + * @brief Gets the current git commit branch + * @return Git commit branch + */ + std::string getCommitBranch(); } } diff --git a/lib/libimhex/source/api/content_registry.cpp b/lib/libimhex/source/api/content_registry.cpp index f25fe6c96..ffb2f7b55 100644 --- a/lib/libimhex/source/api/content_registry.cpp +++ b/lib/libimhex/source/api/content_registry.cpp @@ -301,7 +301,7 @@ namespace hex { } runtime.addDefine("__IMHEX__"); - runtime.addDefine("__IMHEX_VERSION__", IMHEX_VERSION); + runtime.addDefine("__IMHEX_VERSION__", ImHexApi::System::getImHexVersion()); } void addPragma(const std::string &name, const pl::api::PragmaHandler &handler) { diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index b930156d3..901c7068a 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -586,6 +586,39 @@ namespace hex { #endif } + std::string getImHexVersion() { + #if defined IMHEX_VERSION + return IMHEX_VERSION; + #else + return "Unknown"; + #endif + } + + std::string getCommitHash(bool longHash) { + if (longHash) { + #if defined GIT_COMMIT_HASH_LONG + return GIT_COMMIT_HASH_LONG; + #else + return "Unknown"; + #endif + } + else { + #if defined GIT_COMMIT_HASH_SHORT + return GIT_COMMIT_HASH_SHORT; + #else + return "Unknown"; + #endif + } + } + + std::string getCommitBranch() { + #if defined GIT_BRANCH + return GIT_BRANCH; + #else + return "Unknown"; + #endif + } + } } diff --git a/lib/libimhex/source/api/plugin_manager.cpp b/lib/libimhex/source/api/plugin_manager.cpp index 3710a928b..e55ae6ee1 100644 --- a/lib/libimhex/source/api/plugin_manager.cpp +++ b/lib/libimhex/source/api/plugin_manager.cpp @@ -1,4 +1,5 @@ #include +#include #include #include @@ -73,9 +74,13 @@ namespace hex { return false; const auto requestedVersion = getCompatibleVersion(); - if (requestedVersion != IMHEX_VERSION) { - log::error("Refused to load plugin '{}' which was built for a different version of ImHex: '{}'", wolv::util::toUTF8String(this->m_path.filename()), requestedVersion); - return false; + if (requestedVersion != ImHexApi::System::getImHexVersion()) { + if (requestedVersion.empty()) { + log::warn("Plugin '{}' did not specify a compatible version, assuming it is compatible with the current version of ImHex.", wolv::util::toUTF8String(this->m_path.filename())); + } else { + log::error("Refused to load plugin '{}' which was built for a different version of ImHex: '{}'", wolv::util::toUTF8String(this->m_path.filename()), requestedVersion); + return false; + } } if (this->m_initializePluginFunction != nullptr) { diff --git a/main/source/init/splash_window.cpp b/main/source/init/splash_window.cpp index d04741b56..2b838c0f9 100644 --- a/main/source/init/splash_window.cpp +++ b/main/source/init/splash_window.cpp @@ -135,10 +135,10 @@ namespace hex::init { drawList->AddText(ImVec2(15, 120) * scale, ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("WerWolv 2020 - {0}", &__DATE__[7]).c_str()); - #if defined(DEBUG) && defined(GIT_BRANCH) && defined(GIT_COMMIT_HASH_SHORT) - drawList->AddText(ImVec2(15, 140) * scale, ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("{0} : {1} {2}@{3}", IMHEX_VERSION, ICON_FA_CODE_BRANCH, GIT_BRANCH, GIT_COMMIT_HASH_SHORT).c_str()); + #if defined(DEBUG) + drawList->AddText(ImVec2(15, 140) * scale, ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("{0} : {1} {2}@{3}", ImHexApi::System::getImHexVersion(), ICON_FA_CODE_BRANCH, ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash()).c_str()); #else - drawList->AddText(ImVec2(15, 140) * scale, ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("{0}", IMHEX_VERSION).c_str()); + drawList->AddText(ImVec2(15, 140) * scale, ImColor(0xFF, 0xFF, 0xFF, 0xFF), hex::format("{0}", ImHexApi::System::getImHexVersion()).c_str()); #endif } diff --git a/main/source/init/tasks.cpp b/main/source/init/tasks.cpp index b2e37134b..63b1c05d4 100644 --- a/main/source/init/tasks.cpp +++ b/main/source/init/tasks.cpp @@ -39,7 +39,7 @@ namespace hex::init { // Check if we should check for updates if (checkForUpdates == 1){ HttpRequest request("GET", GitHubApiURL + "/releases/latest"s); - request.setTimeout(2000); + request.setTimeout(500); // Query the GitHub API for the latest release version auto response = request.execute().get(); @@ -58,7 +58,7 @@ namespace hex::init { return false; // Convert the current version string to a format that can be compared to the latest release - auto versionString = std::string(IMHEX_VERSION); + auto versionString = ImHexApi::System::getImHexVersion(); size_t versionLength = std::min(versionString.find_first_of('-'), versionString.length()); auto currVersion = "v" + versionString.substr(0, versionLength); @@ -78,34 +78,29 @@ namespace hex::init { ContentRegistry::Settings::write("hex.builtin.setting.general", "hex.builtin.setting.general.uuid", uuid); } - // Make telemetry request - nlohmann::json telemetry = { - { "uuid", uuid }, - { "format_version", "1" }, - { "imhex_version", IMHEX_VERSION }, - #if defined(GIT_COMMIT_HASH_LONG) && defined(GIT_BRANCH) - { "imhex_commit", fmt::format("{}@{}", GIT_COMMIT_HASH_LONG, GIT_BRANCH) }, - #else - { "imhex_commit", "??@??" }, - #endif - { "install_type", ImHexApi::System::isPortableVersion() ? "Portable" : "Installed" }, - { "os", ImHexApi::System::getOSName() }, - { "os_version", ImHexApi::System::getOSVersion() }, - { "arch", ImHexApi::System::getArchitecture() }, - { "gpu_vendor", ImHexApi::System::getGPUVendor() } - }; + TaskManager::createBackgroundTask("Sending statistics...", [uuid, versionString](auto&) { + // Make telemetry request + nlohmann::json telemetry = { + { "uuid", uuid }, + { "format_version", "1" }, + { "imhex_version", versionString }, + { "imhex_commit", fmt::format("{}@{}", ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash()) }, + { "install_type", ImHexApi::System::isPortableVersion() ? "Portable" : "Installed" }, + { "os", ImHexApi::System::getOSName() }, + { "os_version", ImHexApi::System::getOSVersion() }, + { "arch", ImHexApi::System::getArchitecture() }, + { "gpu_vendor", ImHexApi::System::getGPUVendor() } + }; - HttpRequest telemetryRequest("POST", ImHexApiURL + "/telemetry"s); - telemetryRequest.setTimeout(2000); + HttpRequest telemetryRequest("POST", ImHexApiURL + "/telemetry"s); + telemetryRequest.setTimeout(500); - telemetryRequest.setBody(telemetry.dump()); - telemetryRequest.addHeader("Content-Type", "application/json"); - - // Execute request - response = telemetryRequest.execute().get(); - if (response.getStatusCode() != 200) - return false; + telemetryRequest.setBody(telemetry.dump()); + telemetryRequest.addHeader("Content-Type", "application/json"); + // Execute request + telemetryRequest.execute(); + }); } return true; } diff --git a/main/source/main.cpp b/main/source/main.cpp index 2c573f34c..62100d507 100644 --- a/main/source/main.cpp +++ b/main/source/main.cpp @@ -39,10 +39,8 @@ int main(int argc, char **argv, char **envp) { { Window::initNative(); - log::info("Welcome to ImHex {}!", IMHEX_VERSION); - #if defined(GIT_BRANCH) && defined(GIT_COMMIT_HASH_SHORT) - log::info("Compiled using commit {}@{}", GIT_BRANCH, GIT_COMMIT_HASH_SHORT); - #endif + log::info("Welcome to ImHex {}!", ImHexApi::System::getImHexVersion()); + log::info("Compiled using commit {}@{}", ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash()); init::WindowSplash splashWindow; diff --git a/plugins/builtin/CMakeLists.txt b/plugins/builtin/CMakeLists.txt index e61a26917..be29acaf7 100644 --- a/plugins/builtin/CMakeLists.txt +++ b/plugins/builtin/CMakeLists.txt @@ -83,7 +83,8 @@ if (WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-multiple-definition -fvisibility=hidden") endif() -add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}") +target_compile_definitions(${PROJECT_NAME} PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}") +target_compile_definitions(${PROJECT_NAME} PRIVATE IMHEX_VERSION="${IMHEX_VERSION_STRING}") set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) setupCompilerFlags(${PROJECT_NAME}) diff --git a/plugins/builtin/include/content/popups/popup_telemetry_request.hpp b/plugins/builtin/include/content/popups/popup_telemetry_request.hpp index 187e22237..218f092a9 100644 --- a/plugins/builtin/include/content/popups/popup_telemetry_request.hpp +++ b/plugins/builtin/include/content/popups/popup_telemetry_request.hpp @@ -49,12 +49,9 @@ namespace hex::plugin::builtin { ImGui::TextUnformatted("hex.builtin.welcome.server_contact.data_collected.version"_lang); ImGui::TableNextColumn(); ImGui::TextFormattedWrapped("{}\n{}@{}\n{}", - IMHEX_VERSION, - #if defined (GIT_COMMIT_HASH_LONG) && defined (GIT_BRANCH) - GIT_COMMIT_HASH_LONG, GIT_BRANCH, - #else - "??", "??", - #endif + ImHexApi::System::getImHexVersion(), + ImHexApi::System::getCommitHash(true), + ImHexApi::System::getCommitBranch(), ImHexApi::System::isPortableVersion() ? "Portable" : "Installed" ); diff --git a/plugins/builtin/source/content/communication_interface.cpp b/plugins/builtin/source/content/communication_interface.cpp index e8ddc759c..8d8412ed5 100644 --- a/plugins/builtin/source/content/communication_interface.cpp +++ b/plugins/builtin/source/content/communication_interface.cpp @@ -17,15 +17,9 @@ namespace hex::plugin::builtin { nlohmann::json result; result["build"] = { - { "version", IMHEX_VERSION }, - - #if defined(GIT_COMMIT_HASH_LONG) - { "commit", GIT_COMMIT_HASH_LONG }, - #endif - - #if defined(GIT_BRANCH) - { "branch", GIT_BRANCH }, - #endif + { "version", ImHexApi::System::getImHexVersion() }, + { "commit", ImHexApi::System::getCommitHash(true) }, + { "branch", ImHexApi::System::getCommitBranch() } }; std::vector commands; diff --git a/plugins/builtin/source/content/project.cpp b/plugins/builtin/source/content/project.cpp index 4af250ccf..aeca9fcda 100644 --- a/plugins/builtin/source/content/project.cpp +++ b/plugins/builtin/source/content/project.cpp @@ -150,7 +150,7 @@ namespace hex::plugin::builtin { } { - const auto metadataContent = hex::format("{}\n{}", MetadataHeaderMagic, IMHEX_VERSION); + const auto metadataContent = hex::format("{}\n{}", MetadataHeaderMagic, ImHexApi::System::getImHexVersion()); tar.writeString(MetadataPath, metadataContent); } diff --git a/plugins/builtin/source/content/views/view_about.cpp b/plugins/builtin/source/content/views/view_about.cpp index e86f9dcad..274128eb2 100644 --- a/plugins/builtin/source/content/views/view_about.cpp +++ b/plugins/builtin/source/content/views/view_about.cpp @@ -60,13 +60,11 @@ namespace hex::plugin::builtin { ImGui::Image(this->m_logoTexture, scaled({ 64, 64 })); ImGui::TableNextColumn(); - ImGui::TextFormatted("ImHex Hex Editor v{} by WerWolv - " ICON_FA_CODE_BRANCH, IMHEX_VERSION); + ImGui::TextFormatted("ImHex Hex Editor v{} by WerWolv - " ICON_FA_CODE_BRANCH, ImHexApi::System::getImHexVersion()); - #if defined(GIT_BRANCH) && defined(GIT_COMMIT_HASH_SHORT) && defined(GIT_COMMIT_HASH_LONG) - ImGui::SameLine(); - if (ImGui::Hyperlink(hex::format("{0}@{1}", GIT_BRANCH, GIT_COMMIT_HASH_SHORT).c_str())) - hex::openWebpage("https://github.com/WerWolv/ImHex/commit/" GIT_COMMIT_HASH_LONG); - #endif + ImGui::SameLine(); + if (ImGui::Hyperlink(hex::format("{0}@{1}", ImHexApi::System::getCommitBranch(), ImHexApi::System::getCommitHash()).c_str())) + hex::openWebpage("https://github.com/WerWolv/ImHex/commit/" + ImHexApi::System::getCommitHash(true)); ImGui::TextUnformatted("hex.builtin.view.help.about.translator"_lang); diff --git a/plugins/windows/CMakeLists.txt b/plugins/windows/CMakeLists.txt index 4421e731b..f4774267c 100644 --- a/plugins/windows/CMakeLists.txt +++ b/plugins/windows/CMakeLists.txt @@ -34,7 +34,8 @@ if (WIN32) set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wl,--allow-multiple-definition -fvisibility=hidden") endif() - add_compile_definitions(IMHEX_PROJECT_NAME="${PROJECT_NAME}") + target_compile_definitions(${PROJECT_NAME} PRIVATE IMHEX_PROJECT_NAME="${PROJECT_NAME}") + target_compile_definitions(${PROJECT_NAME} PRIVATE IMHEX_VERSION="${IMHEX_VERSION_STRING}") set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE ON) setupCompilerFlags(${PROJECT_NAME})