diff --git a/SparkleLib/Makefile.am b/SparkleLib/Makefile.am index f46f7b52..bfe7c9ee 100644 --- a/SparkleLib/Makefile.am +++ b/SparkleLib/Makefile.am @@ -5,6 +5,7 @@ LINK = $(REF_SPARKLELIB) SOURCES = \ Defines.cs \ + SparkleBackend.cs \ SparkleCommit.cs \ SparkleEvents.cs \ SparkleFetcher.cs \ diff --git a/SparkleLib/SparkleBackend.cs b/SparkleLib/SparkleBackend.cs new file mode 100644 index 00000000..58c3f0c4 --- /dev/null +++ b/SparkleLib/SparkleBackend.cs @@ -0,0 +1,50 @@ +// SparkleShare, an instant update workflow to Git. +// Copyright (C) 2010 Hylke Bons +// +// This program is free software: you can redistribute it and/or modify +// it under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program. If not, see . + + +using System; +using System.IO; + +namespace SparkleLib { + + public class SparkleBackend { + + public static SparkleBackend DefaultBackend; + + public string Name; + public string Path; + + + public SparkleBackend (string name, string [] paths) + { + Name = name; + + foreach (string path in paths) { + if (File.Exists (path)) { + Path = path; + break; + } + } + } + + + public bool IsPresent { + get { + return (Path != null); + } + } + } +} diff --git a/SparkleLib/SparkleGit.cs b/SparkleLib/SparkleGit.cs index a648603a..2bc9add1 100644 --- a/SparkleLib/SparkleGit.cs +++ b/SparkleLib/SparkleGit.cs @@ -25,7 +25,7 @@ namespace SparkleLib { public SparkleGit (string path, string args) : base () { EnableRaisingEvents = true; - StartInfo.FileName = SparklePaths.GitPath; + StartInfo.FileName = SparkleBackend.DefaultBackend.Path; StartInfo.Arguments = args; StartInfo.RedirectStandardOutput = true; StartInfo.UseShellExecute = false; diff --git a/SparkleLib/SparklePaths.cs b/SparkleLib/SparklePaths.cs index c901f9b1..1c7e11ec 100644 --- a/SparkleLib/SparklePaths.cs +++ b/SparkleLib/SparklePaths.cs @@ -14,43 +14,17 @@ // You should have received a copy of the GNU General Public License // along with this program. If not, see . + using System; using System.Diagnostics; using System.IO; + using Mono.Unix; namespace SparkleLib { - public static class Backend { - - public static string Name = "Git"; - - public static string Path { - get { - string [] possible_git_paths = {"/usr/bin/git", - "/usr/local/git/bin/git", - "/usr/local/bin/git"}; - - foreach (string git_path in possible_git_paths) - if (File.Exists (git_path)) - return git_path; - - return null; - } - } - - - public static bool IsPresent { - get { - return (Path != null); - } - } - } - - public static class SparklePaths { - public static string GitPath = Backend.Path; public static string HomePath = new UnixUserInfo (UnixEnvironment.UserName).HomeDirectory; public static string SparklePath = Path.Combine (HomePath ,"SparkleShare"); public static string SparkleTmpPath = Path.Combine (SparklePath, ".tmp"); diff --git a/SparkleLib/SparkleRepo.cs b/SparkleLib/SparkleRepo.cs index 86842276..08972064 100644 --- a/SparkleLib/SparkleRepo.cs +++ b/SparkleLib/SparkleRepo.cs @@ -48,6 +48,7 @@ namespace SparkleLib { private bool has_unsynced_changes; private bool server_online; + public readonly SparkleBackend Backend; public readonly string Name; public readonly string RemoteName; public readonly string Domain; @@ -132,7 +133,7 @@ namespace SparkleLib { public event CommitEndedUpEmptyEventHandler CommitEndedUpEmpty; - public SparkleRepo (string path) + public SparkleRepo (string path, SparkleBackend backend) { LocalPath = path; Name = Path.GetFileName (LocalPath); @@ -142,6 +143,7 @@ namespace SparkleLib { Description = GetDescription (); UserName = GetUserName (); UserEmail = GetUserEmail (); + Backend = backend; this.is_syncing = false; this.is_buffering = false; diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index 8e15a804..ac6a4a2b 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -476,7 +476,7 @@ namespace SparkleShare { if (!SparkleRepo.IsRepo (folder_path)) return; - SparkleRepo repo = new SparkleRepo (folder_path); + SparkleRepo repo = new SparkleRepo (folder_path, SparkleBackend.DefaultBackend); repo.NewCommit += delegate (SparkleCommit commit, string repository_path) { string message = FormatMessage (commit); @@ -705,7 +705,7 @@ namespace SparkleShare { public bool BackendIsPresent { get { - return SparkleLib.Backend.IsPresent; + return SparkleBackend.DefaultBackend.IsPresent; } } diff --git a/SparkleShare/SparkleShare.cs b/SparkleShare/SparkleShare.cs index 7c3fac75..6f941a50 100644 --- a/SparkleShare/SparkleShare.cs +++ b/SparkleShare/SparkleShare.cs @@ -76,6 +76,10 @@ namespace SparkleShare { if (show_help) ShowHelp (p); + // Set the default backend for SparkleLib + string [] git_paths = new string [3] {"/usr/bin/git", "/usr/local/git/bin/git", "/usr/local/bin/git"}; + SparkleBackend.DefaultBackend = new SparkleBackend ("Git", git_paths); + // Load the right controller for the OS string controller_name; switch (SparkleShare.Platform) {