mirror of
				https://github.com/luanti-org/luanti.git
				synced 2025-10-31 15:35:21 +01:00 
			
		
		
		
	Fix server favorites not saving when client/serverlist/ doesn't exist already (#11152)
This commit is contained in:
		| @@ -90,8 +90,11 @@ function serverlistmgr.sync() | |||||||
| end | 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 | 	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") | 	return base .. core.settings:get("serverlist_file") | ||||||
| end | end | ||||||
|  |  | ||||||
| @@ -103,9 +106,8 @@ local function save_favorites(favorites) | |||||||
| 		core.settings:set("serverlist_file", filename:sub(1, #filename - 4) .. ".json") | 		core.settings:set("serverlist_file", filename:sub(1, #filename - 4) .. ".json") | ||||||
| 	end | 	end | ||||||
|  |  | ||||||
| 	local path = get_favorites_path() | 	assert(core.create_dir(get_favorites_path(true))) | ||||||
| 	core.create_dir(path) | 	core.safe_file_write(get_favorites_path(), core.write_json(favorites)) | ||||||
| 	core.safe_file_write(path, core.write_json(favorites)) |  | ||||||
| end | end | ||||||
|  |  | ||||||
| -------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||||||
|   | |||||||
| @@ -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())) | 	if (fs::PathStartsWith(path, fs::TempPath())) | ||||||
| 		return true; | 		return true; | ||||||
| 
 | 
 | ||||||
| 	if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "games"))) | 	std::string path_user = fs::RemoveRelativePathComponents(porting::path_user); | ||||||
| 		return true; |  | ||||||
| 
 | 
 | ||||||
| 	if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "mods"))) | 	if (fs::PathStartsWith(path, path_user + DIR_DELIM "client")) | ||||||
| 		return true; | 		return true; | ||||||
| 
 | 	if (fs::PathStartsWith(path, path_user + DIR_DELIM "games")) | ||||||
| 	if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "textures"))) |  | ||||||
| 		return true; | 		return true; | ||||||
| 
 | 	if (fs::PathStartsWith(path, path_user + DIR_DELIM "mods")) | ||||||
| 	if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_user + DIR_DELIM "worlds"))) | 		return true; | ||||||
|  | 	if (fs::PathStartsWith(path, path_user + DIR_DELIM "textures")) | ||||||
|  | 		return true; | ||||||
|  | 	if (fs::PathStartsWith(path, path_user + DIR_DELIM "worlds")) | ||||||
| 		return true; | 		return true; | ||||||
| 
 | 
 | ||||||
| 	if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_cache))) | 	if (fs::PathStartsWith(path, fs::RemoveRelativePathComponents(porting::path_cache))) | ||||||
|   | |||||||
| @@ -58,7 +58,7 @@ private: | |||||||
| 	 * @param path path to check | 	 * @param path path to check | ||||||
| 	 * @return true if the path may be modified | 	 * @return true if the path may be modified | ||||||
| 	 */ | 	 */ | ||||||
| 	static bool mayModifyPath(const std::string &path); | 	static bool mayModifyPath(std::string path); | ||||||
| 
 | 
 | ||||||
| 	//api calls
 | 	//api calls
 | ||||||
| 
 | 
 | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user