コード例 #1
0
        /// <summary>
        /// Saves the given MapDataBase to disk.
        /// </summary>
        private void SaveData(WorldSavedData par1WorldSavedData)
        {
            if (SaveHandler == null)
            {
                return;
            }

            try
            {
                string file = SaveHandler.GetMapFileFromName(par1WorldSavedData.MapName);

                if (file != null)
                {
                    NBTTagCompound nbttagcompound = new NBTTagCompound();
                    par1WorldSavedData.WriteToNBT(nbttagcompound);
                    NBTTagCompound nbttagcompound1 = new NBTTagCompound();
                    nbttagcompound1.SetCompoundTag("data", nbttagcompound);
                    FileStream fileoutputstream = new FileStream(file, FileMode.Create);
                    CompressedStreamTools.WriteCompressed(nbttagcompound1, fileoutputstream);
                    fileoutputstream.Close();
                }
            }
            catch (Exception exception)
            {
                Utilities.LogException(exception);
            }
        }
コード例 #2
0
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: private void Func_48447_a(AnvilChunkLoaderPending par1AnvilChunkLoaderPending) throws IOException
        private void Func_48447_a(AnvilChunkLoaderPending par1AnvilChunkLoaderPending)
        {
            Stream dataoutputstream = RegionFileCache.GetChunkOutputStream(ChunkSaveLocation, par1AnvilChunkLoaderPending.Field_48427_a.ChunkXPos, par1AnvilChunkLoaderPending.Field_48427_a.ChunkZPos);

            CompressedStreamTools.Write(par1AnvilChunkLoaderPending.Field_48426_b, new BinaryWriter(dataoutputstream));
            dataoutputstream.Close();
        }
コード例 #3
0
        /// <summary>
        /// @args: Takes two arguments - first the name of the directory containing the world and second the new name for
        /// that world. @desc: Renames the world by storing the new name in level.dat. It does *not* rename the directory
        /// containing the world data.
        /// </summary>
        public virtual void RenameWorld(string par1Str, string par2Str)
        {
            string file = IOPath.Combine(SavesDirectory, par1Str);

            if (!File.Exists(file))
            {
                return;
            }

            string file1 = IOPath.Combine(file, "level.dat");

            if (File.Exists(file1))
            {
                try
                {
                    NBTTagCompound nbttagcompound  = CompressedStreamTools.ReadCompressed(new FileStream(file1, FileMode.Open));
                    NBTTagCompound nbttagcompound1 = nbttagcompound.GetCompoundTag("Data");
                    nbttagcompound1.SetString("LevelName", par2Str);
                    CompressedStreamTools.WriteCompressed(nbttagcompound, new FileStream(file1, FileMode.Create));
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.ToString());
                    Console.Write(exception.StackTrace);
                }
            }
        }
コード例 #4
0
        /// <summary>
        /// Writes a compressed NBTTagCompound to the OutputStream
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected void writeNBTTagCompound(NBTTagCompound par1NBTTagCompound, DataOutputStream par2DataOutputStream) throws IOException
        protected virtual void WriteNBTTagCompound(NBTTagCompound par1NBTTagCompound, BinaryWriter par2DataOutputStream)
        {
            if (par1NBTTagCompound == null)
            {
                par2DataOutputStream.Write((short)-1);
            }
            else
            {
                byte[] abyte0 = CompressedStreamTools.Compress(par1NBTTagCompound);
                par2DataOutputStream.Write((short)abyte0.Length);
                par2DataOutputStream.Write(abyte0);
            }
        }
