/[RomCheater]/trunk/RomCheater/Docking/FloatingMemorySearcher.cs
ViewVC logotype

Diff of /trunk/RomCheater/Docking/FloatingMemorySearcher.cs

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

--- trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/21 05:14:38	401
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2012/06/21 06:30:33	402
@@ -1036,7 +1036,7 @@
             e.Result = st;
             //List<ResultType<object>> tmp_Results = new List<ResultType<object>>();
             List<ResultType<object>> second_tmp_Results = new List<ResultType<object>>();
-            const int ElementsBeforeDisplay = 100;
+            //const int ElementsBeforeDisplay = 100;
             SearchArgs.LogSearchOptions();
             uint STEP_SIZE = (uint)SearchArgs.DataType / 8;
 
@@ -1130,7 +1130,7 @@
                         SearchArgs.IsFirstSearch)
                     {
                         NeedToCompare = false;
-                        second_tmp_Results = null; // Free Memory
+                        //second_tmp_Results = null; // Free Memory
                     }
 
                     if (NeedToCompare)
@@ -1141,243 +1141,215 @@
                             st_nonrange_search.Start();
                             //second_tmp_Results = new List<ResultType<object>>(SearchArgs.Results.Count * 1024);
                             ////second_tmp_Results.c
-                            for (int i = 0; i < SearchArgs.Results.Count; i += 1)
+
+                            using (SearchResultReader reader = new SearchResultReader())
                             {
-                                uint address = SearchArgs.Results[i].Address;
-                                if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
-                                r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
-                                switch (SearchArgs.DataType)
+                                for (int i = 0; i < reader.ResultCount; i += 1)
                                 {
-                                    #region Comparer Support
-                                    #region case SearchDataTypes._8bits:
-                                    case SearchDataTypes._8bits:
-                                        if (SearchArgs.IsUnsignedDataType)
-                                        {
-                                            byte lookup_value = r_ms.ReadByte();
-                                            _8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address);
-                                            byte value = 0;
-                                            if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                            {
-                                                value = Convert.ToByte(SearchArgs.Results[i].Value);
-                                                comparer.Value = value;
-                                            }
-                                            else
-                                            {
-                                                value = Convert.ToByte(SearchArgs.CompareStartValue);
-                                                comparer.Value = value;
-                                            }
-                                            if (comparer.Compare(lookup_value, value))
-                                            {
-                                                //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);                                    
-                                                //second_tmp_Results.Add(_tmp_result);
-                                                //_tmp_result = null; // free memory
-                                                //SearchArgs.Results.RemoveAt(i);
-                                                SearchArgs.Results[i].Value = comparer.Value;
-                                                second_tmp_Results.Add(SearchArgs.Results[i]);
-                                            }
-                                            comparer = null; // free memory
-                                        }
-                                        else
-                                        {
-                                            sbyte lookup_value = r_ms.ReadSByte();
-                                            _8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address);
-                                            sbyte value = 0;
-                                            if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                            {
-                                                value = Convert.ToSByte(SearchArgs.Results[i].Value);
-                                            }
-                                            else
-                                            {
-                                                value = Convert.ToSByte(SearchArgs.CompareStartValue);
-                                            }
-                                            if (comparer.Compare(lookup_value, value))
-                                            {
-                                                //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);                                    
-                                                //second_tmp_Results.Add(_tmp_result);
-                                                //_tmp_result = null; // free memory
-                                                //SearchArgs.Results.RemoveAt(i);
-                                                SearchArgs.Results[i].Value = comparer.Value;
-                                                second_tmp_Results.Add(SearchArgs.Results[i]);
-                                            }
-                                            comparer = null; // free memory
-                                        }
-                                        break;
-                                    #endregion
-                                    #region case SearchDataTypes._16bits:
-                                    case SearchDataTypes._16bits:
-                                        if (SearchArgs.IsUnsignedDataType)
-                                        {
-                                            ushort lookup_value = r_ms.ReadUInt16();
-                                            _16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address);
-                                            ushort value = 0;
-                                            if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                            {
-                                                value = Convert.ToUInt16(SearchArgs.Results[i].Value);
-                                                comparer.Value = value;
-                                            }
-                                            else
-                                            {
-                                                value = Convert.ToUInt16(SearchArgs.CompareStartValue);
-                                                comparer.Value = value;
-                                            }
-                                            if (comparer.Compare(lookup_value, value))
-                                            {
-                                                //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);                                    
-                                                //second_tmp_Results.Add(_tmp_result);
-                                                //_tmp_result = null; // free memory
-                                                //SearchArgs.Results.RemoveAt(i);
-                                                SearchArgs.Results[i].Value = comparer.Value;
-                                                second_tmp_Results.Add(SearchArgs.Results[i]);
-                                            }
-                                            comparer = null; // free memory
-                                        }
-                                        else
-                                        {
-                                            short lookup_value = r_ms.ReadInt16();
-                                            _16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address);
-                                            short value = 0;
-                                            if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                            {
-                                                value = Convert.ToInt16(SearchArgs.Results[i].Value);
-                                            }
-                                            else
-                                            {
-                                                value = Convert.ToInt16(SearchArgs.CompareStartValue);
-                                            }
-                                            if (comparer.Compare(lookup_value, value))
-                                            {
-                                                //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);                                    
-                                                //second_tmp_Results.Add(_tmp_result);
-                                                //_tmp_result = null; // free memory
-                                                //SearchArgs.Results.RemoveAt(i);
-                                                SearchArgs.Results[i].Value = comparer.Value;
-                                                second_tmp_Results.Add(SearchArgs.Results[i]);
-                                            }
-                                            comparer = null; // free memory
-                                        }
-                                        break;
-                                    #endregion
-                                    #region case SearchDataTypes._32bits:
-                                    case SearchDataTypes._32bits:
-                                        if (SearchArgs.IsUnsignedDataType)
-                                        {
-                                            uint lookup_value = r_ms.ReadUInt32();
-                                            _32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address);
-                                            uint value = 0;
-                                            if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                            {
-                                                value = Convert.ToUInt32(SearchArgs.Results[i].Value);
-                                                comparer.Value = value;
+                                    uint address = reader.CurrentAddress();
+                                    if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
+                                    r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
+                                    switch (SearchArgs.DataType)
+                                    {
+                                        #region Comparer Support
+                                        #region case SearchDataTypes._8bits:
+                                        case SearchDataTypes._8bits:
+                                            if (SearchArgs.IsUnsignedDataType)
+                                            {
+                                                byte lookup_value = r_ms.ReadByte();
+                                                _8bit_unsigned_comparer_ comparer = new _8bit_unsigned_comparer_(SearchArgs, address);
+                                                byte value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    value = reader.CurrentResult<byte>();
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToByte(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(lookup_value, value))
+                                                {
+                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                                    second_tmp_Results.Add(_tmp_result);
+                                                }
+                                                comparer = null; // free memory
                                             }
                                             else
                                             {
-                                                value = Convert.ToUInt32(SearchArgs.CompareStartValue);
-                                                comparer.Value = value;
-                                            }
-                                            if (comparer.Compare(lookup_value, value))
-                                            {
-                                                //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);                                    
-                                                //second_tmp_Results.Add(_tmp_result);
-                                                //_tmp_result = null; // free memory
-                                                //SearchArgs.Results.RemoveAt(i);
-                                                SearchArgs.Results[i].Value = comparer.Value;
-                                                second_tmp_Results.Add(SearchArgs.Results[i]);
-                                            }
-                                            comparer = null; // free memory
-                                        }
-                                        else
-                                        {
-                                            int lookup_value = r_ms.ReadInt32();
-                                            _32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address);
-                                            int value = 0;
-                                            if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                            {
-                                                value = Convert.ToInt32(SearchArgs.Results[i].Value);
+                                                sbyte lookup_value = r_ms.ReadSByte();
+                                                _8bit_signed_comparer_ comparer = new _8bit_signed_comparer_(SearchArgs, address);
+                                                sbyte value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    value = reader.CurrentResult<sbyte>();
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToSByte(SearchArgs.CompareStartValue);
+                                                }
+                                                if (comparer.Compare(lookup_value, value))
+                                                {
+                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                                    second_tmp_Results.Add(_tmp_result);
+                                                }
+                                                comparer = null; // free memory
+                                            }
+                                            break;
+                                        #endregion
+                                        #region case SearchDataTypes._16bits:
+                                        case SearchDataTypes._16bits:
+                                            if (SearchArgs.IsUnsignedDataType)
+                                            {
+                                                ushort lookup_value = r_ms.ReadUInt16();
+                                                _16bit_unsigned_comparer_ comparer = new _16bit_unsigned_comparer_(SearchArgs, address);
+                                                ushort value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    value = reader.CurrentResult<ushort>();
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToUInt16(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(lookup_value, value))
+                                                {
+                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                                    second_tmp_Results.Add(_tmp_result);
+                                                }
+                                                comparer = null; // free memory
                                             }
                                             else
                                             {
-                                                value = Convert.ToInt32(SearchArgs.CompareStartValue);
-                                            }
-                                            if (comparer.Compare(lookup_value, value))
-                                            {
-                                                //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);                                    
-                                                //second_tmp_Results.Add(_tmp_result);
-                                                //_tmp_result = null; // free memory
-                                                //SearchArgs.Results.RemoveAt(i);
-                                                SearchArgs.Results[i].Value = comparer.Value;
-                                                second_tmp_Results.Add(SearchArgs.Results[i]);
-                                            }
-                                            comparer = null; // free memory
-                                        }
-                                        break;
-                                    #endregion
-                                    #region case SearchDataTypes._64bits:
-                                    case SearchDataTypes._64bits:
-                                        if (SearchArgs.IsUnsignedDataType)
-                                        {
-                                            ulong lookup_value = r_ms.ReadUInt64();
-                                            _64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address);
-                                            ulong value = 0;
-                                            if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                            {
-                                                value = Convert.ToUInt64(SearchArgs.Results[i].Value);
-                                                comparer.Value = value;
+                                                short lookup_value = r_ms.ReadInt16();
+                                                _16bit_signed_comparer_ comparer = new _16bit_signed_comparer_(SearchArgs, address);
+                                                short value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    value = reader.CurrentResult<short>();
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToInt16(SearchArgs.CompareStartValue);
+                                                }
+                                                if (comparer.Compare(lookup_value, value))
+                                                {
+                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                                    second_tmp_Results.Add(_tmp_result);
+                                                }
+                                                comparer = null; // free memory
+                                            }
+                                            break;
+                                        #endregion
+                                        #region case SearchDataTypes._32bits:
+                                        case SearchDataTypes._32bits:
+                                            if (SearchArgs.IsUnsignedDataType)
+                                            {
+                                                uint lookup_value = reader.CurrentResult<uint>();
+                                                _32bit_unsigned_comparer_ comparer = new _32bit_unsigned_comparer_(SearchArgs, address);
+                                                uint value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    value = reader.CurrentResult<uint>();
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToUInt32(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(lookup_value, value))
+                                                {
+                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                                    second_tmp_Results.Add(_tmp_result);
+                                                }
+                                                comparer = null; // free memory
                                             }
                                             else
                                             {
-                                                value = Convert.ToUInt64(SearchArgs.CompareStartValue);
-                                                comparer.Value = value;
-                                            }
-                                            if (comparer.Compare(lookup_value, value))
-                                            {
-                                                //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);                                    
-                                                //second_tmp_Results.Add(_tmp_result);
-                                                //_tmp_result = null; // free memory
-                                                //SearchArgs.Results.RemoveAt(i);
-                                                SearchArgs.Results[i].Value = comparer.Value;
-                                                second_tmp_Results.Add(SearchArgs.Results[i]);
-                                            }
-                                            comparer = null; // free memory
-                                        }
-                                        else
-                                        {
-                                            long lookup_value = r_ms.ReadInt64();
-                                            _64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address);
-                                            long value = 0;
-                                            if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
-                                            {
-                                                value = Convert.ToInt64(SearchArgs.Results[i].Value);
+                                                int lookup_value = r_ms.ReadInt32();
+                                                _32bit_signed_comparer_ comparer = new _32bit_signed_comparer_(SearchArgs, address);
+                                                int value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    value = reader.CurrentResult<int>();
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToInt32(SearchArgs.CompareStartValue);
+                                                }
+                                                if (comparer.Compare(lookup_value, value))
+                                                {
+                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                                    second_tmp_Results.Add(_tmp_result);
+                                                }
+                                                comparer = null; // free memory
+                                            }
+                                            break;
+                                        #endregion
+                                        #region case SearchDataTypes._64bits:
+                                        case SearchDataTypes._64bits:
+                                            if (SearchArgs.IsUnsignedDataType)
+                                            {
+                                                ulong lookup_value = r_ms.ReadUInt64();
+                                                _64bit_unsigned_comparer_ comparer = new _64bit_unsigned_comparer_(SearchArgs, address);
+                                                ulong value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    value = reader.CurrentResult<ulong>();
+                                                    comparer.Value = value;
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToUInt64(SearchArgs.CompareStartValue);
+                                                    comparer.Value = value;
+                                                }
+                                                if (comparer.Compare(lookup_value, value))
+                                                {
+                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                                    second_tmp_Results.Add(_tmp_result);
+                                                }
+                                                comparer = null; // free memory
                                             }
                                             else
                                             {
-                                                value = Convert.ToInt64(SearchArgs.CompareStartValue);
-                                            }
-                                            if (comparer.Compare(lookup_value, value))
-                                            {
-                                                //ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);                                    
-                                                //second_tmp_Results.Add(_tmp_result);
-                                                //_tmp_result = null; // free memory
-                                                //SearchArgs.Results.RemoveAt(i);
-                                                SearchArgs.Results[i].Value = comparer.Value;
-                                                second_tmp_Results.Add(SearchArgs.Results[i]);
-                                            }
-                                            comparer = null; // free memory
-                                        }
-                                        break;
-                                    #endregion
-                                    #endregion
-                                }
+                                                long lookup_value = r_ms.ReadInt64();
+                                                _64bit_signed_comparer_ comparer = new _64bit_signed_comparer_(SearchArgs, address);
+                                                long value = 0;
+                                                if (SearchArgs.CompareValueType == CompareValueTypes.OldValue)
+                                                {
+                                                    value = reader.CurrentResult<long>();
+                                                }
+                                                else
+                                                {
+                                                    value = Convert.ToInt64(SearchArgs.CompareStartValue);
+                                                }
+                                                if (comparer.Compare(lookup_value, value))
+                                                {
+                                                    ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                                    second_tmp_Results.Add(_tmp_result);
+                                                }
+                                                comparer = null; // free memory
+                                            }
+                                            break;
+                                        #endregion
+                                        #endregion
+                                    }
 
