Exemple #1
0
        public static RegionFile CreateOrLoadRegionFile(string par0File, int par1, int par2)
        {
            string file  = IOPath.Combine(par0File, "region");
            string file1 = IOPath.Combine(file, (new StringBuilder()).Append("r.").Append(par1 >> 5).Append(".").Append(par2 >> 5).Append(".mca").ToString());

            WeakReference reference = null;

            if (RegionsByFilename.ContainsKey(file1))
            {
                reference = new WeakReference(RegionsByFilename[file1]);
            }

            if (reference != null)
            {
                RegionFile regionfile = (RegionFile)reference.Target;

                if (regionfile != null)
                {
                    return(regionfile);
                }
            }

            if (!Directory.Exists(file))
            {
                Directory.CreateDirectory(file);
            }

            if (RegionsByFilename.Count >= 256)
            {
                ClearRegionFileReferences();
            }

            RegionFile regionfile1 = new RegionFile(file1);

            RegionsByFilename[file1] = new WeakReference(regionfile1);
            return(regionfile1);
        }
Exemple #2
0
        private void Func_48430_a(string par1File, string par2File, WorldChunkManager par3WorldChunkManager, int par4, int par5, IProgressUpdate par6IProgressUpdate)
        {
            try
            {
                FileInfo   file        = new FileInfo(par2File);
                string     s           = file.Name;
                RegionFile regionfile  = new RegionFile(par2File);
                RegionFile regionfile1 = new RegionFile(IOPath.Combine(par1File, (new StringBuilder()).Append(s.Substring(0, s.Length - ".mcr".Length)).Append(".mca").ToString()));

                for (int i = 0; i < 32; i++)
                {
                    for (int j = 0; j < 32; j++)
                    {
                        if (!regionfile.IsChunkSaved(i, j) || regionfile1.IsChunkSaved(i, j))
                        {
                            continue;
                        }

                        Stream datainputstream = regionfile.GetChunkFileStream(i, j);

                        if (datainputstream == null)
                        {
                            Console.WriteLine("Failed to fetch input stream");
                        }
                        else
                        {
                            NBTTagCompound nbttagcompound = CompressedStreamTools.Read(new BinaryReader(datainputstream));
                            datainputstream.Close();

                            NBTTagCompound nbttagcompound1 = nbttagcompound.GetCompoundTag("Level");

                            AnvilConverterData anvilconverterdata = ChunkLoader.Load(nbttagcompound1);
                            NBTTagCompound     nbttagcompound2    = new NBTTagCompound();
                            NBTTagCompound     nbttagcompound3    = new NBTTagCompound();
                            nbttagcompound2.SetTag("Level", nbttagcompound3);

                            ChunkLoader.ConvertToAnvilFormat(anvilconverterdata, nbttagcompound3, par3WorldChunkManager);

                            Stream dataoutputstream = regionfile1.GetChunkDataOutputStream(i, j);
                            CompressedStreamTools.Write(nbttagcompound2, new BinaryWriter(dataoutputstream));
                            dataoutputstream.Close();
                        }
                    }

                    int k = (int)Math.Round((100D * (double)(par4 * 1024)) / (double)(par5 * 1024));
                    int l = (int)Math.Round((100D * (double)((i + 1) * 32 + par4 * 1024)) / (double)(par5 * 1024));

                    if (l > k)
                    {
                        par6IProgressUpdate.SetLoadingProgress(l);
                    }
                }

                regionfile.Close();
                regionfile1.Close();
            }
            catch (IOException ioexception)
            {
                Utilities.LogException(ioexception);
            }
        }
Exemple #3
0
        /// <summary>
        /// Returns an input stream for the specified chunk. Args: worldDir, chunkX, chunkZ
        /// </summary>
        public static Stream GetChunkFileStream(string par0File, int par1, int par2)
        {
            RegionFile regionfile = CreateOrLoadRegionFile(par0File, par1, par2);

            return(regionfile.GetChunkFileStream(par1 & 0x1f, par2 & 0x1f));
        }
 public RegionFileChunkBuffer(RegionFile par1RegionFile, int par2, int par3)
 {
     RegionFile = par1RegionFile;
     ChunkX     = par2;
     ChunkZ     = par3;
 }