mirror of
https://github.com/crskycode/GARbro.git
synced 2024-11-23 13:45:34 +08:00
(ArcView.Frame.UnsafeCopy): new private method.
This commit is contained in:
parent
882f3ec461
commit
9819218271
@ -108,9 +108,10 @@ namespace GameRes
|
||||
return ptr;
|
||||
}
|
||||
|
||||
[DllImport("kernel32.dll", SetLastError = true)]
|
||||
[DllImport("kernel32.dll", SetLastError = false)]
|
||||
internal static extern void GetSystemInfo (ref SYSTEM_INFO lpSystemInfo);
|
||||
|
||||
[StructLayout (LayoutKind.Sequential)]
|
||||
internal struct SYSTEM_INFO
|
||||
{
|
||||
internal int dwOemId;
|
||||
@ -354,19 +355,20 @@ namespace GameRes
|
||||
int total = (int)Math.Min (Reserve (offset, count), count);
|
||||
if (buf.Length - buf_offset < total)
|
||||
throw new ArgumentException ("Buffer offset and length are out of bounds.");
|
||||
|
||||
unsafe
|
||||
{
|
||||
byte* ptr = m_view.GetPointer (m_offset);
|
||||
try {
|
||||
Marshal.Copy ((IntPtr)(ptr+(offset-m_offset)), buf, buf_offset, total);
|
||||
} finally {
|
||||
m_view.SafeMemoryMappedViewHandle.ReleasePointer();
|
||||
}
|
||||
}
|
||||
UnsafeCopy (offset, buf, buf_offset, total);
|
||||
return total;
|
||||
}
|
||||
|
||||
private unsafe void UnsafeCopy (long offset, byte[] buf, int buf_offset, int count)
|
||||
{
|
||||
byte* ptr = m_view.GetPointer (m_offset);
|
||||
try {
|
||||
Marshal.Copy ((IntPtr)(ptr+(offset-m_offset)), buf, buf_offset, count);
|
||||
} finally {
|
||||
m_view.SafeMemoryMappedViewHandle.ReleasePointer();
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Read <paramref name="count"/> bytes starting from <paramref name="offset"/> into byte array and return that array.
|
||||
/// Returned array could be less than <paramref name="count"/> bytes length if end of the mapped file was reached.
|
||||
@ -375,7 +377,8 @@ namespace GameRes
|
||||
{
|
||||
count = Math.Min (count, Reserve (offset, count));
|
||||
var data = new byte[count];
|
||||
Read (offset, data, 0, count);
|
||||
if (count != 0)
|
||||
UnsafeCopy (offset, data, 0, data.Length);
|
||||
return data;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user