1
0
mirror of synced 2024-12-11 15:25:59 +01:00
Switch-Toolbox/Switch_Toolbox_Library/IO/FileWriter.cs
2019-05-01 19:45:50 -04:00

70 lines
1.8 KiB
C#

using Syroot.BinaryData;
using System.IO;
using System.Text;
namespace Switch_Toolbox.Library.IO
{
public class FileWriter : BinaryDataWriter
{
public FileWriter(Stream stream, bool leaveOpen = false)
: base(stream, Encoding.ASCII, leaveOpen)
{
}
public FileWriter(string fileName)
: this(new FileStream(fileName, FileMode.Create, FileAccess.Write, FileShare.Write))
{
}
public FileWriter(byte[] data)
: this(new MemoryStream(data))
{
}
public void Write(Syroot.Maths.Vector2F v)
{
Write(v.X);
Write(v.Y);
}
public void Write(Syroot.Maths.Vector3F v)
{
Write(v.X);
Write(v.Y);
Write(v.Z);
}
public void Write(Syroot.Maths.Vector4F v)
{
Write(v.X);
Write(v.Y);
Write(v.Z);
Write(v.W);
}
public void WriteSignature(string value)
{
Write(Encoding.ASCII.GetBytes(value));
}
public void WriteString(string value)
{
Write(value, BinaryStringFormat.ZeroTerminated);
}
public void WriteUint64Offset(long target)
{
long pos = Position;
using (TemporarySeek(target, SeekOrigin.Begin))
{
Write(pos);
}
}
//
// RelativeOffsetPosition controls the relative position the offset starts at
//
public void WriteUint32Offset(long target, long RelativeOffsetPosition = 0)
{
long pos = Position;
using (TemporarySeek(target, SeekOrigin.Begin))
{
Write((uint)pos - (uint)RelativeOffsetPosition);
}
}
}
}