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


C# BinaryWriter.WriteNullTerminatedString方法代码示例

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


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

示例1: Write

        public void Write(string path)
        {
            using (var bw = new BinaryWriter(new FileStream(path, FileMode.Create, FileAccess.Write)))
            {
                bw.Write(Encoding.ASCII.GetBytes("GMAD"));

                bw.Write((byte)Header.Version);
                bw.Write(Header.SteamId);
                bw.Write(Convert.ToUInt64((Header.Timestamp - (new DateTime(1970, 1, 1, 0, 0, 0))).TotalSeconds));
                
                bw.Write((byte)0); // will be content block

                bw.WriteNullTerminatedString(Header.Name);
                bw.WriteNullTerminatedString(Header.Description);
                bw.WriteNullTerminatedString(Header.Author);
                bw.Write(Header.AddonVersion);

                // File table block
                uint fileNumber = 1;

                foreach (var file in Files)
                {
                    bw.Write(fileNumber);
                    bw.WriteNullTerminatedString(file.StrName);
                    bw.Write(file.Size);
                    bw.Write(file.CRC);

                    fileNumber++;
                }

                // End file table
                bw.Write(0);

                // File data
                foreach (var file in Files)
                {
                    if (file.LocalFile == false)
                    {
                        if(Reader != null)
                            bw.Write(Reader.GetFile(file));
                        else
                            throw new GmadWriterException("Using files from existing gmad file, but no reader has been given.");
                    }
                    else
                    {
                        // read file from disk
                        using (var fs = new FileStream(file.PhysicalPath, FileMode.Open, FileAccess.Read))
                        {
                            var buffer = new byte[fs.Length];
                            fs.Read(buffer, 0, buffer.Length);

                            bw.Write(buffer);
                        }
                    }
                }

            }
        }
开发者ID:sswires,项目名称:GMAD.NET,代码行数:58,代码来源:Writer.cs

示例2: Write

        public void Write(Stream outputStream)
        {
            BinaryWriter writer = new BinaryWriter(outputStream, Encoding.UTF8, true);

            long headerPosition = outputStream.Position;

            outputStream.Position += 24;
            int valuesPosition = (int) outputStream.Position;
            foreach (var entry in Entries)
            {
                entry.Offset = (int) outputStream.Position - valuesPosition;
                writer.Write((short) 0x0001);
                writer.WriteNullTerminatedString(entry.Value);
            }

            writer.AlignWrite(4, 0x00);

            int keysPosition = (int) outputStream.Position;
            foreach (var entry in Entries.OrderBy(e => e.Key).ThenByDescending(e => e.Offset))
            {
                writer.Write(entry.Key);
                writer.Write(entry.Offset);
            }

            long endPosition = outputStream.Position;

            outputStream.Position = headerPosition;
            writer.Write(0x474e414c); // LANG
            writer.Write(3);
            writer.Write(0x0000454c); // LE
            writer.Write(Entries.Count);
            writer.Write(valuesPosition);
            writer.Write(keysPosition);

            outputStream.Position = endPosition;
        }
开发者ID:kkkkyue,项目名称:FoxEngine.TranslationTool,代码行数:36,代码来源:LangFile.cs

示例3: Create

        /// <summary>
        /// Compiles the specified addon into the specified stream.
        /// </summary>
        /// <param name="addon">The addon to compile.</param>
        /// <param name="stream">The stream which the result should be written to.</param>
        /// <exception cref="IOExecption">Happens if there is a problem with the specified stream.</exception>
        public static void Create(Addon addon, Stream stream)
        {
            BinaryWriter writer = new BinaryWriter(stream);
            writer.BaseStream.Seek(0, SeekOrigin.Begin);
            writer.BaseStream.SetLength(0);

            // Header (5)
            writer.Write(Addon.Ident.ToCharArray()); // Ident (4)
            writer.Write((char)Addon.Version); // Version (1)
            // SteamID (8) [unused]
            writer.Write((ulong)0);
            // TimeStamp (8)
            writer.Write((ulong)
                (((TimeSpan)(DateTime.Now - new DateTime(1970, 1, 1, 0, 0, 0).ToLocalTime())).TotalSeconds));
            // Required content (a list of strings)
            writer.Write((char)0); // signifies nothing
            // Addon Name (n)
            writer.WriteNullTerminatedString(addon.Title);
            // Addon Description (n)
            writer.WriteNullTerminatedString(addon.DescriptionJSON);
            // Addon Author (n) [unused]
            writer.WriteNullTerminatedString("Author Name");
            // Addon version (4) [unused]
            writer.Write((int)1);

            // File list
            uint fileNum = 0;

            foreach (ContentFile f in addon.Files)
            {
                // Remove prefix / from filename
                string file = f.Path.TrimStart('/');

                fileNum++;

                writer.Write(fileNum); // File number (4)
                writer.WriteNullTerminatedString(file.ToLowerInvariant()); // File name (all lower case!) (n)
                writer.Write(f.Size); // File size (8) unsigned long
                writer.Write(f.CRC); // File CRC (4) long long
            }
            writer.Flush();

            // Zero to signify the end of files
            fileNum = 0;
            writer.Write(fileNum);

            // The files
            foreach (ContentFile f in addon.Files)
            {
                writer.Write(f.Content);
                writer.Flush();
            }

            // CRC what we've written (to verify that the download isn't shitted) (4)
            writer.Seek(0, SeekOrigin.Begin);
            byte[] buffer_whole = new byte[writer.BaseStream.Length];
            writer.BaseStream.Read(buffer_whole, 0, (int)writer.BaseStream.Length);
            ulong addonCRC = System.Cryptography.CRC32.ComputeChecksum(buffer_whole);
            writer.Write(addonCRC);
            writer.Flush();

            writer.BaseStream.Seek(0, SeekOrigin.Begin);
        }
