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


C# BinaryWriter.WriteString方法代码示例

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


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

示例1: Save

        /// <summary>
        /// Saves the file. The progress parameter is a way for us
        /// to report progress to the calling thread.
        /// </summary>
        /// <param name="progress"></param>
        public async Task Save(string filePath, IProgress<int> progress)
        {
            var stream = new MemoryStream();
            writer = new BinaryWriter(stream);

            writer.Write(DataHeader);
            writer.Write(RowCount);
            writer.Write(getDefaultRecordLength());
            writer.Write(ColumnCount);

            foreach (SHNColumn col in Columns)
            {
                if (col.ColumnName.Contains("UnkCol"))
                {
                    writer.Write(new byte[0x30]);
                }
                else
                {
                    writer.WriteString(col.ColumnName, 0x30);
                }

                if (col.SHNType == SHNType.UnknownLengthString)
                    writer.Write((uint)0x1A);
                else
                    writer.Write(getIDFromType(col.DataType));

                writer.Write(col.Length);
            }

            writeRows(new Progress<int>(p => progress.Report(p)));

            var length = stream.Length;
            var destinationArray = new byte[length];

            Array.Copy(stream.GetBuffer(), destinationArray, length);

            if (Encryption != null)
                Crypter.Crypt(Encryption, destinationArray, 0, destinationArray.Length);
            else
                Crypter.Crypt(destinationArray, 0, destinationArray.Length);

            writer.Close();
            writer = new BinaryWriter(File.Create(filePath));

            writer.Write(BaseHeader);
            writer.Write(destinationArray.Length + 0x24);
            writer.Write(destinationArray);
            writer.Close();

            FilePath = filePath;
        }
开发者ID:Wicious,项目名称:Spark-Editor,代码行数:56,代码来源:SHNFile.cs

示例2: Save

        public static byte[] Save(TDX tdx)
        {
            byte[] buffer;

            using (MemoryStream ms = new MemoryStream())
            using (BinaryWriter bw = new BinaryWriter(ms))
            {
                bw.Write(new byte[] { 0, 2 });

                bw.Write((short)tdx.MipMaps[0].Width);
                bw.Write((short)tdx.MipMaps[0].Height);
                bw.Write((short)tdx.MipMaps.Count);
                bw.Write((int)tdx.flags);
                bw.WriteString(tdx.ShortFormat);

                for (int i = 0; i < tdx.MipMaps.Count; i++) { bw.Write(tdx.MipMaps[i].Data); }

                bw.Flush();
                ms.Flush();

                buffer = ms.ToArray();
            }

            return buffer;
        }
开发者ID:DevilboxGames,项目名称:ToxicRagers,代码行数:25,代码来源:crTDX.cs

示例3: SaveInner

        private void SaveInner(BinaryWriter writer)
        {
            writer.Write(_achievements.Count);
            for (int i = 0; i < _achievements.Length; i++)
            {
                writer.WriteString(_achievements[i].Name);
                writer.Write(_achievements[i].Progression);

                object tag = _achievements[i].Tag;
                if (tag is IBinarySerializable) // ... i guess this is ok
                {
                    writer.Write(tag.Cast<IBinarySerializable>());
                }
            }
        }
开发者ID:JaakkoLipsanen,项目名称:Flai.XNA,代码行数:15,代码来源:AchievementManager.cs

