/[RomCheater]/trunk/RomCheater/Serialization/SearchResultReader.cs
ViewVC logotype

Diff of /trunk/RomCheater/Serialization/SearchResultReader.cs

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

--- trunk/RomCheater/Serialization/SearchResultReader.cs	2013/06/03 17:43:12	475
+++ trunk/RomCheater/Serialization/SearchResultReader.cs	2013/06/03 18:22:20	476
@@ -161,7 +161,7 @@
                         else { items[i] = new ResultItem(v.Address, false, Convert.ToInt64(v.Value)); }
                         break;
                 }
-                arr[i] = null; // free memory used by the data
+                //arr[i] = null; // free memory used by the data
             }
             return items;
         }
@@ -175,21 +175,21 @@
             {
                 var v = arr[i];
                 items[i] = v.Address;
-                arr[i] = null; // free memory used by the data
+                //arr[i] = null; // free memory used by the data
             }
             return items;
         }
-        public ResultType<object>[] GetResults(bool unsigned, SearchDataTypes datatype, Action<int, string> update_progress)
+        public StructResultType<ulong>[] GetResults(bool unsigned, SearchDataTypes datatype, Action<int, string> update_progress)
         {
             return GetResultsInternal(unsigned, datatype, update_progress);
         }
 
-        private ResultType<object>[] GetResultsInternal(bool unsigned, SearchDataTypes datatype, Action<int, string> update_progress)
+        private StructResultType<ulong>[] GetResultsInternal(bool unsigned, SearchDataTypes datatype, Action<int, string> update_progress)
         {
             update_progress.Invoke(0, string.Empty);
             int Last_Whole_Percent_Done = 0;
 
-            ResultType<object>[] results = new ResultType<object>[ResultCount];
+            StructResultType<ulong>[] results = new StructResultType<ulong>[ResultCount];
             using (FileStream fs = CreateReader())
             {
                 using (BinaryReader binReader = new BinaryReader(fs))
@@ -199,23 +199,23 @@
                     for (int i = 0; i < ResultCount; i++)
                     {                        
                         uint Address = binReader.ReadUInt32();
-                        object Value = 0;
+                        ulong Value = 0;
                         switch (datatype)
                         {
                             case SearchDataTypes._8bits:
-                                if (unsigned) { Value = binReader.ReadByte(); } else { Value = binReader.ReadSByte(); }
+                                if (unsigned) { Value = binReader.ReadByte(); } else { Value = (ulong)binReader.ReadSByte(); }
                                 break;
                             case SearchDataTypes._16bits:
-                                if (unsigned) { Value = binReader.ReadUInt16(); } else { Value = binReader.ReadInt16(); }
+                                if (unsigned) { Value = binReader.ReadUInt16(); } else { Value = (ulong)binReader.ReadInt16(); }
                                 break;
                             case SearchDataTypes._32bits:
-                                if (unsigned) { Value = binReader.ReadUInt32(); } else { Value = binReader.ReadInt32(); }
+                                if (unsigned) { Value = binReader.ReadUInt32(); } else { Value = (ulong)binReader.ReadInt32(); }
                                 break;
                             case SearchDataTypes._64bits:
-                                if (unsigned) { Value = binReader.ReadUInt64(); } else { Value = binReader.ReadInt64(); }
+                                if (unsigned) { Value = binReader.ReadUInt64(); } else { Value = (ulong)binReader.ReadInt64(); }
                                 break;
                         }
-                        results[i] = new ResultType<object>(Address, Value);
+                        results[i] = new StructResultType<ulong>(Address, Value);
 
                         double double_percent_done = 100.0 * (double)((double)i / (double)ResultCount);
                         int int_percent_done = (int)double_percent_done;
@@ -247,14 +247,13 @@
             return results;
         }
 
-        public ResultType<object>[] GetResultRangeAtIndex(int index, int count, bool unsigned, SearchDataTypes datatype, Action<int, string> update_progress)
+        public StructResultType<ulong>[] GetResultRangeAtIndex(int index, int count, bool unsigned, SearchDataTypes datatype, Action<int, string> update_progress)
         {
-            ResultType<object>[] results = new ResultType<object>[index+count];
+            StructResultType<ulong>[] results = new StructResultType<ulong>[index + count];
             for (int i = 0; i < count; i++)
             {
-                ResultType<object> result = GetResultAtIndex(i + index, unsigned, datatype, update_progress);
+                StructResultType<ulong> result = GetResultAtIndex(i + index, unsigned, datatype, update_progress);
                 results[i] = result;
-                result = null;
                 //double percent = 100.0 * ((double)i / (double)count);
                 //update_progress.Invoke((int)percent, string.Format("-> Reading Address: 0x{1:x8} from index: 0x{1:x8}", results[i].Address, i + index));
             }
@@ -295,11 +294,11 @@
             }
             return result;
         }
-        public ResultType<object> GetResultAtIndex(int index, bool unsigned, SearchDataTypes datatype, Action<int, string> update_progress)
+        public StructResultType<ulong> GetResultAtIndex(int index, bool unsigned, SearchDataTypes datatype, Action<int, string> update_progress)
         {
             //update_progress.Invoke(0, string.Empty);
             int data_size = sizeof(uint); // address size ... should be 4 bytes (could be 8, if we have a 64-bit address)
-            ResultType<object> result = new ResultType<object>();
+            StructResultType<ulong> result = StructResultType<ulong>.Empty;
             using (FileStream fs = CreateReader())
             {
                 using (BinaryReader binReader = new BinaryReader(fs))
@@ -309,39 +308,40 @@
                     long offset = data_size * index;
                     binReader.BaseStream.Seek(offset, SeekOrigin.Current);
                     uint Address = binReader.ReadUInt32();
-                    object Value = 0;
+                    ulong Value = 0;
                     switch (datatype)
                     {
                         case SearchDataTypes._8bits:
-                            if (unsigned) { Value = binReader.ReadByte(); } else { Value = binReader.ReadSByte(); }
+                            if (unsigned) { Value = binReader.ReadByte(); } else { Value = (ulong)binReader.ReadSByte(); }
                             break;
                         case SearchDataTypes._16bits:
-                            if (unsigned) { Value = binReader.ReadUInt16(); } else { Value = binReader.ReadInt16(); }
+                            if (unsigned) { Value = binReader.ReadUInt16(); } else { Value = (ulong)binReader.ReadInt16(); }
                             break;
                         case SearchDataTypes._32bits:
-                            if (unsigned) { Value = binReader.ReadUInt32(); } else { Value = binReader.ReadInt32(); }
+                            if (unsigned) { Value = binReader.ReadUInt32(); } else { Value = (ulong)binReader.ReadInt32(); }
                             break;
                         case SearchDataTypes._64bits:
-                            if (unsigned) { Value = binReader.ReadUInt64(); } else { Value = binReader.ReadInt64(); }
+                            if (unsigned) { Value = binReader.ReadUInt64(); } else { Value = (ulong)binReader.ReadInt64(); }
                             break;
                     }
-                    result = new ResultType<object>(Address, Value);
+                    result = new StructResultType<ulong>(Address, Value);
                 }
             }
             return result;
         }
 
