using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.IO;
namespace Vestris.ResourceLib
{
///
/// Resource utilities.
///
public abstract class ResourceUtil
{
///
/// Pad data to a WORD.
///
/// Binary stream.
/// New position within the binary stream.
internal static long PadToWORD(BinaryWriter w)
{
long pos = w.BaseStream.Position;
if (pos % 2 != 0)
{
long count = 2 - pos % 2;
Pad(w, (UInt16)count);
pos += count;
}
return pos;
}
///
/// Pad bytes.
///
/// Binary stream.
/// Number of bytes to write.
/// New position within the stream.
internal static long Pad(BinaryWriter w, UInt16 len)
{
while (len-- > 0)
w.Write((byte)0);
return w.BaseStream.Position;
}
///
/// Pad data to a DWORD.
///
/// Binary stream.
/// New position within the binary stream.
internal static long PadToDWORD(BinaryWriter w)
{
long pos = w.BaseStream.Position;
if (pos % 4 != 0)
{
long count = 4 - pos % 4;
Pad(w, (UInt16)count);
pos += count;
}
return pos;
}
}
}