当前位置: 首页>>代码示例>>C#>>正文


C# BinaryReader.ReadChars方法代码示例

本文整理汇总了C#中System.IO.BinaryReader.ReadChars方法的典型用法代码示例。如果您正苦于以下问题:C# BinaryReader.ReadChars方法的具体用法?C# BinaryReader.ReadChars怎么用?C# BinaryReader.ReadChars使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.IO.BinaryReader的用法示例。


在下文中一共展示了BinaryReader.ReadChars方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Read

        public override void Read(string fileIn)
        {
            BinaryReader br = new BinaryReader(File.OpenRead(fileIn));
            nscr = new sNSCR();

            // Generic header
            nscr.header.id = br.ReadChars(4);
            nscr.header.endianess = br.ReadUInt16();
            if (nscr.header.endianess == 0xFFFE)
                nscr.header.id.Reverse<char>();
            nscr.header.constant = br.ReadUInt16();
            nscr.header.file_size = br.ReadUInt32();
            nscr.header.header_size = br.ReadUInt16();
            nscr.header.nSection = br.ReadUInt16();

            // Read section
            nscr.nrcs.id = br.ReadChars(4);
            nscr.nrcs.section_size = br.ReadUInt32();
            nscr.nrcs.width = br.ReadUInt16();
            nscr.nrcs.height = br.ReadUInt16();
            nscr.nrcs.padding = br.ReadUInt32();
            nscr.nrcs.data_size = br.ReadUInt32();
            nscr.nrcs.mapData = new NTFS[nscr.nrcs.data_size / 2];

            for (int i = 0; i < nscr.nrcs.mapData.Length; i++)
                nscr.nrcs.mapData[i] = Actions.MapInfo(br.ReadUInt16());

            br.Close();

            Set_Map(nscr.nrcs.mapData, true, nscr.nrcs.width, nscr.nrcs.height);
        }
开发者ID:MetLob,项目名称:tinke,代码行数:31,代码来源:NSCR.cs

示例2: LoadDirectoriesFromStream

        protected void LoadDirectoriesFromStream( BinaryReader reader )
        {
            Directories = new List<DirectoryEntry>();

            while( reader.PeekChar() != INT_RecordSeparator )
            {
                var entry = CreateDirectoryObject();
                char[] buffer = reader.ReadChars( Leader.SizeFieldTag );
                string tag = new string( buffer );
                if( tag == "0000" )
                    entry.Tag = DirectoryDataType.Filename;
                else if( tag == "0001" )
                    entry.Tag = DirectoryDataType.DDFRecordIdentifier;
                else
                    entry.Tag = (DirectoryDataType)Enum.Parse( typeof( DirectoryDataType ), tag );
                if( entry.Tag == DirectoryDataType.Unknown )
                    throw new InvalidDataException( String.Format("Unknown tag {0}", tag) );
                buffer = reader.ReadChars( Leader.SizeFieldLength );
                entry.Length = int.Parse( new string( buffer ) );
                buffer = reader.ReadChars( Leader.SizeFieldPos );
                entry.Position = int.Parse( new string( buffer ) );
                Directories.Add( entry );
            }
            reader.Read();
        }
开发者ID:PeteFohl,项目名称:SDTS-Browser,代码行数:25,代码来源:Record.cs

示例3: ReadFromFile

        public static TileSet ReadFromFile(string fileName)
        {
            var data = ZFile.ReadFile(fileName);
            if (data == null)
                return null;

            var reader = new BinaryReader(new MemoryStream(data));
            var tileSet = new TileSet(null);

            tileSet.Signature		= new string(reader.ReadChars(4));
            tileSet.Version			= new string(reader.ReadChars(4));
            tileSet.ColorDepth		= (BitsPerColor)reader.ReadByte();
            tileSet.ExtendedOptions = ZMath.GetBool(reader.ReadByte());
            var tileDataSize		= reader.ReadByte();		// maybe can be check for some conditions?
            var nameLength			= reader.ReadByte();
            var tilesCount			= reader.ReadInt32();
            tileSet.Name			= new string(reader.ReadChars(64), 0, nameLength);

            for (int i = 0; i < tilesCount; i++)
            {
                try		{	tileSet.Add(new Tile(reader.ReadUInt64()));	}
                catch	{	return null;	}
            }

            return tileSet;
        }
