LoadFromFile() public method

Loads NBT data from a file. Existing RootTag will be replaced. Compression will be auto-detected.
is null. If given file was not found. If file ended earlier than expected. If file compression could not be detected, or decompressing failed. If an error occurred while parsing data in NBT format. If an I/O error occurred while reading the file.
public LoadFromFile ( [ fileName ) : long
fileName [ Name of the file from which data will be loaded.
return long
示例#1
0
 public Map LoadHeader( string fileName ) {
     if( fileName == null ) throw new ArgumentNullException( "fileName" );
     NbtFile file = new NbtFile();
     file.LoadFromFile( fileName, NbtCompression.None, HeaderTagSelector );
     NbtCompound root = file.RootTag;
     return LoadHeaderInternal( root );
 }
示例#2
0
 /// <summary>
 /// Load a map file into memory and display information
 /// </summary>
 /// <param name="fi">The map file to load</param>
 private void Load(FileInfo fi)
 {
     NbtFile f = new NbtFile();
     fullName = fi.FullName;
     shortName = fi.Name;
     try
     {
         f.LoadFromFile(fullName);
     }
     catch (Exception ex)
     {
         string s = string.Format("Error loading {0}: {1}", fi.Name, ex.Message);
         MessageBox.Show(s);
         return;
     }
     try
     {
         var dataTag = f.RootTag["data"];
         Scale = dataTag["scale"].ByteValue;
         xCenter = dataTag["xCenter"].IntValue;
         zCenter = dataTag["zCenter"].IntValue;
         Height = dataTag["height"].IntValue;
         Width = dataTag["width"].IntValue;
         Dimension = dataTag["dimension"].ByteValue;
         Colors = dataTag["colors"].ByteArrayValue;
         MCMapToBitmap();
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#3
0
 public Map Load( string fileName ) {
     if( fileName == null ) throw new ArgumentNullException( "fileName" );
     NbtFile file = new NbtFile();
     file.LoadFromFile( fileName, NbtCompression.None, null );
     NbtCompound root = file.RootTag;
     Map map = LoadHeaderInternal( root );
     map.Blocks = root["MapData"]["Blocks"].ByteArrayValue;
     return map;
 }
        private void Walk(DirectoryInfo folder)
        {
            foreach (FileInfo file in folder.GetFiles("level.dat"))
            {
                try
                {
                    var nbt = new NbtFile();
                    nbt.LoadFromFile(file.FullName);

                    var data = nbt.RootTag["Data"];
                    this.Worlds[data["LevelName"].StringValue] = folder;
                }
                catch
                {
                    // ignore any load problems...
                }
            }

            foreach (DirectoryInfo child in folder.GetDirectories())
                this.Walk(child);
        }
示例#5
0
 /// <summary>
 /// Read the information from a file and load it into Node.  The file is expected to hold Minecraft map data in NBT format.
 /// </summary>
 /// <param name="fi">Object that holds File information</param>
 public void GetFileInfo(FileInfo fi)
 {
     NbtFile f = null;
     try
     {
         f = new NbtFile();
         f.LoadFromFile(fi.FullName);
         var dataTag = f.RootTag["data"];
         if (dataTag != null)
         {
             mapLevel = dataTag["scale"] == null ? -1 : dataTag["scale"].ByteValue; ;
             xCenter = dataTag["xCenter"] == null ? -1 : dataTag["xCenter"].IntValue;
             zCenter = dataTag["zCenter"] == null ? -1 : dataTag["zCenter"].IntValue;
         }
         Debug.WriteLine(string.Format("{0} {1}", fi.Name, dataTag["scale"] == null ? -1 : dataTag["scale"].ByteValue));
     }
     catch (Exception ex)
     {
         string s = string.Format("{0} error: {1}", fi.Name, ex.Message);
         throw new Exception(s);
     }
 }
示例#6
0
        public void Initialize()
        {
            _basePath = _basePath ?? Config.GetProperty("PCWorldFolder", "World").Trim();

            NbtFile file = new NbtFile();
            file.LoadFromFile(Path.Combine(_basePath, "level.dat"));
            NbtTag dataTag = file.RootTag["Data"];
            _level = new LevelInfo(dataTag);

            _waterOffsetY = (byte) Config.GetProperty("PCWaterOffset", 0);

            _ignore = new List<int>();
            _ignore.Add(23);
            _ignore.Add(25);
            _ignore.Add(28);
            _ignore.Add(29);
            _ignore.Add(33);
            _ignore.Add(34);
            _ignore.Add(36);
            _ignore.Add(55);
            _ignore.Add(69);
            _ignore.Add(70);
            _ignore.Add(71);
            _ignore.Add(72);
            //			_ignore.Add(75);
            //			_ignore.Add(76);
            _ignore.Add(77);
            _ignore.Add(84);
            _ignore.Add(87);
            _ignore.Add(88);
            _ignore.Add(93);
            _ignore.Add(94);
            _ignore.Add(97);
            _ignore.Add(113);
            _ignore.Add(115);
            _ignore.Add(117);
            _ignore.Add(118);
            //			_ignore.Add(123);
            _ignore.Add(131);
            _ignore.Add(132);
            _ignore.Add(138);
            _ignore.Add(140);
            _ignore.Add(143);
            _ignore.Add(144);
            _ignore.Add(145);
            _ignore.Sort();

            _gaps = new List<int>();
            _gaps.Add(23);
            _gaps.Add(25);
            //			_gaps.Add(27);
            _gaps.Add(28);
            _gaps.Add(29);
            _gaps.Add(33);
            _gaps.Add(34);
            _gaps.Add(36);
            _gaps.Add(55);
            //			_gaps.Add(66);
            _gaps.Add(69);
            _gaps.Add(70);
            _gaps.Add(72);
            _gaps.Add(75);
            _gaps.Add(76);
            _gaps.Add(77);
            _gaps.Add(84);
            //			_gaps.Add(87);
            _gaps.Add(88);
            _gaps.Add(90);
            _gaps.Add(93);
            _gaps.Add(94);
            _gaps.Add(95);
            _gaps.Add(97);
            //			_gaps.Add(99);
            //			_gaps.Add(100);
            //			_gaps.Add(106);
            //			_gaps.Add(111);
            _gaps.Add(115);
            _gaps.Add(116);
            _gaps.Add(117);
            _gaps.Add(118);
            _gaps.Add(119);
            //			_gaps.Add(120);
            //			_gaps.Add(121);
            _gaps.Add(122);
            _gaps.Add(123);
            _gaps.Add(124);
            _gaps.Add(125);
            _gaps.Add(126);
            //			_gaps.Add(127);
            _gaps.Add(130);
            _gaps.Add(131);
            _gaps.Add(132);
            _gaps.Add(137);
            _gaps.Add(138);
            _gaps.Add(140);
            _gaps.Add(143);
            _gaps.Add(144);
            _gaps.Add(145);
            _gaps.Add(146);
            _gaps.Add(147);
            _gaps.Add(148);
            _gaps.Add(149);
            _gaps.Add(150);
            _gaps.Add(151);
            _gaps.Add(152);
            _gaps.Add(153);
            _gaps.Add(154);
            _gaps.Add(160);
            _gaps.Add(165);
            _gaps.Add(166);
            _gaps.Add(167);
            _gaps.Add(168);
            _gaps.Add(169);
            _gaps.Sort();
        }
示例#7
0
        public void Init()
        {
            _basePath = _basePath ?? Config.GetProperty("PCWorldFolder", "World").Trim();

            var file = new NbtFile();
            if (File.Exists(Path.Combine(_basePath, "level.dat")))
            {
                file.LoadFromFile(Path.Combine(_basePath, "level.dat"));
                var dataTag = file.RootTag["Data"];
                _level = new LevelInfo(dataTag);
            }
            else
            {
                throw new Exception(@"Could not load Anvil world!");
            }

            _waterOffsetY = (byte)Config.GetProperty("PCWaterOffset", 0);
        }
示例#8
0
		public void LoadAnvilLevelLoadTest()
		{
			NbtFile file = new NbtFile();
			file.LoadFromFile(@"D:\Downloads\KingsLanding1\KingsLanding1\level.dat");
			NbtTag dataTag = file.RootTag["Data"];
			Assert.NotNull(dataTag);

			Assert.NotNull(dataTag["version"]);
			Assert.AreEqual(19133, dataTag["version"].IntValue);
			Assert.NotNull(dataTag["initialized"]);

			var level = new LevelInfo();

			level.GetPropertyValue(dataTag, () => level.Version);
			Assert.AreEqual(19133, level.Version);
			Assert.AreEqual(19133, level.GetPropertyValue(dataTag, () => level.Version));

			Assert.AreEqual(true, level.GetPropertyValue(dataTag, () => level.Initialized));
			Assert.AreEqual("WesterosCraft", level.GetPropertyValue(dataTag, () => level.LevelName));

			var levelFromNbt = new LevelInfo(dataTag);
			Assert.AreEqual(19133, levelFromNbt.Version);
			Assert.AreEqual(true, levelFromNbt.Initialized);
			Assert.AreEqual("WesterosCraft", levelFromNbt.LevelName);
		}
示例#9
0
        internal static World LoadWorld( string worldName, string fileName, WorldDataCategory cats ) {
            if( fileName == null ) throw new ArgumentNullException( "fileName" );
            NbtFile file = new NbtFile();
            file.LoadFromFile( fileName, NbtCompression.None, null );
            NbtCompound root = file.RootTag;

            Map map = LoadHeaderInternal( root );
            if( ( cats & WorldDataCategory.MapData ) != 0 ) {
                map.Blocks = root["MapData"]["Blocks"].ByteArrayValue;
            }

            World world = new World( worldName ) { Map = map };

            NbtCompound backupSettingsTag = root.Get<NbtCompound>( "BackupSettings" );
            if( ( cats & WorldDataCategory.BackupSettings ) != 0 && backupSettingsTag != null ) {
                YesNoAuto backupMode;
                if( !Enum.TryParse( backupSettingsTag["EnabledState"].StringValue, out backupMode ) ) {
                    throw new MapFormatException( "Could not parse BackupEnabledState." );
                }
                world.BackupInterval = TimeSpan.FromSeconds( backupSettingsTag["Interval"].IntValue );
                world.BackupEnabledState = backupMode;
            }

            NbtCompound accessSecurityTag = root.Get<NbtCompound>( "AccessSecurity" );
            if( ( cats & WorldDataCategory.AccessPermissions ) != 0 && accessSecurityTag != null ) {
                world.AccessSecurity = new SecurityController( accessSecurityTag );
            }

            NbtCompound buildSecurityTag = root.Get<NbtCompound>( "BuildSecurity" );
            if( ( cats & WorldDataCategory.BuildPermissions ) != 0 && buildSecurityTag != null ) {
                world.BuildSecurity = new SecurityController( buildSecurityTag );
            }

            NbtCompound envTag = root.Get<NbtCompound>( "Environment" );
            if( ( cats & WorldDataCategory.Environment ) != 0 && envTag != null ) {
                world.CloudColor = envTag["CloudColor"].IntValue;
                world.FogColor = envTag["FogColor"].IntValue;
                world.SkyColor = envTag["SkyColor"].IntValue;
                world.EdgeLevel = envTag["EdgeLevel"].ShortValue;
                world.EdgeBlock = (Block)envTag["EdgeBlock"].ByteValue;
            }

            NbtCompound blockDBSettingsTag = root.Get<NbtCompound>( "BlockDBSettings" );
            if( ( cats & WorldDataCategory.BlockDBSettings ) != 0 && blockDBSettingsTag != null ) {
                world.BlockDB.LoadSettings( blockDBSettingsTag );
            }

            NbtCompound worldEventsTag = root.Get<NbtCompound>( "WorldEvents" );
            if( ( cats & WorldDataCategory.WorldEvents ) != 0 && worldEventsTag != null ) {
                world.LoadedBy = worldEventsTag["LoadedBy"].StringValue;
                world.LoadedOn = DateTimeUtil.TryParseDateTime( worldEventsTag["LoadedOn"].LongValue );
                // TODO: UnloadedBy/UnloadedOn
                world.MapChangedBy = worldEventsTag["MapChangedBy"].StringValue;
                world.MapChangedOn = DateTimeUtil.TryParseDateTime( worldEventsTag["MapChangedOn"].LongValue );
                world.LockedBy = worldEventsTag["LockedBy"].StringValue;
                world.LockedOn = DateTimeUtil.TryParseDateTime( worldEventsTag["LockedOn"].LongValue );
                world.UnlockedBy = worldEventsTag["UnlockedBy"].StringValue;
                world.UnlockedOn = DateTimeUtil.TryParseDateTime( worldEventsTag["UnlockedOn"].LongValue );
            }
            return world;
        }