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


C# Stream.ReadASCII方法代码示例

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


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

示例1: WavLoader

		public WavLoader(Stream s)
		{
			while (s.Position < s.Length)
			{
				if ((s.Position & 1) == 1)
					s.ReadByte(); // Alignment

				var type = s.ReadASCII(4);
				switch (type)
				{
					case "RIFF":
						FileSize = s.ReadInt32();
						Format = s.ReadASCII(4);
						if (Format != "WAVE")
							throw new NotSupportedException("Not a canonical WAVE file.");
						break;
					case "fmt ":
						FmtChunkSize = s.ReadInt32();
						AudioFormat = s.ReadInt16();
						Type = (WaveType)AudioFormat;
						if (Type != WaveType.Pcm && Type != WaveType.ImaAdpcm)
							throw new NotSupportedException("Compression type is not supported.");
						Channels = s.ReadInt16();
						SampleRate = s.ReadInt32();
						ByteRate = s.ReadInt32();
						BlockAlign = s.ReadInt16();
						BitsPerSample = s.ReadInt16();

						s.ReadBytes(FmtChunkSize - 16);
						break;
					case "fact":
						{
							var chunkSize = s.ReadInt32();
							UncompressedSize = s.ReadInt32();
							s.ReadBytes(chunkSize - 4);
						}

						break;
					case "data":
						DataSize = s.ReadInt32();
						RawOutput = s.ReadBytes(DataSize);
						break;
					default:
						// Ignore unknown chunks
						{
							var chunkSize = s.ReadInt32();
							s.ReadBytes(chunkSize);
						}

						break;
				}
			}

			if (Type == WaveType.ImaAdpcm)
			{
				RawOutput = DecodeImaAdpcmData();
				BitsPerSample = 16;
			}
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:59,代码来源:WavLoader.cs

示例2: BigFile

        public BigFile(FileSystem context, string filename)
        {
            Name = filename;

            s = context.Open(filename);
            try
            {
                if (s.ReadASCII(4) != "BIGF")
                    throw new InvalidDataException("Header is not BIGF");

                // Total archive size.
                s.ReadUInt32();

                var entryCount = s.ReadUInt32();
                if (BitConverter.IsLittleEndian)
                    entryCount = int2.Swap(entryCount);

                // First entry offset? This is apparently bogus for EA's .big files
                // and we don't have to try seeking there since the entries typically start next in EA's .big files.
                s.ReadUInt32();

                for (var i = 0; i < entryCount; i++)
                {
                    var entry = new Entry(s);
                    index.Add(entry.Path, entry);
                }
            }
            catch
            {
                Dispose();
                throw;
            }
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:33,代码来源:BigFile.cs

示例3: MSCabCompression

        public MSCabCompression(Stream stream)
        {
            this.stream = stream;

            var signature = stream.ReadASCII(4);
            if (signature != "MSCF")
                throw new InvalidDataException("Not a Microsoft CAB package!");

            stream.Position += 12;
            var filesOffset = stream.ReadUInt32();
            stream.Position += 6;
            var folderCount = stream.ReadUInt16();
            var fileCount = stream.ReadUInt16();
            if (stream.ReadUInt16() != 0)
                throw new InvalidDataException("Only plain packages (without reserved header space or prev/next archives) are supported!");

            stream.Position += 4;

            folders = new CabFolder[folderCount];
            for (var i = 0; i < folderCount; i++)
            {
                folders[i] = new CabFolder(stream);
                if (folders[i].CompressionType != 1)
                    throw new InvalidDataException("Compression type is not supported");
            }

            files = new CabFile[fileCount];
            stream.Seek(filesOffset, SeekOrigin.Begin);
            for (var i = 0; i < fileCount; i++)
                files[i] = new CabFile(stream);
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:31,代码来源:MSCabCompression.cs

示例4: VxlReader

        public VxlReader(Stream s)
        {
            if (!s.ReadASCII(16).StartsWith("Voxel Animation"))
                throw new InvalidDataException("Invalid vxl header");

            s.ReadUInt32();
            LimbCount = s.ReadUInt32();
            s.ReadUInt32();
            BodySize = s.ReadUInt32();
            s.Seek(770, SeekOrigin.Current);

            // Read Limb headers
            Limbs = new VxlLimb[LimbCount];
            for (var i = 0; i < LimbCount; i++)
            {
                Limbs[i] = new VxlLimb();
                Limbs[i].Name = s.ReadASCII(16);
                s.Seek(12, SeekOrigin.Current);
            }

            // Skip to the Limb footers
            s.Seek(802 + 28*LimbCount + BodySize, SeekOrigin.Begin);

            var LimbDataOffset = new uint[LimbCount];
            for (var i = 0; i < LimbCount; i++)
            {
                LimbDataOffset[i] = s.ReadUInt32();
                s.Seek(8, SeekOrigin.Current);
                Limbs[i].Scale = s.ReadFloat();
                s.Seek(48, SeekOrigin.Current);

                Limbs[i].Bounds = new float[6];
                for (var j = 0; j < 6; j++)
                    Limbs[i].Bounds[j] = s.ReadFloat();
                Limbs[i].Size = s.ReadBytes(3);
                Limbs[i].Type = (NormalType)s.ReadByte();
            }

            for (var i = 0; i < LimbCount; i++)
            {
                s.Seek(802 + 28*LimbCount + LimbDataOffset[i], SeekOrigin.Begin);
                ReadVoxelData(s, Limbs[i]);
            }
        }
开发者ID:TiriliPiitPiit,项目名称:OpenRA,代码行数:44,代码来源:VxlReader.cs

示例5: WavLoader

        public WavLoader(Stream s)
        {
            while (s.Position < s.Length)
            {
                if ((s.Position & 1) == 1)
                    s.ReadByte(); // Alignment

                var type = s.ReadASCII(4);
                switch (type)
                {
                    case "RIFF":
                        FileSize = s.ReadInt32();
                        Format = s.ReadASCII(4);
                        if (Format != "WAVE")
                            throw new NotSupportedException("Not a canonical WAVE file.");
                        break;
                    case "fmt ":
                        FmtChunkSize = s.ReadInt32();
                        if (FmtChunkSize != 16)
                            throw new NotSupportedException("{0} fmt chunk size is not a supported encoding scheme.".F(FmtChunkSize));
                        AudioFormat = s.ReadInt16();
                        if (AudioFormat != 1)
                            throw new NotSupportedException("Non-PCM compression is not supported.");
                        Channels = s.ReadInt16();
                        SampleRate = s.ReadInt32();
                        ByteRate = s.ReadInt32();
                        BlockAlign = s.ReadInt16();
                        BitsPerSample = s.ReadInt16();
                        break;
                    case "data":
                        DataSize = s.ReadInt32();
                        RawOutput = s.ReadBytes(DataSize);
                        break;
                    default:
                        // Ignore unknown chunks
                        var chunkSize = s.ReadInt32();
                        s.ReadBytes(chunkSize);
                        break;
                }
            }
        }
开发者ID:TiriliPiitPiit,项目名称:OpenRA,代码行数:41,代码来源:WavLoader.cs

示例6: InstallShieldPackage

        public InstallShieldPackage(FileSystem context, string filename)
        {
            Name = filename;

            s = context.Open(filename);
            try
            {
                // Parse package header
                var signature = s.ReadUInt32();
                if (signature != 0x8C655D13)
                    throw new InvalidDataException("Not an Installshield package");

                s.Position += 8;
                /*var FileCount = */s.ReadUInt16();
                s.Position += 4;
                /*var ArchiveSize = */s.ReadUInt32();
                s.Position += 19;
                var tocAddress = s.ReadInt32();
                s.Position += 4;
                var dirCount = s.ReadUInt16();

                // Parse the directory list
                s.Position = tocAddress;

                // Parse directories
                var directories = new Dictionary<string, uint>();
                for (var i = 0; i < dirCount; i++)
                {
                    // Parse directory header
                    var fileCount = s.ReadUInt16();
                    var chunkSize = s.ReadUInt16();
                    var nameLength = s.ReadUInt16();
                    var dirName = s.ReadASCII(nameLength);

                    // Skip to the end of the chunk
                    s.ReadBytes(chunkSize - nameLength - 6);
                    directories.Add(dirName, fileCount);
                }

                // Parse files
                foreach (var dir in directories)
                    for (var i = 0; i < dir.Value; i++)
                        ParseFile(s, dir.Key);
            }
            catch
            {
                Dispose();
                throw;
            }
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:50,代码来源:InstallShieldPackage.cs

示例7: WaveLength

        public static float WaveLength(Stream s)
        {
            s.Position = 12;
            var fmt = s.ReadASCII(4);

            if (fmt != "fmt ")
                return 0;

            s.Position = 22;
            var channels = s.ReadInt16();
            var sampleRate = s.ReadInt32();

            s.Position = 34;
            var bitsPerSample = s.ReadInt16();
            var length = s.Length * 8;

            return length / (channels * sampleRate * bitsPerSample);
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:18,代码来源:WavReader.cs

示例8: VqaReader

        public VqaReader(Stream stream)
        {
            this.stream = stream;

            // Decode FORM chunk
            if (stream.ReadASCII(4) != "FORM")
                throw new InvalidDataException("Invalid vqa (invalid FORM section)");
            /*var length = */ stream.ReadUInt32();

            if (stream.ReadASCII(8) != "WVQAVQHD")
                throw new InvalidDataException("Invalid vqa (not WVQAVQHD)");
            /* var length = */stream.ReadUInt32();

            /*var version = */stream.ReadUInt16();
            /*var flags = */stream.ReadUInt16();
            Frames = stream.ReadUInt16();
            Width = stream.ReadUInt16();
            Height = stream.ReadUInt16();

            blockWidth = stream.ReadUInt8();
            blockHeight = stream.ReadUInt8();
            Framerate = stream.ReadUInt8();
            cbParts = stream.ReadUInt8();
            blocks = new int2(Width / blockWidth, Height / blockHeight);

            numColors = stream.ReadUInt16();
            /*var maxBlocks = */stream.ReadUInt16();
            /*var unknown1 = */stream.ReadUInt16();
            /*var unknown2 = */stream.ReadUInt32();

            // Audio
            /*var freq = */stream.ReadUInt16();
            /*var channels = */stream.ReadByte();
            /*var bits = */stream.ReadByte();
            /*var unknown3 = */stream.ReadBytes(14);

            var frameSize = Exts.NextPowerOf2(Math.Max(Width, Height));
            cbf = new byte[Width*Height];
            cbp = new byte[Width*Height];
            palette = new uint[numColors];
            origData = new byte[2*blocks.X*blocks.Y];
            frameData = new uint[frameSize, frameSize];

            var type = stream.ReadASCII(4);
            if (type != "FINF")
            {
                stream.Seek(27, SeekOrigin.Current);
                type = stream.ReadASCII(4);
            }

            /*var length = */stream.ReadUInt16();
            /*var unknown4 = */stream.ReadUInt16();

            // Frame offsets
            offsets = new UInt32[Frames];
            for (var i = 0; i < Frames; i++)
            {
                offsets[i] = stream.ReadUInt32();
                if (offsets[i] > 0x40000000)
                    offsets[i] -= 0x40000000;
                offsets[i] <<= 1;
            }

            CollectAudioData();

            Reset();
        }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:67,代码来源:VqaReader.cs

示例9: DecodeVQFR

        // VQA Frame
        public void DecodeVQFR(Stream s)
        {
            while (true)
            {
                // Chunks are aligned on even bytes; may be padded with a single null
                if (s.Peek() == 0) s.ReadByte();
                var type = s.ReadASCII(4);
                var subchunkLength = (int)int2.Swap(s.ReadUInt32());

                switch(type)
                {
                    // Full frame-modifier
                    case "CBFZ":
                        Format80.DecodeInto(s.ReadBytes(subchunkLength), cbf);
                    break;
                    case "CBF0":
                        cbf = s.ReadBytes(subchunkLength);
                    break;

                    // frame-modifier chunk
                    case "CBP0":
                    case "CBPZ":
                        // Partial buffer is full; dump and recreate
                        if (cbChunk == cbParts)
                        {
                            if (type == "CBP0")
                                cbf = (byte[])cbp.Clone();
                            else
                                Format80.DecodeInto(cbp, cbf);

                            cbOffset = cbChunk = 0;
                        }

                        var bytes = s.ReadBytes(subchunkLength);
                        bytes.CopyTo(cbp,cbOffset);
                        cbOffset += subchunkLength;
                        cbChunk++;
                    break;

                    // Palette
                    case "CPL0":
                        for (var i = 0; i < numColors; i++)
                        {
                            var r = (byte)(s.ReadUInt8() << 2);
                            var g = (byte)(s.ReadUInt8() << 2);
                            var b = (byte)(s.ReadUInt8() << 2);
                            palette[i] = (uint)((255 << 24) | (r << 16) | (g << 8) | b);
                        }
                    break;

                    // Frame data
                    case "VPTZ":
                        Format80.DecodeInto(s.ReadBytes(subchunkLength), origData);
                        // This is the last subchunk
                        return;
                    default:
                        throw new InvalidDataException("Unknown sub-chunk {0}".F(type));
                }
            }
        }
开发者ID:RobotCaleb,项目名称:OpenRA,代码行数:61,代码来源:VqaReader.cs

示例10: LoadSound

        public bool LoadSound(Stream s)
        {
            var type = s.ReadASCII(4);
            if (type != "RIFF")
                return false;

            FileSize = s.ReadInt32();
            Format = s.ReadASCII(4);
            if (Format != "WAVE")
                return false;
            while (s.Position < s.Length)
            {
                if ((s.Position & 1) == 1)
                    s.ReadByte(); // Alignment

                type = s.ReadASCII(4);
                switch (type)
                {
                    case "fmt ":
                        FmtChunkSize = s.ReadInt32();
                        AudioFormat = s.ReadInt16();
                        Type = (WaveType)AudioFormat;

                        if (!Enum.IsDefined(typeof(WaveType), Type))
                            throw new NotSupportedException("Compression type {0} is not supported.".F(AudioFormat));

                        Channels = s.ReadInt16();
                        SampleRate = s.ReadInt32();
                        ByteRate = s.ReadInt32();
                        BlockAlign = s.ReadInt16();
                        BitsPerSample = s.ReadInt16();

                        s.ReadBytes(FmtChunkSize - 16);
                        break;
                    case "fact":
                        var chunkSize = s.ReadInt32();
                        UncompressedSize = s.ReadInt32();
                        s.ReadBytes(chunkSize - 4);
                        break;
                    case "data":
                        DataSize = s.ReadInt32();
                        RawOutput = s.ReadBytes(DataSize);
                        break;
                    default:
                        var unknownChunkSize = s.ReadInt32();
                        s.ReadBytes(unknownChunkSize);
                        break;
                }
            }

            if (Type == WaveType.ImaAdpcm)
            {
                RawOutput = DecodeImaAdpcmData();
                BitsPerSample = 16;
            }

            return true;
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:58,代码来源:WavReader.cs

示例11: ParseFile

        void ParseFile(Stream s, string dirName)
        {
            s.Position += 7;
            var compressedSize = s.ReadUInt32();
            s.Position += 12;
            var chunkSize = s.ReadUInt16();
            s.Position += 4;
            var nameLength = s.ReadByte();
            var fileName = dirName + "\\" + s.ReadASCII(nameLength);

            // Use index syntax to overwrite any duplicate entries with the last value
            index[fileName] = new Entry(accumulatedData, compressedSize);
            accumulatedData += compressedSize;

            // Skip to the end of the chunk
            s.Position += chunkSize - nameLength - 30;
        }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:17,代码来源:InstallShieldPackage.cs

示例12: IsWave

        bool IsWave(Stream s)
        {
            var start = s.Position;
            var type = s.ReadASCII(4);
            s.Position += 4;
            var format = s.ReadASCII(4);
            s.Position = start;

            return type == "RIFF" && format == "WAVE";
        }
开发者ID:pchote,项目名称:OpenRA,代码行数:10,代码来源:WavLoader.cs

示例13: Read

 public static VocFileHeader Read(Stream s)
 {
     VocFileHeader vfh;
     vfh.Description = s.ReadASCII(20);
     vfh.DatablockOffset = s.ReadUInt16();
     vfh.Version = s.ReadUInt16();
     vfh.ID = s.ReadUInt16();
     return vfh;
 }
开发者ID:CH4Code,项目名称:OpenRA,代码行数:9,代码来源:VocLoader.cs

示例14: VqaReader

		public VqaReader(Stream stream)
		{
			this.stream = stream;

			// Decode FORM chunk
			if (stream.ReadASCII(4) != "FORM")
				throw new InvalidDataException("Invalid vqa (invalid FORM section)");
			/*var length = */stream.ReadUInt32();

			if (stream.ReadASCII(8) != "WVQAVQHD")
				throw new InvalidDataException("Invalid vqa (not WVQAVQHD)");
			/*var length2 = */stream.ReadUInt32();

			/*var version = */stream.ReadUInt16();
			videoFlags = stream.ReadUInt16();
			Frames = stream.ReadUInt16();
			Width = stream.ReadUInt16();
			Height = stream.ReadUInt16();

			blockWidth = stream.ReadUInt8();
			blockHeight = stream.ReadUInt8();
			Framerate = stream.ReadUInt8();
			chunkBufferParts = stream.ReadUInt8();
			blocks = new int2(Width / blockWidth, Height / blockHeight);

			numColors = stream.ReadUInt16();
			/*var maxBlocks = */stream.ReadUInt16();
			/*var unknown1 = */stream.ReadUInt16();
			/*var unknown2 = */stream.ReadUInt32();

			// Audio
			sampleRate = stream.ReadUInt16();
			audioChannels = stream.ReadByte();
			sampleBits = stream.ReadByte();

			/*var unknown3 =*/stream.ReadUInt32();
			/*var unknown4 =*/stream.ReadUInt16();
			/*maxCbfzSize =*/stream.ReadUInt32(); // Unreliable

			/*var unknown5 =*/stream.ReadUInt32();

			var frameSize = Exts.NextPowerOf2(Math.Max(Width, Height));

			if (IsHqVqa)
			{
				cbfBuffer = new byte[maxCbfzSize];
				cbf = new byte[maxCbfzSize * 3];
				origData = new byte[maxCbfzSize];
			}
			else
			{
				cbfBuffer = new byte[Width * Height];
				cbf = new byte[Width * Height];
				cbp = new byte[Width * Height];
				origData = new byte[2 * blocks.X * blocks.Y];
			}

			palette = new uint[numColors];
			frameData = new uint[frameSize, frameSize];
			var type = stream.ReadASCII(4);
			while (type != "FINF")
			{
				// Sub type is a file tag
				if (type[3] == 'F')
				{
					var jmp = int2.Swap(stream.ReadUInt32());
					stream.Seek(jmp, SeekOrigin.Current);
					type = stream.ReadASCII(4);
				}
				else
					throw new NotSupportedException("Vqa uses unknown Subtype: {0}".F(type));
			}

			/*var length = */stream.ReadUInt16();
			/*var unknown4 = */stream.ReadUInt16();

			// Frame offsets
			offsets = new uint[Frames];
			for (var i = 0; i < Frames; i++)
			{
				offsets[i] = stream.ReadUInt32();
				if (offsets[i] > 0x40000000)
					offsets[i] -= 0x40000000;
				offsets[i] <<= 1;
			}

			CollectAudioData();

			Reset();
		}
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:90,代码来源:VqaReader.cs

示例15: DecodeVQFR

		// VQA Frame
		public void DecodeVQFR(Stream s, string parentType = "VQFR")
		{
			while (true)
			{
				// Chunks are aligned on even bytes; may be padded with a single null
				if (s.Peek() == 0) s.ReadByte();
				var type = s.ReadASCII(4);
				var subchunkLength = (int)int2.Swap(s.ReadUInt32());

				switch (type)
				{
					// Full frame-modifier
					case "CBFZ":
						var decodeMode = s.Peek() == 0;
						s.ReadBytes(fileBuffer, 0, subchunkLength);
						Array.Clear(cbf, 0, cbf.Length);
						Array.Clear(cbfBuffer, 0, cbfBuffer.Length);
						var decodeCount = 0;
						decodeCount = Format80.DecodeInto(fileBuffer, cbfBuffer, decodeMode ? 1 : 0, decodeMode);
						if ((videoFlags & 0x10) == 16)
						{
							var p = 0;
							for (var i = 0; i < decodeCount; i += 2)
							{
								var packed = cbfBuffer[i + 1] << 8 | cbfBuffer[i];
								/* 15      bit      0
								   0rrrrrgg gggbbbbb
								   HI byte  LO byte*/
								cbf[p++] = (byte)((packed & 0x7C00) >> 7);
								cbf[p++] = (byte)((packed & 0x3E0) >> 2);
								cbf[p++] = (byte)((packed & 0x1f) << 3);
							}
						}
						else
						{
							cbf = cbfBuffer;
						}

						if (parentType == "VQFL")
							return;
						break;
					case "CBF0":
						cbf = s.ReadBytes(subchunkLength);
						break;

					// frame-modifier chunk
					case "CBP0":
					case "CBPZ":
						// Partial buffer is full; dump and recreate
						if (currentChunkBuffer == chunkBufferParts)
						{
							if (type == "CBP0")
								cbf = (byte[])cbp.Clone();
							else
								Format80.DecodeInto(cbp, cbf);

							chunkBufferOffset = currentChunkBuffer = 0;
						}

						var bytes = s.ReadBytes(subchunkLength);
						bytes.CopyTo(cbp, chunkBufferOffset);
						chunkBufferOffset += subchunkLength;
						currentChunkBuffer++;
						break;

					// Palette
					case "CPL0":
						for (var i = 0; i < numColors; i++)
						{
							var r = (byte)(s.ReadUInt8() << 2);
							var g = (byte)(s.ReadUInt8() << 2);
							var b = (byte)(s.ReadUInt8() << 2);
							palette[i] = (uint)((255 << 24) | (r << 16) | (g << 8) | b);
						}

						break;

					// Frame data
					case "VPTZ":
						Format80.DecodeInto(s.ReadBytes(subchunkLength), origData);

						// This is the last subchunk
						return;
					case "VPRZ":
						Array.Clear(origData, 0, origData.Length);
						s.ReadBytes(fileBuffer, 0, subchunkLength);
						if (fileBuffer[0] != 0)
							vtprSize = Format80.DecodeInto(fileBuffer, origData);
						else
							Format80.DecodeInto(fileBuffer, origData, 1, true);
						return;
					case "VPTR":
						Array.Clear(origData, 0, origData.Length);
						s.ReadBytes(origData, 0, subchunkLength);
						vtprSize = subchunkLength;
						return;
					default:
						throw new InvalidDataException("Unknown sub-chunk {0}".F(type));
				}
//.........这里部分代码省略.........
开发者ID:Roger-luo,项目名称:OpenRA,代码行数:101,代码来源:VqaReader.cs


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