コード例 #5
0
        /// <summary>
        /// gets the world info
        /// </summary>
        public virtual WorldInfo GetWorldInfo(string par1Str)
        {
            string file = IOPath.Combine(SavesDirectory, par1Str);

            if (!Directory.Exists(file))
            {
                return(null);
            }

            string file1 = IOPath.Combine(file, "level.dat");

            if (File.Exists(file1))
            {
                try
                {
                    MemoryStream stream = new MemoryStream();
                    using (var fs = new FileStream(file1, FileMode.Open))
                    {
                        fs.CopyTo(stream);
                    }
                    stream.Seek(0, SeekOrigin.Begin);

                    NBTTagCompound nbttagcompound  = CompressedStreamTools.ReadCompressed(stream);
                    NBTTagCompound nbttagcompound2 = nbttagcompound.GetCompoundTag("Data");
                    return(new WorldInfo(nbttagcompound2));
                }
                catch (Exception exception)
                {
                    Utilities.LogException(exception);
                }
            }

            file1 = IOPath.Combine(file, "level.dat_old");

            if (File.Exists(file1))
            {
                try
                {
                    NBTTagCompound nbttagcompound1 = CompressedStreamTools.ReadCompressed(new FileStream(file1, FileMode.Open));
                    NBTTagCompound nbttagcompound3 = nbttagcompound1.GetCompoundTag("Data");
                    return(new WorldInfo(nbttagcompound3));
                }
                catch (Exception exception1)
                {
                    Utilities.LogException(exception1);
                }
            }

            return(null);
        }
コード例 #6
0
        /// <summary>
        /// Returns an unique new data id for the given prefix and saves the idCounts map to the 'idcounts' file.
        /// </summary>
        public virtual int GetUniqueDataId(string par1Str)
        {
            short short1 = IdCounts[par1Str];

            if (short1 == null)
            {
                short1 = 0;
            }
            else
            {
                short short2 = short1;
                short short3 = short1 = (short)(short1 + 1);
                short _tmp   = short2;
            }

            IdCounts[par1Str] = short1;

            if (SaveHandler == null)
            {
                return((short)short1);
            }

            try
            {
                string file = SaveHandler.GetMapFileFromName("idcounts");

                if (file != null)
                {
                    NBTTagCompound nbttagcompound = new NBTTagCompound();
                    string         s;
                    short          word0;

                    for (IEnumerator <string> iterator = IdCounts.Keys.GetEnumerator(); iterator.MoveNext(); nbttagcompound.SetShort(s, word0))
                    {
                        s     = (string)iterator.Current;
                        word0 = IdCounts[s];
                    }

                    BinaryWriter dataoutputstream = new BinaryWriter(new FileStream(file, FileMode.Create));
                    CompressedStreamTools.Write(nbttagcompound, dataoutputstream);
                    dataoutputstream.Close();
                }
            }
            catch (Exception exception)
            {
                Utilities.LogException(exception);
            }

            return((short)short1);
        }
コード例 #7
0
        /// <summary>
        /// Reads a compressed NBTTagCompound from the FileStream
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: protected NBTTagCompound readNBTTagCompound(BinaryReader par1NetworkStream) throws IOException
        protected virtual NBTTagCompound ReadNBTTagCompound(BinaryReader par1NetworkStream)
        {
            short word0 = par1NetworkStream.ReadInt16();

            if (word0 < 0)
            {
                return(null);
            }
            else
            {
                byte[] abyte0 = new byte[word0];
                par1NetworkStream.Read(abyte0, 0, abyte0.Length);
                return(CompressedStreamTools.Decompress(abyte0));
            }
        }
