add pack.request_writeable(...) & update gui.confirm screen
This commit is contained in:
@@ -41,10 +41,23 @@ static std::set<std::string> writeable_entry_points {
|
||||
"world", "export", "config"
|
||||
};
|
||||
|
||||
static bool is_writeable(const std::string& entryPoint) {
|
||||
if (entryPoint.length() < 2) {
|
||||
return false;
|
||||
}
|
||||
if (entryPoint.substr(0, 2) == "W.") {
|
||||
return true;
|
||||
}
|
||||
if (writeable_entry_points.find(entryPoint) != writeable_entry_points.end()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static io::path get_writeable_path(lua::State* L) {
|
||||
io::path path = lua::require_string(L, 1);
|
||||
auto entryPoint = path.entryPoint();
|
||||
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
|
||||
if (!is_writeable(entryPoint)) {
|
||||
throw std::runtime_error("access denied");
|
||||
}
|
||||
return path;
|
||||
@@ -60,7 +73,7 @@ static int l_write(lua::State* L) {
|
||||
static int l_remove(lua::State* L) {
|
||||
io::path path = lua::require_string(L, 1);
|
||||
auto entryPoint = path.entryPoint();
|
||||
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
|
||||
if (!is_writeable(entryPoint)) {
|
||||
throw std::runtime_error("access denied");
|
||||
}
|
||||
return lua::pushboolean(L, io::remove(path));
|
||||
@@ -69,7 +82,7 @@ static int l_remove(lua::State* L) {
|
||||
static int l_remove_tree(lua::State* L) {
|
||||
io::path path = lua::require_string(L, 1);
|
||||
auto entryPoint = path.entryPoint();
|
||||
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
|
||||
if (!is_writeable(entryPoint)) {
|
||||
throw std::runtime_error("access denied");
|
||||
}
|
||||
return lua::pushinteger(L, io::remove_all(path));
|
||||
@@ -222,10 +235,7 @@ static int l_read_combined_object(lua::State* L) {
|
||||
static int l_is_writeable(lua::State* L) {
|
||||
io::path path = lua::require_string(L, 1);
|
||||
auto entryPoint = path.entryPoint();
|
||||
if (writeable_entry_points.find(entryPoint) == writeable_entry_points.end()) {
|
||||
return lua::pushboolean(L, false);
|
||||
}
|
||||
return lua::pushboolean(L, true);
|
||||
return lua::pushboolean(L, is_writeable(entryPoint));
|
||||
}
|
||||
|
||||
const luaL_Reg filelib[] = {
|
||||
@@ -249,4 +259,5 @@ const luaL_Reg filelib[] = {
|
||||
{"read_combined_list", lua::wrap<l_read_combined_list>},
|
||||
{"read_combined_object", lua::wrap<l_read_combined_object>},
|
||||
{"is_writeable", lua::wrap<l_is_writeable>},
|
||||
{NULL, NULL}};
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
@@ -7,6 +7,9 @@
|
||||
#include "assets/AssetsLoader.hpp"
|
||||
#include "content/Content.hpp"
|
||||
#include "engine/Engine.hpp"
|
||||
#include "graphics/ui/gui_util.hpp"
|
||||
#include "graphics/ui/elements/Menu.hpp"
|
||||
#include "frontend/locale.hpp"
|
||||
#include "world/files/WorldFiles.hpp"
|
||||
#include "io/engine_paths.hpp"
|
||||
#include "world/Level.hpp"
|
||||
@@ -247,6 +250,20 @@ static int l_pack_assemble(lua::State* L) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int l_pack_request_writeable(lua::State* L) {
|
||||
auto packid = lua::require_string(L, 1);
|
||||
lua::pushvalue(L, 2);
|
||||
auto handler = lua::create_lambda_nothrow(L);
|
||||
|
||||
auto str = langs::get(L"Grant %{0} pack modification permission?");
|
||||
util::replaceAll(str, L"%{0}", util::str2wstr_utf8(packid));
|
||||
guiutil::confirm(*engine, str, [packid, handler]() {
|
||||
handler({engine->getPaths().createWriteablePackDevice(packid)});
|
||||
engine->getGUI()->getMenu()->reset();
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
|
||||
const luaL_Reg packlib[] = {
|
||||
{"get_folder", lua::wrap<l_pack_get_folder>},
|
||||
{"get_installed", lua::wrap<l_pack_get_installed>},
|
||||
@@ -254,4 +271,6 @@ const luaL_Reg packlib[] = {
|
||||
{"get_info", lua::wrap<l_pack_get_info>},
|
||||
{"get_base_packs", lua::wrap<l_pack_get_base_packs>},
|
||||
{"assemble", lua::wrap<l_pack_assemble>},
|
||||
{NULL, NULL}};
|
||||
{"request_writeable", lua::wrap<l_pack_request_writeable>},
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user