开发者ID:ZeroByte1987,项目名称:ConsoleGames,代码行数:26,代码来源:TileSet.cs

示例4: GetGameData

        public FruaGameData GetGameData()
        {
            var data = new FruaGameData();

            using (var stream = new FileStream(_fullPath, FileMode.Open, FileAccess.Read))
            {
                using (var reader = new BinaryReader(stream))
                {
                    data.Name = new string(reader.ReadChars(32)).RemoveNulls();
                    data.StartingXp = reader.ReadInt32();
                    data.StartingPp = reader.ReadInt32();
                    data.StartingGems = reader.ReadInt32();
                    data.StartingJewelry = reader.ReadInt32();
                    data.StartingModule = reader.ReadByte();
                    data.StartingTown = reader.ReadByte();
                    data.StartingEquipment = reader.ReadByte();

                    reader.ReadByte(); // unused or unknown byte

                    for (int i = 0; i < 8; i++)
                    {
                        data.Keys.Add(new string(reader.ReadChars(16)).RemoveNulls());
                    }

                    for (int i = 0; i < 12; i++)
                    {
                        data.Items.Add(new string(reader.ReadChars(16)).RemoveNulls());
                    }

                    data.Password = new string(reader.ReadChars(15)).RemoveNulls();
                }
            }

            return data;
        }
开发者ID:bsimser,项目名称:goldbox,代码行数:35,代码来源:FruaGameDataFile.cs

示例5: ReadTextures

        public TextureArchive[] ReadTextures(BinaryReader pacStream)
        {
            int nfiles = pacStream.ReadInt32();
            pacStream.ReadBytes(12); //The rest of the header. Not important...

            var textures = new TextureArchive[nfiles];
            for (var i = 0; i < nfiles; i++)
            {
                var texture = new TextureArchive();
                texture.alignedstring = new string(pacStream.ReadChars(16));

                texture.extension = new string(pacStream.ReadChars(4));
                texture.size = pacStream.ReadInt32();
                texture.offset = pacStream.ReadInt32();
                pacStream.ReadBytes(4);

                var pos = pacStream.BaseStream.Position;
                pacStream.BaseStream.Position = texture.offset;
                texture.stream = pacStream.ReadBytes(texture.size);
                pacStream.BaseStream.Position = pos;
                textures[i] = texture;
            }

            return textures;
        }
开发者ID:zaq12345,项目名称:WWE2K15-Tools,代码行数:25,代码来源:TextureParser.cs

示例6: Entity

        /// <summary>
        /// Creates a new entity that was embedded next in the stream
        /// </summary>
        /// <param name="stream">The System.IO.BinaryReader to use.</param>
        public Entity(BinaryReader stream)
        {
            X = stream.ReadInt16();
            Y = stream.ReadInt16();
            Layer = stream.ReadInt16();
            Scripts = new List<string>();
            Type = (EntityType)stream.ReadInt16();
            stream.ReadBytes(8);

            short len;
            if (Type == EntityType.Person)
            {
                len = stream.ReadInt16();
                Name = new string(stream.ReadChars(len));
                len = stream.ReadInt16();
                Spriteset = new string(stream.ReadChars(len));
                int scripts = stream.ReadInt16();

                // read the person script data
                for (int i = 0; i < scripts; ++i)
                {
                    len = stream.ReadInt16();
                    Scripts.Add(new string(stream.ReadChars(len)));
                }

                stream.ReadBytes(16); // reserved
            }
            else
            {
                len = stream.ReadInt16();
                Function = new string(stream.ReadChars(len));
                Trigger = new CompiledMethod(Program._engine, Function);
            }
        }
开发者ID:Radnen,项目名称:sphere-sfml,代码行数:38,代码来源:Entity.cs

