Exemplo n.º 1
0
        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);
        }
Exemplo n.º 2
0
        public static void ResizeBackingFile(BlockDB db)
        {
            Server.s.Log("Resizing BlockDB for " + db.MapName, true);
            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)
                {
                    int           entries  = (int)(src.Length / EntrySize) - 1;
                    BlockDBEntry *entryPtr = (BlockDBEntry *)ptr;

                    while (entries > 0)
                    {
                        int read = Math.Min(entries, BulkEntries);
                        ReadFully(src, bulk, read * EntrySize);

                        for (int i = 0; i < read; 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, read * EntrySize);
                        entries -= read;
                    }
                }
            }

            File.Delete(filePath);
            File.Move(tempPath, filePath);
        }