setup: Add progress indication when adding a new folder
This commit is contained in:
parent
824fd3392b
commit
f3cb3e6e0f
|
@ -18,6 +18,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
|
|
||||||
namespace SparkleLib {
|
namespace SparkleLib {
|
||||||
|
@ -86,9 +87,45 @@ namespace SparkleLib {
|
||||||
public override bool Fetch ()
|
public override bool Fetch ()
|
||||||
{
|
{
|
||||||
this.git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
this.git = new SparkleGit (SparkleConfig.DefaultConfig.TmpPath,
|
||||||
"clone \"" + base.remote_url + "\" " + "\"" + base.target_folder + "\"");
|
"clone " +
|
||||||
|
"--progress " + // Redirects progress stats to standarderror
|
||||||
|
"\"" + base.remote_url + "\" " + "\"" + base.target_folder + "\"");
|
||||||
|
|
||||||
|
this.git.StartInfo.RedirectStandardError = true;
|
||||||
this.git.Start ();
|
this.git.Start ();
|
||||||
|
|
||||||
|
double percentage = 1.0;
|
||||||
|
Regex progress_regex = new Regex (@"([0-9]+)%", RegexOptions.Compiled);
|
||||||
|
|
||||||
|
while (!this.git.StandardError.EndOfStream) {
|
||||||
|
string line = this.git.StandardError.ReadLine ();
|
||||||
|
Match match = progress_regex.Match (line);
|
||||||
|
|
||||||
|
double number = 0.0;
|
||||||
|
if (match.Success) {
|
||||||
|
number = double.Parse (match.Groups [1].Value);
|
||||||
|
|
||||||
|
// The cloning progress consists of two stages: the "Compressing
|
||||||
|
// objects" stage which we count as 20% of the total progress, and
|
||||||
|
// the "Receiving objects" stage which we count as the last 80%
|
||||||
|
if (line.Contains ("|"))
|
||||||
|
// "Receiving objects" stage
|
||||||
|
number = (number / 100 * 75 + 20);
|
||||||
|
else
|
||||||
|
// "Compressing objects" stage
|
||||||
|
number = (number / 100 * 20);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (number >= percentage) {
|
||||||
|
percentage = number;
|
||||||
|
|
||||||
|
// FIXME: for some reason it doesn't go above 95%
|
||||||
|
base.OnProgressChanged (percentage);
|
||||||
|
}
|
||||||
|
|
||||||
|
System.Threading.Thread.Sleep (100);
|
||||||
|
}
|
||||||
|
|
||||||
this.git.WaitForExit ();
|
this.git.WaitForExit ();
|
||||||
|
|
||||||
SparkleHelpers.DebugInfo ("Git", "Exit code " + this.git.ExitCode.ToString ());
|
SparkleHelpers.DebugInfo ("Git", "Exit code " + this.git.ExitCode.ToString ());
|
||||||
|
|
|
@ -31,10 +31,12 @@ namespace SparkleLib {
|
||||||
public delegate void StartedEventHandler ();
|
public delegate void StartedEventHandler ();
|
||||||
public delegate void FinishedEventHandler ();
|
public delegate void FinishedEventHandler ();
|
||||||
public delegate void FailedEventHandler ();
|
public delegate void FailedEventHandler ();
|
||||||
|
public delegate void ProgressChangedEventHandler (double percentage);
|
||||||
|
|
||||||
public event StartedEventHandler Started;
|
public event StartedEventHandler Started;
|
||||||
public event FinishedEventHandler Finished;
|
public event FinishedEventHandler Finished;
|
||||||
public event FailedEventHandler Failed;
|
public event FailedEventHandler Failed;
|
||||||
|
public event ProgressChangedEventHandler ProgressChanged;
|
||||||
|
|
||||||
protected string target_folder;
|
protected string target_folder;
|
||||||
protected string remote_url;
|
protected string remote_url;
|
||||||
|
@ -117,7 +119,13 @@ namespace SparkleLib {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
protected void OnProgressChanged (double percentage) {
|
||||||
|
if (ProgressChanged != null)
|
||||||
|
ProgressChanged (percentage);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private void DisableHostKeyCheckingForHost (string host)
|
private void DisableHostKeyCheckingForHost (string host)
|
||||||
{
|
{
|
||||||
string path = SparkleConfig.DefaultConfig.HomePath;
|
string path = SparkleConfig.DefaultConfig.HomePath;
|
||||||
|
|
|
@ -295,11 +295,20 @@ namespace SparkleShare {
|
||||||
"Are you sure it’s not coffee o'clock?";
|
"Are you sure it’s not coffee o'clock?";
|
||||||
|
|
||||||
ProgressIndicator = new NSProgressIndicator () {
|
ProgressIndicator = new NSProgressIndicator () {
|
||||||
Frame = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
|
Frame = new RectangleF (190, Frame.Height - 200, 640 - 150 - 80, 20),
|
||||||
Style = NSProgressIndicatorStyle.Bar
|
Style = NSProgressIndicatorStyle.Bar,
|
||||||
|
MinValue = 0.0,
|
||||||
|
MaxValue = 100.0
|
||||||
};
|
};
|
||||||
|
|
||||||
ProgressIndicator.StartAnimation (this);
|
// ProgressIndicator.StartAnimation (this);
|
||||||
|
|
||||||
|
Controller.UpdateProgressBarEvent += delegate (double percentage) {
|
||||||
|
InvokeOnMainThread (delegate {
|
||||||
|
ProgressIndicator.DoubleValue = percentage;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
ContentView.AddSubview (ProgressIndicator);
|
ContentView.AddSubview (ProgressIndicator);
|
||||||
|
|
||||||
FinishButton = new NSButton () {
|
FinishButton = new NSButton () {
|
||||||
|
|
|
@ -46,6 +46,9 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public event FolderFetchErrorEventHandler FolderFetchError;
|
public event FolderFetchErrorEventHandler FolderFetchError;
|
||||||
public delegate void FolderFetchErrorEventHandler ();
|
public delegate void FolderFetchErrorEventHandler ();
|
||||||
|
|
||||||
|
public event FolderFetchingEventHandler FolderFetching;
|
||||||
|
public delegate void FolderFetchingEventHandler (double percentage);
|
||||||
|
|
||||||
public event FolderListChangedEventHandler FolderListChanged;
|
public event FolderListChangedEventHandler FolderListChanged;
|
||||||
public delegate void FolderListChangedEventHandler ();
|
public delegate void FolderListChangedEventHandler ();
|
||||||
|
@ -1055,6 +1058,12 @@ namespace SparkleShare {
|
||||||
if (Directory.Exists (tmp_path))
|
if (Directory.Exists (tmp_path))
|
||||||
Directory.Delete (tmp_path, true);
|
Directory.Delete (tmp_path, true);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
this.fetcher.ProgressChanged += delegate (double percentage) {
|
||||||
|
if (FolderFetching != null)
|
||||||
|
FolderFetching (percentage);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
this.fetcher.Start ();
|
this.fetcher.Start ();
|
||||||
|
|
|
@ -43,10 +43,8 @@ namespace SparkleShare {
|
||||||
private Button SyncButton;
|
private Button SyncButton;
|
||||||
|
|
||||||
private Table Table;
|
private Table Table;
|
||||||
|
private ProgressBar progress_bar = new ProgressBar ();
|
||||||
private ProgressBar progress_bar = new ProgressBar () { PulseStep = 0.01 };
|
|
||||||
private Timer progress_bar_pulse_timer = new Timer () { Interval = 25, Enabled = true };
|
|
||||||
|
|
||||||
|
|
||||||
// Short alias for the translations
|
// Short alias for the translations
|
||||||
public static string _ (string s)
|
public static string _ (string s)
|
||||||
|
@ -314,11 +312,11 @@ namespace SparkleShare {
|
||||||
AddButton (cancel_button);
|
AddButton (cancel_button);
|
||||||
AddButton (finish_button);
|
AddButton (finish_button);
|
||||||
|
|
||||||
this.progress_bar_pulse_timer.Elapsed += delegate {
|
Controller.UpdateProgressBarEvent += delegate (double percentage) {
|
||||||
Application.Invoke (delegate {
|
Application.Invoke (delegate {
|
||||||
progress_bar.Pulse ();
|
this.progress_bar.Fraction = percentage / 100;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
if (this.progress_bar.Parent != null)
|
if (this.progress_bar.Parent != null)
|
||||||
(this.progress_bar.Parent as Container).Remove (this.progress_bar);
|
(this.progress_bar.Parent as Container).Remove (this.progress_bar);
|
||||||
|
|
|
@ -33,6 +33,9 @@ namespace SparkleShare {
|
||||||
|
|
||||||
public event ChangePageEventHandler ChangePageEvent;
|
public event ChangePageEventHandler ChangePageEvent;
|
||||||
public delegate void ChangePageEventHandler (PageType page);
|
public delegate void ChangePageEventHandler (PageType page);
|
||||||
|
|
||||||
|
public event UpdateProgressBarEventHandler UpdateProgressBarEvent;
|
||||||
|
public delegate void UpdateProgressBarEventHandler (double percentage);
|
||||||
|
|
||||||
public string PreviousServer {
|
public string PreviousServer {
|
||||||
get {
|
get {
|
||||||
|
@ -120,6 +123,11 @@ namespace SparkleShare {
|
||||||
|
|
||||||
this.syncing_folder = "";
|
this.syncing_folder = "";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
SparkleShare.Controller.FolderFetching += delegate (double percentage) {
|
||||||
|
if (UpdateProgressBarEvent != null)
|
||||||
|
UpdateProgressBarEvent (percentage);
|
||||||
|
};
|
||||||
|
|
||||||
SparkleShare.Controller.FetchFolder (server, folder_name);
|
SparkleShare.Controller.FetchFolder (server, folder_name);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue