From 85bec2210a94a880b7741c7aa42e53a4190a3627 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 15 Mar 2012 03:56:10 +0000 Subject: [PATCH] windows: Add migration code to use ~/SparkleShare instead of ~/My Documents/SparkleShare --- SparkleLib/SparkleConfig.cs | 40 +++++++++++++++++++++-- SparkleShare/SparkleControllerBase.cs | 9 ++--- SparkleShare/Windows/SparkleController.cs | 14 ++++++-- 3 files changed, 53 insertions(+), 10 deletions(-) diff --git a/SparkleLib/SparkleConfig.cs b/SparkleLib/SparkleConfig.cs index 8e02e978..5eccb8a7 100755 --- a/SparkleLib/SparkleConfig.cs +++ b/SparkleLib/SparkleConfig.cs @@ -40,10 +40,21 @@ namespace SparkleLib { public string HomePath { get { - if (GetConfigOption ("home_path") != null) + if (GetConfigOption ("home_path") != null) { return GetConfigOption ("home_path"); - else - return Environment.GetFolderPath (Environment.SpecialFolder.Personal); + + } else { + try { + Environment.SpecialFolder folder = + (Environment.SpecialFolder) Enum.Parse ( + typeof(Environment.SpecialFolder), "UserProfile"); + + return (Environment.GetFolderPath (folder)); + + } catch { + return Environment.GetFolderPath (Environment.SpecialFolder.Personal); + } + } } } @@ -58,6 +69,29 @@ namespace SparkleLib { public SparkleConfig (string config_path, string config_file_name) { + try { + Environment.SpecialFolder folder = + (Environment.SpecialFolder) Enum.Parse( + typeof(Environment.SpecialFolder), "UserProfile"); + + string old_path = Path.Combine ( + Environment.GetFolderPath (Environment.SpecialFolder.Personal), "SparkleShare"); + + if (Directory.Exists (old_path) && + Environment.OSVersion.Platform == PlatformID.Win32NT) { + + string new_path = Path.Combine (Environment.GetFolderPath (folder), "SparkleShare"); + Directory.Move (old_path, new_path); + + Console.WriteLine ("Migrated SparkleShare folder to %USERPROFILE%"); + + } + + } catch (Exception e) { + Console.WriteLine ("Failed to migrate: " + e.Message); + // TODO: Remove this block when most people have migrated to the new path + } + FullPath = Path.Combine (config_path, config_file_name); LogFilePath = Path.Combine (config_path, "debug.log"); diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 095a95f1..d13e4419 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -235,9 +235,9 @@ namespace SparkleShare { public void UIHasLoaded () - { - // if (FirstRun) - ShowSetupWindow (PageType.Setup); + { + if (FirstRun) + ShowSetupWindow (PageType.Setup); } @@ -950,7 +950,8 @@ namespace SparkleShare { if (!Directory.Exists (tmp_path)) { Directory.CreateDirectory (tmp_path); - File.SetAttributes (tmp_path, FileAttributes.Directory | FileAttributes.Hidden); + File.SetAttributes (tmp_path, // FIXME: Doesn't seem to be hidden + File.GetAttributes (tmp_path) | FileAttributes.Hidden); } string canonical_name = Path.GetFileNameWithoutExtension (remote_path); diff --git a/SparkleShare/Windows/SparkleController.cs b/SparkleShare/Windows/SparkleController.cs index 54a442f0..d46dc1c7 100644 --- a/SparkleShare/Windows/SparkleController.cs +++ b/SparkleShare/Windows/SparkleController.cs @@ -108,9 +108,13 @@ namespace SparkleShare { string startup_folder_path = Environment.GetFolderPath ( Environment.SpecialFolder.Startup); - string shortcut_path = Path.Combine (startup_folder_path, "SparkleShare.lnk"); - string shortcut_target = Forms.Application.ExecutablePath; - + string shortcut_path = Path.Combine (startup_folder_path, "SparkleShare.lnk"); + + if (File.Exists (shortcut_path)) + File.Delete (shortcut_path); + + string shortcut_target = Forms.Application.ExecutablePath; + Shortcut shortcut = new Shortcut (); shortcut.Create (shortcut_path, shortcut_target); } @@ -146,6 +150,10 @@ namespace SparkleShare { Environment.SpecialFolder.UserProfile); string shortcut_path = Path.Combine (user_profile_path, "Links", "SparkleShare.lnk"); + + if (File.Exists (shortcut_path)) + File.Delete (shortcut_path); + string shortcut_target = SparkleConfig.DefaultConfig.FoldersPath; Shortcut shortcut = new Shortcut ();