本文整理汇总了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();
}