开发者ID:JohnnyCrazy,项目名称:SharpGMad,代码行数:69,代码来源:Writer.cs

示例4: Serialize

        /// <summary>
        /// Serializes the current object into a byte array.
        /// </summary>
        public byte[] Serialize()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    foreach (KeyValuePair<long, string> doodadName in this.DoodadNames)
                    {
                        bw.WriteNullTerminatedString(doodadName.Value);
                    }
                }

                return ms.ToArray();
            }
        }
开发者ID:Nihlus,项目名称:libwarcraft,代码行数:18,代码来源:ModelDoodadPaths.cs

示例5: Serialize

        public byte[] Serialize()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    foreach (string filename in this.Filenames)
                    {
                        bw.WriteNullTerminatedString(filename);
                    }
                }

                return ms.ToArray();
            }
        }
开发者ID:Nihlus,项目名称:libwarcraft,代码行数:15,代码来源:TerrainWorldModelObjects.cs

示例6: Serialize

        public byte[] Serialize()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    // Each block begins with two empty strings
                    bw.Write('\0');
                    bw.Write('\0');

                    // Then the actual data
                    for (int i = 0; i < this.GroupNames.Count; ++i)
                    {
                        bw.WriteNullTerminatedString(this.GroupNames.ElementAt(i).Value);
                    }

                    // Then zero padding to an even 4-byte boundary at the end
                    long count = 4 - (ms.Position % 4);
                    if (count < 4)
                    {
                        for (long i = 0; i < count; ++i)
                        {
                            bw.Write('\0');
                        }
                    }
                }

                return ms.ToArray();
            }
        }
开发者ID:Nihlus,项目名称:libwarcraft,代码行数:30,代码来源:ModelGroupNames.cs

示例7: WriteString

 public void WriteString(Stream output)
 {
     BinaryWriter writer = new BinaryWriter(output, Encoding.Default, true);
     StringOffset = (int) output.Position;
     string value = ValueEncrypted ? Encoding.Default.GetString(EncryptedValue) : Value;
     StringLength = value.Length;
     writer.WriteNullTerminatedString(value);
 }
开发者ID:Last-Bullet-Development,项目名称:GzsTool,代码行数:8,代码来源:FpkString.cs

示例8: Serialize

        public byte[] Serialize()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    foreach (KeyValuePair<long, string> texture in this.Textures)
                    {
                        if (ms.Position % 4 == 0)
                        {
                            bw.WriteNullTerminatedString(texture.Value);
                        }
                        else
                        {
                            // Pad with nulls, then write
                            long stringPadCount = 4 - (ms.Position % 4);
                            for (int i = 0; i < stringPadCount; ++i)
                            {
                                bw.Write('\0');
                            }

                            bw.WriteNullTerminatedString(texture.Value);
                        }
                    }

                    // Finally, pad until the next alignment
                    long padCount = 4 - (ms.Position % 4);
                    for (int i = 0; i < padCount; ++i)
                    {
                        bw.Write('\0');
                    }
                }

                return ms.ToArray();
            }
        }
开发者ID:Nihlus,项目名称:libwarcraft,代码行数:36,代码来源:ModelTextures.cs

示例9: Serialize

        public byte[] Serialize()
        {
            using (MemoryStream ms = new MemoryStream())
            {
                using (BinaryWriter bw = new BinaryWriter(ms))
                {
                    if (string.IsNullOrEmpty(this.SkyboxName))
                    {
                        bw.Write(new byte[4]);
                    }
                    else
                    {
                        bw.WriteNullTerminatedString(this.SkyboxName);
                    }
                }

                return ms.ToArray();
            }
        }
开发者ID:Nihlus,项目名称:libwarcraft,代码行数:19,代码来源:ModelSkybox.cs


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