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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 472 - (hide annotations) (download)
Mon Jun 3 07:39:39 2013 UTC (8 years, 2 months ago) by william
File size: 5421 byte(s)

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

  ViewVC Help
Powered by ViewVC 1.1.22