-                                double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
-                                int int_percent_done = (int)double_percent_done;
-                                if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
-                                {
-                                    resultsprogress.Value = int_percent_done;
-                                    resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
-                                    Last_Whole_Percent_Done = int_percent_done;
-                                    //Application.DoEvents();
-                                }
+                                    double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
+                                    int int_percent_done = (int)double_percent_done;
+                                    if (int_percent_done != Last_Whole_Percent_Done)
+                                    {
+                                        resultsprogress.Value = int_percent_done;
+                                        resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart);
+                                        Last_Whole_Percent_Done = int_percent_done;
+                                        //Application.DoEvents();
+                                    }
 
+                                }
                             }
                             st_nonrange_search.Stop();
                             logger.Profiler.WriteLine("Non-Ranged search took a total of {0} seconds to complete.", st_nonrange_search.Elapsed.TotalSeconds);
@@ -1392,43 +1364,46 @@
 
                             start = SearchArgs.CompareStartValue;
                             end = SearchArgs.CompareEndValue;
-                            for (int i = 0; i < SearchArgs.Results.Count; i += 1)
+                            using (SearchResultReader reader = new SearchResultReader())
                             {
-                                uint address = SearchArgs.Results[i].Address;
-                                if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
-                                r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
-                                if (SearchArgs.CompareType == SearchCompareTypes.Between)
+                                for (int i = 0; i < reader.ResultCount; i += 1)
                                 {
-                                    InRangeComparer comparer = new InRangeComparer(address, 0);
-                                    if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
+                                    uint address = reader.CurrentAddress();
+                                    if (MemoryRangeStart > 0 && !SearchArgs.IsFirstSearch) { address = address - MemoryRangeStart; }
+                                    r_ms.BaseStream.Seek(address, SeekOrigin.Begin);
+                                    if (SearchArgs.CompareType == SearchCompareTypes.Between)
                                     {
-                                        SearchArgs.Results[i].Value = comparer.Value;
-                                        second_tmp_Results.Add(SearchArgs.Results[i]);
+                                        InRangeComparer comparer = new InRangeComparer(address, 0);
+                                        if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
+                                        {
+                                            ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                            second_tmp_Results.Add(_tmp_result);
+                                        }
+                                        comparer = null;
                                     }
-                                    comparer = null;
-                                }
-                                else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
-                                {
-                                    NotInRangeComparer comparer = new NotInRangeComparer(address, 0);
-                                    if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
+                                    else if (SearchArgs.CompareType == SearchCompareTypes.NotBetween)
                                     {
-                                        SearchArgs.Results[i].Value = comparer.Value;
-                                        second_tmp_Results.Add(SearchArgs.Results[i]);
+                                        NotInRangeComparer comparer = new NotInRangeComparer(address, 0);
+                                        if (comparer.Compare(start, end, SearchArgs.DataType, SearchArgs.IsUnsignedDataType, r_ms))
+                                        {
+                                            ResultType<object> _tmp_result = new ResultType<object>(comparer.Address, comparer.Value);
+                                            second_tmp_Results.Add(_tmp_result);
+                                        }
+                                        comparer = null;
+                                    }
+                                    else
+                                    {
+                                        throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
+                                    }
+                                    double double_percent_done = 100.0 * (double)((double)i / (double)reader.ResultCount);
+                                    int int_percent_done = (int)double_percent_done;
+                                    if (int_percent_done != Last_Whole_Percent_Done)
+                                    {
+                                        resultsprogress.Value = int_percent_done;
+                                        resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i + MemoryRangeStart);
+                                        Last_Whole_Percent_Done = int_percent_done;
+                                        //Application.DoEvents();
                                     }
-                                    comparer = null;
-                                }
-                                else
-                                {
-                                    throw new InvalidOperationException("Encounted unkown range search type: " + SearchArgs.CompareType);
-                                }
-                                double double_percent_done = 100.0 * (double)((double)i / (double)SearchArgs.Results.Count);
-                                int int_percent_done = (int)double_percent_done;
-                                if (int_percent_done != Last_Whole_Percent_Done && i % ElementsBeforeDisplay == 0)
-                                {
-                                    resultsprogress.Value = int_percent_done;
-                                    resultsprogress.Message = string.Format(" -> Reading Address: 0x{0:x8}", i);
-                                    Last_Whole_Percent_Done = int_percent_done;
-                                    //Application.DoEvents();
                                 }
                             }
                             st_ranged_search.Stop();
