Add some functions

This commit is contained in:
Federico Cecchetto 2022-01-31 02:22:58 +01:00
parent 4f8c875c35
commit b2247f7ae3

View File

@ -89,6 +89,7 @@ namespace ui_scripting::lua
{ {
state["io"]["fileexists"] = utils::io::file_exists; state["io"]["fileexists"] = utils::io::file_exists;
state["io"]["writefile"] = utils::io::write_file; state["io"]["writefile"] = utils::io::write_file;
state["io"]["movefile"] = utils::io::move_file;
state["io"]["filesize"] = utils::io::file_size; state["io"]["filesize"] = utils::io::file_size;
state["io"]["createdirectory"] = utils::io::create_directory; state["io"]["createdirectory"] = utils::io::create_directory;
state["io"]["directoryexists"] = utils::io::directory_exists; state["io"]["directoryexists"] = utils::io::directory_exists;
@ -1117,6 +1118,7 @@ namespace ui_scripting::lua
event event; event event;
event.element = &ui_element; event.element = &ui_element;
event.name = "http_request_done"; event.name = "http_request_done";
if (result.has_value()) if (result.has_value())
{ {
event.arguments = {id, true, result.value()}; event.arguments = {id, true, result.value()};
@ -1132,6 +1134,35 @@ namespace ui_scripting::lua
return id; return id;
}; };
game_type["httpgettofile"] = [](const game&, const std::string& url,
const std::string& dest)
{
const auto id = request_id++;
::scheduler::once([url, id, dest]()
{
const auto result = utils::http::get_data(url);
::scheduler::once([result, id, dest]
{
event event;
event.element = &ui_element;
event.name = "http_request_done";
if (result.has_value())
{
const auto write = utils::io::write_file(dest, result.value(), false);
event.arguments = {id, write};
}
else
{
event.arguments = {id, false};
}
notify(event);
}, ::scheduler::pipeline::renderer);
}, ::scheduler::pipeline::async);
return id;
};
game_type["sha"] = [](const game&, const std::string& data) game_type["sha"] = [](const game&, const std::string& data)
{ {
return utils::string::to_upper(utils::cryptography::sha1::compute(data, true)); return utils::string::to_upper(utils::cryptography::sha1::compute(data, true));
@ -1144,9 +1175,8 @@ namespace ui_scripting::lua
game_type["binaryname"] = [](const game&) game_type["binaryname"] = [](const game&)
{ {
char name[MAX_PATH] = {0}; utils::nt::library self;
GetModuleBaseName(GetCurrentProcess(), GetModuleHandle(NULL), name, MAX_PATH); return self.get_name();
return std::string(name);
}; };
struct player struct player