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

Annotation of /trunk/RomCheater/Serialization/SerializationReader.cs

Parent Directory Parent Directory | Revision Log Revision Log


Revision 444 - (hide annotations) (download)
Sun Jun 2 18:56:41 2013 UTC (8 years, 4 months ago) by william
File size: 4317 byte(s)
+ update serialization reader/writer to include a search results guid

1 william 401 using System;
2     using System.Collections.Generic;
3     using System.Linq;
4     using System.Text;
5 william 402 using System.IO;
6 william 401
7     namespace RomCheater.Serialization
8     {
9 william 402 public abstract class SerializationReader : ISerializationResultCount, IDisposable
10 william 401 {
11 william 444 private static string CreateFilename(Guid guid)
12     {
13     if (guid == Guid.Empty)
14     {
15     return DEFAULT_PATH;
16     }
17     else
18     {
19     return string.Format(@"{0}\{1}", DEFAULT_FOLDER, string.Format("{0}.tmp", guid.ToString()));
20     }
21     }
22 william 402 private const string DEFAULT_FOLDER = "tmp";
23     private const string DEFAULT_FILENAME = "SerializedMemoryResults.tmp";
24     private static string DEFAULT_PATH = string.Format(@"{0}\{1}", DEFAULT_FOLDER, DEFAULT_FILENAME);
25 william 444 //public SerializationReader() : this(CreateFilename(Guid.Empty)) { CreateReader(Guid.Empty); }
26     public SerializationReader(Guid guid) { CreateReader(guid); }
27     protected SerializationReader(string filename) { FileName = filename; }
28 william 402
29 william 444
30 william 402
31     #region ISerializationResultCount members
32     public int ResultCount { get; protected set; }
33     #endregion
34     private FileStream fileStream;
35     protected BinaryReader binReader;
36     protected string FileName { get; private set; }
37 william 444 private void CreateReader(Guid guid)
38 william 402 {
39     fileStream = new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
40     binReader = new BinaryReader(fileStream);
41     }
42     #region IDisposable Support
43     // Track whether Dispose has been called.
44     private bool disposed = false;
45     // Implement IDisposable.
46     // Do not make this method virtual.
47     // A derived class should not be able to override this method.
48     public void Dispose()
49     {
50     Dispose(true);
51     // This object will be cleaned up by the Dispose method.
52     // Therefore, you should call GC.SupressFinalize to
53     // take this object off the finalization queue
54     // and prevent finalization code for this object
55     // from executing a second time.
56     GC.SuppressFinalize(this);
57     }
58     // Dispose(bool disposing) executes in two distinct scenarios.
59     // If disposing equals true, the method has been called directly
60     // or indirectly by a user's code. Managed and unmanaged resources
61     // can be disposed.
62     // If disposing equals false, the method has been called by the
63     // runtime from inside the finalizer and you should not reference
64     // other objects. Only unmanaged resources can be disposed.
65     protected virtual void Dispose(bool disposing)
66     {
67     // Check to see if Dispose has already been called.
68     if (!this.disposed)
69     {
70     // If disposing equals true, dispose all managed
71     // and unmanaged resources.
72     if (disposing)
73     {
74     // Dispose managed resources.
75     //component.Dispose();
76     }
77    
78     // Call the appropriate methods to clean up
79     // unmanaged resources here.
80     // If disposing is false,
81     // only the following code is executed.
82    
83     // clean up any resources
84     binReader.Close();
85     binReader = null;
86     fileStream = null;
87     // Note disposing has been done.
88     disposed = true;
89    
90     }
91     }
92     // Use C# destructor syntax for finalization code.
93     // This destructor will run only if the Dispose method
94     // does not get called.
95     // It gives your base class the opportunity to finalize.
96     // Do not provide destructors in types derived from this class.
97     ~SerializationReader()
98     {
99     // Do not re-create Dispose clean-up code here.
100     // Calling Dispose(false) is optimal in terms of
101     // readability and maintainability.
102     Dispose(false);
103     }
104     #endregion
105 william 401 }
106     }

  ViewVC Help
Powered by ViewVC 1.1.22