From 9a981f9173e8b8d52e90c99feb1ebe721f7e6e45 Mon Sep 17 00:00:00 2001 From: fed <58637860+fedddddd@users.noreply.github.com> Date: Thu, 15 Jun 2023 01:19:30 +0200 Subject: [PATCH] Force update if never updated --- src/client/component/ui_scripting.cpp | 1 + src/client/component/updater.cpp | 6 ++++++ src/client/component/updater.hpp | 2 ++ src/client/resources/ui_scripts/updater.lua | 24 ++++++++++++--------- 4 files changed, 23 insertions(+), 10 deletions(-) diff --git a/src/client/component/ui_scripting.cpp b/src/client/component/ui_scripting.cpp index 484b9428..ebf53e2f 100644 --- a/src/client/component/ui_scripting.cpp +++ b/src/client/component/ui_scripting.cpp @@ -444,6 +444,7 @@ namespace ui_scripting updater_table["getupdatedownloadstatus"] = updater::get_update_download_status; updater_table["cancelupdate"] = updater::cancel_update; updater_table["isrestartrequired"] = updater::is_restart_required; + updater_table["shouldforceupdate"] = updater::should_force_update; updater_table["getlasterror"] = updater::get_last_error; updater_table["getcurrentfile"] = updater::get_current_file; diff --git a/src/client/component/updater.cpp b/src/client/component/updater.cpp index bed584a6..ed1ec677 100644 --- a/src/client/component/updater.cpp +++ b/src/client/component/updater.cpp @@ -568,6 +568,12 @@ namespace updater }, scheduler::pipeline::async); } + bool should_force_update() + { + const auto folder = (utils::properties::get_appdata_path() / CLIENT_DATA_FOLDER).generic_string(); + return !utils::io::directory_exists(folder) || utils::io::directory_is_empty(folder); + } + class component final : public component_interface { public: diff --git a/src/client/component/updater.hpp b/src/client/component/updater.hpp index 0301a6c3..ae93d3c0 100644 --- a/src/client/component/updater.hpp +++ b/src/client/component/updater.hpp @@ -25,4 +25,6 @@ namespace updater void start_update_check(); void start_update_download(); void cancel_update(); + + bool should_force_update(); } \ No newline at end of file diff --git a/src/client/resources/ui_scripts/updater.lua b/src/client/resources/ui_scripts/updater.lua index 95f4e27e..ee4a79f8 100644 --- a/src/client/resources/ui_scripts/updater.lua +++ b/src/client/resources/ui_scripts/updater.lua @@ -31,17 +31,21 @@ function startupdatecheck(popup, autoclose) return end - LUI.yesnopopup({ - title = Engine.Localize("@MENU_NOTICE"), - text = Engine.Localize("@MENU_CCS_NEW_PATCH_NOTICE") .. " " .. Engine.Localize("@MENU_DOWNLOAD_AUTOUPDATE_PATCH"), - callback = function(result) - if (result) then - startupdatedownload(popup, autoclose) - else - LUI.FlowManager.RequestLeaveMenu(popup) + if (updater.shouldforceupdate()) then + startupdatedownload(popup, autoclose) + else + LUI.yesnopopup({ + title = Engine.Localize("@MENU_NOTICE"), + text = Engine.Localize("@MENU_CCS_NEW_PATCH_NOTICE") .. " " .. Engine.Localize("@MENU_DOWNLOAD_AUTOUPDATE_PATCH"), + callback = function(result) + if (result) then + startupdatedownload(popup, autoclose) + else + LUI.FlowManager.RequestLeaveMenu(popup) + end end - end - }) + }) + end end) updater.startupdatecheck()