From 98192182716556234a21266c7233c68b49a7db27 Mon Sep 17 00:00:00 2001 From: morkt Date: Fri, 23 Dec 2016 23:17:53 +0400 Subject: [PATCH] (ArcView.Frame.UnsafeCopy): new private method. --- GameRes/ArcView.cs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/GameRes/ArcView.cs b/GameRes/ArcView.cs index 778e1657..5ef1eb5a 100644 --- a/GameRes/ArcView.cs +++ b/GameRes/ArcView.cs @@ -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(); + } + } + /// /// Read bytes starting from into byte array and return that array. /// Returned array could be less than 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; }