This commit is contained in:
Federico Cecchetto 2022-05-30 23:03:36 +02:00
parent da90d37846
commit 502b7ac3dd
5 changed files with 170 additions and 152 deletions

View File

@ -67,7 +67,7 @@ function addrequest(request)
left = 1, left = 1,
bottom = -1, bottom = -1,
right = -1, right = -1,
material = luiglobals.RegisterMaterial("white"), material = RegisterMaterial("white"),
color = { color = {
r = 0, r = 0,
b = 0, b = 0,
@ -81,7 +81,7 @@ function addrequest(request)
leftAnchor = true, leftAnchor = true,
rightAnchor = true, rightAnchor = true,
bottomAnchor = true, bottomAnchor = true,
material = luiglobals.RegisterMaterial("btn_focused_rect_innerglow"), material = RegisterMaterial("btn_focused_rect_innerglow"),
}) })
border:setup9SliceImage(10, 5, 0.25, 0.12) border:setup9SliceImage(10, 5, 0.25, 0.12)
@ -105,7 +105,7 @@ function addrequest(request)
width = 32, width = 32,
height = 32, height = 32,
left = 1, left = 1,
material = luiglobals.RegisterMaterial(avatarmaterial) material = RegisterMaterial(avatarmaterial)
}) })
local username = LUI.UIText.new({ local username = LUI.UIText.new({
@ -113,7 +113,7 @@ function addrequest(request)
topAnchor = true, topAnchor = true,
height = 12, height = 12,
left = 32 + paddingvalue, left = 32 + paddingvalue,
color = luiglobals.Colors.white, color = Colors.white,
alignment = LUI.Alignment.Left, alignment = LUI.Alignment.Left,
rightAnchor = true, rightAnchor = true,
font = CoD.TextSettings.BodyFontBold.Font font = CoD.TextSettings.BodyFontBold.Font
@ -137,7 +137,7 @@ function addrequest(request)
topAnchor = true, topAnchor = true,
height = 18, height = 18,
width = 85, width = 85,
material = luiglobals.RegisterMaterial("btn_focused_rect_innerglow"), material = RegisterMaterial("btn_focused_rect_innerglow"),
}) })
local center = LUI.UIText.new({ local center = LUI.UIText.new({
@ -214,7 +214,7 @@ function addrequest(request)
bottom = -3, bottom = -3,
left = 3, left = 3,
width = 200 - 6, width = 200 - 6,
material = luiglobals.RegisterMaterial("white"), material = RegisterMaterial("white"),
height = 2, height = 2,
color = { color = {
r = 92 / 255, r = 92 / 255,
@ -236,7 +236,7 @@ function addrequest(request)
avatar:registerEventHandler("update", function() avatar:registerEventHandler("update", function()
local avatarmaterial = discord.getavatarmaterial(request.userid) local avatarmaterial = discord.getavatarmaterial(request.userid)
avatar:setImage(luiglobals.RegisterMaterial(avatarmaterial)) avatar:setImage(RegisterMaterial(avatarmaterial))
end) end)
avatar:addElement(LUI.UITimer.new(100, "update")) avatar:addElement(LUI.UITimer.new(100, "update"))

View File

@ -16,6 +16,7 @@
#include "mods.hpp" #include "mods.hpp"
#include "fastfiles.hpp" #include "fastfiles.hpp"
#include "scripting.hpp" #include "scripting.hpp"
#include "updater.hpp"
#include "game/ui_scripting/execution.hpp" #include "game/ui_scripting/execution.hpp"
#include "game/scripting/execution.hpp" #include "game/scripting/execution.hpp"
@ -40,6 +41,7 @@ namespace ui_scripting
utils::hook::detour hks_load_hook; utils::hook::detour hks_load_hook;
const auto lui_common = utils::nt::load_resource(LUI_COMMON); const auto lui_common = utils::nt::load_resource(LUI_COMMON);
const auto lui_updater = utils::nt::load_resource(LUI_UPDATER);
const auto lua_json = utils::nt::load_resource(LUA_JSON); const auto lua_json = utils::nt::load_resource(LUA_JSON);
struct script struct script
@ -331,6 +333,29 @@ namespace ui_scripting
}, ::scheduler::pipeline::server); }, ::scheduler::pipeline::server);
}; };
} }
auto updater_table = table();
lua["updater"] = updater_table;
updater_table["relaunch"] = updater::relaunch;
updater_table["sethastriedupdate"] = updater::set_has_tried_update;
updater_table["gethastriedupdate"] = updater::get_has_tried_update;
updater_table["autoupdatesenabled"] = updater::auto_updates_enabled;
updater_table["startupdatecheck"] = updater::start_update_check;
updater_table["isupdatecheckdone"] = updater::is_update_check_done;
updater_table["getupdatecheckstatus"] = updater::get_update_check_status;
updater_table["isupdateavailable"] = updater::is_update_available;
updater_table["startupdatedownload"] = updater::start_update_download;
updater_table["isupdatedownloaddone"] = updater::is_update_download_done;
updater_table["getupdatedownloadstatus"] = updater::get_update_download_status;
updater_table["cancelupdate"] = updater::cancel_update;
updater_table["isrestartrequired"] = updater::is_restart_required;
updater_table["getlasterror"] = updater::get_last_error;
updater_table["getcurrentfile"] = updater::get_current_file;
} }
void start() void start()
@ -347,6 +372,7 @@ namespace ui_scripting
lua["luiglobals"] = lua; lua["luiglobals"] = lua;
load_script("lui_common", lui_common); load_script("lui_common", lui_common);
load_script("lui_updater", lui_updater);
load_script("lua_json", lua_json); load_script("lua_json", lua_json);
for (const auto& path : filesystem::get_search_paths()) for (const auto& path : filesystem::get_search_paths())

