[paths] Add a SparklePath for git

This commit is contained in:
Hylke Bons 2010-11-27 21:23:44 +00:00
parent 62a9afbb70
commit 71017990a9
4 changed files with 35 additions and 89 deletions

View file

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

View file

@ -15,6 +15,7 @@
// along with this program. If not, see <http://www.gnu.org/licenses/>.
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;
}
}
}

View file

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

View file

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