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

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

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

revision 472 by william, Mon Jun 3 07:39:39 2013 UTC revision 486 by william, Mon Jun 3 20:11:43 2013 UTC
# Line 1  Line 1 
1  ´╗┐using System;  ´╗┐#region Logging Defines
2    // include this any class or method that required logging, and comment-out what is not needed
3    
4    #region Enabled logging levels
5    #define LOGGING_ENABLE_INFO
6    #define LOGGING_ENABLE_WARN
7    #define LOGGING_ENABLE_DEBUG
8    #define LOGGING_ENABLE_VERBOSEDEBUG
9    #define LOGGING_ENABLE_ERROR
10    #define LOGGING_ENABLE_VERBOSEERROR
11    #define LOGGING_ENABLE_PROFILER
12    #endregion
13    #endregion
14    using System;
15  using System.Collections.Generic;  using System.Collections.Generic;
16  using System.Linq;  using System.Linq;
17  using System.Text;  using System.Text;
18  using System.IO;  using System.IO;
19    using RomCheater.Logging;
20    
21  namespace RomCheater.Serialization  namespace RomCheater.Serialization
22  {  {
# Line 43  namespace RomCheater.Serialization Line 57  namespace RomCheater.Serialization
57   protected const string DEFAULT_FILENAME = "SerializedMemoryResults.tmp";   protected const string DEFAULT_FILENAME = "SerializedMemoryResults.tmp";
58          //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);
59          //public SerializationReader() : this(CreateFilename(Guid.Empty)) { CreateReader(Guid.Empty); }          //public SerializationReader() : this(CreateFilename(Guid.Empty)) { CreateReader(Guid.Empty); }
60   public SerializationReader(Guid guid) { ReaderGuid = guid; CreateFilename(guid); }   public SerializationReader(Guid guid) : this(guid,false) { }
61     public SerializationReader(Guid guid, bool delete) { Delete = delete; ReaderGuid = guid; CreateFilename(guid); }
62          //protected SerializationReader(string filename) { FileName = filename; }          //protected SerializationReader(string filename) { FileName = filename; }
63    
64    
65            private bool Delete { get; set; }
66    
67          protected virtual string TemporaryFolder { get { return string.Empty; } }          protected virtual string TemporaryFolder { get { return string.Empty; } }
68    
69          protected bool Cancelled { get; set; }          protected bool Cancelled { get; set; }
# Line 68  namespace RomCheater.Serialization Line 86  namespace RomCheater.Serialization
86          {                    {          
87              return new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);              return new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
88          }          }
89            private void DestroyReader(Guid guid)
90            {
91                try
92                {
93                    FileInfo fi = new FileInfo(CreateDynamicFilename(guid));
94                    try
95                    {
96                        if (fi.Exists)
97                        {
98                            fi.Delete();
99                        }
100    
101                    }
102                    catch (Exception ex)
103                    {
104                        logger.Error.WriteLine("Failed to delete result file: {0}", fi.Name);
105                        logger.VerboseError.WriteLine(ex.ToString());
106                    }
107                }
108                catch (Exception ex)
109                {
110                    logger.Error.WriteLine("Failed to delete result file with guid: {0}", guid.ToString());
111                    logger.VerboseError.WriteLine(ex.ToString());
112                }
113                    
114            }
115              #region IDisposable Support              #region IDisposable Support
116          // Track whether Dispose has been called.          // Track whether Dispose has been called.
117          private bool disposed = false;          private bool disposed = false;
# Line 114  namespace RomCheater.Serialization Line 158  namespace RomCheater.Serialization
158                  //binReader = null;                  //binReader = null;
159                  //fileStream = null;                                  //fileStream = null;                
160                  // Note disposing has been done.                  // Note disposing has been done.
161    
162                    if (Delete)
163                    {
164                        DestroyReader(ReaderGuid);
165                    }
166    
167                  disposed = true;                  disposed = true;
168    
169              }              }

Legend:
Removed from v.472  
changed lines
  Added in v.486

  ViewVC Help
Powered by ViewVC 1.1.22