diff options
-rw-r--r-- | builtin/mainmenu/serverlistmgr.lua | 10 | ||||
-rw-r--r-- | src/script/lua_api/l_mainmenu.cpp | 19 | ||||
-rw-r--r-- | src/script/lua_api/l_mainmenu.h | 2 |
3 files changed, 18 insertions, 13 deletions
diff --git a/builtin/mainmenu/serverlistmgr.lua b/builtin/mainmenu/serverlistmgr.lua index 9876d8ac5..964d0c584 100644 --- a/builtin/mainmenu/serverlistmgr.lua +++ b/builtin/mainmenu/serverlistmgr.lua @@ -90,8 +90,11 @@ function serverlistmgr.sync() end -------------------------------------------------------------------------------- -local function get_favorites_path() +local function get_favorites_path(folder) local base = core.get_user_path() .. DIR_DELIM .. "client" .. DIR_DELIM .. "serverlist" .. DIR_DELIM + if folder then + return base + end return base .. core.settings:get("serverlist_file") end @@ -103,9 +106,8 @@ local function save_favorites(favorites) core.settings:set("serverlist_file", filename:sub(1, #filename - 4) .. ".json") end - local path = get_favorites_path() - core.create_dir(path) - core.safe_file_write(path, core.write_json(favorites)) + assert(core.create_dir(get_favorites_path(true))) + core.safe_file_write(get_favorites_path(), core.write_json(favorites)) end -------------------------------------------------------------------------------- diff --git a/src/script/lua_api/l_mainmenu.cpp b/src/script/lua_api/l_mainmenu.cpp index ba7f708a4..3e9709bde 100644 --- a/src/script/lua_api/l_mainmenu.cpp +++ b/src/script/lua_api/l_mainmenu.cpp @@ -716,21 +716,24 @@ int ModApiMainMenu::l_get_mainmenu_path(lua_State *L) } /******************************************************************************/ -bool ModApiMainMenu::mayModifyPath(const std::string &path) +bool ModApiMainMenu::mayModifyPath(std::string path) { + path = fs::RemoveRelativePathComponents(path); + if (fs::PathStartsWith(path, fs::TempPath())) return true; - if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "games"))) - return true; + std::string path_user = fs::RemoveRelativePathComponents(porting::path_user); - if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "mods"))) + if (fs::PathStartsWith(path, path_user + DIR_DELIM "client")) return true; - - if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "textures"))) + if (fs::PathStartsWith(path, path_user + DIR_DELIM "games")) return true; - - if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "worlds"))) + if (fs::PathStartsWith(path, path_user + DIR_DELIM "mods")) + return true; + if (fs::PathStartsWith(path, path_user + DIR_DELIM "textures")) + return true; + if (fs::PathStartsWith(path, path_user + DIR_DELIM "worlds")) return true; if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_cache))) diff --git a/src/script/lua_api/l_mainmenu.h b/src/script/lua_api/l_mainmenu.h index 49ce7c251..33ac9e721 100644 --- a/src/script/lua_api/l_mainmenu.h +++ b/src/script/lua_api/l_mainmenu.h @@ -58,7 +58,7 @@ private: * @param path path to check * @return true if the path may be modified */ - static bool mayModifyPath(const std::string &path); + static bool mayModifyPath(std::string path); //api calls |