示例7: Entity

        /// <summary>
        /// Creates a new entity that was embedded next in the stream
        /// </summary>
        /// <param name="stream">The System.IO.BinaryReader to use.</param>
        public Entity(BinaryReader stream)
        {
            X = stream.ReadInt16();
            Y = stream.ReadInt16();
            Layer = stream.ReadInt16();
            Scripts = new List<string>();
            Type = (EntityType)stream.ReadInt16();
            stream.ReadBytes(8);

            short len;
            if (Type == EntityType.Person)
            {
                len = stream.ReadInt16();
                Name = new string(stream.ReadChars(len));
                len = stream.ReadInt16();
                Spriteset = new string(stream.ReadChars(len));
                int scripts = stream.ReadInt16();

                // read the person script data
                for (int i = 0; i < scripts; ++i)
                {
                    len = stream.ReadInt16();
                    Scripts.Add(new string(stream.ReadChars(len)));
                }

                stream.ReadBytes(16); // reserved
                _graphic = new Bitmap(Properties.Resources.person);
            }
            else
            {
                len = stream.ReadInt16();
                Function = new string(stream.ReadChars(len));
                _graphic = new Bitmap(Properties.Resources.trigger);
            }
        }
开发者ID:Radnen,项目名称:spherestudio,代码行数:39,代码来源:Entity.cs

示例8: ReadUHL

        private UserHeaderLabel ReadUHL(BinaryReader br)
        {
            char[] header = br.ReadChars(4);
            if (new string(header) != "UHL1")
                throw new Exception("Wrong UHL header");

            UserHeaderLabel uhl = new UserHeaderLabel();

            uhl.Longitude = ReadGeoAngle(br, 3, 2);
            uhl.Latitude = ReadGeoAngle(br, 3, 2);
            uhl.LonInterval = ReadInterval(br);
            uhl.LatInterval = ReadInterval(br);

            char[] accuracy = br.ReadChars(4);
            char[] classification = br.ReadChars(3);
            char[] uniqueRef = br.ReadChars(12);

            uhl.Accuracy = new string(accuracy);
            uhl.Classification = new string(classification);
            uhl.UniqueRef = new string(uniqueRef);

            uhl.LongitudeLines = ReadInt(br, 4);
            uhl.LatitudePoints = ReadInt(br, 4);
            uhl.MultipleAccuracy = br.ReadChar() == '1';
            char[] reserved = br.ReadChars(24);

            return uhl;
        }
开发者ID:itaibh,项目名称:GeoUtils.Net,代码行数:28,代码来源:DTEDFile.cs

示例9: FsaNajka

 public FsaNajka(Stream stream, bool leaveOpen = false)
 {
     using (var file = new BinaryReader(stream, Encoding.UTF8, leaveOpen))
     {
         if (new string(file.ReadChars(4)) != "@naj")
             throw new Exception("Invalid header");
         if (file.ReadByte() != 1)
             throw new Exception("Invalid version");
         _type = file.ReadByte();
         _id2Char = file.ReadChars(file.ReadByte());
         _tree = file.ReadBytes((int)(file.BaseStream.Length - file.BaseStream.Position));
     }
     _id2ConvertedChar = new char[4][];
     _id2ConvertedChar[0] = _id2Char;
     _id2ConvertedChar[1] = new char[_id2Char.Length];
     _id2ConvertedChar[2] = new char[_id2Char.Length];
     _id2ConvertedChar[3] = new char[_id2Char.Length];
     for (var i = 0; i < _id2Char.Length; i++)
     {
         _id2ConvertedChar[1][i] = char.ToLowerInvariant(_id2Char[i]);
         _id2ConvertedChar[2][i] = _id2Char[i].RemoveDiacritics();
         _id2ConvertedChar[3][i] = char.ToLowerInvariant(_id2ConvertedChar[2][i]);
     }
     _nodePrefix = SinkTo(0, '!');
     _nodePostfix = SinkTo(0, '^');
 }
开发者ID:Bobris,项目名称:Najka,代码行数:26,代码来源:FsaNajka.cs

示例10: Load

        public void Load(string destinationDirectory, string resourceName, BinaryReader binaryReader)
        {
            var start = binaryReader.BaseStream.Position;
            uint totalLength = binaryReader.ReadUInt32();
            var container = new string(binaryReader.ReadChars(4));

            switch (container) {
                case "FORM":
                case "RIFF":
                    uint length = binaryReader.ReadUInt32(); // this is probably not really a length, with values like 0xcccccccc
                    var header = new string(binaryReader.ReadChars(4));
                    switch (header) {
                        case "XMID":
                        case "XDIR":
                            new XMidiLoader().Load(destinationDirectory, resourceName, binaryReader, totalLength);
                            break;
                        case "WAVE":
                            break;
                    }
                    break;
                default:
                    // Possibly a WAV but without a header
                    binaryReader.BaseStream.Seek(start, SeekOrigin.Begin);
                    new WaveLoader().Load(destinationDirectory, resourceName, binaryReader, (int)totalLength, true);
                    break;
            }
        }
