/[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	2013/06/05 08:19:24	530
+++ trunk/RomCheater/Docking/FloatingMemorySearcher.cs	2013/06/05 09:01:44	532
@@ -75,8 +75,10 @@
             resultsprogress.Message = pm.Message;
         }
 
+        private bool ShouldCancelAnySearchOperation() { return SearchWorkerThread.CancellationPending; }
+
         private void UpdateProgress(int progress, string message)
-        {
+        {            
             // detach the progress update from execution within the current thread (so it does not block a cpu-intensive or long running sequence)
             Thread t = new Thread(new ParameterizedThreadStart(thread_UpdateProgress));
             t.SetApartmentState(ApartmentState.STA);
@@ -1828,7 +1830,7 @@
                                     if (unsigned)
                                     {
                                         #region 8bits - unsigned
-                                        var t_data = BitTools.ConvertByteArray<byte>(data);
+                                        var t_data = BitTools.ConvertByteArray<byte>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                         foreach (var Value in t_data)
                                         {
                                             if (SearchWorkerThread.CancellationPending) { break; }
@@ -1869,7 +1871,7 @@
                                     else
                                     {
                                         #region 8bits - signed
-                                        var t_data = BitTools.ConvertByteArray<sbyte>(data);
+                                        var t_data = BitTools.ConvertByteArray<sbyte>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                         foreach (var Value in t_data)
                                         {
                                             if (SearchWorkerThread.CancellationPending) { break; }
@@ -1911,7 +1913,7 @@
                                     if (unsigned)
                                     {
                                         #region 16bits - unsigned
-                                          var t_data = BitTools.ConvertByteArray<ushort>(data);
+                                        var t_data = BitTools.ConvertByteArray<ushort>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                           foreach (var Value in t_data)
                                           {
                                               if (SearchWorkerThread.CancellationPending) { break; }
@@ -1952,7 +1954,7 @@
                                     else
                                     {
                                         #region 16bits - signed
-                                         var t_data = BitTools.ConvertByteArray<short>(data);
+                                        var t_data = BitTools.ConvertByteArray<short>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                          foreach (var Value in t_data)
                                          {
                                              if (SearchWorkerThread.CancellationPending) { break; }
@@ -1994,7 +1996,7 @@
                                     if (unsigned)
                                     {
                                         #region 32bits - unsigned
-                                         var t_data = BitTools.ConvertByteArray<uint>(data);
+                                        var t_data = BitTools.ConvertByteArray<uint>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                          foreach (var Value in t_data)
                                          {
                                              if (SearchWorkerThread.CancellationPending) { break; }
@@ -2035,7 +2037,7 @@
                                     else
                                     {
                                         #region 32bits - signed
-                                         var t_data = BitTools.ConvertByteArray<int>(data);
+                                        var t_data = BitTools.ConvertByteArray<int>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                          foreach (var Value in t_data)
                                          {
                                              if (SearchWorkerThread.CancellationPending) { break; }
@@ -2077,7 +2079,7 @@
                                     if (unsigned)
                                     {
                                         #region 64bits - unsigned
-                                         var t_data = BitTools.ConvertByteArray<ulong>(data);
+                                        var t_data = BitTools.ConvertByteArray<ulong>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                          foreach (var Value in t_data)
                                          {
                                              if (SearchWorkerThread.CancellationPending) { break; }
@@ -2118,7 +2120,7 @@
                                     else
                                     {
                                         #region 64bits - signed
-                                         var t_data = BitTools.ConvertByteArray<long>(data);
+                                        var t_data = BitTools.ConvertByteArray<long>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                          foreach (var Value in t_data)
                                          {
                                              if (SearchWorkerThread.CancellationPending) { break; }
@@ -2275,6 +2277,15 @@
                                 int index = 0;
                                 foreach (var k in reader.GetResults(SearchArgs.IsUnsignedDataType, SearchArgs.DataType, new Action<int, string>(UpdateProgress)))
                                 {
+                                    if (SearchWorkerThread.CancellationPending)
+                                    {
+                                        provider_st.Stop();
+                                        st.Stop();
+                                        writer.CancelRequest();
+                                        writer.Dispose();
+                                        e.Result = true;
+                                        return;
+                                    }
                                     int Last_Whole_Percent_Done = 0;
                                     provider.OpenProvider();
                                     int bytesRead = 0;
@@ -2287,7 +2298,7 @@
                                     string message = string.Format(" -> Reading Address 0x{0:x8} from index 0x{1}", k.Address, index.ToString("X"));
                                     double double_percent_done = 100.0 * (double)((double)index / (double)reader.ResultCount);
                                     int int_percent_done = (int)double_percent_done;
-                                    if ((int_percent_done != Last_Whole_Percent_Done) && (index % 10000) == 0)
+                                    if ((int_percent_done != Last_Whole_Percent_Done) && (index % 1000000) == 0)
                                     {
                                         UpdateProgress((int)double_percent_done, message);
                                         Last_Whole_Percent_Done = int_percent_done;
@@ -2300,7 +2311,7 @@
                                             if (unsigned)
                                             {
                                                 #region 8bits - unsigned
-                                                var t_data = BitTools.ConvertByteArray<byte>(data);
+                                                var t_data = BitTools.ConvertByteArray<byte>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                                 foreach (var Value in t_data)
                                                 {
                                                     if (SearchWorkerThread.CancellationPending) { break; }
@@ -2341,7 +2352,7 @@
                                             else
                                             {
                                                 #region 8bits - signed
-                                                var t_data = BitTools.ConvertByteArray<sbyte>(data);
+                                                var t_data = BitTools.ConvertByteArray<sbyte>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                                 foreach (var Value in t_data)
                                                 {
                                                     if (SearchWorkerThread.CancellationPending) { break; }
@@ -2383,7 +2394,7 @@
                                             if (unsigned)
                                             {
                                                 #region 16bits - unsigned
-                                                var t_data = BitTools.ConvertByteArray<ushort>(data);
+                                                var t_data = BitTools.ConvertByteArray<ushort>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                                 foreach (var Value in t_data)
                                                 {
                                                     if (SearchWorkerThread.CancellationPending) { break; }
@@ -2424,7 +2435,7 @@
                                             else
                                             {
                                                 #region 16bits - signed
-                                                var t_data = BitTools.ConvertByteArray<short>(data);
+                                                var t_data = BitTools.ConvertByteArray<short>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                                 foreach (var Value in t_data)
                                                 {
                                                     if (SearchWorkerThread.CancellationPending) { break; }
@@ -2466,7 +2477,7 @@
                                             if (unsigned)
                                             {
                                                 #region 32bits - unsigned
-                                                var t_data = BitTools.ConvertByteArray<uint>(data);
+                                                var t_data = BitTools.ConvertByteArray<uint>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                                 foreach (var Value in t_data)
                                                 {
                                                     if (SearchWorkerThread.CancellationPending) { break; }
@@ -2507,7 +2518,7 @@
                                             else
                                             {
                                                 #region 32bits - signed
-                                                var t_data = BitTools.ConvertByteArray<int>(data);
+                                                var t_data = BitTools.ConvertByteArray<int>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                                 foreach (var Value in t_data)
                                                 {
                                                     if (SearchWorkerThread.CancellationPending) { break; }
@@ -2549,7 +2560,7 @@
                                             if (unsigned)
                                             {
                                                 #region 64bits - unsigned
-                                                var t_data = BitTools.ConvertByteArray<ulong>(data);
+                                                var t_data = BitTools.ConvertByteArray<ulong>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                                 foreach (var Value in t_data)
                                                 {
                                                     if (SearchWorkerThread.CancellationPending) { break; }
@@ -2590,7 +2601,7 @@
                                             else
                                             {
                                                 #region 64bits - signed
-                                                var t_data = BitTools.ConvertByteArray<long>(data);
+                                                var t_data = BitTools.ConvertByteArray<long>(data, new Func<bool>(ShouldCancelAnySearchOperation));
                                                 foreach (var Value in t_data)
                                                 {
                                                     if (SearchWorkerThread.CancellationPending) { break; }

 

  ViewVC Help
Powered by ViewVC 1.1.22