/[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

--- trunk/RomCheater/Serialization/SerializationReader.cs	2013/06/03 20:03:06	485
+++ trunk/RomCheater/Serialization/SerializationReader.cs	2013/06/03 20:11:43	486
@@ -1,8 +1,22 @@
-´╗┐using System;
+´╗┐#region Logging Defines
+// include this any class or method that required logging, and comment-out what is not needed
+
+#region Enabled logging levels
+#define LOGGING_ENABLE_INFO
+#define LOGGING_ENABLE_WARN
+#define LOGGING_ENABLE_DEBUG
+#define LOGGING_ENABLE_VERBOSEDEBUG
+#define LOGGING_ENABLE_ERROR
+#define LOGGING_ENABLE_VERBOSEERROR
+#define LOGGING_ENABLE_PROFILER
+#endregion
+#endregion
+using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;
 using System.IO;
+using RomCheater.Logging;
 
 namespace RomCheater.Serialization
 {
@@ -43,9 +57,13 @@
  protected const string DEFAULT_FILENAME = "SerializedMemoryResults.tmp";
         //private static string DEFAULT_PATH = string.Format(@"{0}\{1}", DEFAULT_FOLDER, DEFAULT_FILENAME);
         //public SerializationReader() : this(CreateFilename(Guid.Empty)) { CreateReader(Guid.Empty); }
- public SerializationReader(Guid guid) { ReaderGuid = guid; CreateFilename(guid); } 
+ public SerializationReader(Guid guid) : this(guid,false) { }
+ public SerializationReader(Guid guid, bool delete) { Delete = delete; ReaderGuid = guid; CreateFilename(guid); } 
         //protected SerializationReader(string filename) { FileName = filename; }
 
+
+        private bool Delete { get; set; }
+
         protected virtual string TemporaryFolder { get { return string.Empty; } }
 
         protected bool Cancelled { get; set; }
@@ -68,6 +86,32 @@
         {           
             return new FileStream(FileName, FileMode.Open, FileAccess.Read, FileShare.Read);
         }
+        private void DestroyReader(Guid guid)
+        {
+            try
+            {
+                FileInfo fi = new FileInfo(CreateDynamicFilename(guid));
+                try
+                {
+                    if (fi.Exists)
+                    {
+                        fi.Delete();
+                    }
+
+                }
+                catch (Exception ex)
+                {
+                    logger.Error.WriteLine("Failed to delete result file: {0}", fi.Name);
+                    logger.VerboseError.WriteLine(ex.ToString());
+                }
+            }
+            catch (Exception ex)
+            {
+                logger.Error.WriteLine("Failed to delete result file with guid: {0}", guid.ToString());
+                logger.VerboseError.WriteLine(ex.ToString());
+            }
+                
+        }
             #region IDisposable Support
         // Track whether Dispose has been called.
         private bool disposed = false;
@@ -114,6 +158,12 @@
                 //binReader = null;
                 //fileStream = null;                
                 // Note disposing has been done.
+
+                if (Delete)
+                {
+                    DestroyReader(ReaderGuid);
+                }
+
                 disposed = true;
 
             }

 

  ViewVC Help
Powered by ViewVC 1.1.22