/[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 402 by william, Thu Jun 21 06:30:33 2012 UTC revision 448 by william, Sun Jun 2 20:22:04 2013 UTC
# Line 8  namespace RomCheater.Serialization Line 8  namespace RomCheater.Serialization
8  {  {
9      public interface ISerializationResultCount      public interface ISerializationResultCount
10      {      {
11          int ResultCount { get; }          int ResultCount { get; }    
12      }      }
13      
14      public abstract class SerializationWriter : ISerializationResultCount, IDisposable      public abstract class SerializationWriter : ISerializationResultCount, IDisposable
15      {      {
16          private const string DEFAULT_FOLDER = "tmp";          private void CreateFilename(Guid guid)
17            {
18                if (guid == Guid.Empty)
19                {
20                    if (this.TemporaryFolder != string.Empty)
21                    {
22                        FileName= string.Format(@"{0}\{1}\{2}", DEFAULT_FOLDER, TemporaryFolder, DEFAULT_FILENAME);
23                    }
24                    else
25                    {
26                        FileName = string.Format(@"{0}\{1}", DEFAULT_FOLDER, DEFAULT_FILENAME);
27                    }
28                    
29                }
30                else
31                {
32                    if (this.TemporaryFolder != string.Empty)
33                    {
34                        FileName = string.Format(@"{0}\{1}\{2}", DEFAULT_FOLDER, TemporaryFolder, string.Format("{0}.tmp", guid.ToString()));
35                    }
36                    else
37                    {
38                        FileName = string.Format(@"{0}\{1}", DEFAULT_FOLDER, string.Format("{0}.tmp", guid.ToString()));
39                    }
40                }
41            }
42            protected const string DEFAULT_FOLDER = "tmp";
43          private const string DEFAULT_FILENAME = "SerializedMemoryResults.tmp";          private const string DEFAULT_FILENAME = "SerializedMemoryResults.tmp";
44          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);
45          public SerializationWriter() : this(DEFAULT_PATH) { }  
46          protected SerializationWriter(string filename) : this(filename, 0, true) { }          protected virtual string TemporaryFolder { get { return string.Empty; } }
47          public SerializationWriter(int resultCount) : this(DEFAULT_PATH, resultCount, true) { }  
48          public SerializationWriter(string filename, int resultCount, bool delete) { FileName = filename; ResultCount = resultCount; CreateFile(delete); }          //public SerializationWriter() : this(CreateFilename(Guid.Empty)) {  }
49    
50    
51            public static void CleanupTemporarySearchResultFiles()
52            {
53                DirectoryInfo di = new DirectoryInfo(string.Format(@"{0}\{1}", DEFAULT_FOLDER, SearchResultsConstants.SearchResultsFolder));
54                if (di.Exists)
55                {
56                    di.Delete(true);
57                }
58            }
59    
60    
61            public SerializationWriter(int resultCount, Guid guid) : this(resultCount,guid, true) { }
62            public SerializationWriter(int resultCount, Guid guid, bool delete) { CreateFilename(guid); ResultCount = resultCount; CreateFile(delete); }
63            //protected SerializationWriter(Guid guid) : this(0, guid, true) { }
64            //protected SerializationWriter(string filename) { FileName = filename; }
65    
66          #region ISerializationResultCount members          #region ISerializationResultCount members
67          public int ResultCount { get; protected set; }                  public int ResultCount { get; protected set; }
68          #endregion          #endregion
69          private FileStream fileStream;          protected FileStream fileStream;
70          protected BinaryWriter binWriter;          protected BinaryWriter binWriter;
71          protected string FileName { get; private set; }          protected string FileName { get; private set; }
72    
73            protected bool Cancelled { get; set; }
74            public void CancelRequest() { Cancelled = true; }
75          private bool DeleteResultFile()          private bool DeleteResultFile()
76          {          {
77              try              try

Legend:
Removed from v.402  
changed lines
  Added in v.448

  ViewVC Help
Powered by ViewVC 1.1.22