Skip to content

Commit

Permalink
Fix world deletion (#7494)
Browse files Browse the repository at this point in the history
* Fix world deletion
  • Loading branch information
numberZero authored and nerzhul committed Jun 30, 2018
1 parent f3b7be9 commit 9f19b7d
Showing 1 changed file with 9 additions and 22 deletions.
31 changes: 9 additions & 22 deletions src/script/lua_api/l_mainmenu.cpp
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -594,31 +594,18 @@ int ModApiMainMenu::l_create_world(lua_State *L)
/******************************************************************************/ /******************************************************************************/
int ModApiMainMenu::l_delete_world(lua_State *L) int ModApiMainMenu::l_delete_world(lua_State *L)
{ {
int worldidx = luaL_checkinteger(L,1) -1; int world_id = luaL_checkinteger(L, 1) - 1;

std::vector<WorldSpec> worlds = getAvailableWorlds(); std::vector<WorldSpec> worlds = getAvailableWorlds();

if (world_id < 0 || world_id >= (int) worlds.size()) {
if ((worldidx >= 0) &&
(worldidx < (int) worlds.size())) {

WorldSpec spec = worlds[worldidx];

std::vector<std::string> paths;
paths.push_back(spec.path);
fs::GetRecursiveSubPaths(spec.path, paths, true);

// Delete files
if (!fs::DeletePaths(paths)) {
lua_pushstring(L, "Failed to delete world");
}
else {
lua_pushnil(L);
}
}
else {
lua_pushstring(L, "Invalid world index"); lua_pushstring(L, "Invalid world index");
return 1;
} }
return 1; const WorldSpec &spec = worlds[world_id];
if (!fs::RecursiveDelete(spec.path)) {
lua_pushstring(L, "Failed to delete world");
return 1;
}
return 0;
} }


/******************************************************************************/ /******************************************************************************/
Expand Down

0 comments on commit 9f19b7d

Please sign in to comment.