diff --git a/lib/libimhex/CMakeLists.txt b/lib/libimhex/CMakeLists.txt index 49ab76023..1bdfe8467 100644 --- a/lib/libimhex/CMakeLists.txt +++ b/lib/libimhex/CMakeLists.txt @@ -133,6 +133,9 @@ endif () addDefineToSource(source/api/imhex_api.cpp "IMHEX_VERSION=\"${IMHEX_VERSION_STRING}\"") +string(TIMESTAMP IMHEX_BUILD_DATE UTC) +addDefineToSource(source/api/imhex_api.cpp "IMHEX_BUILD_DATE=\"${IMHEX_BUILD_DATE}\"") + enableUnityBuild(libimhex) setupCompilerFlags(libimhex) diff --git a/lib/libimhex/include/hex/api/imhex_api.hpp b/lib/libimhex/include/hex/api/imhex_api.hpp index c9bf81f8a..04ce4f4b9 100644 --- a/lib/libimhex/include/hex/api/imhex_api.hpp +++ b/lib/libimhex/include/hex/api/imhex_api.hpp @@ -6,6 +6,7 @@ #include #include +#include #include #include #include @@ -654,6 +655,12 @@ EXPORT_MODULE namespace hex { */ std::string getCommitBranch(); + /** + * @brief Gets the time ImHex was built + * @return The time ImHex was built + */ + std::optional getBuildTime(); + /** * @brief Checks if ImHex was built in debug mode * @return True if ImHex was built in debug mode, false otherwise diff --git a/lib/libimhex/source/api/imhex_api.cpp b/lib/libimhex/source/api/imhex_api.cpp index 8bef2903f..332a09375 100644 --- a/lib/libimhex/source/api/imhex_api.cpp +++ b/lib/libimhex/source/api/imhex_api.cpp @@ -883,7 +883,7 @@ namespace hex { } SemanticVersion getImHexVersion() { - #if defined IMHEX_VERSION + #if defined(IMHEX_VERSION) static auto version = SemanticVersion(IMHEX_VERSION); return version; #else @@ -892,7 +892,7 @@ namespace hex { } std::string getCommitHash(bool longHash) { - #if defined GIT_COMMIT_HASH_LONG + #if defined(GIT_COMMIT_HASH_LONG) if (longHash) { return GIT_COMMIT_HASH_LONG; } else { @@ -905,13 +905,21 @@ namespace hex { } std::string getCommitBranch() { - #if defined GIT_BRANCH + #if defined(GIT_BRANCH) return GIT_BRANCH; #else return "Unknown"; #endif } + std::optional getBuildTime() { + #if defined(IMHEX_BUILD_DATE) + return hex::parseTime("%Y-%m-%dT%H:%M:%SZ", IMHEX_BUILD_DATE); + #else + return std::nullopt; + #endif + } + bool isDebugBuild() { #if defined DEBUG return true; diff --git a/plugins/builtin/source/content/init_tasks.cpp b/plugins/builtin/source/content/init_tasks.cpp index 804b9bf1e..a792ce1db 100644 --- a/plugins/builtin/source/content/init_tasks.cpp +++ b/plugins/builtin/source/content/init_tasks.cpp @@ -51,11 +51,16 @@ namespace hex::plugin::builtin { } // Check if the response is valid - if (!releases.contains("published_at") || !releases["published_at"].is_string()) + if (!releases.contains("assets") || !releases["assets"].is_array()) return; - const auto nightlyUpdateTime = hex::parseTime("%FT%TZ", releases["published_at"].get()); - if (nightlyUpdateTime.has_value() && *nightlyUpdateTime > std::chrono::system_clock::now()) { + const auto firstAsset = releases["assets"].front(); + if (!firstAsset.is_object() || !firstAsset.contains("updated_at")) + return; + + const auto nightlyUpdateTime = hex::parseTime("%Y-%m-%dT%H:%M:%SZ", firstAsset["updated_at"].get()); + const auto imhexBuildTime = ImHexApi::System::getBuildTime(); + if (nightlyUpdateTime.has_value() && imhexBuildTime.has_value() && *nightlyUpdateTime > *imhexBuildTime) { updateString = "Nightly"; } } else {