From 3001e1c2c1ccd289e70246880506b9cf849ed1a3 Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Thu, 25 Oct 2012 18:15:04 +0100 Subject: [PATCH] controller: don't crash when the SparkleShare folder is on an unmounted drive --- SparkleShare/Linux/SparkleController.cs | 4 ++-- SparkleShare/Mac/SparkleController.cs | 24 +++++++++++------------ SparkleShare/SparkleControllerBase.cs | 20 ++++++++++++++++--- SparkleShare/Windows/SparkleController.cs | 7 +++---- 4 files changed, 33 insertions(+), 22 deletions(-) diff --git a/SparkleShare/Linux/SparkleController.cs b/SparkleShare/Linux/SparkleController.cs index 460e9420..4f3fd0dd 100755 --- a/SparkleShare/Linux/SparkleController.cs +++ b/SparkleShare/Linux/SparkleController.cs @@ -123,8 +123,8 @@ namespace SparkleShare { bool folder_created = false; if (!Directory.Exists (SparkleConfig.DefaultConfig.FoldersPath)) { - Directory.CreateDirectory (SparkleConfig.DefaultConfig.FoldersPath); - SparkleLogger.LogInfo ("Controller", "Created '" + SparkleConfig.DefaultConfig.FoldersPath + "'"); + Directory.CreateDirectory (SparkleConfig.DefaultConfig.FoldersPath); + SparkleLogger.LogInfo ("Controller", "Created '" + SparkleConfig.DefaultConfig.FoldersPath + "'"); folder_created = true; } diff --git a/SparkleShare/Mac/SparkleController.cs b/SparkleShare/Mac/SparkleController.cs index 43dc255d..93add783 100755 --- a/SparkleShare/Mac/SparkleController.cs +++ b/SparkleShare/Mac/SparkleController.cs @@ -55,13 +55,9 @@ namespace SparkleShare { NSApplication.Init (); } - // Let's use the bundled git first - SparkleLib.Git.SparkleGit.GitPath = - Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core", "git"); - - SparkleLib.Git.SparkleGit.ExecPath = - Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core"); + SparkleLib.Git.SparkleGit.GitPath = Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core", "git"); + SparkleLib.Git.SparkleGit.ExecPath = Path.Combine (NSBundle.MainBundle.ResourcePath, "git", "libexec", "git-core"); } @@ -91,11 +87,9 @@ namespace SparkleShare { // There aren't any bindings in MonoMac to support this yet, so // we call out to an applescript to do the job Process process = new Process (); - process.StartInfo.FileName = "osascript"; - process.StartInfo.RedirectStandardOutput = true; - process.StartInfo.UseShellExecute = false; - - process.StartInfo.Arguments = "-e 'tell application \"System Events\" to " + + process.StartInfo.FileName = "osascript"; + process.StartInfo.UseShellExecute = false; + process.StartInfo.Arguments = "-e 'tell application \"System Events\" to " + "make login item at end with properties {path:\"" + NSBundle.MainBundle.BundlePath + "\", hidden:false}'"; process.Start (); @@ -170,11 +164,15 @@ namespace SparkleShare { if (!Directory.Exists (Program.Controller.FoldersPath)) { Directory.CreateDirectory (Program.Controller.FoldersPath); + + NSWorkspace.SharedWorkspace.SetIconforFile (NSImage.ImageNamed ("sparkleshare-folder.icns"), + Program.Controller.FoldersPath, 0); + return true; - } else { - return false; } + + return false; } diff --git a/SparkleShare/SparkleControllerBase.cs b/SparkleShare/SparkleControllerBase.cs index 88240671..c900ad82 100644 --- a/SparkleShare/SparkleControllerBase.cs +++ b/SparkleShare/SparkleControllerBase.cs @@ -161,6 +161,8 @@ namespace SparkleShare { private Object repo_lock = new Object (); private Object check_repos_lock = new Object (); + private bool lost_folders_path = false; + public SparkleControllerBase () { @@ -178,9 +180,14 @@ namespace SparkleShare { SparklePlugin.PluginsPath = PluginsPath; InstallProtocolHandler (); - // Create the SparkleShare folder and add it to the bookmarks - if (CreateSparkleShareFolder ()) - AddToBookmarks (); + try { + // Create the SparkleShare folder and add it to the bookmarks + if (CreateSparkleShareFolder ()) + AddToBookmarks (); + + } catch (DirectoryNotFoundException) { + this.lost_folders_path = true; + } if (FirstRun) { this.config.SetConfigOption ("notifications", bool.TrueString); @@ -237,6 +244,13 @@ namespace SparkleShare { public void UIHasLoaded () { + if (this.lost_folders_path) { + Program.UI.Bubbles.Controller.ShowBubble ("Where's your SparkleShare folder?", + "Did you put it on a disattached drive?", null); + + Environment.Exit (-1); + } + if (FirstRun) { ShowSetupWindow (PageType.Setup); diff --git a/SparkleShare/Windows/SparkleController.cs b/SparkleShare/Windows/SparkleController.cs index 2f593824..749b9c06 100644 --- a/SparkleShare/Windows/SparkleController.cs +++ b/SparkleShare/Windows/SparkleController.cs @@ -131,9 +131,9 @@ namespace SparkleShare { if (Directory.Exists (FoldersPath)) return false; - Directory.CreateDirectory (FoldersPath); - File.SetAttributes (FoldersPath, File.GetAttributes (FoldersPath) | FileAttributes.System); + Directory.CreateDirectory (FoldersPath); + File.SetAttributes (FoldersPath, File.GetAttributes (FoldersPath) | FileAttributes.System); SparkleLogger.LogInfo ("Config", "Created '" + FoldersPath + "'"); string app_path = Path.GetDirectoryName (Forms.Application.ExecutablePath); @@ -155,8 +155,7 @@ namespace SparkleShare { File.GetAttributes (ini_file_path) | FileAttributes.Hidden | FileAttributes.System); } catch (IOException e) { - SparkleLogger.LogInfo ("Config", - "Failed setting icon for '" + FoldersPath + "': " + e.Message); + SparkleLogger.LogInfo ("Config", "Failed setting icon for '" + FoldersPath + "': " + e.Message); } return true;