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

Diff of /trunk/RomCheater/Serialization/SerializationWriter.cs

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 401 by william, Thu Jun 21 05:14:38 2012 UTC revision 444 by william, Sun Jun 2 18:56:41 2013 UTC
# Line 6  using System.IO; Line 6  using System.IO;
6    
7  namespace RomCheater.Serialization  namespace RomCheater.Serialization
8  {  {
9      public interface ISerializationWriter      public interface ISerializationResultCount
10      {      {
11          int ResultCount { get; }          int ResultCount { get; }    
12      }      }
13      public abstract class SerializationWriter : ISerializationWriter, IDisposable    
14        public abstract class SerializationWriter : ISerializationResultCount, IDisposable
15      {      {
16            private static string CreateFilename(Guid guid)
17            {
18                if (guid == Guid.Empty)
19                {
20                    return DEFAULT_PATH;
21                }
22                else
23                {
24                    return string.Format(@"{0}\{1}", DEFAULT_FOLDER, string.Format("{0}.tmp", guid.ToString()));
25                }
26            }
27          private const string DEFAULT_FOLDER = "tmp";          private const string DEFAULT_FOLDER = "tmp";
28          private const string DEFAULT_FILENAME = "SerializedMemoryResults.tmp";          private const string DEFAULT_FILENAME = "SerializedMemoryResults.tmp";
29          private static string DEFAULT_PATH = string.Format(@"{0}\{1}", DEFAULT_FOLDER,DEFAULT_FILENAME);          private static string DEFAULT_PATH = string.Format(@"{0}\{1}", DEFAULT_FOLDER,DEFAULT_FILENAME);
30          public SerializationWriter() : this(DEFAULT_PATH) { }          //public SerializationWriter() : this(CreateFilename(Guid.Empty)) {  }
31          protected SerializationWriter(string filename) : this(filename, 0) { }          
32          public SerializationWriter(int resultCount) : this(DEFAULT_PATH, resultCount) { }          public SerializationWriter(int resultCount, Guid guid) : this(resultCount,guid, true) { }
33          public SerializationWriter(string filename, int resultCount) { FileName = filename; ResultCount = resultCount; CreateFile(); }          public SerializationWriter(int resultCount, Guid guid, bool delete) : this(CreateFilename(guid)) {  ResultCount = resultCount; CreateFile(delete); }
34            protected SerializationWriter(Guid guid) : this(0, guid, true) { }
35            protected SerializationWriter(string filename) { FileName = filename; }
36    
37          #region ISerializationWriter members          #region ISerializationResultCount members
38          public int ResultCount { get; protected set; }          public int ResultCount { get; protected set; }
           
39          #endregion          #endregion
40          private FileStream fileStream;          private FileStream fileStream;
41          protected BinaryWriter binWriter;          protected BinaryWriter binWriter;
# Line 44  namespace RomCheater.Serialization Line 57  namespace RomCheater.Serialization
57                  return false;                  return false;
58              }              }
59          }          }
60          private void CreateFile()          private void CreateFile(bool delete)
61          {          {
62              DeleteResultFile();              if (delete)
63                    DeleteResultFile();
64              FileInfo fi = new FileInfo(FileName);              FileInfo fi = new FileInfo(FileName);
65              if (!fi.Exists)              if (!fi.Exists)
66              {              {

Legend:
Removed from v.401  
changed lines
  Added in v.444

  ViewVC Help
Powered by ViewVC 1.1.22