Example #1
0
        public override bool Save()
        {
            if (_world == null)
            {
                return(false);
            }

            try {
                string  path = Path.Combine(_world.Path, _world.DataDirectory);
                NBTFile nf   = new NBTFile(Path.Combine(path, "idcounts.dat"));

                using (Stream zipstr = nf.GetDataOutputStream(CompressionType.None))
                {
                    if (zipstr == null)
                    {
                        NbtIOException nex = new NbtIOException("Failed to initialize uncompressed NBT stream for output");
                        nex.Data["DataManager"] = this;
                        throw nex;
                    }

                    new NbtTree(BuildTree() as TagNodeCompound).WriteTo(zipstr);
                }

                return(true);
            }
            catch (Exception ex) {
                Exception lex = new Exception("Could not save idcounts.dat file.", ex);
                lex.Data["DataManager"] = this;
                throw lex;
            }
        }
Example #2
0
        /// <summary>
        /// Saves a <see cref="Level"/> object to disk as a standard compressed NBT stream.
        /// </summary>
        /// <returns>True if the level was saved; false otherwise.</returns>
        /// <exception cref="LevelIOException">Thrown when an error is encountered writing out the level.</exception>
        public bool Save()
        {
            if (_world == null)
            {
                return(false);
            }

            try {
                NBTFile nf = new NBTFile(Path.Combine(_world.Path, "level.dat"));
                using (Stream zipstr = nf.GetDataOutputStream())
                {
                    if (zipstr == null)
                    {
                        NbtIOException nex = new NbtIOException("Failed to initialize compressed NBT stream for output");
                        nex.Data["Level"] = this;
                        throw nex;
                    }

                    new NbtTree(BuildTree() as TagNodeCompound).WriteTo(zipstr);
                }

                return(true);
            }
            catch (Exception ex) {
                LevelIOException lex = new LevelIOException("Could not save level file.", ex);
                lex.Data["Level"] = this;
                throw lex;
            }
        }
Example #3
0
        /// <summary>
        /// Saves a <see cref="Map"/> object to disk as a standard compressed NBT stream.
        /// </summary>
        /// <returns>True if the map was saved; false otherwise.</returns>
        /// <exception cref="Exception">Thrown when an error is encountered writing out the level.</exception>
        public bool Save()
        {
            if (_world == null)
            {
                return(false);
            }

            try {
                string  path = Path.Combine(_world.Path, _world.DataDirectory);
                NBTFile nf   = new NBTFile(Path.Combine(path, "map_" + _id + ".dat"));

                Stream zipstr = nf.GetDataOutputStream();
                if (zipstr == null)
                {
                    NbtIOException nex = new NbtIOException("Failed to initialize compressed NBT stream for output");
                    nex.Data["Map"] = this;
                    throw nex;
                }

                new NbtTree(BuildTree() as TagNodeCompound).WriteTo(zipstr);
                zipstr.Close();

                return(true);
            }
            catch (Exception ex) {
                Exception mex = new Exception("Could not save map file.", ex); // TODO: Exception Type
                mex.Data["Map"] = this;
                throw mex;
            }
        }