ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Serialization/SearchResultWriter.cs
(Generate patch)

Comparing trunk/RomCheater/Serialization/SearchResultWriter.cs (file contents):
Revision 401 by william, Thu Jun 21 05:14:38 2012 UTC vs.
Revision 429 by william, Tue May 28 15:16:05 2013 UTC

--- trunk/RomCheater/Serialization/SearchResultWriter.cs	2012/06/21 05:14:38	401
+++ trunk/RomCheater/Serialization/SearchResultWriter.cs	2013/05/28 15:16:05	429
@@ -3,6 +3,7 @@ using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.IO;
+using System.Diagnostics;
 
 namespace RomCheater.Serialization
 {
@@ -12,8 +13,14 @@ namespace RomCheater.Serialization
     }
     public class SearchResultWriter : SerializationWriter, ISearchResultWriter
     {
+
+        private int ResultsWritten = 0;
+
         public SearchResultWriter() : base() { }
         public SearchResultWriter(int resultCount) : base(resultCount) { WriteHeader(); }
+        public SearchResultWriter(string filename) : base(filename) { WriteHeader(); }
+        public SearchResultWriter(string filename, int resultCount) : base(filename, resultCount, false) { WriteHeader(); }
+        public SearchResultWriter(string filename, int resultCount, bool delete) : base(filename, resultCount, delete) { WriteHeader(); }
         #region ISearchResultWriter members
         public void WriteResult<TValue>(uint address, TValue value) where TValue : IConvertible
         {
@@ -48,6 +55,7 @@ namespace RomCheater.Serialization
                     binWriter.Write(Convert.ToInt64(value));
                     break;
             }
+            ResultsWritten++;
         }
         #endregion
 
@@ -60,5 +68,17 @@ namespace RomCheater.Serialization
             // write count (int)
             binWriter.Write(ResultCount);
         }
+
+        protected override void Dispose(bool disposing)
+        {            
+            base.Dispose(disposing);
+            // ensure ResultCount and ResultsWritten are equal            
+            if (ResultCount != ResultsWritten)
+            {
+                string message = string.Format("ResultCount does not match ResultsWritten: 0x{0:x8} != 0x{1:x8} -- offset: 0x{2:x8}", ResultCount, ResultsWritten, ResultCount - ResultsWritten);
+                Logging.logger.Error.WriteLine(message);
+                throw new InvalidOperationException(message);
+            }
+        }
     }
 }