/[RomCheater]/trunk/RomCheater/Docking/UI/UIMemoryViewer.cs
ViewVC logotype

Diff of /trunk/RomCheater/Docking/UI/UIMemoryViewer.cs

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

--- trunk/RomCheater/Docking/UI/UIMemoryViewer.cs	2012/06/03 13:30:16	244
+++ trunk/RomCheater/Docking/UI/UIMemoryViewer.cs	2012/06/03 14:50:09	245
@@ -54,8 +54,10 @@
             if (!DesignMode)
             {
                 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
+                provider.OpenProvider();
                 uint addr = 0;
                 provider.ReadFirstNonZeroByte(MemoryStart, MemorySize, out addr);
+                provider.CloseProvider();
                 GotoAddress(addr);
             }
         }
@@ -190,22 +192,29 @@
         }
         private byte[] GetMemory()
         {
+            byte[] data = new byte[] { };
             try
             {
                 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
+                provider.OpenProvider();
                 int bytesReadSize;
-                byte[] data;
                 provider.ReadProcessMemory(CURRENT_TOP_ADDR, max_ram_view, out bytesReadSize, out data);
-                //this.Logger.LogDebugMessage(string.Format("GetMemory() -> Memory Size: {0}0x{2:X8}{1}", "{", "}", data.Length));
-                return data;
+                provider.CloseProvider();
+
             }
             catch (Exception ex)
             {
                 logger.Error.WriteLine("{0}.GetMemory():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString());
-                byte[] data = new byte[max_ram_view];
-                for (int i = 0; i < data.Length; i++) { data[i] = 0x0; }
-                return data;
             }
+            finally
+            {
+                if (data.Length == 0)
+                {
+                    data = new byte[max_ram_view];
+                    for (int i = 0; i < data.Length; i++) { data[i] = 0x0; }
+                }
+            }
+            return data;
         }
         private void UpdateMemroyView() { this.UpdateMemroyView(this.CURRENT_TOP_ADDR); }
         private void UpdateMemroyView(uint address)
@@ -282,6 +291,7 @@
                 // Byte changed
                 //byte[] data = (txtData.ByteProvider as DynamicByteProvider).Bytes.ToArray();
                 GenericMemoryProvider provider = new GenericMemoryProvider((IAcceptsProcessAndConfig)this);
+                provider.OpenProvider();
                 int bytesReadSize;
 
                 for (int i = 0; i < data.Length; i ++)
@@ -290,6 +300,7 @@
                     byte data_to_write = data[i];
                     provider.WriteProcessMemory(addr, data_to_write, out bytesReadSize);
                 }
+                provider.CloseProvider();
             }
             catch (Exception ex) { logger.Error.WriteLine("{0}.WriteCurrentBytes():{1}{2}", this.GetType().Name, System.Environment.NewLine, ex.ToString()); }
         }

 

  ViewVC Help
Powered by ViewVC 1.1.22