public static void ResizeBackingFile(BlockDB db) { Logger.Log(LogType.BackgroundActivity, "Resizing BlockDB for " + db.MapName); string filePath = FilePath(db.MapName); 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); int width = db.Dims.X, length = db.Dims.Z; byte[] bulk = new byte[BulkEntries * EntrySize]; fixed(byte *ptr = bulk) { BlockDBEntry *entryPtr = (BlockDBEntry *)ptr; while (true) { int count = V1.ReadForward(src, bulk, entryPtr); if (count == 0) { break; } for (int i = 0; i < count; i++) { int index = entryPtr[i].Index; int x = index % dims.X; int y = (index / dims.X) / dims.Z; int z = (index / dims.X) % dims.Z; entryPtr[i].Index = (y * length + z) * width + x; } dst.Write(bulk, 0, count * EntrySize); } } } File.Delete(filePath); File.Move(tempPath, filePath); }