-        public ResultType<object>[] GetSearchAddressValueMatches(IAcceptsProcessAndConfig iapc, SearchType SearchArgs, Action<int, string> update_progress)
+        public StructResultType<ulong>[] GetSearchAddressValueMatches(IAcceptsProcessAndConfig iapc, SearchType SearchArgs, Action<int, string> update_progress)
         {
             int Last_Whole_Percent_Done = 0;
             bool unsigned = SearchArgs.IsUnsignedDataType;
             SearchDataTypes sdt = SearchArgs.DataType;
-            var addresses = this.GetAddressRangeAtIndex(0, this.ResultCount, unsigned, sdt, update_progress);
+            //var addresses = this.GetAddressRangeAtIndex(0, this.ResultCount, unsigned, sdt, update_progress);
+            var addresses = this.GetResultAddresses(unsigned, sdt, update_progress);
 
 
             uint STEP_SIZE = (uint)sdt/8;
 
-            List<ResultType<object>> foundAddresses = new List<ResultType<object>>();
+            List<StructResultType<ulong>> foundAddresses = new List<StructResultType<ulong>>();
 
             int count = 0;
             int totalcount = addresses.Length;
@@ -394,7 +394,7 @@
                                         }
                                         if (comparer.Compare(Convert.ToByte(Value), value))
                                         {
-                                            foundAddresses.Add(new ResultType<object>(comparer.Address, comparer.Value));
+                                            foundAddresses.Add(new StructResultType<ulong>(comparer.Address, (ulong)comparer.Value));
                                         }
                                     }
                                     #endregion
