controller: don't crash when the SparkleShare folder is on an unmounted drive

This commit is contained in:
Hylke Bons 2012-10-25 18:15:04 +01:00
parent e32f45214c
commit 3001e1c2c1
4 changed files with 33 additions and 22 deletions

View file

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

View file

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

View file

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

View file

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