/[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	2013/06/02 18:56:41	444
+++ trunk/RomCheater/Serialization/SerializationWriter.cs	2013/06/02 20:22:04	448
@@ -13,33 +13,65 @@
    
     public abstract class SerializationWriter : ISerializationResultCount, IDisposable
     {
-        private static string CreateFilename(Guid guid)
+        private void CreateFilename(Guid guid)
         {
             if (guid == Guid.Empty)
             {
-                return DEFAULT_PATH;
+                if (this.TemporaryFolder != string.Empty)
+                {
+                    FileName= string.Format(@"{0}\{1}\{2}", DEFAULT_FOLDER, TemporaryFolder, DEFAULT_FILENAME);
+                }
+                else
+                {
+                    FileName = string.Format(@"{0}\{1}", DEFAULT_FOLDER, DEFAULT_FILENAME);
+                }
+                
             }
             else
             {
-                return string.Format(@"{0}\{1}", DEFAULT_FOLDER, string.Format("{0}.tmp", guid.ToString()));
+                if (this.TemporaryFolder != string.Empty)
+                {
+                    FileName = string.Format(@"{0}\{1}\{2}", DEFAULT_FOLDER, TemporaryFolder, string.Format("{0}.tmp", guid.ToString()));
+                }
+                else
+                {
+                    FileName = string.Format(@"{0}\{1}", DEFAULT_FOLDER, string.Format("{0}.tmp", guid.ToString()));
+                }
             }
         }
-        private const string DEFAULT_FOLDER = "tmp";
+        protected 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);
+        //private static string DEFAULT_PATH = string.Format(@"{0}\{1}", DEFAULT_FOLDER,DEFAULT_FILENAME);
+
+        protected virtual string TemporaryFolder { get { return string.Empty; } }
+
         //public SerializationWriter() : this(CreateFilename(Guid.Empty)) {  }
-        
+
+
+        public static void CleanupTemporarySearchResultFiles()
+        {
+            DirectoryInfo di = new DirectoryInfo(string.Format(@"{0}\{1}", DEFAULT_FOLDER, SearchResultsConstants.SearchResultsFolder));
+            if (di.Exists)
+            {
+                di.Delete(true);
+            }
+        }
+
+
         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; }
+        public SerializationWriter(int resultCount, Guid guid, bool delete) { CreateFilename(guid); ResultCount = resultCount; CreateFile(delete); }
+        //protected SerializationWriter(Guid guid) : this(0, guid, true) { }
+        //protected SerializationWriter(string filename) { FileName = filename; }
 
         #region ISerializationResultCount members
         public int ResultCount { get; protected set; }
         #endregion
-        private FileStream fileStream;
+        protected FileStream fileStream;
         protected BinaryWriter binWriter;
         protected string FileName { get; private set; }
+
+        protected bool Cancelled { get; set; }
+        public void CancelRequest() { Cancelled = true; }
         private bool DeleteResultFile()
         {
             try

 

  ViewVC Help
Powered by ViewVC 1.1.22