mirror of
https://github.com/ClassiCube/MCGalaxy.git
synced 2025-09-24 05:03:34 -04:00
DB: now /server upgradeblockdb actually saves .cbdb file and deletes the SQL table.
This commit is contained in:
parent
0125ccac05
commit
7ecab96b60
@ -37,9 +37,6 @@ namespace MCGalaxy.DB {
|
||||
/// <summary> The path of this BlockDB's backing file on disc. </summary>
|
||||
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"; } }
|
||||
|
||||
/// <summary> Used to synchronise adding to Cache by multiple threads. </summary>
|
||||
internal readonly object CacheLock = new object();
|
||||
|
||||
|
@ -29,9 +29,11 @@ namespace MCGalaxy.DB {
|
||||
public const int BulkEntries = 256;
|
||||
|
||||
public static string FilePath(string map) { return "blockdb/" + map + ".cbdb"; }
|
||||
public static string DumpPath(string map) { return "blockdb/" + map + ".dump"; }
|
||||
public static string TempPath(string map) { return "blockdb/" + map + ".temp"; }
|
||||
|
||||
public static void WriteHeader(Stream s, Vec3U16 dims) {
|
||||
byte[] header = new byte[EntrySize * HeaderEntries];
|
||||
byte[] header = new byte[EntrySize * HeaderEntries * 4];
|
||||
NetUtils.WriteAscii("CBDB_MCG", header, 0);
|
||||
WriteU16(Version, header, 8);
|
||||
WriteU16(dims.X, header, 10);
|
||||
@ -157,7 +159,10 @@ namespace MCGalaxy.DB {
|
||||
|
||||
public static void ResizeBackingFile(BlockDB db) {
|
||||
Server.s.Log("Resizing BlockDB for " + db.MapName, true);
|
||||
using (Stream src = File.OpenRead(db.FilePath), dst = File.Create(db.TempPath)) {
|
||||
string filePath = FilePath(db.FilePath);
|
||||
string tempPath = TempPath(db.MapName);
|
||||
|
||||
using (Stream src = File.OpenRead(filePath), dst = File.Create(tempPath)) {
|
||||
Vec3U16 dims;
|
||||
ReadHeader(src, out dims);
|
||||
WriteHeader(dst, db.Dims);
|
||||
@ -186,8 +191,8 @@ namespace MCGalaxy.DB {
|
||||
}
|
||||
}
|
||||
|
||||
File.Delete(db.FilePath);
|
||||
File.Move(db.TempPath, db.FilePath);
|
||||
File.Delete(filePath);
|
||||
File.Move(tempPath, filePath);
|
||||
}
|
||||
|
||||
static ushort ReadU16(byte[] array, int offset) {
|
||||
|
@ -47,13 +47,14 @@ namespace MCGalaxy.DB {
|
||||
Database.ExecuteReader("SELECT * FROM `" + table + "`", DumpRow);
|
||||
WriteBuffer(false);
|
||||
AppendCbdbFile();
|
||||
SaveCbdbFile();
|
||||
} finally {
|
||||
if (stream != null) stream.Close();
|
||||
stream = null;
|
||||
}
|
||||
|
||||
if (errorOccurred) return;
|
||||
//Database.Backend.DeleteTable(table); TODO: delete once tested
|
||||
Database.Backend.DeleteTable(table);
|
||||
}
|
||||
|
||||
void DumpRow(IDataReader reader) {
|
||||
@ -61,7 +62,7 @@ namespace MCGalaxy.DB {
|
||||
|
||||
try {
|
||||
if (stream == null) {
|
||||
stream = File.Create("blockdb/" + mapName + ".dump");
|
||||
stream = File.Create(BlockDBFile.DumpPath(mapName));
|
||||
string lvlPath = LevelInfo.LevelPath(mapName);
|
||||
dims = IMapImporter.Formats[0].ReadDimensions(lvlPath);
|
||||
BlockDBFile.WriteHeader(stream, dims);
|
||||
@ -104,11 +105,23 @@ namespace MCGalaxy.DB {
|
||||
cbdb.Read(bulk, 0, BlockDBFile.EntrySize); // header
|
||||
int read = 0;
|
||||
while ((read = cbdb.Read(bulk, 0, 4096)) > 0) {
|
||||
stream.Write(cbdb, 0, read);
|
||||
stream.Write(bulk, 0, read);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void SaveCbdbFile() {
|
||||
if (stream == null) return;
|
||||
stream.Close();
|
||||
stream = null;
|
||||
|
||||
string dumpPath = BlockDBFile.DumpPath(mapName);
|
||||
string filePath = BlockDBFile.FilePath(mapName);
|
||||
if (File.Exists(filePath)) File.Delete(filePath);
|
||||
File.Move(dumpPath, filePath);
|
||||
}
|
||||
|
||||
|
||||
void UpdateBlock(IDataReader reader) {
|
||||
entry.OldRaw = Block.Invalid;
|
||||
entry.NewRaw = reader.GetByte(5);
|
||||
|
Loading…
x
Reference in New Issue
Block a user