@@ -1442,10 +1417,33 @@
                     // leave SearchArgs.Results alone, if false
                     if (NeedToCompare)
                     {
-                        SearchArgs.Results = second_tmp_Results.GetRange(0, second_tmp_Results.Count);
                         // fix addresses when memory start is not zero
-                        if (MemoryRangeStart > 0 && SearchArgs.IsFirstSearch) { for (int i = 0; i < SearchArgs.Results.Count; i++) { SearchArgs.Results[i].Address = SearchArgs.Results[i].Address + MemoryRangeStart; } }
-                        second_tmp_Results = null; // free memory
+                        if (MemoryRangeStart > 0 && SearchArgs.IsFirstSearch)
+                        {
+                            using (SearchResultWriter writer = new SearchResultWriter(second_tmp_Results.Count))
+                            {
+                                for (int i = 0; i < second_tmp_Results.Count; i++)
+                                {
+                                    second_tmp_Results[i].Address = second_tmp_Results[i].Address + MemoryRangeStart;
+                                    switch (sdt)
+                                    {
+                                        case SearchDataTypes._8bits:
+                                            if (unsigned) { writer.WriteResult<Byte>((uint)i, Convert.ToByte(second_tmp_Results[i].Value)); }
+                                            else { writer.WriteResult<SByte>((uint)i, Convert.ToSByte(second_tmp_Results[i].Value)); } break;
+                                        case SearchDataTypes._16bits:
+                                            if (unsigned) { writer.WriteResult<UInt16>((uint)i, Convert.ToUInt16(second_tmp_Results[i].Value)); }
+                                            else { writer.WriteResult<Int16>((uint)i, Convert.ToInt16(second_tmp_Results[i].Value)); } break;
+                                        case SearchDataTypes._32bits:
+                                            if (unsigned) { writer.WriteResult<UInt32>((uint)i, Convert.ToUInt32(second_tmp_Results[i].Value)); }
+                                            else { writer.WriteResult<Int32>((uint)i,Convert.ToInt32(second_tmp_Results[i].Value)); } break;
+                                        case SearchDataTypes._64bits:
+                                            if (unsigned) { writer.WriteResult<UInt64>((uint)i, Convert.ToUInt64(second_tmp_Results[i].Value)); }
+                                            else { writer.WriteResult<Int64>((uint)i, Convert.ToInt64(second_tmp_Results[i].Value)); } break;
+                                    }
+                                }
+                            }
+                        }
+                        second_tmp_Results = null; // free memory                       
                     }
 
                     r_ms.Close();