View File

@ -4,6 +4,7 @@
#include "scheduler.hpp" #include "scheduler.hpp"
#include "dvars.hpp" #include "dvars.hpp"
#include "updater.hpp" #include "updater.hpp"
#include "game/ui_scripting/execution.hpp"
#include "version.h" #include "version.h"
@ -63,14 +64,9 @@ namespace updater
utils::concurrency::container<update_data_t> update_data; utils::concurrency::container<update_data_t> update_data;
std::string get_branch()
{
return GIT_BRANCH;
}
std::string select(const std::string& main, const std::string& develop) std::string select(const std::string& main, const std::string& develop)
{ {
if (get_branch() == "develop") if (GIT_BRANCH == "develop"s)
{ {
return develop; return develop;
} }
@ -78,14 +74,12 @@ namespace updater
return main; return main;
} }
std::string get_data_path() void notify(const std::string& name)
{ {
if (get_branch() == "develop") scheduler::once([=]()
{ {
return DATA_PATH_DEV; ui_scripting::notify(name, {});
} }, scheduler::pipeline::lui);
return DATA_PATH;
} }
void set_update_check_status(bool done, bool success, const std::string& error = {}) void set_update_check_status(bool done, bool success, const std::string& error = {})
@ -95,6 +89,8 @@ namespace updater
data_.check.done = done; data_.check.done = done;
data_.check.success = success; data_.check.success = success;
data_.error = error; data_.error = error;
notify("update_check_done");
}); });
} }
@ -105,6 +101,7 @@ namespace updater
data_.download.done = done; data_.download.done = done;
data_.download.success = success; data_.download.success = success;
data_.error = error; data_.error = error;
notify("update_done");
}); });
} }
@ -126,11 +123,8 @@ namespace updater
std::string load_binary_name() std::string load_binary_name()
{ {
// utils::nt::library self; utils::nt::library self;
// return self.get_name(); return self.get_name();
// returns the game's name and not the client's
return BINARY_NAME;
} }
std::string get_binary_name() std::string get_binary_name()
@ -217,7 +211,7 @@ namespace updater
char current_dir[MAX_PATH]; char current_dir[MAX_PATH];
GetCurrentDirectoryA(sizeof(current_dir), current_dir); GetCurrentDirectoryA(sizeof(current_dir), current_dir);
char buf[1024] = {0}; char buf[1024] = {0};
const auto command_line = utils::string::va("%s %s", GetCommandLineA(), get_mode_flag().data()); const auto command_line = utils::string::va("%s %s", GetCommandLineA(), get_mode_flag().data());
strcpy_s(buf, 1024, command_line); strcpy_s(buf, 1024, command_line);
@ -392,6 +386,8 @@ namespace updater
data_.check.success = true; data_.check.success = true;
data_.required_files = required_files; data_.required_files = required_files;
}); });
notify("update_check_done");
}, scheduler::pipeline::async); }, scheduler::pipeline::async);
} }
@ -468,4 +464,4 @@ namespace updater
}; };
} }
//REGISTER_COMPONENT(updater::component) REGISTER_COMPONENT(updater::component)

