Beispiel #1
0
        public RegionFile(string file)
        {
            // Referenced classes of package net.minecraft.src:
            //            RegionFileChunkBuffer
            lastModified = 0L;
            fileName     = file;
            Debugln((new java.lang.StringBuilder()).Append("REGION LOAD ").Append(fileName).ToString
                        ());
            sizeDelta = 0;
            try
            {
                if (File.Exists(file))
                {
                    lastModified = new DateTimeOffset(File.GetLastWriteTime(file)).ToUnixTimeMilliseconds();
                }

                string dir = System.IO.Path.GetDirectoryName(file);
                if (!Directory.Exists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                fs         = File.Open(file, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.ReadWrite);
                dataFile   = new DataOutputStream(fs);              //new java.io.RandomAccessFile(file, "rw");
                dataFileIn = new DataInputStream(fs);
                if (dataFile.Length < 4096L)
                {
                    for (int i = 0; i < 1024; i++)
                    {
                        dataFile.WriteInt(0);
                    }
                    for (int j = 0; j < 1024; j++)
                    {
                        dataFile.WriteInt(0);
                    }
                    sizeDelta += 8192;
                }
                if ((dataFile.Length & 4095L) != 0L)
                {
                    for (int k = 0; (long)k < (dataFile.Length & 4095L); k++)
                    {
                        dataFile.Write(0);
                    }
                }
                int l = (int)dataFile.Length / 4096;
                sectorFree = new System.Collections.ArrayList(l);
                for (int i1 = 0; i1 < l; i1++)
                {
                    sectorFree.Add(true);
                }
                sectorFree[0] = false;
                sectorFree[1] = false;
                dataFile.Seek(0L);
                for (int j1 = 0; j1 < 1024; j1++)
                {
                    int l1 = dataFileIn.ReadInt();
                    offsets[j1] = l1;
                    if (l1 == 0 || (l1 >> 8) + (l1 & 0xff) > sectorFree.Count)
                    {
                        continue;
                    }
                    for (int j2 = 0; j2 < (l1 & 0xff); j2++)
                    {
                        sectorFree[(l1 >> 8) + j2] = false;
                    }
                }
                for (int k1 = 0; k1 < 1024; k1++)
                {
                    int i2 = dataFileIn.ReadInt();
                    chunkTimestamps[k1] = i2;
                }
            }
            catch (System.IO.IOException ioexception)
            {
                Sharpen.Runtime.PrintStackTrace(ioexception);
            }
        }