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

View File

@ -16,6 +16,7 @@
#include "mods.hpp"
#include "fastfiles.hpp"
#include "scripting.hpp"
#include "updater.hpp"
#include "game/ui_scripting/execution.hpp"
#include "game/scripting/execution.hpp"
@ -40,6 +41,7 @@ namespace ui_scripting
utils::hook::detour hks_load_hook;
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);
struct script
@ -331,6 +333,29 @@ namespace ui_scripting
}, ::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()
@ -347,6 +372,7 @@ namespace ui_scripting
lua["luiglobals"] = lua;
load_script("lui_common", lui_common);
load_script("lui_updater", lui_updater);
load_script("lua_json", lua_json);
for (const auto& path : filesystem::get_search_paths())

View File

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