开发者ID:asik,项目名称:Settlers-2-Remake,代码行数:27,代码来源:SoundLoader.cs

示例11: BIF_KEY

        public BIF_KEY(String filename)
        {
            BinaryReader br = new BinaryReader(new FileStream(filename, FileMode.Open));

            signature = br.ReadChars(4);
            version = br.ReadChars(4);

            FILETABLE_ENTRIES = br.ReadUInt32();
            KEYTABLE_ENTRIES = br.ReadUInt32();
            br.ReadBytes(4);

            FILETABLE_OFFSET = br.ReadUInt32();
            KEYTABLE_OFFSET = br.ReadUInt32();
            BUILD_YEAR += br.ReadUInt32();
            BUILD_DAY = br.ReadUInt32();

               // MessageBox.Show(this+"");

            br.BaseStream.Seek(FILETABLE_OFFSET, SeekOrigin.Begin);

            for (int i = 0; i < FILETABLE_ENTRIES; i++)
            {
                FILETABLE.Add(new BIF_FILETABLE_ENTRY(br));
            }

            br.BaseStream.Seek(KEYTABLE_OFFSET, SeekOrigin.Begin);

            for (int i = 0; i < KEYTABLE_ENTRIES; i++)
            {
                BIF_KEYTABLE_ENTRY key = new BIF_KEYTABLE_ENTRY(br);
                FILETABLE[(int)key.ResourceIdx].ownedResources.Add(key);
            }

            br.Close();
        }
开发者ID:returns-null,项目名称:GeraltOfBIFFia,代码行数:35,代码来源:BIF_KEY.cs

示例12: wavefile

        public wavefile(FileStream file)
        {
            BinaryReader binRead = new BinaryReader(file);

            //head data
            ChunkID =  binRead.ReadChars(4);
            ChunkSize = binRead.ReadInt32();
            Format = binRead.ReadChars(4);
            Subchunk1ID = binRead.ReadChars(4);
            Subchunk1Size = binRead.ReadInt32();//in bytes
            AudioFormat = binRead.ReadInt16();
            NumChannels = binRead.ReadInt16();
            SampleRate = binRead.ReadInt32();//samples per second?
            ByteRate = binRead.ReadInt32();
            BlockAlign = binRead.ReadInt16();
            BitsPerSample = binRead.ReadInt16();
            Subchunk2ID = binRead.ReadChars(4);
            Subchunk2Size = binRead.ReadInt32();//in bytes

            int numSamples = Subchunk2Size / (BitsPerSample / 8);
            data = new byte[numSamples];
            wave = new float[numSamples];

            data = binRead.ReadBytes(numSamples);

            for (int i = 0; i < numSamples; i++)
            {
                wave[i] = ((float)data[i] - 128) / 128;
            }
        }
开发者ID:Dvorak-the-Explorak,项目名称:music,代码行数:30,代码来源:wavefile.cs

示例13: ReadPrintDataRec

        //-------------------------------------------------------------------------------
        private static void ReadPrintDataRec(short i, BinaryReader f, StreamWriter log)
        {
            short id;
            char[] code = new char[3];
            char[] name = new char[17];
            char[] continent = new char[11];
            char[] region = new char[10];
            int surfaceArea;
            short yearOfIndep;
            long population;
            float lifeExp;
            int gnp;

            id = f.ReadInt16();
            code = f.ReadChars(3);
            name = f.ReadChars(17);
            continent = f.ReadChars(11);
            region = f.ReadChars(10);
            surfaceArea = f.ReadInt32();
            yearOfIndep = f.ReadInt16();
            population = f.ReadInt64();
            lifeExp = f.ReadSingle();
            gnp = f.ReadInt32();
            if (id == 0)
                log.WriteLine("[{0:000}] EMPTY SPOT", i);
            else
                log.WriteLine("[{0:000}] {1:000}|{2}|{3}|{4}|{5}|" +
                    "{6,10:N0}|{7,5}|{8,13:N0}|{9,4:N1}|{10,9:N0}|",
                    i, id, new string(code), new string(name),
                    new string(continent), new string(region),
                    surfaceArea, yearOfIndep, population, lifeExp, gnp);
        }