@@ -430,7 +430,7 @@
                                         }
                                         if (comparer.Compare(Convert.ToSByte(Value), value))
                                         {
-                                            foundAddresses.Add(new ResultType<object>(comparer.Address, comparer.Value));
+                                            foundAddresses.Add(new StructResultType<ulong>(comparer.Address, (ulong)comparer.Value));
                                         }
                                     }
                                     #endregion
@@ -468,7 +468,7 @@
                                         }
                                         if (comparer.Compare(Convert.ToUInt16(Value), value))
                                         {
-                                            foundAddresses.Add(new ResultType<object>(comparer.Address, comparer.Value));
+                                            foundAddresses.Add(new StructResultType<ulong>(comparer.Address, (ulong)comparer.Value));
                                         }
                                     }
                                     #endregion
@@ -504,7 +504,7 @@
                                         }
                                         if (comparer.Compare(Convert.ToInt16(Value), value))
                                         {
-                                            foundAddresses.Add(new ResultType<object>(comparer.Address, comparer.Value));
+                                            foundAddresses.Add(new StructResultType<ulong>(comparer.Address, (ulong)comparer.Value));
                                         }
                                     }
                                     #endregion
@@ -542,7 +542,7 @@
                                         }
                                         if (comparer.Compare(Convert.ToUInt32(Value), value))
                                         {
-                                            foundAddresses.Add(new ResultType<object>(comparer.Address, comparer.Value));
+                                            foundAddresses.Add(new StructResultType<ulong>(comparer.Address, (ulong)comparer.Value));
                                         }
                                     }
                                     #endregion
@@ -578,7 +578,7 @@
                                         }
                                         if (comparer.Compare(Convert.ToInt32(Value), value))
                                         {
-                                            foundAddresses.Add(new ResultType<object>(comparer.Address, comparer.Value));
+                                            foundAddresses.Add(new StructResultType<ulong>(comparer.Address, (ulong)comparer.Value));
                                         }
                                     }
                                     #endregion
@@ -616,7 +616,7 @@
                                         }
                                         if (comparer.Compare(Convert.ToUInt64(Value), value))
                                         {
-                                            foundAddresses.Add(new ResultType<object>(comparer.Address, comparer.Value));
+                                            foundAddresses.Add(new StructResultType<ulong>(comparer.Address, (ulong)comparer.Value));
                                         }
                                     }
                                     #endregion
@@ -652,7 +652,7 @@
                                         }
                                         if (comparer.Compare(Convert.ToInt64(Value), value))
                                         {
-                                            foundAddresses.Add(new ResultType<object>(comparer.Address, comparer.Value));
+                                            foundAddresses.Add(new StructResultType<ulong>(comparer.Address, (ulong)comparer.Value));
                                         }
                                     }
                                     #endregion

 

  ViewVC Help
Powered by ViewVC 1.1.22