From 25e8c0539cb32b53255acb6a843472e961226d74 Mon Sep 17 00:00:00 2001 From: Zephyron Date: Sat, 12 Jul 2025 09:23:29 +1000 Subject: [PATCH] updater: Improve version detection with build system fallback Add build system version detection as a fallback in GetCurrentVersion(): - Include common/scm_rev.h to access build version information - Use Common::g_build_version when version.txt doesn't exist - Automatically create version.txt with build version for future use - Update comments to clarify version resolution priority This ensures the updater can properly detect the current application version even when version.txt hasn't been created yet, while maintaining the existing priority system for version detection. Signed-off-by: Zephyron --- src/citron/updater/updater_service.cpp | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/citron/updater/updater_service.cpp b/src/citron/updater/updater_service.cpp index 7c84cf825..e9c8ff59a 100644 --- a/src/citron/updater/updater_service.cpp +++ b/src/citron/updater/updater_service.cpp @@ -4,6 +4,7 @@ #include "citron/updater/updater_service.h" #include "common/logging/log.h" #include "common/fs/path_util.h" +#include "common/scm_rev.h" #include #include @@ -360,7 +361,7 @@ void UpdaterService::CancelUpdate() { } std::string UpdaterService::GetCurrentVersion() const { - // Try to read version from version.txt file + // Try to read version from version.txt file first (updated versions) std::filesystem::path version_file = app_directory / CITRON_VERSION_FILE; if (std::filesystem::exists(version_file)) { @@ -374,7 +375,24 @@ std::string UpdaterService::GetCurrentVersion() const { } } - // Fallback to application version + // Use build version from the build system + std::string build_version = Common::g_build_version; + if (!build_version.empty()) { + // Create version.txt file if it doesn't exist + try { + std::ofstream vfile(version_file); + if (vfile.is_open()) { + vfile << build_version; + vfile.close(); + LOG_INFO(Frontend, "Created version.txt with build version: {}", build_version); + } + } catch (const std::exception& e) { + LOG_WARNING(Frontend, "Failed to create version.txt: {}", e.what()); + } + return build_version; + } + + // Final fallback to application version return QCoreApplication::applicationVersion().toStdString(); }