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

--- trunk/RomCheater/Serialization/SerializationWriter.cs	2012/06/21 05:14:38	401
+++ trunk/RomCheater/Serialization/SerializationWriter.cs	2013/06/02 18:56:41	444
@@ -6,23 +6,36 @@
 
 namespace RomCheater.Serialization
 {
-    public interface ISerializationWriter
+    public interface ISerializationResultCount
     {
-        int ResultCount { get; }
+        int ResultCount { get; }     
     }
-    public abstract class SerializationWriter : ISerializationWriter, IDisposable
+   
+    public abstract class SerializationWriter : ISerializationResultCount, IDisposable
     {
+        private static string CreateFilename(Guid guid)
+        {
+            if (guid == Guid.Empty)
+            {
+                return DEFAULT_PATH;
+            }
+            else
+            {
+                return string.Format(@"{0}\{1}", DEFAULT_FOLDER, string.Format("{0}.tmp", guid.ToString()));
+            }
+        }
         private const string DEFAULT_FOLDER = "tmp";
         private const string DEFAULT_FILENAME = "SerializedMemoryResults.tmp";
         private static string DEFAULT_PATH = string.Format(@"{0}\{1}", DEFAULT_FOLDER,DEFAULT_FILENAME);
-        public SerializationWriter() : this(DEFAULT_PATH) { }
-        protected SerializationWriter(string filename) : this(filename, 0) { }
-        public SerializationWriter(int resultCount) : this(DEFAULT_PATH, resultCount) { }
-        public SerializationWriter(string filename, int resultCount) { FileName = filename; ResultCount = resultCount; CreateFile(); }
+        //public SerializationWriter() : this(CreateFilename(Guid.Empty)) {  }
+        
+        public SerializationWriter(int resultCount, Guid guid) : this(resultCount,guid, true) { }
+        public SerializationWriter(int resultCount, Guid guid, bool delete) : this(CreateFilename(guid)) {  ResultCount = resultCount; CreateFile(delete); }
+        protected SerializationWriter(Guid guid) : this(0, guid, true) { }
+        protected SerializationWriter(string filename) { FileName = filename; }
 
-        #region ISerializationWriter members
+        #region ISerializationResultCount members
         public int ResultCount { get; protected set; }
-        
         #endregion
         private FileStream fileStream;
         protected BinaryWriter binWriter;
@@ -44,9 +57,10 @@
                 return false;
             }
         }
-        private void CreateFile()
+        private void CreateFile(bool delete)
         {
-            DeleteResultFile();
+            if (delete)
+                DeleteResultFile();
             FileInfo fi = new FileInfo(FileName);
             if (!fi.Exists)
             {

 

  ViewVC Help
Powered by ViewVC 1.1.22