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

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

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

--- trunk/RomCheater/Serialization/SearchResultWriter.cs	2013/06/02 19:21:16	445
+++ trunk/RomCheater/Serialization/SearchResultWriter.cs	2013/06/03 20:11:43	486
@@ -1,4 +1,17 @@
-´╗┐using System;
+´╗┐#region Logging Defines
+// include this any class or method that required logging, and comment-out what is not needed
+
+#region Enabled logging levels
+#define LOGGING_ENABLE_INFO
+#define LOGGING_ENABLE_WARN
+#define LOGGING_ENABLE_DEBUG
+#define LOGGING_ENABLE_VERBOSEDEBUG
+#define LOGGING_ENABLE_ERROR
+#define LOGGING_ENABLE_VERBOSEERROR
+#define LOGGING_ENABLE_PROFILER
+#endregion
+#endregion
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
@@ -15,9 +28,10 @@
     {
 
         private int ResultsWritten = 0;
-
+        protected override string TemporaryFolder { get { return SearchResultsConstants.SearchResultsFolder; } }
         //public SearchResultWriter() : base() { }
-        public SearchResultWriter(int resultCount, Guid guid) : base(resultCount, guid) { WriteHeader(guid); }
+        public SearchResultWriter(int resultCount, Guid guid) : this(resultCount, guid,false) { WriteHeader(guid); }
+        public SearchResultWriter(int resultCount, Guid guid, bool delete) : base(resultCount, guid,delete) { WriteHeader(guid); }
         //public SearchResultWriter(string filename, Guid guid) : base(CreateFileName(filename,guid), guid) { WriteHeader(guid); }
         //public SearchResultWriter(string filename, int resultCount, Guid guid) : base(filename, resultCount, guid, false) { WriteHeader(guid); }
         //public SearchResultWriter(string filename, int resultCount, Guid guid, bool delete) : base(filename, resultCount, guid, delete) { WriteHeader(guid); }      
@@ -65,6 +79,7 @@
         }
         #endregion
 
+        long ResultCountOffset = 0;
         private void WriteHeader(Guid guid)
         {
             try
@@ -86,6 +101,7 @@
                 }
                 // write count (int)
                 binWriter.Write(ResultCount);
+                ResultCountOffset = binWriter.BaseStream.Position - sizeof(int);
             }
             catch (Exception ex)
             {
@@ -95,16 +111,24 @@
 
         protected override void Dispose(bool disposing)
         {
+            if (Cancelled) { binWriter.Close(); fileStream.Close(); return; }
             try
             {
-                base.Dispose(disposing);
-                // ensure ResultCount and ResultsWritten are equal            
+               
+                //// 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);
+                //}
                 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);
+                    // update the number of results written
+                    binWriter.BaseStream.Seek(ResultCountOffset, SeekOrigin.Begin);
+                    binWriter.Write(ResultsWritten);
                 }
+                base.Dispose(disposing);
             }
             catch (Exception ex)
             {

 

  ViewVC Help
Powered by ViewVC 1.1.22