/[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

revision 447 by william, Sun Jun 2 19:58:37 2013 UTC revision 456 by william, Mon Jun 3 01:45:40 2013 UTC
# Line 15  namespace RomCheater.Serialization Line 15  namespace RomCheater.Serialization
15      {      {
16    
17          private int ResultsWritten = 0;          private int ResultsWritten = 0;
18            protected override string TemporaryFolder { get { return SearchResultsConstants.SearchResultsFolder; } }
19          //public SearchResultWriter() : base() { }          //public SearchResultWriter() : base() { }
20          public SearchResultWriter(int resultCount, Guid guid) : base(resultCount, guid) { WriteHeader(guid); }          public SearchResultWriter(int resultCount, Guid guid) : base(resultCount, guid) { WriteHeader(guid); }
21          //public SearchResultWriter(string filename, Guid guid) : base(CreateFileName(filename,guid), guid) { WriteHeader(guid); }          //public SearchResultWriter(string filename, Guid guid) : base(CreateFileName(filename,guid), guid) { WriteHeader(guid); }
# Line 65  namespace RomCheater.Serialization Line 65  namespace RomCheater.Serialization
65          }          }
66          #endregion          #endregion
67    
68            long ResultCountOffset = 0;
69          private void WriteHeader(Guid guid)          private void WriteHeader(Guid guid)
70          {          {
71              try              try
# Line 86  namespace RomCheater.Serialization Line 87  namespace RomCheater.Serialization
87                  }                  }
88                  // write count (int)                  // write count (int)
89                  binWriter.Write(ResultCount);                  binWriter.Write(ResultCount);
90                    ResultCountOffset = binWriter.BaseStream.Position - sizeof(int);
91              }              }
92              catch (Exception ex)              catch (Exception ex)
93              {              {
# Line 95  namespace RomCheater.Serialization Line 97  namespace RomCheater.Serialization
97    
98          protected override void Dispose(bool disposing)          protected override void Dispose(bool disposing)
99          {          {
100              if (Cancelled) { return; }              if (Cancelled) { binWriter.Close(); fileStream.Close(); return; }
101              try              try
102              {              {
103                  base.Dispose(disposing);                
104                  // ensure ResultCount and ResultsWritten are equal                              //// ensure ResultCount and ResultsWritten are equal            
105                    //if (ResultCount != ResultsWritten)
106                    //{
107                    //    string message = string.Format("ResultCount does not match ResultsWritten: 0x{0:x8} != 0x{1:x8} -- offset: 0x{2:x8}", ResultCount, ResultsWritten, ResultCount - ResultsWritten);
108                    //    Logging.logger.Error.WriteLine(message);
109                    //    throw new InvalidOperationException(message);
110                    //}
111                  if (ResultCount != ResultsWritten)                  if (ResultCount != ResultsWritten)
112                  {                  {
113                      string message = string.Format("ResultCount does not match ResultsWritten: 0x{0:x8} != 0x{1:x8} -- offset: 0x{2:x8}", ResultCount, ResultsWritten, ResultCount - ResultsWritten);                      // update the number of results written
114                      Logging.logger.Error.WriteLine(message);                      binWriter.BaseStream.Seek(ResultCountOffset, SeekOrigin.Begin);
115                      throw new InvalidOperationException(message);                      binWriter.Write(ResultsWritten);
116                  }                  }
117                    base.Dispose(disposing);
118              }              }
119              catch (Exception ex)              catch (Exception ex)
120              {              {

Legend:
Removed from v.447  
changed lines
  Added in v.456

  ViewVC Help
Powered by ViewVC 1.1.22