MCGalaxy icon indicating copy to clipboard operation
MCGalaxy copied to clipboard

Back up files for bots, blockdefs, blockprops and level properties when a map gets deleted.

Open forkiesassds opened this issue 2 years ago • 2 comments

forkiesassds avatar Oct 31 '21 14:10 forkiesassds

adding search term /deletelvl for this issue.

Also: I'd suggest the final backup should be stored under levels/backups the same way all the others are.

rdebath avatar Dec 22 '22 19:12 rdebath

This seems to do the trick. Probably get rid of Paths.DeletedMapFile too.

diff --git a/MCGalaxy/Levels/LevelActions.cs b/MCGalaxy/Levels/LevelActions.cs
index 3ba1dd83d..f5a028e72 100644
--- a/MCGalaxy/Levels/LevelActions.cs
+++ b/MCGalaxy/Levels/LevelActions.cs
@@ -153,23 +153,14 @@ namespace MCGalaxy
                           "A game may currently be running on it.");
                 return false;
             }
-
-            p.Message("Created backup.");
-            if (!Directory.Exists("levels/deleted"))
-                Directory.CreateDirectory("levels/deleted");
-
-            if (File.Exists(Paths.DeletedMapFile(map))) {
-                int num = 0;
-                while (File.Exists(Paths.DeletedMapFile(map + num))) num++;

-                File.Move(LevelInfo.MapPath(map), Paths.DeletedMapFile(map + num));
-            } else {
-                File.Move(LevelInfo.MapPath(map), Paths.DeletedMapFile(map));
-            }
+            string backup = LevelInfo.NextBackup(map);
+            Backup(map, backup);

             DoAll(map, "", action_delete);
             DeleteDatabaseTables(map);
             BlockDBFile.DeleteBackingFile(map);
+            File.Delete(LevelInfo.MapPath(map));
             OnLevelDeletedEvent.Call(map);
             return true;
         }

rdebath avatar Mar 30 '23 17:03 rdebath