ViewVC Help
View File | Revision Log | Show Annotations | Download File | View Changeset | Root Listing
root/RomCheater/trunk/RomCheater/Serialization/SerializationReader.cs
Revision: 402
Committed: Thu Jun 21 06:30:33 2012 UTC (11 years, 3 months ago) by william
File size: 3850 byte(s)
Log Message:

File Contents

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