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

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

Parent Directory Parent Directory | Revision Log Revision Log


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

1 using System;
2 using System.Collections.Generic;
3 using System.Linq;
4 using System.Text;
5 using System.IO;
6
7 namespace RomCheater.Serialization
8 {
9 public abstract class SerializationReader : ISerializationResultCount, IDisposable
10 {
11 private string CreateDynamicFilename(Guid guid)
12 {
13 if (guid == Guid.Empty)
14 {
15 if (this.TemporaryFolder != string.Empty)
16 {
17 return string.Format(@"{0}\{1}\{2}", DEFAULT_FOLDER, TemporaryFolder, DEFAULT_FILENAME);
18 }
19 else
20 {
21 return string.Format(@"{0}\{1}", DEFAULT_FOLDER, DEFAULT_FILENAME);
22 }
23
24 }
25 else
26 {
27 if (this.TemporaryFolder != string.Empty)
28 {
29 return string.Format(@"{0}\{1}\{2}", DEFAULT_FOLDER, TemporaryFolder, string.Format("{0}.tmp", guid.ToString()));
30 }
31 else
32 {
33 return string.Format(@"{0}\{1}", DEFAULT_FOLDER, string.Format("{0}.tmp", guid.ToString()));
34 }
35 }
36 }
37 private void CreateFilename(Guid guid)
38 {
39 FileName = CreateDynamicFilename(guid);
40 }
41
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 //public SerializationReader() : this(CreateFilename(Guid.Empty)) { CreateReader(Guid.Empty); }
46 public SerializationReader(Guid guid) { ReaderGuid = guid; CreateFilename(guid); }
47 //protected SerializationReader(string filename) { FileName = filename; }
48
49 protected virtual string TemporaryFolder { get { return string.Empty; } }
50
51 protected bool Cancelled { get; set; }
52
53 public void CancelRequest() { Cancelled = true; }
54
55 protected Guid ReaderGuid { get; set; }
56
57 #region ISerializationResultCount members
58 public int ResultCount { get; protected set; }
59 #endregion
60 //private FileStream fileStream;
61 //protected BinaryReader binReader;
62 protected string FileName { get; private set; }
63 protected FileStream CreateReader()
64 {
65 return new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
66 }
67 protected FileStream CreateReader(Guid guid)
68 {
69 return new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
70 }
71 #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 //// clean up any resources
113 //binReader.Close();
114 //binReader = null;
115 //fileStream = null;
116 // 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 }
135 }

  ViewVC Help
Powered by ViewVC 1.1.22