DB: Fix /deletelvl and /renamelvl with binary BlockDB files

This commit is contained in:
UnknownShadow200 2016-12-24 08:02:05 +11:00
parent 62410fc34a
commit 8f89e79afe
3 changed files with 23 additions and 2 deletions

View File

@ -35,7 +35,7 @@ namespace MCGalaxy.DB {
public static DateTime Epoch = new DateTime(2010, 1, 1, 0, 0, 0, DateTimeKind.Utc);
/// <summary> The path of this BlockDB's backing file on disc. </summary>
public string FilePath { get { return "blockdb/" + MapName + ".cbdb"; } }
public string FilePath { get { return BlockDBFile.FilePath(MapName); } }
/// <summary> The path of this BlockDB's temp backing file on disc for resizing. </summary>
public string TempPath { get { return "blockdb/" + MapName + ".temp"; } }

View File

@ -27,6 +27,8 @@ namespace MCGalaxy.DB {
const int entrySize = 16;
const int bulkEntries = 256;
public static string FilePath(string map) { return "blockdb/" + map + ".cbdb"; }
public static void WriteHeader(Stream s, Vec3U16 dims) {
byte[] header = new byte[entrySize * 4];
NetUtils.WriteAscii("CBDB_MCG", header, 0);
@ -136,6 +138,21 @@ namespace MCGalaxy.DB {
}
}
/// <summary> Deletes the backing file on disc if it exists. </summary>
public static void DeleteBackingFile(string map) {
string path = FilePath(map);
if (!File.Exists(path)) return;
File.Delete(path);
}
/// <summary> Moves the backing file on disc if it exists. </summary>
public static void MoveBackingFile(string srcMap, string dstMap) {
string srcPath = FilePath(srcMap), dstPath = FilePath(dstMap);
if (!File.Exists(srcPath)) return;
if (File.Exists(dstPath)) File.Delete(dstPath);
File.Move(srcPath, dstPath);
}
public static void ResizeBackingFile(BlockDB db) {
Server.s.Log("Resizing BlockDB for " + db.MapName, true);

View File

@ -18,6 +18,7 @@
using System;
using System.IO;
using MCGalaxy.Bots;
using MCGalaxy.DB;
using MCGalaxy.SQL;
using MCGalaxy.Util;
@ -60,6 +61,7 @@ namespace MCGalaxy {
}
BotsFile.MoveBots(src, dst);
RenameDatabaseTables(src, dst);
BlockDBFile.MoveBackingFile(src, dst);
}
static void RenameDatabaseTables(string src, string dst) {
@ -135,9 +137,10 @@ namespace MCGalaxy {
if (File.Exists("blockdefs/lvl_" + name + ".json"))
File.Delete("blockdefs/lvl_" + name + ".json");
} catch {}
BotsFile.DeleteBots(name);
DeleteDatabaseTables(name);
BlockDBFile.DeleteBackingFile(name);
}
static void DeleteDatabaseTables(string name) {
@ -159,6 +162,7 @@ namespace MCGalaxy {
}
public static void Replace(Level old, Level lvl) {
LevelDB.SaveBlockDB(old);
LevelInfo.Loaded.Remove(old);
LevelInfo.Loaded.Add(lvl);