开发者ID:TheKidCoder,项目名称:CS-3310,代码行数:33,代码来源:DisplayBackupFileProg.cs

示例14: DbmReader

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="file">Path to the DBM module to open.</param>
        public DbmReader(string file)
        {
            using (var dbm = new BinaryReader(File.OpenRead(file)))
            {
                // Header
                HeaderID = new string(dbm.ReadChars(4));

                // Skip to module name. Also cut off any padded bytes.
                dbm.BaseStream.Position = 0x10;
                string modName = new string(dbm.ReadChars(44));
                ModuleName = modName.Substring(0, modName.LastIndexOf('\0'));

                // Number of instruments.
                dbm.BaseStream.Position = NameChunkOffset + NameChunkSize + 8; // + 8 is to skip over the chunk name and length indicators.
                NumInstruments = BitConverter.IsLittleEndian ? dbm.ReadInt16()>>8 : dbm.ReadInt16();

                // Number of samples
                dbm.BaseStream.Position = NameChunkOffset + NameChunkSize + 10;
                NumSamples = BitConverter.IsLittleEndian ? dbm.ReadInt16()>>8 : dbm.ReadInt16();

                // Number of songs.
                dbm.BaseStream.Position = NameChunkOffset + NameChunkSize + 12;
                NumSongs = BitConverter.IsLittleEndian ? dbm.ReadInt16()>>8 : dbm.ReadInt16();

                // Number of patterns
                dbm.BaseStream.Position = NameChunkOffset + NameChunkSize + 14;
                NumPatterns = BitConverter.IsLittleEndian ? dbm.ReadInt16()>>8 : dbm.ReadInt16();

                // Number of channels
                dbm.BaseStream.Position = NameChunkOffset + NameChunkSize + 16;
                NumChannels = BitConverter.IsLittleEndian ? dbm.ReadInt16()>>8 : dbm.ReadInt16();
            }
        }
开发者ID:lioncash,项目名称:GameMusicInfoLib,代码行数:37,代码来源:DbmReader.cs

示例15: PsfReader

        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="path">Path to the PSF file</param>
        public PsfReader(string path)
        {
            using (var fs = new BinaryReader(File.OpenRead(path)))
            {
                // Header ID
                HeaderID = new string(fs.ReadChars(3));

                // Skip version byte (don't care)
                fs.BaseStream.Position += 1;

                // Reserved area length and compressed data length
                int resLen  = fs.ReadInt32();
                int dataLen = fs.ReadInt32();

                // CRC32 of the data
                CRC32 = fs.ReadUInt32();

                // Skip those lengths, we don't read any of this.
                fs.BaseStream.Position += (resLen + dataLen);

                // Check if we have any metadata, and read it if we do.
                bool endOfStream = (fs.BaseStream.Position == fs.BaseStream.Length);
                if (!endOfStream && new string(fs.ReadChars(5)) == "[TAG]")
                {
                    // Now read in the metadata
                    this.tag = new string(fs.ReadChars((int)(fs.BaseStream.Length - fs.BaseStream.Position)));

                    // Check for "_lib[n]" tags
                    ReferencedLibs = ParseIncludedLibs();

                    // Actual tag metadata
                    Artist     = GetInfo("artist=");
                    Game       = GetInfo("game=");
                    SongTitle  = GetInfo("title=");
                    Genre      = GetInfo("genre=");
                    Copyright  = GetInfo("copyright=");
                    Year       = GetInfo("year=");
                    Comment    = GetInfo("comment=");
                    XSFRipper  = GetXSFRipper(path);
                    Volume     = GetInfo("volume=");
                    Length     = GetInfo("length=");
                    FadeLength = GetInfo("fade=");
                }
                else
                {
                    Artist     = "N/A";
                    Game       = "N/A";
                    SongTitle  = "N/A";
                    Genre      = "N/A";
                    Copyright  = "N/A";
                    Year       = "N/A";
                    Comment    = "N/A";
                    XSFRipper  = "N/A";
                    Volume     = "N/A";
                    Length     = "N/A";
                    FadeLength = "N/A";
                }
            }
        }
开发者ID:lioncash,项目名称:GameMusicInfoLib,代码行数:63,代码来源:PsfReader.cs


注:本文中的System.IO.BinaryReader.ReadChars方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。