mirror of
https://github.com/KillzXGaming/Switch-Toolbox
synced 2024-11-26 22:40:27 +00:00
69 lines
1.8 KiB
C#
69 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);
|
|
}
|
|
}
|
|
}
|
|
}
|