Moved the pithos.db location to the same location as the user settings. This will...
authorPanagiotis Kanavos <pkanavos@gmail.com>
Sun, 19 Feb 2012 17:07:14 +0000 (19:07 +0200)
committerPanagiotis Kanavos <pkanavos@gmail.com>
Sun, 19 Feb 2012 17:07:14 +0000 (19:07 +0200)
trunk/Pithos.Core/Agents/StatusAgent.cs

index d5fda6d..5a92d05 100644 (file)
@@ -31,22 +31,45 @@ namespace Pithos.Core.Agents
         public StatusAgent()
         {            
             var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
-            _pithosDataPath = Path.Combine(appDataPath , "Pithos");
+            
+
 
+            _pithosDataPath = Path.Combine(appDataPath , "GRNET");
             if (!Directory.Exists(_pithosDataPath))
                 Directory.CreateDirectory(_pithosDataPath);
+
+            var dbPath = Path.Combine(_pithosDataPath, "pithos.db");
+
+            MigrateOldDb(dbPath, appDataPath);
+
             var source = GetConfiguration(_pithosDataPath);
             ActiveRecordStarter.Initialize(source,typeof(FileState),typeof(FileTag));
             ActiveRecordStarter.UpdateSchema();
-            
 
-            if (!File.Exists(Path.Combine(_pithosDataPath ,"pithos.db")))
+
+            if (!File.Exists(dbPath))
                 ActiveRecordStarter.CreateSchema();
 
             CreateTrigger();
             
         }
 
+
+        private static void MigrateOldDb(string dbPath, string appDataPath)
+        {
+            Contract.Requires(!String.IsNullOrWhiteSpace(dbPath));
+            Contract.Requires(!String.IsNullOrWhiteSpace(appDataPath));
+
+            var oldDbPath = Path.Combine(appDataPath, "Pithos", "pithos.db");
+            var oldDbInfo = new FileInfo(oldDbPath);
+            if (oldDbInfo.Exists && !File.Exists(dbPath))
+            {
+                var oldDirectory = oldDbInfo.Directory;
+                oldDbInfo.MoveTo(dbPath);                
+                oldDirectory.Delete(true);
+            }
+        }
+
         private void CreateTrigger()
         {
             using (var connection = GetConnection())