diff --git a/src/component/io.cpp b/src/component/io.cpp index 8b8316e..34a98b3 100644 --- a/src/component/io.cpp +++ b/src/component/io.cpp @@ -6,6 +6,7 @@ #include "game/scripting/event.hpp" #include "game/scripting/execution.hpp" #include "game/scripting/functions.hpp" +#include "game/scripting/array.hpp" #include "gsc.hpp" @@ -72,6 +73,79 @@ namespace io return result; }); + + gsc::function::add("fileexists", [](gsc::function_args args) + { + const auto path = args[0].as(); + return utils::io::file_exists(path); + }); + + gsc::function::add("writefile", [](gsc::function_args args) + { + const auto path = args[0].as(); + const auto data = args[1].as(); + + auto append = false; + if (args.size() > 2) + { + append = args[2].as(); + } + + return utils::io::write_file(path, data, append); + }); + + gsc::function::add("readfile", [](gsc::function_args args) + { + const auto path = args[0].as(); + return utils::io::read_file(path); + }); + + gsc::function::add("filesize", [](gsc::function_args args) + { + const auto path = args[0].as(); + return utils::io::file_size(path); + }); + + gsc::function::add("createdirectory", [](gsc::function_args args) + { + const auto path = args[0].as(); + return utils::io::create_directory(path); + }); + + gsc::function::add("directoryexists", [](gsc::function_args args) + { + const auto path = args[0].as(); + return utils::io::directory_exists(path); + }); + + gsc::function::add("directoryisempty", [](gsc::function_args args) + { + const auto path = args[0].as(); + return utils::io::directory_is_empty(path); + }); + + gsc::function::add("listfiles", [](gsc::function_args args) + { + const auto path = args[0].as(); + const auto files = utils::io::list_files(path); + + scripting::array array; + for (const auto& file : files) + { + array.push(file); + } + + return array.get_raw(); + }); + + gsc::function::add("copyfolder", [](gsc::function_args args) + { + const auto source = args[0].as(); + const auto target = args[1].as(); + utils::io::copy_folder(source, target); + + return scripting::script_value{}; + }); } }; }