コード例 #8
0
        /// <summary>
        /// Loads an existing MapDataBase corresponding to the given String id from disk, instantiating the given Class, or
        /// returns null if none such file exists. args: Class to instantiate, String dataid
        /// </summary>
        public virtual WorldSavedData LoadData(Type par1Class, string par2Str)
        {
            WorldSavedData worldsaveddata = LoadedDataMap[par2Str];

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

            if (SaveHandler != null)
            {
                try
                {
                    string file = SaveHandler.GetMapFileFromName(par2Str);

                    if (file != null && File.Exists(file))
                    {
                        try
                        {
                            worldsaveddata = (WorldSavedData)Activator.CreateInstance(par1Class, new object[] { par2Str });
                        }
                        catch (Exception exception1)
                        {
                            throw new Exception(new StringBuilder().Append("Failed to instantiate ").Append(par1Class.ToString()).ToString(), exception1);
                        }

                        FileStream     fileinputstream = new FileStream(file, FileMode.Open);
                        NBTTagCompound nbttagcompound  = CompressedStreamTools.ReadCompressed(fileinputstream);
                        fileinputstream.Close();
                        worldsaveddata.ReadFromNBT(nbttagcompound.GetCompoundTag("data"));
                    }
                }
                catch (Exception exception)
                {
                    Utilities.LogException(exception);
                }
            }

            if (worldsaveddata != null)
            {
                LoadedDataMap[par2Str] = worldsaveddata;
                LoadedDataList.Add(worldsaveddata);
            }

            return(worldsaveddata);
        }
コード例 #9
0
        /// <summary>
        /// Loads the specified(XZ) chunk into the specified world.
        /// </summary>
//JAVA TO C# CONVERTER WARNING: Method 'throws' clauses are not available in .NET:
//ORIGINAL LINE: public Chunk loadChunk(World par1World, int par2, int par3) throws IOException
        public virtual Chunk LoadChunk(World par1World, int par2, int par3)
        {
            NBTTagCompound    nbttagcompound    = null;
            ChunkCoordIntPair chunkcoordintpair = new ChunkCoordIntPair(par2, par3);

            lock (Field_48450_c)
            {
                if (Field_48449_b.Contains(chunkcoordintpair))
                {
                    int i = 0;

                    do
                    {
                        if (i >= Field_48451_a.Count)
                        {
                            break;
                        }

                        if (Field_48451_a[i].Field_48427_a.Equals(chunkcoordintpair))
                        {
                            nbttagcompound = Field_48451_a[i].Field_48426_b;
                            break;
                        }

                        i++;
                    }while (true);
                }
            }

            if (nbttagcompound == null)
            {
                Stream datainputstream = RegionFileCache.GetChunkFileStream(ChunkSaveLocation, par2, par3);

                if (datainputstream != null)
                {
                    nbttagcompound = CompressedStreamTools.Read(new BinaryReader(datainputstream));
                }
                else
                {
                    return(null);
                }
            }

            return(Func_48443_a(par1World, par2, par3, nbttagcompound));
        }
コード例 #10
0
        /// <summary>
        /// Load the server list from servers.dat
        /// </summary>
        private void LoadServerList()
        {
            try
            {
                NBTTagCompound nbttagcompound = CompressedStreamTools.Read(System.IO.Path.Combine(Mc.McDataDir, "servers.dat"));
                NBTTagList     nbttaglist     = nbttagcompound.GetTagList("servers");
                ServerList.Clear();

                for (int i = 0; i < nbttaglist.TagCount(); i++)
                {
                    ServerList.Add(ServerNBTStorage.CreateServerNBTStorage((NBTTagCompound)nbttaglist.TagAt(i)));
                }
            }
            catch (Exception exception)
            {
                Utilities.LogException(exception);
            }
        }
コード例 #11
0
        /// <summary>
        /// Loads the idCounts Map from the 'idcounts' file.
        /// </summary>
        private void LoadIdCounts()
        {
            try
            {
                IdCounts.Clear();

                if (SaveHandler == null)
                {
                    return;
                }

                string file = SaveHandler.GetMapFileFromName("idcounts");

                if (file != null && File.Exists(file))
                {
                    BinaryReader   datainputstream = new BinaryReader(new FileStream(file, FileMode.Open));
                    NBTTagCompound nbttagcompound  = CompressedStreamTools.Read(datainputstream);
                    datainputstream.Close();
                    IEnumerator <NBTBase> iterator = nbttagcompound.GetTags().GetEnumerator();

                    do
                    {
                        if (!iterator.MoveNext())
                        {
                            break;
                        }

                        NBTBase nbtbase = iterator.Current;

                        if (nbtbase is NBTTagShort)
                        {
                            NBTTagShort nbttagshort = (NBTTagShort)nbtbase;
                            string      s           = nbttagshort.GetName();
                            short       word0       = nbttagshort.Data;
                            IdCounts[s] = word0;
                        }
                    }while (true);
                }
            }
            catch (Exception exception)
            {
                Utilities.LogException(exception);
            }
        }
