/[RomCheater]/trunk/RomCheater.Core/BitTools.cs
ViewVC logotype

Diff of /trunk/RomCheater.Core/BitTools.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

--- trunk/RomCheater.Core/BitTools.cs	2013/06/05 08:03:28	526
+++ trunk/RomCheater.Core/BitTools.cs	2013/06/05 09:01:44	532
@@ -133,7 +133,7 @@
 
         #region Structure Support
 
-        public static T[] ConvertByteArray<T>(byte[] data) where T : IConvertible
+        public static T[] ConvertByteArray<T>(byte[] data, Func<bool> cancelmethod) where T : IConvertible
         {
             Type t = typeof(T);
             string name = t.Name.ToLower();
@@ -143,8 +143,24 @@
             switch (name)
             {
                 case "byte":  // unsigned byte
+                    list = new List<T>();
+                    using (MemoryStream ms = new MemoryStream(data))
+                    {
+                        using (BinaryReader br = new BinaryReader(ms))
+                        {
+                            while (br.BaseStream.Position < br.BaseStream.Length) { if (cancelmethod.Invoke()) { break; } list.Add((T)Convert.ChangeType(br.ReadByte(), typeof(T))); }
+                        }
+                    }
+                    break;
                 case "sbyte": // signed byte
-                    list = data.Cast<T>().ToList();
+                    list = new List<T>();
+                    using (MemoryStream ms = new MemoryStream(data))
+                    {
+                        using (BinaryReader br = new BinaryReader(ms))
+                        {
+                            while (br.BaseStream.Position < br.BaseStream.Length) { if (cancelmethod.Invoke()) { break; } list.Add((T)Convert.ChangeType(br.ReadSByte(), typeof(T))); }
+                        }
+                    }
                     break;
                 case "int16": // short  
                     list = new List<T>();
@@ -152,7 +168,7 @@
                     {
                         using (BinaryReader br = new BinaryReader(ms))
                         {
-                            while (br.BaseStream.Position < br.BaseStream.Length) { list.Add((T)Convert.ChangeType(br.ReadInt16(), typeof(T))); }
+                            while (br.BaseStream.Position < br.BaseStream.Length) { if (cancelmethod.Invoke()) { break; } list.Add((T)Convert.ChangeType(br.ReadInt16(), typeof(T))); }
                         }
                     }
                     break;
@@ -162,7 +178,7 @@
                     {
                         using (BinaryReader br = new BinaryReader(ms))
                         {
-                            while (br.BaseStream.Position < br.BaseStream.Length) { list.Add((T)Convert.ChangeType(br.ReadUInt16(), typeof(T))); }
+                            while (br.BaseStream.Position < br.BaseStream.Length) { if (cancelmethod.Invoke()) { break; } list.Add((T)Convert.ChangeType(br.ReadUInt16(), typeof(T))); }
                         }
                     }
                     break;
@@ -172,7 +188,7 @@
                     {
                         using (BinaryReader br = new BinaryReader(ms))
                         {
-                            while (br.BaseStream.Position < br.BaseStream.Length) { list.Add((T)Convert.ChangeType(br.ReadInt32(), typeof(T))); }
+                            while (br.BaseStream.Position < br.BaseStream.Length) { if (cancelmethod.Invoke()) { break; } list.Add((T)Convert.ChangeType(br.ReadInt32(), typeof(T))); }
                         }
                     }
                     break;
@@ -182,7 +198,7 @@
                     {
                         using (BinaryReader br = new BinaryReader(ms))
                         {
-                            while (br.BaseStream.Position < br.BaseStream.Length) { list.Add((T)Convert.ChangeType(br.ReadUInt32(), typeof(T))); }
+                            while (br.BaseStream.Position < br.BaseStream.Length) { if (cancelmethod.Invoke()) { break; } list.Add((T)Convert.ChangeType(br.ReadUInt32(), typeof(T))); }
                         }
                     }
                     break;
@@ -192,7 +208,7 @@
                     {
                         using (BinaryReader br = new BinaryReader(ms))
                         {
-                            while (br.BaseStream.Position < br.BaseStream.Length) { list.Add((T)Convert.ChangeType(br.ReadInt64(), typeof(T))); }
+                            while (br.BaseStream.Position < br.BaseStream.Length) { if (cancelmethod.Invoke()) { break; } list.Add((T)Convert.ChangeType(br.ReadInt64(), typeof(T))); }
                         }
                     }
                     break;
@@ -202,7 +218,7 @@
                     {
                         using (BinaryReader br = new BinaryReader(ms))
                         {
-                            while (br.BaseStream.Position < br.BaseStream.Length) { list.Add((T)Convert.ChangeType(br.ReadUInt64(), typeof(T))); }
+                            while (br.BaseStream.Position < br.BaseStream.Length) { if (cancelmethod.Invoke()) { break; } list.Add((T)Convert.ChangeType(br.ReadUInt64(), typeof(T))); }
                         }
                     }
                     break;

 

  ViewVC Help
Powered by ViewVC 1.1.22