View File

@ -38,7 +38,9 @@ LUI.MenuBuilder.m_types_build["generic_waiting_popup_"] = function (menu, event)
end end
}) })
popup.text = popup:getLastChild():getPreviousSibling():getPreviousSibling() local listchildren = getchildren(popup:getChildById("LUIHorizontalList"))
local children = getchildren(listchildren[2])
popup.text = children[2]
stack = { stack = {
ret = popup ret = popup
@ -171,4 +173,4 @@ LUI.confirmationpopup = function(data)
end end
LUI.FlowManager.RequestPopupMenu(nil, "generic_confirmation_popup_") LUI.FlowManager.RequestPopupMenu(nil, "generic_confirmation_popup_")
return stack.ret return stack.ret
end end

View File

@ -1,164 +1,158 @@
updatecancelled = false if (not Engine.InFrontend()) then
taskinterval = 100 return
end
updatecancelled = false
updater.cancelupdate() updater.cancelupdate()
function startupdatecheck(popup, autoclose) function startupdatecheck(popup, autoclose)
updatecancelled = false Engine.GetLuiRoot():registerEventHandler("update_check_done", function(element, event)
if (updatecancelled) then
return
end
local callback = function() if (not updater.getupdatecheckstatus()) then
if (not updater.getupdatecheckstatus()) then if (autoclose) then
if (autoclose) then LUI.FlowManager.RequestLeaveMenu(popup)
LUI.FlowManager.RequestLeaveMenu(popup) return
return end
end
popup.text:setText("Error: " .. updater.getlasterror()) popup.text:setText("Error: " .. updater.getlasterror())
return return
end end
if (not updater.isupdateavailable()) then if (not updater.isupdateavailable()) then
if (autoclose) then if (autoclose) then
LUI.FlowManager.RequestLeaveMenu(popup) LUI.FlowManager.RequestLeaveMenu(popup)
return return
end end
popup.text:setText("No updates available") popup.text:setText("No updates available")
return return
end end
LUI.yesnopopup({ LUI.yesnopopup({
title = "NOTICE", title = "NOTICE",
text = "An update is available, proceed with installation?", text = "An update is available, proceed with installation?",
callback = function(result) callback = function(result)
if (result) then if (result) then
startupdatedownload(popup, autoclose) startupdatedownload(popup, autoclose)
else else
LUI.FlowManager.RequestLeaveMenu(popup) LUI.FlowManager.RequestLeaveMenu(popup)
end end
end end
}) })
end end)
updater.startupdatecheck() updater.startupdatecheck()
createtask({
done = updater.isupdatecheckdone,
cancelled = isupdatecancelled,
callback = callback,
interval = taskinterval
})
end end
function startupdatedownload(popup, autoclose) function startupdatedownload(popup, autoclose)
updater.startupdatedownload() local textupdate = nil
local previousfile = nil
local timer = LUI.UITimer.new(10, "update_file")
local textupdate = nil popup:addElement(timer)
local previousfile = nil popup:registerEventHandler("update_file", function()
textupdate = game:oninterval(function() local file = updater.getcurrentfile()
local file = updater.getcurrentfile() if (file == previousfile) then
if (file == previousfile) then return
return end
end
file = previousfile file = previousfile
popup.text:setText("Downloading file " .. updater.getcurrentfile() .. "...") popup.text:setText("Downloading file " .. updater.getcurrentfile() .. "...")
end, 10) end)
local callback = function() Engine.GetLuiRoot():registerEventHandler("update_done", function(element, event)
textupdate:clear() timer:close()
if (not updater.getupdatedownloadstatus()) then if (updatecancelled) then
if (autoclose) then return
LUI.FlowManager.RequestLeaveMenu(popup) end
return
end
popup.text:setText("Error: " .. updater.getlasterror()) if (not updater.getupdatedownloadstatus()) then
return if (autoclose) then
end LUI.FlowManager.RequestLeaveMenu(popup)
return
end
popup.text:setText("Update successful") popup.text:setText("Error: " .. updater.getlasterror())
return
end
if (updater.isrestartrequired()) then popup.text:setText("Update successful")
LUI.confirmationpopup({
title = "RESTART REQUIRED",
text = "Update requires restart",
buttontext = "RESTART",
callback = function()
updater.relaunch()
end
})
else
if (LUI.mp_menus) then
Engine.Exec("lui_restart; lui_open mp_main_menu")
else
Engine.Exec("lui_restart")
end
end
if (autoclose) then if (updater.isrestartrequired()) then
LUI.FlowManager.RequestLeaveMenu(popup) LUI.confirmationpopup({
end title = "RESTART REQUIRED",
end text = "Update requires restart",
buttontext = "RESTART",
callback = function()
updater.relaunch()
end
})
else
Engine.Exec("lui_restart")
end
createtask({ if (autoclose) then
done = updater.isupdatedownloaddone, LUI.FlowManager.RequestLeaveMenu(popup)
cancelled = isupdatecancelled, end
callback = callback, end)
interval = taskinterval
}) updater.startupdatedownload()
end end
function updaterpopup(oncancel) function updaterpopup(oncancel)
return LUI.openpopupmenu("generic_waiting_popup_", { return LUI.openpopupmenu("generic_waiting_popup_", {
oncancel = oncancel, oncancel = oncancel,
withcancel = true, withcancel = true,
text = "Checking for updates..." text = "Checking for updates..."
}) })
end end
function createtask(data) function createtask(data)
local interval = nil local interval = nil
interval = game:oninterval(function() interval = game:oninterval(function()
if (data.cancelled()) then if (data.cancelled()) then
interval:clear() interval:clear()
return return
end end
if (data.done()) then if (data.done()) then
interval:clear() interval:clear()
data.callback() data.callback()
end end
end, data.interval) end, data.interval)
return interval return interval
end
function isupdatecancelled()
return updatecancelled
end end
function tryupdate(autoclose) function tryupdate(autoclose)
updatecancelled = false updatecancelled = false
local popup = updaterpopup(function() local popup = updaterpopup(function()
updater.cancelupdate() updater.cancelupdate()
updatecancelled = true updatecancelled = true
end) end)
startupdatecheck(popup, autoclose) startupdatecheck(popup, autoclose)
end end
function tryautoupdate() function tryautoupdate()
if (not updater.autoupdatesenabled()) then if (not updater.autoupdatesenabled()) then
return return
end end
if (not updater.gethastriedupdate()) then if (not updater.gethastriedupdate()) then
game:ontimeout(function() local timer = LUI.UITimer.new(100, "tryupdate")
updater.sethastriedupdate(true) Engine.GetLuiRoot():addElement(timer)
tryupdate(true) Engine.GetLuiRoot():registerEventHandler("tryupdate", function()
end, 100) timer:close()
end updater.sethastriedupdate(true)
tryupdate(true)
end)
end
end end
LUI.tryupdating = tryupdate
LUI.onmenuopen("main_lockout", tryautoupdate)
LUI.onmenuopen("mp_main_menu", tryautoupdate) LUI.onmenuopen("mp_main_menu", tryautoupdate)
LUI.onmenuopen("main_lockout", tryautoupdate)