コード例 #12
0
        /// <summary>
        /// Save the server list to servers.dat
        /// </summary>
        private void SaveServerList()
        {
            try
            {
                NBTTagList nbttaglist = new NBTTagList();

                for (int i = 0; i < ServerList.Count; i++)
                {
                    nbttaglist.AppendTag(ServerList[i].GetCompoundTag());
                }

                NBTTagCompound nbttagcompound = new NBTTagCompound();
                nbttagcompound.SetTag("servers", nbttaglist);
                CompressedStreamTools.SafeWrite(nbttagcompound, System.IO.Path.Combine(Mc.McDataDir, "servers.dat"));
            }
            catch (Exception exception)
            {
                Utilities.LogException(exception);
            }
        }
コード例 #13
0
        /// <summary>
        /// Saves the passed in world info.
        /// </summary>
        public virtual void SaveWorldInfo(WorldInfo par1WorldInfo)
        {
            NBTTagCompound nbttagcompound  = par1WorldInfo.GetNBTTagCompound();
            NBTTagCompound nbttagcompound1 = new NBTTagCompound();

            nbttagcompound1.SetTag("Data", nbttagcompound);

            try
            {
                string file  = IOPath.Combine(SaveDirectory, "level.dat_new");
                string file1 = IOPath.Combine(SaveDirectory, "level.dat_old");
                string file2 = IOPath.Combine(SaveDirectory, "level.dat");
                CompressedStreamTools.WriteCompressed(nbttagcompound1, new FileStream(file, FileMode.Create));

                if (File.Exists(file1))
                {
                    File.Delete(file1);
                }

                File.Move(file2, file1);

                if (File.Exists(file2))
                {
                    File.Delete(file2);
                }

                File.Move(file, file2);

                if (File.Exists(file))
                {
                    File.Delete(file);
                }
            }
            catch (Exception exception)
            {
                Console.WriteLine(exception.ToString());
                Console.Write(exception.StackTrace);
            }
        }
コード例 #14
0
        /// <summary>
        /// Loads and returns the world info
        /// </summary>
        public virtual WorldInfo LoadWorldInfo()
        {
            string file = IOPath.Combine(SaveDirectory, "level.dat");

            if (File.Exists(file))
            {
                try
                {
                    NBTTagCompound nbttagcompound  = CompressedStreamTools.ReadCompressed(new FileStream(file, FileMode.Open));
                    NBTTagCompound nbttagcompound2 = nbttagcompound.GetCompoundTag("Data");
                    return(new WorldInfo(nbttagcompound2));
                }
                catch (Exception exception)
                {
                    Console.WriteLine(exception.ToString());
                    Console.Write(exception.StackTrace);
                }
            }

            file = IOPath.Combine(SaveDirectory, "level.dat_old");

            if (File.Exists(file))
            {
                try
                {
                    NBTTagCompound nbttagcompound1 = CompressedStreamTools.ReadCompressed(new FileStream(file, FileMode.Open));
                    NBTTagCompound nbttagcompound3 = nbttagcompound1.GetCompoundTag("Data");
                    return(new WorldInfo(nbttagcompound3));
                }
                catch (Exception exception1)
                {
                    Console.WriteLine(exception1.ToString());
                    Console.Write(exception1.StackTrace);
                }
            }

            return(null);
        }
コード例 #15
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);
            }
        }