[tomboy/xdg-migration2] Implement data migration of BugzillaNoteAddin.



commit e565a2c94b98c3742660d38e6d7ba4e14f3d7bd0
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date:   Sun Aug 23 22:08:41 2009 -0700

    Implement data migration of BugzillaNoteAddin.
    
    Move recursive CopyDirectory to new IOUtils static class.

 Tomboy/AddinManager.cs                      |   13 +------------
 Tomboy/Addins/Bugzilla/BugzillaNoteAddin.cs |   25 ++++++++++++++++++-------
 Tomboy/Utils.cs                             |   17 +++++++++++++++++
 3 files changed, 36 insertions(+), 19 deletions(-)
---
diff --git a/Tomboy/AddinManager.cs b/Tomboy/AddinManager.cs
index faec6bf..d784c36 100644
--- a/Tomboy/AddinManager.cs
+++ b/Tomboy/AddinManager.cs
@@ -44,17 +44,6 @@ namespace Tomboy
 
 			InitializeMonoAddins (old_tomboy_conf_dir);
 		}
-		
-		// TODO: Move to Utils.cs
-		private void CopyDirectory (string old_path, string new_path)
-		{
-			// NOTE: Assume that old_path exists and new_path doesn't
-			Directory.CreateDirectory (new_path);
-			foreach (string file_path in Directory.GetFiles (old_path))
-				File.Copy (file_path, Path.Combine (new_path, Path.GetFileName (file_path)));
-			foreach (string dir_path in Directory.GetDirectories (old_path))
-				CopyDirectory (dir_path, Path.Combine (new_path, Path.GetFileName (dir_path)));
-		}
 
 		void InitializeMonoAddins (string old_conf_dir)
 		{
@@ -66,7 +55,7 @@ namespace Tomboy
 					string new_dir_path =
 						Path.Combine (tomboy_conf_dir, Path.GetFileName (dir_path));
 					if (!Directory.Exists (new_dir_path))
-						CopyDirectory (dir_path, new_dir_path);
+						IOUtils.CopyDirectory (dir_path, new_dir_path);
 				}
 			}
 
diff --git a/Tomboy/Addins/Bugzilla/BugzillaNoteAddin.cs b/Tomboy/Addins/Bugzilla/BugzillaNoteAddin.cs
index 61c0b57..608e83a 100644
--- a/Tomboy/Addins/Bugzilla/BugzillaNoteAddin.cs
+++ b/Tomboy/Addins/Bugzilla/BugzillaNoteAddin.cs
@@ -16,13 +16,24 @@ namespace Tomboy.Bugzilla
 	{
 		public const string BugzillaLinkTagName = "link:bugzilla";
 
-		public static string ImageDirectory { get; private set; }
-
-		static BugzillaNoteAddin ()
-		{
-			// TODO: Migration
-			ImageDirectory = Path.Combine (Services.NativeApplication.ConfigurationDirectory,
-			                               "BugzillaIcons");
+		private static string image_dir = null;
+
+		public static string ImageDirectory {
+			get {
+				if (image_dir == null) {
+					image_dir = Path.Combine (Services.NativeApplication.ConfigurationDirectory,
+					                          "BugzillaIcons");
+
+					// Perform migration if necessary
+					if (!Directory.Exists (ImageDirectory)) {
+						string old_image_dir = Path.Combine (Services.NativeApplication.PreOneDotZeroNoteDirectory,
+						                                     "BugzillaIcons");
+						if (Directory.Exists (old_image_dir))
+							IOUtils.CopyDirectory (old_image_dir, image_dir);
+					}
+				}
+				return image_dir;
+			}
 		}
 
 		public override void Initialize ()
diff --git a/Tomboy/Utils.cs b/Tomboy/Utils.cs
index 1ed72d8..b074d74 100644
--- a/Tomboy/Utils.cs
+++ b/Tomboy/Utils.cs
@@ -953,4 +953,21 @@ namespace Tomboy
 			}
 		}
 	}
+
+	public static class IOUtils
+	{
+		/// <summary>
+		/// Recursively copy the directory specified by old_path to
+		/// new_path. Assumes that old_path is an existing directory
+		/// and new_path does not exist.
+		/// </summary>
+		public static void CopyDirectory (string old_path, string new_path)
+		{
+			Directory.CreateDirectory (new_path);
+			foreach (string file_path in Directory.GetFiles (old_path))
+				File.Copy (file_path, Path.Combine (new_path, Path.GetFileName (file_path)));
+			foreach (string dir_path in Directory.GetDirectories (old_path))
+				CopyDirectory (dir_path, Path.Combine (new_path, Path.GetFileName (dir_path)));
+		}
+	}
 }



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]