コード例 #1
0
    public override TagCompound Load(string fileName, NbtOptions options)
    {
      TagCompound tag;
      BinaryTagReader reader;

      if (string.IsNullOrEmpty(fileName))
        throw new ArgumentNullException("fileName");

      if (!File.Exists(fileName))
        throw new FileNotFoundException("Cannot find source file.", fileName);

      //Check if gzipped stream
      try
      {
        using (FileStream input = File.OpenRead(fileName))
        {
          using (GZipStream gzipStream = new GZipStream(input, CompressionMode.Decompress))
          {
            reader = new BinaryTagReader(gzipStream, NbtOptions.Header);
            tag = (TagCompound)reader.Read();
          }
        }
      }
      catch (Exception)
      {
        tag = null;
      }

      if (tag != null)
        return tag;

      //Try Deflate stream
      try
      {
        using (FileStream input = File.OpenRead(fileName))
        {
          using (DeflateStream deflateStream = new DeflateStream(input, CompressionMode.Decompress))
          {
            reader = new BinaryTagReader(deflateStream, NbtOptions.Header);
            tag = (TagCompound)reader.Read();
          }
        }
      }
      catch (Exception)
      {
        tag = null;
      }

      if (tag != null)
        return tag;

      //Assume uncompressed stream
      using (FileStream input = File.OpenRead(fileName))
      {
        reader = new BinaryTagReader(input, NbtOptions.Header);
        tag = (TagCompound)reader.Read();
      }

      return tag;
    }
コード例 #2
0
 private void ConvertSchematicToJson()
 {
     using (var stream = this.sourceFile.OpenRead())
     {
         var reader = new BinaryTagReader(stream, NbtOptions.None);
         var tag = reader.Read();
         Diagnostic.Info("Read: {0}", tag.ToString());
     }
 }