windows: Add migration code to use ~/SparkleShare instead of ~/My Documents/SparkleShare

This commit is contained in:
Hylke Bons 2012-03-15 03:56:10 +00:00
parent 8bff4c7b8b
commit 85bec2210a
3 changed files with 53 additions and 10 deletions

View file

@ -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");

View file

@ -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);

View file

@ -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 ();