[tomboy/xdg-migration2: 10/16] Implement migration for notes and basic add-in stuff (not bugzilla, etc).
- From: Sanford Armstrong <sharm src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [tomboy/xdg-migration2: 10/16] Implement migration for notes and basic add-in stuff (not bugzilla, etc).
- Date: Mon, 24 Aug 2009 02:01:31 +0000 (UTC)
commit 51d6ac35166bd9d8082afce34866254467f4f303
Author: Sandy Armstrong <sanfordarmstrong gmail com>
Date: Sat Aug 22 21:47:45 2009 -0700
Implement migration for notes and basic add-in stuff (not bugzilla, etc).
Tomboy/AddinManager.cs | 32 +++++++++++++++++--
Tomboy/GnomeApplication.cs | 6 ++--
Tomboy/NoteManager.cs | 76 +++++++++++++++++++++++++++++++++++++++-----
3 files changed, 100 insertions(+), 14 deletions(-)
---
diff --git a/Tomboy/AddinManager.cs b/Tomboy/AddinManager.cs
index fc2efa8..f827a12 100644
--- a/Tomboy/AddinManager.cs
+++ b/Tomboy/AddinManager.cs
@@ -31,17 +31,32 @@ namespace Tomboy
public event System.EventHandler ApplicationAddinListChanged;
- public AddinManager (string tomboy_conf_dir)
+ public AddinManager (string tomboy_conf_dir) : this (tomboy_conf_dir, null)
+ {
+ }
+
+ public AddinManager (string tomboy_conf_dir, string old_tomboy_conf_dir)
{
this.tomboy_conf_dir = tomboy_conf_dir;
app_addins = new Dictionary<string, ApplicationAddin> ();
note_addins = new Dictionary<Note, List<NoteAddinInfo>> ();
note_addin_infos = new Dictionary<string, List<NoteAddinInfo>> ();
- InitializeMonoAddins ();
+ 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 ()
+ void InitializeMonoAddins (string old_conf_dir)
{
Logger.Info ("Initializing Mono.Addins");
@@ -49,6 +64,17 @@ namespace Tomboy
if (!Directory.Exists (addins_dir))
Directory.CreateDirectory (addins_dir);
+ // Perform migration if necessary
+ if (!String.IsNullOrEmpty (old_conf_dir)) {
+ foreach (string dir_path in Directory.GetDirectories (old_conf_dir, "addin*")) {
+ // TODO: Check existence stuff
+ 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);
+ }
+ }
+
// Make sure a Tomboy.addins file exists
string addins_file = Path.Combine (addins_dir, "Tomboy.addins");
diff --git a/Tomboy/GnomeApplication.cs b/Tomboy/GnomeApplication.cs
index c5c7666..c940ec9 100644
--- a/Tomboy/GnomeApplication.cs
+++ b/Tomboy/GnomeApplication.cs
@@ -30,9 +30,9 @@ namespace Tomboy
cacheDir = Path.Combine (XdgBaseDirectorySpec.GetUserDirectory ("XDG_CACHE_HOME",
".cache"),
tomboyDirName);
-
- // TODO: Create with 0700 perms if they don't exist
- // (probably best to do this in NoteManager, AddinManager, etc, or Tomboy.cs?)
+
+ // NOTE: Other directories created on demand
+ // (non-existence is an indicator that migration is needed)
if (!Directory.Exists (cacheDir))
Directory.CreateDirectory (cacheDir);
}
diff --git a/Tomboy/NoteManager.cs b/Tomboy/NoteManager.cs
index 60788c8..bbd9d7e 100644
--- a/Tomboy/NoteManager.cs
+++ b/Tomboy/NoteManager.cs
@@ -51,12 +51,52 @@ public NoteManager (string directory) :
notes_dir = directory;
backup_dir = backup_directory;
notes = new List<Note> ();
+
+ string conf_dir = Services.NativeApplication.ConfigurationDirectory;
+
+ string old_notes_dir = null;
+ bool migration_needed = false;
bool first_run = FirstRun ();
+ if (first_run) {
+ old_notes_dir = Services.NativeApplication.PreOneDotZeroNoteDirectory;
+ migration_needed = DirectoryExists (old_notes_dir);
+ }
CreateNotesDir ();
+ if (!Directory.Exists (conf_dir))
+ Directory.CreateDirectory (conf_dir);
+
+ if (migration_needed) {
+ // Copy notes
+ foreach (string noteFile in Directory.GetFiles (old_notes_dir, "*.note"))
+ File.Copy (noteFile, Path.Combine (notes_dir, Path.GetFileName (noteFile)));
+
+ // Copy deleted notes
+ string old_backup = Path.Combine (old_notes_dir, "Backup");
+ if (DirectoryExists (old_backup)) {
+ Directory.CreateDirectory (backup_dir);
+ foreach (string noteFile in Directory.GetFiles (old_backup, "*.note"))
+ File.Copy (noteFile, Path.Combine (backup_dir, Path.GetFileName (noteFile)));
+ }
+
+ // Copy configuration data
+ // NOTE: Add-in configuration data copied by AddinManager
+ string sync_manifest_name = "manifest.xml";
+ string old_sync_manifest_path =
+ Path.Combine (old_notes_dir, sync_manifest_name);
+ if (File.Exists (old_sync_manifest_path))
+ File.Copy (old_sync_manifest_path,
+ Path.Combine (conf_dir, sync_manifest_name));
+
+
+ // NOTE: Not copying cached data
+
+ first_run = false;
+ }
trie_controller = CreateTrieController ();
- addin_mgr = CreateAddinManager ();
+ addin_mgr = new AddinManager (conf_dir,
+ migration_needed ? old_notes_dir : null);
if (first_run) {
// First run. Create "Start Here" notes.
@@ -65,6 +105,33 @@ public NoteManager (string directory) :
LoadNotes ();
}
+ if (migration_needed) {
+ // Create migration notification note
+ // TODO: Finish content, perform duplicate title check...
+ string migration_note_content =
+ Catalog.GetString ("<note-content>" +
+ "Your Notes Have Moved\n\n" +
+ "<bold>Welcome to Tomboy!</bold>\n\n" +
+ "Use this \"Start Here\" note to begin organizing " +
+ "your ideas and thoughts.\n\n" +
+ "You can create new notes to hold your ideas by " +
+ "selecting the \"Create New Note\" item from the " +
+ "Tomboy Notes menu in your GNOME Panel. " +
+ "Your note will be saved automatically.\n\n" +
+ "Then organize the notes you create by linking " +
+ "related notes and ideas together!\n\n" +
+ "We've created a note called " +
+ "<link:internal>Using Links in Tomboy</link:internal>. " +
+ "Notice how each time we type <link:internal>Using " +
+ "Links in Tomboy</link:internal> it automatically " +
+ "gets underlined? Click on the link to open the note." +
+ "</note-content>");
+ Note migration_note = Create (Catalog.GetString ("Your Notes Have Moved"),
+ migration_note_content);
+ migration_note.QueueSave (ChangeType.ContentChanged);
+ migration_note.Window.Show ();
+ }
+
Tomboy.ExitingEvent += OnExitingEvent;
}
@@ -75,13 +142,6 @@ public NoteManager (string directory) :
return new TrieController (this);
}
- protected virtual AddinManager CreateAddinManager ()
- {
- string tomboy_conf_dir = Services.NativeApplication.ConfigurationDirectory;
-
- return new AddinManager (tomboy_conf_dir);
- }
-
// For overriding in test methods.
protected virtual bool DirectoryExists (string directory)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]