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); 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> /// <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> /// <summary> The path of this BlockDB's temp backing file on disc for resizing. </summary>
public string TempPath { get { return "blockdb/" + MapName + ".temp"; } } public string TempPath { get { return "blockdb/" + MapName + ".temp"; } }

View File

@ -27,6 +27,8 @@ namespace MCGalaxy.DB {
const int entrySize = 16; const int entrySize = 16;
const int bulkEntries = 256; const int bulkEntries = 256;
public static string FilePath(string map) { return "blockdb/" + map + ".cbdb"; }
public static void WriteHeader(Stream s, Vec3U16 dims) { public static void WriteHeader(Stream s, Vec3U16 dims) {
byte[] header = new byte[entrySize * 4]; byte[] header = new byte[entrySize * 4];
NetUtils.WriteAscii("CBDB_MCG", header, 0); NetUtils.WriteAscii("CBDB_MCG", header, 0);
@ -137,6 +139,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) { public static void ResizeBackingFile(BlockDB db) {
Server.s.Log("Resizing BlockDB for " + db.MapName, true); Server.s.Log("Resizing BlockDB for " + db.MapName, true);
using (Stream src = File.OpenRead(db.FilePath), dst = File.Create(db.TempPath)) { using (Stream src = File.OpenRead(db.FilePath), dst = File.Create(db.TempPath)) {

View File

@ -18,6 +18,7 @@
using System; using System;
using System.IO; using System.IO;
using MCGalaxy.Bots; using MCGalaxy.Bots;
using MCGalaxy.DB;
using MCGalaxy.SQL; using MCGalaxy.SQL;
using MCGalaxy.Util; using MCGalaxy.Util;
@ -60,6 +61,7 @@ namespace MCGalaxy {
} }
BotsFile.MoveBots(src, dst); BotsFile.MoveBots(src, dst);
RenameDatabaseTables(src, dst); RenameDatabaseTables(src, dst);
BlockDBFile.MoveBackingFile(src, dst);
} }
static void RenameDatabaseTables(string src, string dst) { static void RenameDatabaseTables(string src, string dst) {
@ -138,6 +140,7 @@ namespace MCGalaxy {
BotsFile.DeleteBots(name); BotsFile.DeleteBots(name);
DeleteDatabaseTables(name); DeleteDatabaseTables(name);
BlockDBFile.DeleteBackingFile(name);
} }
static void DeleteDatabaseTables(string name) { static void DeleteDatabaseTables(string name) {
@ -159,6 +162,7 @@ namespace MCGalaxy {
} }
public static void Replace(Level old, Level lvl) { public static void Replace(Level old, Level lvl) {
LevelDB.SaveBlockDB(old);
LevelInfo.Loaded.Remove(old); LevelInfo.Loaded.Remove(old);
LevelInfo.Loaded.Add(lvl); LevelInfo.Loaded.Add(lvl);