@@ -1472,47 +1470,53 @@
             }
             
             resultsprogress.Value = 100;
-            logger.Debug.WriteLine(string.Format("Results Count -> 0x{0:x8}", SearchArgs.Results.Count));
 
-            if (SearchArgs.Results.Count == 1) // debug message for 1 result using 32bit unsigned
-                logger.Debug.WriteLine(string.Format("Debug: Found 1 result -> Address: 0x{0:x8} Value: 0x{1:x8}", SearchArgs.Results[0].Address, SearchArgs.Results[0].Value));
+            using (SearchResultReader reader = new SearchResultReader())
+            {
 
-           logger.Info.WriteLine(string.Format("Found 0x{0:x8} results", SearchArgs.Results.Count));
+                logger.Debug.WriteLine(string.Format("Results Count -> 0x{0:x8}", reader.ResultCount));
 
-            if (SearchArgs.Results.Count <= MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY)
-            {
-                lstResults.Items.Clear();
-                List<ResultItem> items = new List<ResultItem>();
-                for (int i = 0; i < SearchArgs.Results.Count; i++)
+
+                if (reader.ResultCount == 1) // debug message for 1 result using 32bit unsigned
+                    logger.Debug.WriteLine(string.Format("Debug: Found 1 result -> Address: 0x{0:x8} Value: 0x{1:x16}", reader.CurrentAddress(), reader.CurrentResult<ulong>()));
+
+                logger.Info.WriteLine(string.Format("Found 0x{0:x8} results", reader.ResultCount));
+
+                if (reader.ResultCount <= MIN_NUMBER_OF_RESULTS_BEFORE_DISPLAY)
                 {
-                    ResultItem item = new ResultItem(0, false);
-                    //item.Text = string.Format("0x{0:x8}", SearchArgs.Results[i].Address);
-                    //item.SubItems.Add(string.Format("0x{0:x8}", SearchArgs.Results[i].Address));
-                    switch (SearchArgs.DataType)
+                    lstResults.Items.Clear();
+                    List<ResultItem> items = new List<ResultItem>();
+                    for (int i = 0; i < reader.ResultCount; i++)
                     {
+                        ResultItem item = new ResultItem(0, false);
+                        //item.Text = string.Format("0x{0:x8}", SearchArgs.Results[i].Address);
+                        //item.SubItems.Add(string.Format("0x{0:x8}", SearchArgs.Results[i].Address));
+                        switch (SearchArgs.DataType)
+                        {
 
-                        case SearchDataTypes._8bits:
-                            if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToByte(SearchArgs.Results[i].Value)); }
-                            else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToSByte(SearchArgs.Results[i].Value)); }
-                            break;
-                        case SearchDataTypes._16bits:
-                            if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt16(SearchArgs.Results[i].Value)); }
-                            else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt16(SearchArgs.Results[i].Value)); }
-                            break;
-                        case SearchDataTypes._32bits:
-                            if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt32(SearchArgs.Results[i].Value)); }
-                            else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt32(SearchArgs.Results[i].Value)); }
-                            break;
-                        case SearchDataTypes._64bits:
-                            if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToUInt64(SearchArgs.Results[i].Value)); }
-                            else { item = new ResultItem(SearchArgs.Results[i].Address, false, Convert.ToInt64(SearchArgs.Results[i].Value)); }
-                            break;
-                    }
+                            case SearchDataTypes._8bits:
+                                if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(reader.CurrentAddress(), false, reader.CurrentResult<byte>()); }
+                                else { item = new ResultItem(reader.CurrentAddress(), false, reader.CurrentResult<sbyte>()); }
+                                break;
+                            case SearchDataTypes._16bits:
+                                if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(reader.CurrentAddress(), false, reader.CurrentResult<ushort>()); }
+                                else { item = new ResultItem(reader.CurrentAddress(), false, reader.CurrentResult<short>()); }
+                                break;
+                            case SearchDataTypes._32bits:
+                                if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(reader.CurrentAddress(), false, reader.CurrentResult<uint>()); }
+                                else { item = new ResultItem(reader.CurrentAddress(), false, reader.CurrentResult<int>()); }
+                                break;
+                            case SearchDataTypes._64bits:
+                                if (SearchArgs.IsUnsignedDataType) { item = new ResultItem(reader.CurrentAddress(), false, reader.CurrentResult<ulong>()); }
+                                else { item = new ResultItem(reader.CurrentAddress(), false, reader.CurrentResult<long>()); }
+                                break;
+                        }
 
-                    if (!items.Contains(item))
-                        items.Add(item);
+                        if (!items.Contains(item))
+                            items.Add(item);
+                    }
+                    lstResults.Items.AddRange(items.ToArray());
                 }
-                lstResults.Items.AddRange(items.ToArray());
             }
 
             this.DoSearchDoneSpecific();
@@ -1675,7 +1679,7 @@
             if (!args.IsFirstSearch && SearchArgs != null)
             {
                 //args.Results.AddRange(SearchArgs.Results.ToArray());
-                args.Results = SearchArgs.Results;
+                //args.Results = SearchArgs.Results;
             }
             SearchArgs = args;
 #if DONOT_HAVE_RANGED_SEARCH_SUPPORT
@@ -1705,8 +1709,8 @@
             //btnCancel.Enabled = false;
             this.DoResetSpecific();
             lstResults.Items.Clear();
-            try { SearchArgs.Results = new List<ResultType<object>>(); }
-            catch { }
+            //try { SearchArgs.Results = new List<ResultType<object>>(); }
+            //catch { }
         }
 
         private void btnCancel_Click(object sender, EventArgs e)

 

  ViewVC Help
Powered by ViewVC 1.1.22