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


C# Info.ToByteArray方法代码示例

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


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

示例1: Save

        /// <summary>
        /// Saves Tag to the specified File (creates it if it doesn't exist)
        /// </summary>
        /// <param name="filename">filename of file to save tag to</param>
        public void Save(string filename)
        {
            FileStream File = new FileStream(filename, FileMode.Create);
            BinaryWriter binWriter = new BinaryWriter(File);
            Info header = new Info();
            this.Filename = filename;
            header.type = this.Type;

            File.Position = Info.Size;
            //header.cacheInformationOffset = (int)File.Position;
            //binWriter.Write(IsCached);
            //binWriter.Write(Padding.GetBytes(File.Position, 4));
            //binWriter.Write(RawOffsets.Length);
            //foreach (int i in RawOffsets)
            //    binWriter.Write(i);
            //binWriter.Write(StringIdOffsets.Length);
            //foreach (int i in StringIdOffsets)
            //    binWriter.Write(i);
            //binWriter.Write(TagReferenceOffsets.Length);
            //foreach (int i in TagReferenceOffsets)
            //    binWriter.Write(i);
            //binWriter.Write(PointerOffsets.Length);
            //foreach (int i in PointerOffsets)
            //    binWriter.Write(i);

            header.metaOffset = (int)File.Position;
            binWriter.Write(TagStream.ToArray());
            header.metaLength = (int)File.Position - header.metaOffset;

            if (ResourceStream.Length > 0)
            {
                binWriter.Write(Padding.GetBytes(File.Position, 512));

                header.rawOffset = (int)File.Position;
                binWriter.Write(ResourceStream.ToArray());
                header.rawLength = (int)File.Position - header.rawOffset;

                header.rawReferencesCount = ResourceInformation.Length;
                header.rawReferencesOffset = (int)File.Position;
                for (int i = 0; i < ResourceInformation.Length; i++)
                {
                    binWriter.Write(ResourceInformation[i].Address);
                    binWriter.Write(ResourceInformation[i].Length);
                }
            }

            if (Strings.Count > 0)
            {
                binWriter.Write(Padding.GetBytes(File.Position, 512));

                header.stringReferencesCount = Strings.Count;
                header.stringReferencesOffset = (int)File.Position;
                for (int i = 0; i < Strings.Count; i++)
                {
                    binWriter.Write(Encoding.UTF8.GetBytes(Strings[i]));
                    binWriter.Write(byte.MinValue);
                }
                if (Strings.Count > 1)
                    File.Position -= 1;
                header.stringReferencesLength = (int)File.Position - header.stringReferencesOffset;
            }

            if (TagReferences.Count > 0)
            {

                binWriter.Write(Padding.GetBytes(File.Position, 512));

                header.idReferencesOffset = (int)File.Position;
                header.idReferencesCount = TagReferences.Count;
                for (int i = 0; i < TagReferences.Count; i++)
                {
                    if (TagReferences[i] == "{THIS}")
                    {
                        binWriter.Write(Encoding.UTF8.GetBytes(this.Filename));
                    }
                    else
                    {
                        binWriter.Write(Encoding.UTF8.GetBytes(TagReferences[i]));
                    }
                    binWriter.Write(byte.MinValue);
                }
                File.Position -= 1;
                header.idReferencesLength = (int)File.Position - header.idReferencesOffset;
            }
            binWriter.Write(Padding.GetBytes(File.Position, 512));
            File.Position = 0;
            binWriter.Write(header.ToByteArray());

            binWriter.Flush();
            File.Close();
        }
开发者ID:kholdfuzion,项目名称:halo2x-sunfish,代码行数:95,代码来源:Tag.cs


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