pass transfer speeds in bytes, not strings. report both directions when needed.
This commit is contained in:
parent
7c71c3d67f
commit
6015950fc5
|
@ -229,7 +229,7 @@ namespace SparkleLib.Git {
|
|||
while (!git.StandardError.EndOfStream) {
|
||||
string line = git.StandardError.ReadLine ();
|
||||
Match match = progress_regex.Match (line);
|
||||
string speed = "";
|
||||
double speed = 0.0;
|
||||
double number = 0.0;
|
||||
|
||||
if (match.Success) {
|
||||
|
@ -247,10 +247,16 @@ namespace SparkleLib.Git {
|
|||
number = (number / 100 * 80 + 20);
|
||||
|
||||
if (line.Contains ("|")) {
|
||||
speed = line.Substring (line.IndexOf ("|") + 1).Trim ();
|
||||
speed = speed.Replace (", done.", "").Trim ();
|
||||
speed = speed.Replace ("KiB/s", "ᴋʙ/s");
|
||||
speed = speed.Replace ("MiB/s", "ᴍʙ/s");
|
||||
string s = line.Substring (line.IndexOf ("|") + 1).Trim ();
|
||||
s = s.Replace (", done.", "").Trim ();
|
||||
s = s.Replace ("KiB/s", "ᴋʙ/s");
|
||||
s = s.Replace ("MiB/s", "ᴍʙ/s");
|
||||
|
||||
if (line.Contains ("KiB/s"))
|
||||
speed = double.Parse (s);
|
||||
|
||||
if (line.Contains ("MiB/s"))
|
||||
speed = double.Parse (s);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -311,7 +317,7 @@ namespace SparkleLib.Git {
|
|||
while (!git.StandardError.EndOfStream) {
|
||||
string line = git.StandardError.ReadLine ();
|
||||
Match match = progress_regex.Match (line);
|
||||
string speed = "";
|
||||
double speed = 0.0;
|
||||
double number = 0.0;
|
||||
|
||||
if (match.Success) {
|
||||
|
@ -329,10 +335,16 @@ namespace SparkleLib.Git {
|
|||
number = (number / 100 * 80 + 20);
|
||||
|
||||
if (line.Contains ("|")) {
|
||||
speed = line.Substring (line.IndexOf ("|") + 1).Trim ();
|
||||
speed = speed.Replace (", done.", "").Trim ();
|
||||
speed = speed.Replace ("KiB/s", "ᴋʙ/s");
|
||||
speed = speed.Replace ("MiB/s", "ᴍʙ/s");
|
||||
string s = line.Substring (line.IndexOf ("|") + 1).Trim ();
|
||||
s = s.Replace (", done.", "").Trim ();
|
||||
s = s.Replace ("KiB/s", "ᴋʙ/s");
|
||||
s = s.Replace ("MiB/s", "ᴍʙ/s");
|
||||
|
||||
if (line.Contains ("KiB/s"))
|
||||
speed = double.Parse (s);
|
||||
|
||||
if (line.Contains ("MiB/s"))
|
||||
speed = double.Parse (s);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -451,6 +463,7 @@ namespace SparkleLib.Git {
|
|||
string error_output = git.StartAndReadStandardError ();
|
||||
|
||||
if (git.ExitCode != 0) {
|
||||
// Stop when we can't rebase due to locked local files
|
||||
// error: cannot stat 'filename': Permission denied
|
||||
if (error_output.Contains ("error: cannot stat")) {
|
||||
Error = ErrorStatus.LockedFiles;
|
||||
|
|
|
@ -53,5 +53,22 @@ namespace SparkleLib {
|
|||
|
||||
return BitConverter.ToString (md5_bytes).ToLower ().Replace ("-", "");
|
||||
}
|
||||
|
||||
|
||||
// Format a file size nicely with small caps.
|
||||
// Example: 1048576 becomes "1 ᴍʙ"
|
||||
public static string ToSize (this double byte_count)
|
||||
{
|
||||
if (byte_count >= 1099511627776)
|
||||
return String.Format ("{0:##.##} ᴛʙ", Math.Round (byte_count / 1099511627776, 1));
|
||||
else if (byte_count >= 1073741824)
|
||||
return String.Format ("{0:##.##} ɢʙ", Math.Round (byte_count / 1073741824, 1));
|
||||
else if (byte_count >= 1048576)
|
||||
return String.Format ("{0:##.##} ᴍʙ", Math.Round (byte_count / 1048576, 0));
|
||||
else if (byte_count >= 1024)
|
||||
return String.Format ("{0:##.##} ᴋʙ", Math.Round (byte_count / 1024, 0));
|
||||
else
|
||||
return byte_count.ToString () + " bytes";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ namespace SparkleLib {
|
|||
public delegate void SyncStatusChangedEventHandler (SyncStatus new_status);
|
||||
|
||||
public event ProgressChangedEventHandler ProgressChanged = delegate { };
|
||||
public delegate void ProgressChangedEventHandler (double percentage, string speed);
|
||||
public delegate void ProgressChangedEventHandler ();
|
||||
|
||||
public event NewChangeSetEventHandler NewChangeSet = delegate { };
|
||||
public delegate void NewChangeSetEventHandler (SparkleChangeSet change_set);
|
||||
|
@ -80,7 +80,7 @@ namespace SparkleLib {
|
|||
public ErrorStatus Error { get; protected set; }
|
||||
public bool IsBuffering { get; private set; }
|
||||
public double ProgressPercentage { get; private set; }
|
||||
public string ProgressSpeed { get; private set; }
|
||||
public double ProgressSpeed { get; private set; }
|
||||
|
||||
public string Identifier {
|
||||
get {
|
||||
|
@ -297,7 +297,7 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
|
||||
protected void OnProgressChanged (double progress_percentage, string progress_speed)
|
||||
protected void OnProgressChanged (double progress_percentage, double progress_speed)
|
||||
{
|
||||
if (progress_percentage < 1)
|
||||
return;
|
||||
|
@ -313,7 +313,7 @@ namespace SparkleLib {
|
|||
ProgressSpeed = progress_speed;
|
||||
this.progress_last_change = DateTime.Now;
|
||||
|
||||
ProgressChanged (progress_percentage, progress_speed);
|
||||
ProgressChanged ();
|
||||
}
|
||||
|
||||
|
||||
|
@ -357,7 +357,7 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
ProgressPercentage = 0.0;
|
||||
ProgressSpeed = "";
|
||||
ProgressSpeed = 0.0;
|
||||
|
||||
if (!UseCustomWatcher)
|
||||
this.watcher.Enable ();
|
||||
|
@ -417,7 +417,7 @@ namespace SparkleLib {
|
|||
}
|
||||
|
||||
ProgressPercentage = 0.0;
|
||||
ProgressSpeed = "";
|
||||
ProgressSpeed = 0.0;
|
||||
|
||||
if (!UseCustomWatcher)
|
||||
this.watcher.Enable ();
|
||||
|
|
|
@ -45,7 +45,8 @@ namespace SparkleShare {
|
|||
public string FoldersPath { get; private set; }
|
||||
|
||||
public double ProgressPercentage = 0.0;
|
||||
public string ProgressSpeed = "";
|
||||
public double ProgressSpeedUp = 0.0;
|
||||
public double ProgressSpeedDown = 0.0;
|
||||
|
||||
|
||||
public event ShowSetupWindowEventHandler ShowSetupWindowEvent = delegate { };
|
||||
|
@ -307,15 +308,33 @@ namespace SparkleShare {
|
|||
repo.SyncStatusChanged += delegate (SyncStatus status) {
|
||||
if (status == SyncStatus.Idle) {
|
||||
ProgressPercentage = 0.0;
|
||||
ProgressSpeed = "";
|
||||
ProgressSpeedUp = 0.0;
|
||||
ProgressSpeedDown = 0.0;
|
||||
}
|
||||
|
||||
UpdateState ();
|
||||
};
|
||||
|
||||
repo.ProgressChanged += delegate (double percentage, string speed) {
|
||||
ProgressPercentage = percentage;
|
||||
ProgressSpeed = speed;
|
||||
repo.ProgressChanged += delegate {
|
||||
ProgressPercentage = 0.0;
|
||||
ProgressSpeedUp = 0.0;
|
||||
ProgressSpeedDown = 0.0;
|
||||
|
||||
double percentage = 0.0;
|
||||
int repo_count = 0;
|
||||
|
||||
foreach (SparkleRepoBase rep in Repositories) {
|
||||
if (rep.ProgressPercentage > 0) {
|
||||
percentage += rep.ProgressPercentage;
|
||||
repo_count++;
|
||||
}
|
||||
|
||||
if (rep.Status == SyncStatus.SyncUp)
|
||||
ProgressSpeedUp += rep.ProgressSpeed;
|
||||
|
||||
if (rep.Status == SyncStatus.SyncDown)
|
||||
ProgressSpeedDown += rep.ProgressSpeed;
|
||||
}
|
||||
|
||||
UpdateState ();
|
||||
};
|
||||
|
@ -781,23 +800,6 @@ namespace SparkleShare {
|
|||
}
|
||||
|
||||
|
||||
// Format a file size nicely with small caps.
|
||||
// Example: 1048576 becomes "1 ᴍʙ"
|
||||
public string FormatSize (double byte_count)
|
||||
{
|
||||
if (byte_count >= 1099511627776)
|
||||
return String.Format ("{0:##.##} ᴛʙ", Math.Round (byte_count / 1099511627776, 1));
|
||||
else if (byte_count >= 1073741824)
|
||||
return String.Format ("{0:##.##} ɢʙ", Math.Round (byte_count / 1073741824, 1));
|
||||
else if (byte_count >= 1048576)
|
||||
return String.Format ("{0:##.##} ᴍʙ", Math.Round (byte_count / 1048576, 0));
|
||||
else if (byte_count >= 1024)
|
||||
return String.Format ("{0:##.##} ᴋʙ", Math.Round (byte_count / 1024, 0));
|
||||
else
|
||||
return byte_count.ToString () + " bytes";
|
||||
}
|
||||
|
||||
|
||||
public virtual void Quit ()
|
||||
{
|
||||
foreach (SparkleRepoBase repo in Repositories)
|
||||
|
|
|
@ -117,14 +117,14 @@ namespace SparkleShare {
|
|||
if (repo.Size == 0)
|
||||
return "???";
|
||||
else
|
||||
return Program.Controller.FormatSize (repo.Size);
|
||||
return repo.Size.ToSize ();
|
||||
}
|
||||
}
|
||||
|
||||
if (size == 0)
|
||||
return "???";
|
||||
else
|
||||
return Program.Controller.FormatSize (size);
|
||||
return size.ToSize ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -140,14 +140,14 @@ namespace SparkleShare {
|
|||
if (repo.HistorySize == 0)
|
||||
return "???";
|
||||
else
|
||||
return Program.Controller.FormatSize (repo.HistorySize);
|
||||
return repo.HistorySize.ToSize ();
|
||||
}
|
||||
}
|
||||
|
||||
if (size == 0)
|
||||
return "???";
|
||||
else
|
||||
return Program.Controller.FormatSize (size);
|
||||
return size.ToSize ();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -62,7 +62,7 @@ namespace SparkleShare {
|
|||
if (size == 0)
|
||||
return "";
|
||||
else
|
||||
return "— " + Program.Controller.FormatSize (size);
|
||||
return "— " + size.ToSize ();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -74,7 +74,22 @@ namespace SparkleShare {
|
|||
|
||||
public string ProgressSpeed {
|
||||
get {
|
||||
return Program.Controller.ProgressSpeed;
|
||||
string progress_speed = "";
|
||||
|
||||
if (Program.Controller.ProgressSpeedDown == 0 && Program.Controller.ProgressSpeedUp > 0) {
|
||||
progress_speed = Program.Controller.ProgressSpeedUp.ToSize () + "/s ";
|
||||
|
||||
} else if (Program.Controller.ProgressSpeedUp == 0 && Program.Controller.ProgressSpeedDown > 0) {
|
||||
progress_speed = Program.Controller.ProgressSpeedDown.ToSize () + "/s ";
|
||||
|
||||
} else if (Program.Controller.ProgressSpeedUp > 0 &&
|
||||
Program.Controller.ProgressSpeedDown > 0) {
|
||||
|
||||
progress_speed = "Up: " + Program.Controller.ProgressSpeedUp.ToSize () + "/s " +
|
||||
"Down: " + Program.Controller.ProgressSpeedDown.ToSize () + "/s";
|
||||
}
|
||||
|
||||
return progress_speed;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue