From 71017990a9f0ae040cce3faf32c1ca24bf82fc9d Mon Sep 17 00:00:00 2001 From: Hylke Bons Date: Sat, 27 Nov 2010 21:23:44 +0000 Subject: [PATCH] [paths] Add a SparklePath for git --- SparkleLib/SparkleFetcher.cs | 82 +------------------------------ SparkleLib/SparklePaths.cs | 28 +++++++++-- SparkleLib/SparkleRepo.cs | 10 ++-- SparkleShare/SparkleController.cs | 4 +- 4 files changed, 35 insertions(+), 89 deletions(-) diff --git a/SparkleLib/SparkleFetcher.cs b/SparkleLib/SparkleFetcher.cs index e8e87b31..59c97975 100644 --- a/SparkleLib/SparkleFetcher.cs +++ b/SparkleLib/SparkleFetcher.cs @@ -35,7 +35,6 @@ namespace SparkleLib { private string TargetFolder; private string RemoteOriginUrl; - public SparkleProgress Progress; public SparkleFetcher (string url, string folder) @@ -43,7 +42,6 @@ namespace SparkleLib { TargetFolder = folder; RemoteOriginUrl = url; - Progress = new SparkleProgress (); } @@ -67,25 +65,10 @@ namespace SparkleLib { process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.UseShellExecute = false; - process.StartInfo.FileName = "git"; + process.StartInfo.FileName = SparklePaths.GitPath; process.StartInfo.Arguments = "clone --progress " + "\"" + RemoteOriginUrl + "\" " + "\"" + TargetFolder + "\""; -Timer timer = new Timer () { -Interval = 1000 -}; -timer.Elapsed += delegate { -Console.WriteLine ("ppppppppppppppp"); - Console.WriteLine (process.StandardError.ReadToEnd ()); - -}; - process.ErrorDataReceived += delegate (object o, DataReceivedEventArgs args) { - Console.WriteLine (">>>>>>>>>" + args.Data); - Progress.Speed = ""; - Progress.Fraction = 0; - }; - - process.Exited += delegate { SparkleHelpers.DebugInfo ("Git", "Exit code " + process.ExitCode.ToString ()); @@ -110,7 +93,7 @@ Console.WriteLine ("ppppppppppppppp"); } }; -timer.Start(); + process.Start (); process.BeginErrorReadLine (); @@ -165,66 +148,5 @@ timer.Start(); } } - - - public class SparkleProgress { - - public string _Speed; - public int _Fraction; - - public delegate void ProgressChangedEventHandler (); - public event ProgressChangedEventHandler ProgressChanged; - - - public SparkleProgress () - { - - _Speed = "0 B/s"; - _Fraction = 0; - - } - - - public string Speed - { - - get { - - return _Speed; - - } - - set { - - _Speed = value; - - if (ProgressChanged != null) - ProgressChanged (); - - } - - } - - public int Fraction - { - - get { - - return _Fraction; - - } - - set { - - _Fraction = value; - - if (ProgressChanged != null) - ProgressChanged (); - - } - - } - - } } diff --git a/SparkleLib/SparklePaths.cs b/SparkleLib/SparklePaths.cs index ceda3e40..c45adc01 100644 --- a/SparkleLib/SparklePaths.cs +++ b/SparkleLib/SparklePaths.cs @@ -15,6 +15,7 @@ // along with this program. If not, see . using System; +using System.Diagnostics; using System.IO; using Mono.Unix; @@ -22,10 +23,10 @@ namespace SparkleLib { public static class SparklePaths { + + public static string GitPath = GetGitPath (); - private static UnixUserInfo UnixUserInfo = new UnixUserInfo (UnixEnvironment.UserName); - - public static string HomePath = UnixUserInfo.HomeDirectory; + public static string HomePath = new UnixUserInfo (UnixEnvironment.UserName).HomeDirectory; public static string SparklePath = Path.Combine (HomePath ,"SparkleShare"); @@ -42,6 +43,27 @@ namespace SparkleLib { public static string SparkleIconPath = SparkleHelpers.CombineMore (Defines.PREFIX, "share", "sparkleshare", "icons"); + + private static string GetGitPath () + { + + Process process = new Process (); + + process.StartInfo.RedirectStandardOutput = true; + process.StartInfo.UseShellExecute = false; + process.StartInfo.FileName = "which"; + process.StartInfo.Arguments = "git"; + process.Start (); + + string git_path = process.StandardOutput.ReadToEnd ().Trim (); + + if (!string.IsNullOrEmpty (git_path)) + return git_path; + else + return null; + + } + } } diff --git a/SparkleLib/SparkleRepo.cs b/SparkleLib/SparkleRepo.cs index cd4e5f67..443bfa9d 100644 --- a/SparkleLib/SparkleRepo.cs +++ b/SparkleLib/SparkleRepo.cs @@ -258,7 +258,7 @@ namespace SparkleLib { EnableRaisingEvents = true }; - Process.StartInfo.FileName = "/opt/local/bin/git"; + Process.StartInfo.FileName = SparklePaths.GitPath; Process.StartInfo.RedirectStandardOutput = true; Process.StartInfo.UseShellExecute = false; Process.StartInfo.WorkingDirectory = LocalPath; @@ -430,7 +430,7 @@ namespace SparkleLib { EnableRaisingEvents = true }; - process.StartInfo.FileName = "/opt/local/bin/git"; + process.StartInfo.FileName = SparklePaths.GitPath; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.WorkingDirectory = LocalPath; @@ -663,7 +663,7 @@ namespace SparkleLib { EnableRaisingEvents = true }; - process.StartInfo.FileName = "/opt/local/bin/git"; + process.StartInfo.FileName = SparklePaths.GitPath; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.UseShellExecute = false; process.StartInfo.WorkingDirectory = LocalPath; @@ -831,9 +831,9 @@ namespace SparkleLib { Process.StartInfo.Arguments = "push origin master"; - Process.Start (); Process.WaitForExit (); - + Process.Start (); + Process.Exited += delegate { _IsSyncing = false; diff --git a/SparkleShare/SparkleController.cs b/SparkleShare/SparkleController.cs index 59c9d22d..eb6d00f4 100644 --- a/SparkleShare/SparkleController.cs +++ b/SparkleShare/SparkleController.cs @@ -275,6 +275,9 @@ namespace SparkleShare { // Creates the SparkleShare folder in the user's home folder public abstract bool CreateSparkleShareFolder (); + // Opens the SparkleShare folder or an (optional) subfolder + public abstract void OpenSparkleShareFolder (string subfolder); + // Fires events for the current syncing state private void UpdateState () @@ -523,7 +526,6 @@ namespace SparkleShare { } - public abstract void OpenSparkleShareFolder (string subfolder); // Adds the user's SparkleShare key to the ssh-agent, // so all activity is done with this key