示例4: Save

        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.Write((short)ModelFiles.Count);

            ModelFiles.ForEach(modelFile => {
                writer.WriteString(modelFile);
                writer.Write((byte)0);
            });

            writer.Write((short)TextureFiles.Count);

            TextureFiles.ForEach(texture => {
                writer.WriteString(texture.FilePath);
                writer.Write((byte)0);
                writer.Write((short)(texture.UseSkinShader ? 1 : 0));
                writer.Write((short)(texture.AlphaEnabled ? 1 : 0));
                writer.Write((short)(texture.TwoSided ? 1 : 0));
                writer.Write((short)(texture.AlphaTestEnabled ? 1 : 0));
                writer.Write(texture.AlphaReference);
                writer.Write((short)(texture.DepthTestEnabled ? 1 : 0));
                writer.Write((short)(texture.DepthWriteEnabled ? 1 : 0));
                writer.Write((short)texture.BlendType);
                writer.Write((short)(texture.UseSpecularShader ? 1 : 0));
                writer.Write(texture.Alpha);
                writer.Write((short)texture.GlowType);
                writer.Write(texture.GlowColour.ToVector3());
            });

            writer.Write((short)EffectFiles.Count);

            EffectFiles.ForEach(effectFile => {
                writer.WriteString(effectFile);
                writer.Write((byte)0);
            });

            writer.Write((short)Objects.Count);

            Objects.ForEach(@object => {
                writer.Write((int)@object.BoundingCylinder.Radius);
                writer.Write((int)@object.BoundingCylinder.Center.X);
                writer.Write((int)@object.BoundingCylinder.Center.Y);

                writer.Write((short)@object.Parts.Count);

                if (@object.Parts.Count > 0) {
                    @object.Parts.ForEach(part => {
                        writer.Write(part.Model);
                        writer.Write(part.Texture);

                        if (part.Position != Vector3.Zero) {
                            writer.Write((byte)ModelListPropertyType.Position);
                            writer.Write((byte)(sizeof(float) * 3));
                            writer.Write(part.Position);
                        }

                        if (part.Rotation != Quaternion.Zero) {
                            writer.Write((byte)ModelListPropertyType.Rotation);
                            writer.Write((byte)(sizeof(float) * 4));
                            writer.Write(part.Rotation, true);
                        }

                        if (part.Scale != Vector3.Zero) {
                            writer.Write((byte)ModelListPropertyType.Scale);
                            writer.Write((byte)(sizeof(float) * 3));
                            writer.Write(part.Scale);
                        }

                        if (part.AxisRotation != Quaternion.Zero) {
                            writer.Write((byte)ModelListPropertyType.AxisRotation);
                            writer.Write((byte)(sizeof(float) * 4));
                            writer.Write(part.AxisRotation, true);
                        }

                        if (part.Parent != 0) {
                            writer.Write((byte)ModelListPropertyType.Parent);
                            writer.Write((byte)sizeof(short));
                            writer.Write(part.Parent);
                        }

                        if (part.Collision != 0) {
                            writer.Write((byte)ModelListPropertyType.Collision);
                            writer.Write((byte)sizeof(short));
                            writer.Write((short)part.Collision);
                        }

                        if (string.Compare(part.AnimationFilePath, string.Empty) != 0) {
                            writer.Write((byte)ModelListPropertyType.ConstantAnimation);
                            writer.WriteByteString(part.AnimationFilePath);
                        }

                        if (part.VisibleRangeSet != 0) {
                            writer.Write((byte)ModelListPropertyType.VisibleRangeSet);
                            writer.Write((byte)sizeof(short));
                            writer.Write(part.VisibleRangeSet);
//.........这里部分代码省略.........
开发者ID:Jiwan,项目名称:Revise,代码行数:101,代码来源:ModelListFile.cs

示例5: HelloAsync

 /// <summary>
 /// A simple hello world function that sends the passed message to the server
 /// then immediately returns. To receive notification of the server's response,
 /// add an event handler to <see cref="OnHelloComplete"/>.
 /// </summary>
 /// <param name="message">A String that contains the message to send to the
 /// server.</param>
 public void HelloAsync(string message)
 {
     MemoryStream ms = new MemoryStream();
     BinaryWriter bw = new BinaryWriter(ms, Encoding.UTF8);
     bw.Write(HelloProtocol.PROTOCOL_IDENTIFIER);
     bw.WriteString(message);
     Session.Send(ms);
     Log(Level.Info, string.Format("Client says: {0}", message));
 }
开发者ID:liemqv,项目名称:DotNetOpenServerSDK,代码行数:16,代码来源:HelloProtocolClient.cs

示例6: Serialize

        public override byte[] Serialize()
        {
            MemoryStream mstream = new MemoryStream ();
            BinaryWriter mwriter = new BinaryWriter (mstream);
            //Export data types
            var module = assembly.MainModule;
            mwriter.Write (module.Types.Count);
            foreach (var et in module.Types) {
                //Name of data type
                mwriter.WriteString (et.FullName);
                //Serialized form of data type, prefixed with length for fast-load (we will load and compile 1 class at a time)
                byte[] data = new UALType (et).Serialize ();
                mwriter.Write (data.Length);
                mwriter.Write (data);

            }

            //Export methods import table
            mwriter.Write (UALMethod.MethodTable.Count);
            foreach (var et in UALMethod.MethodTable) {
                mwriter.Write (et.Value);
                mwriter.WriteString (et.Key);
            }

            return mstream.ToArray ();
        }
开发者ID:IDWMaster,项目名称:UALCompiler,代码行数:26,代码来源:UALSpec.cs

示例7: Save

        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.WriteString(Name);
            writer.Write((byte)0);

            for (int h = 0; h < Height; h++) {
                for (int w = 0; w < Width; w++) {
                    writer.Write(values[h, w]);
                }
            }
        }
开发者ID:Jiwan,项目名称:Revise,代码行数:17,代码来源:LevelOfDetailFile.cs

示例8: Save

        public void Save(string path)
        {
            using (BinaryWriter bw = new BinaryWriter(new FileStream(path, FileMode.Create)))
            {
                bw.WriteString("Kaydara FBX Binary");
                bw.Write(new byte[] { 0x20, 0x20, 0x0, 0x1A, 0x0 });
                bw.Write(this.version);

                this.calc_offsets_children_root((int)bw.BaseStream.Position, false);
                this.write_children_root(bw, false);

                bw.Write(new byte[] { 0xfa, 0xbc, 0xab, 0x09, 0xd0, 0xc8, 0xd4, 0x66, 0xb1, 0x76, 0xfb, 0x83, 0x1c, 0xf7, 0x26, 0x7e });
                bw.Write(new byte[4]);

                int ofs = (int)bw.BaseStream.Position;
                int pad = ((ofs + 15) & ~15) - ofs;
                if (pad == 0) { pad = 16; }
                bw.Write(new byte[pad]);

                bw.Write(this.version);
                bw.Write(new byte[120]);
                bw.Write(new byte[] { 0xf8, 0x5a, 0x8c, 0x6a, 0xde, 0xf5, 0xd9, 0x7e, 0xec, 0xe9, 0x0c, 0xe3, 0x75, 0x8f, 0x29, 0x0b });
            }
        }
开发者ID:DevilboxGames,项目名称:ToxicRagers,代码行数:24,代码来源:cFBX.cs

示例9: Write

 /// <summary>
 /// Writes the condition data to the underlying stream.
 /// </summary>
 /// <param name="writer">The writer.</param>
 public void Write(BinaryWriter writer)
 {
     if (UseText) {
         writer.WriteString(Text);
     } else {
         writer.Write(StringID);
     }
 }
开发者ID:Jiwan,项目名称:Revise,代码行数:12,代码来源:SayMessageAction.cs

示例10: Save

        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.Unicode);

            writer.Write(ColumnCount);
            writer.Write(rows.Count);

            long[,] offsets = new long[rows.Count, ColumnCount];

            for (int i = 0; i < rows.Count; i++) {
                LanguageRow row = rows[i];

                for (int j = 0; j < ColumnCount; j++) {
                    offsets[i, j] = stream.Position;

                    writer.Write(0);
                    writer.Write((short)row[j].Length);
                }
            }

            for (int i = 0; i < rows.Count; i++) {
                LanguageRow row = rows[i];

                for (int j = 0; j < ColumnCount; j++) {
                    long offset = stream.Position;
                    writer.WriteString(row[j], Encoding.Unicode);

                    long previousPosition = stream.Position;
                    stream.Seek(offsets[i, j], SeekOrigin.Begin);

                    writer.Write((int)offset);

                    stream.Seek(previousPosition, SeekOrigin.Begin);
                }
            }
        }
开发者ID:Jiwan,项目名称:Revise,代码行数:40,代码来源:LanguageFile.cs

示例11: Save

        private static void Save(BinaryWriter bw, CNT cnt)
        {
            int nameLength = cnt.Name.Length;
            int padding = (((nameLength / 4) + (nameLength % 4 > 0 ? 1 : 0)) * 4) - nameLength;

            bw.Write(nameLength);
            bw.WriteString(cnt.Name);
            bw.Write(new byte[padding]);

            bw.Write((byte)0);

            bw.Write((int)0);

            bw.Write(cnt.Transform.M11);
            bw.Write(cnt.Transform.M12);
            bw.Write(cnt.Transform.M13);
            bw.Write(cnt.Transform.M21);
            bw.Write(cnt.Transform.M22);
            bw.Write(cnt.Transform.M23);
            bw.Write(cnt.Transform.M31);
            bw.Write(cnt.Transform.M32);
            bw.Write(cnt.Transform.M33);
            bw.Write(cnt.Transform.M41);
            bw.Write(cnt.Transform.M42);
            bw.Write(cnt.Transform.M43);

            bw.WriteString(cnt.Section.ToString());

            switch (cnt.Section)
            {
                case NodeType.LITg:
                    if (cnt.EmbeddedLight)
                    {
                        bw.Write(2);
                        LIGHT.Save(bw, cnt.Light);
                    }
                    else
                    {
                        bw.Write(3);
                        nameLength = cnt.LightName.Length;
                        padding = (((nameLength / 4) + (nameLength % 4 > 0 ? 1 : 0)) * 4) - nameLength;

                        bw.Write(cnt.LightName.Length);
                        bw.WriteString(cnt.LightName);
                        bw.Write(new byte[padding]);
                    }
                    break;

                case NodeType.MODL:
                case NodeType.SKIN:
                    nameLength = cnt.Model.Length;
                    padding = (((nameLength / 4) + (nameLength % 4 > 0 ? 1 : 0)) * 4) - nameLength;

                    bw.Write(nameLength);
                    bw.WriteString(cnt.Model);
                    bw.Write(new byte[padding]);
                    break;

                case NodeType.NULL:
                    break;

                default:
                    throw new NotImplementedException(string.Format("Save code for CNT section {0} does not exist!", cnt.Section));
            }

            bw.Write(cnt.Children.Count);
            foreach (CNT c in cnt.Children) { Save(bw, c); }
            bw.Write((int)0);
        }
开发者ID:DevilboxGames,项目名称:ToxicRagers,代码行数:69,代码来源:sCNT.cs

示例12: Save

        public void Save(string path)
        {
            int nameLength, padding;
            this.CalculateExtents();

            using (BinaryWriter bw = new BinaryWriter(new FileStream(path, FileMode.Create)))
            {
                bw.Write(new byte[] { 0x45, 0x23 });    // Magic Number
                bw.Write(new byte[] { 2, 6 });          // Version (6.2)

                bw.Write(new byte[] { 0, 0, 0, 0 });    // Checksum, to calculate
                bw.Write((int)this.flags);

                int prepDataSize = 4 + (this.faces.Count * 16) + 4 + (this.verts.Count * 44) + 2;

                for (int i = 0; i < this.meshes.Count; i++)
                {
                    var mesh = this.meshes[i];

                    prepDataSize += 52;
                    prepDataSize += (4 * mesh.StripList.Count);

                    prepDataSize += 12;
                    prepDataSize += (4 * mesh.TriList.Count);
                }

                bw.Write(prepDataSize);                 // PREP data size

                bw.Write(this.faces.Count);             // USER face count
                bw.Write(this.verts.Count);             // USER vert count

                bw.Write(0);                            // Back filled post save

                bw.Write(this.extents.Radius);
                bw.Write(this.extents.Min.X);
                bw.Write(this.extents.Min.Y);
                bw.Write(this.extents.Min.Z);
                bw.Write(this.extents.Max.X);
                bw.Write(this.extents.Max.Y);
                bw.Write(this.extents.Max.Z);
                bw.Write(this.extents.Centre.X);
                bw.Write(this.extents.Centre.Y);
                bw.Write(this.extents.Centre.Z);

                bw.Write((short)this.Meshes.Count);

                for (int i = 0; i < this.Meshes.Count; i++)
                {
                    nameLength = this.Meshes[i].Name.Length;
                    padding = (((nameLength / 4) + (nameLength % 4 > 0 ? 1 : 0)) * 4) - nameLength + 4;

                    bw.Write(nameLength);
                    bw.WriteString(this.Meshes[i].Name);
                    bw.Write(new byte[padding]);
                }

                bw.Write(this.faces.Count);

                for (int i = 0; i < this.faces.Count; i++)
                {
                    bw.Write((short)this.faces[i].MaterialID);
                    bw.Write((short)0);
                    bw.Write(this.faces[i].Verts[0]);
                    bw.Write(this.faces[i].Verts[1]);
                    bw.Write(this.faces[i].Verts[2]);
                }

                bw.Write(this.verts.Count);

                for (int i = 0; i < this.verts.Count; i++)
                {
                    bw.Write(this.verts[i].Position.X);
                    bw.Write(this.verts[i].Position.Y);
                    bw.Write(this.verts[i].Position.Z);

                    bw.Write(this.verts[i].Normal.X);
                    bw.Write(this.verts[i].Normal.Y);
                    bw.Write(this.verts[i].Normal.Z);

                    bw.Write(this.verts[i].UV.X);
                    bw.Write(this.verts[i].UV.Y);

                    bw.Write(this.verts[i].UV2.X);
                    bw.Write(this.verts[i].UV2.Y);

                    bw.Write(this.verts[i].Colour.R);
                    bw.Write(this.verts[i].Colour.G);
                    bw.Write(this.verts[i].Colour.B);
                    bw.Write(this.verts[i].Colour.A);
                }

                bw.Write((short)this.meshes.Count);

                for (int i = 0; i < this.meshes.Count; i++)
                {
                    var mesh = this.meshes[i];

                    bw.Write(mesh.Extents.Centre.X);
                    bw.Write(mesh.Extents.Centre.Y);
                    bw.Write(mesh.Extents.Centre.Z);
//.........这里部分代码省略.........
开发者ID:DevilboxGames,项目名称:ToxicRagers,代码行数:101,代码来源:sMDL.cs

示例13: writeData

        /**
         * Method declaration
         *
         *
         * @param out
         * @param l
         * @param type
         * @param data
         *
         * @throws IOException
         */
        public static void writeData(BinaryWriter dout, int l, int[] type, object[] data)
        {
            for (int i = 0; i < l; i++)
            {
                object o = data[i];

                if (o == null)
                {
                    dout.Write(NULL);
                }
                else
                {
                    int t = type[i];

                    dout.Write(t);

                    switch (t)
                    {

                        case NULL:
                            o = null;
                            break;

                        case FLOAT:
                        case REAL:
                            dout.Write((float)o);
                            break;

                        case DOUBLE:
                            dout.Write((double)o);
                            break;

                        case BIT:
                            dout.Write((bool)o);
                            break;

                        case TINYINT:
                            dout.Write((byte)o);
                            break;

                        case SMALLINT:
                            dout.Write((short)o);
                            break;

                        case INTEGER:
                            dout.Write((int)o);
                            break;

                        case BIGINT:
                            dout.Write((long)o);
                            break;

                        case BINARY:
                        case VARBINARY:
                        case LONGVARBINARY:
                        case OTHER:
                            byte[] b = ((ByteArray)o).byteValue();
                            dout.Write(b.Length);
                            dout.Write(b);
                            break;

                        default:
                            dout.WriteString(o.ToString());
                            break;
                    }
                }
            }
        }
开发者ID:ricardodemauro,项目名称:SharpHSQL,代码行数:79,代码来源:Column.cs

示例14: Save

        public void Save(string path)
        {
            using (BinaryWriter bw = new BinaryWriter(new FileStream(path, FileMode.Create)))
            {
                BasicFlags basic = 0;
                AdvancedFlags compression = 0;
                int dataSize = 0;

                if (this.planeFormat == PlaneFormat.Format1planeARGB)
                {
                    dataSize = this.planes.First().Output.Length;
                }
                else
                {
                    basic = BasicFlags.Compressed;

                    if (this.planes.Any(p => p.Method == CompressionMethod.RLE && p.PoorCompression))
                    {
                        Parallel.ForEach(
                            this.planes,
                            p =>
                            {
                                p.Compress(CompressionMethod.Huffman);
                            }
                        );

                        compression = AdvancedFlags.Huffman;
                    }
                    else if (this.planes.Any(p => p.Method == CompressionMethod.Huffman))
                    {
                        compression = AdvancedFlags.Huffman;
                    }

                    dataSize = (this.planes.Count * 4) + this.planes.Sum(p => p.DataSize);
                }

                bw.WriteString("IMAGEMAP");
                bw.Write(new byte[] { 0x1, 0x1 }); // version 1.1
                bw.Write((byte)(basic | BasicFlags.DisableDownSample | BasicFlags.DisableMipMaps));
                bw.Write((byte)(compression | AdvancedFlags.DontAutoJPEG));
                bw.Write((int)planeFormat);
                bw.Write(dataSize);
                bw.Write((short)this.width);
                bw.Write((short)this.height);
                bw.Write(0x64);

                if (this.planeFormat != PlaneFormat.Format1planeARGB)
                {
                    foreach (var plane in this.planes.OrderByDescending(p => p.Index))
                    {
                        bw.Write(plane.DataSize);
                    }
                }

                foreach (var plane in this.planes.OrderByDescending(p => p.Index))
                {
                    bw.Write(plane.Output);
                }
            }
        }
开发者ID:DevilboxGames,项目名称:ToxicRagers,代码行数:60,代码来源:sIMG.cs

示例15: Save

        /// <summary>
        /// Saves the file to the specified stream.
        /// </summary>
        /// <param name="stream">The stream to save to.</param>
        public override void Save(Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream, Encoding.GetEncoding("EUC-KR"));

            writer.WriteString(FILE_IDENTIFIER);
            writer.Write((int)ProjectionType);

            writer.Write(ModelView);
            writer.Write(Projection);

            writer.Write(FieldOfView);
            writer.Write(AspectRatio);
            writer.Write(NearPlane);
            writer.Write(FarPlane);

            writer.Write(Eye);
            writer.Write(Center);
            writer.Write(Up);
        }
开发者ID:osROSE,项目名称:UnityRose,代码行数:23,代码来源:CameraFile.cs


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