1
0
mirror of https://github.com/Ylianst/MeshCentralRouter synced 2025-12-06 00:13:33 +00:00

Added transfer rate and eta.

This commit is contained in:
Ylian Saint-Hilaire
2021-07-05 16:35:57 -07:00
parent 5c815fd54a
commit f932f9108e
6 changed files with 218 additions and 10 deletions

View File

@@ -36,6 +36,7 @@
this.progressBar1 = new System.Windows.Forms.ProgressBar();
this.mainLabel1 = new System.Windows.Forms.Label();
this.updateTimer = new System.Windows.Forms.Timer(this.components);
this.mainLabel2 = new System.Windows.Forms.Label();
this.mainGroupBox.SuspendLayout();
this.SuspendLayout();
//
@@ -50,6 +51,7 @@
// mainGroupBox
//
resources.ApplyResources(this.mainGroupBox, "mainGroupBox");
this.mainGroupBox.Controls.Add(this.mainLabel2);
this.mainGroupBox.Controls.Add(this.progressBar2);
this.mainGroupBox.Controls.Add(this.progressBar1);
this.mainGroupBox.Controls.Add(this.mainLabel1);
@@ -76,6 +78,11 @@
this.updateTimer.Interval = 500;
this.updateTimer.Tick += new System.EventHandler(this.updateTimer_Tick);
//
// mainLabel2
//
resources.ApplyResources(this.mainLabel2, "mainLabel2");
this.mainLabel2.Name = "mainLabel2";
//
// FileTransferStatusForm
//
resources.ApplyResources(this, "$this");
@@ -102,5 +109,6 @@
private System.Windows.Forms.ProgressBar progressBar1;
private System.Windows.Forms.Label mainLabel1;
private System.Windows.Forms.Timer updateTimer;
private System.Windows.Forms.Label mainLabel2;
}
}

View File

@@ -48,6 +48,15 @@ namespace MeshCentralRouter
if (x > (int)fileViewer.uploadFileSize) { x = (int)fileViewer.uploadFileSize; }
progressBar1.Value = x;
// Compute bytes per second & estimated time left
double elapseTimeSeconds = DateTime.Now.Subtract(fileViewer.uploadFileStartTime).TotalMilliseconds / 1000;
if (elapseTimeSeconds < 5) { mainLabel2.Text = Translate.T(Properties.Resources.EstimatingDotDotDot); } else
{
double bytePerSecond = x / elapseTimeSeconds;
double secondsLeft = Math.Round((fileViewer.uploadFileSize - x) / bytePerSecond);
mainLabel2.Text = bytePerSecondToString(bytePerSecond) + ", " + secondsLeftToString(secondsLeft);
}
progressBar2.Maximum = fileViewer.uploadFileArray.Count;
x = (int)(int)fileViewer.uploadFileSize;
if (x < 0) { x = 0; }
@@ -63,6 +72,15 @@ namespace MeshCentralRouter
if (x > (int)fileViewer.downloadFileSize) { x = (int)fileViewer.downloadFileSize; }
progressBar1.Value = x;
// Compute bytes per second & estimated time left
double elapseTimeSeconds = DateTime.Now.Subtract(fileViewer.downloadFileStartTime).TotalMilliseconds / 1000;
if (elapseTimeSeconds < 5) { mainLabel2.Text = Translate.T(Properties.Resources.EstimatingDotDotDot); } else
{
double bytePerSecond = x / elapseTimeSeconds;
double secondsLeft = Math.Round((fileViewer.downloadFileSize - x) / bytePerSecond);
mainLabel2.Text = bytePerSecondToString(bytePerSecond) + ", " + secondsLeftToString(secondsLeft);
}
progressBar2.Maximum = fileViewer.downloadFileArray.Count;
x = (int)(int)fileViewer.downloadFileSize;
if (x < 0) { x = 0; }
@@ -72,6 +90,22 @@ namespace MeshCentralRouter
else { Close(); }
}
private string secondsLeftToString(double x)
{
if (x > 5400) return String.Format(Translate.T(Properties.Resources.xhoursleft), Math.Round(x / 60 / 60));
if (x > 90) return String.Format(Translate.T(Properties.Resources.xminutesleft), Math.Round(x / 60));
if (x > 1) return String.Format(Translate.T(Properties.Resources.xsecondsleft), Math.Round(x));
return Translate.T(Properties.Resources.Almostdone);
}
private string bytePerSecondToString(double x)
{
if (x > 1200000000) return String.Format(Translate.T(Properties.Resources.XGbytesPersec), Math.Round((x / 1024 / 1024 / 1024) * 10) / 10);
if (x > 1200000) return String.Format(Translate.T(Properties.Resources.XMbytesPersec), Math.Round((x / 1024 / 1024) * 10) / 10);
if (x > 1200) return String.Format(Translate.T(Properties.Resources.XKbytesPersec), Math.Round((x / 1024) * 10) / 10);
return String.Format(Translate.T(Properties.Resources.XbytesPersec), x);
}
private void FileTransferStatusForm_FormClosing(object sender, FormClosingEventArgs e)
{
if (fileViewer.uploadActive) { fileViewer.uploadStop = true; }

View File

@@ -123,7 +123,7 @@
</data>
<assembly alias="System.Drawing" name="System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<data name="cancelButton.Location" type="System.Drawing.Point, System.Drawing">
<value>277, 113</value>
<value>277, 130</value>
</data>
<data name="cancelButton.Size" type="System.Drawing.Size, System.Drawing">
<value>75, 23</value>
@@ -150,11 +150,41 @@
<data name="mainGroupBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Bottom, Left, Right</value>
</data>
<data name="mainLabel2.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
</data>
<data name="mainLabel2.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
<value>NoControl</value>
</data>
<data name="mainLabel2.Location" type="System.Drawing.Point, System.Drawing">
<value>14, 42</value>
</data>
<data name="mainLabel2.Size" type="System.Drawing.Size, System.Drawing">
<value>309, 13</value>
</data>
<data name="mainLabel2.TabIndex" type="System.Int32, mscorlib">
<value>5</value>
</data>
<data name="mainLabel2.Text" xml:space="preserve">
<value>---</value>
</data>
<data name="&gt;&gt;mainLabel2.Name" xml:space="preserve">
<value>mainLabel2</value>
</data>
<data name="&gt;&gt;mainLabel2.Type" xml:space="preserve">
<value>System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="&gt;&gt;mainLabel2.Parent" xml:space="preserve">
<value>mainGroupBox</value>
</data>
<data name="&gt;&gt;mainLabel2.ZOrder" xml:space="preserve">
<value>0</value>
</data>
<data name="progressBar2.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
</data>
<data name="progressBar2.Location" type="System.Drawing.Point, System.Drawing">
<value>17, 64</value>
<value>17, 83</value>
</data>
<data name="progressBar2.Size" type="System.Drawing.Size, System.Drawing">
<value>306, 16</value>
@@ -172,13 +202,13 @@
<value>mainGroupBox</value>
</data>
<data name="&gt;&gt;progressBar2.ZOrder" xml:space="preserve">
<value>0</value>
<value>1</value>
</data>
<data name="progressBar1.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
</data>
<data name="progressBar1.Location" type="System.Drawing.Point, System.Drawing">
<value>17, 42</value>
<value>17, 61</value>
</data>
<data name="progressBar1.Size" type="System.Drawing.Size, System.Drawing">
<value>306, 16</value>
@@ -196,7 +226,7 @@
<value>mainGroupBox</value>
</data>
<data name="&gt;&gt;progressBar1.ZOrder" xml:space="preserve">
<value>1</value>
<value>2</value>
</data>
<data name="mainLabel1.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
<value>Top, Left, Right</value>
@@ -223,13 +253,13 @@
<value>mainGroupBox</value>
</data>
<data name="&gt;&gt;mainLabel1.ZOrder" xml:space="preserve">
<value>2</value>
<value>3</value>
</data>
<data name="mainGroupBox.Location" type="System.Drawing.Point, System.Drawing">
<value>12, 12</value>
</data>
<data name="mainGroupBox.Size" type="System.Drawing.Size, System.Drawing">
<value>340, 95</value>
<value>340, 112</value>
</data>
<data name="mainGroupBox.TabIndex" type="System.Int32, mscorlib">
<value>4</value>
@@ -259,7 +289,7 @@
<value>6, 13</value>
</data>
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
<value>364, 148</value>
<value>364, 165</value>
</data>
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>

View File

@@ -59,6 +59,7 @@ namespace MeshCentralRouter
public FileStream uploadFileStream = null;
public long uploadFilePtr = 0;
public long uploadFileSize = 0;
public DateTime uploadFileStartTime = DateTime.MinValue;
// Download state
public bool downloadActive = false;
@@ -71,6 +72,7 @@ namespace MeshCentralRouter
public FileStream downloadFileStream = null;
public long downloadFilePtr = 0;
public long downloadFileSize = 0;
public DateTime downloadFileStartTime = DateTime.MinValue;
public FileViewer(MeshCentralServer server, NodeClass node)
{
@@ -951,7 +953,7 @@ namespace MeshCentralRouter
if (overWriteCount > 0)
{
FileConfirmOverwriteForm f = new FileConfirmOverwriteForm();
if (overWriteCount == 1) { f.mainTextLabel = String.Format("Overwrite 1 file?", overWriteCount); } else { f.mainTextLabel = String.Format("Overwrite {0} files?", overWriteCount); }
if (overWriteCount == 1) { f.mainTextLabel = String.Format(Translate.T(Properties.Resources.OverwriteOneFile), overWriteCount); } else { f.mainTextLabel = String.Format(Translate.T(Properties.Resources.OverwriteXfiles), overWriteCount); }
if (f.ShowDialog(this) == DialogResult.OK) { performFileUpload(); }
}
else
@@ -994,6 +996,7 @@ namespace MeshCentralRouter
uploadFileStream = File.OpenRead(localFilePath);
uploadFileSize = new FileInfo(localFilePath).Length;
uploadFilePtr = 0;
uploadFileStartTime = DateTime.Now;
// Send UPLOAD command
string cmd = "{\"action\":\"upload\",\"reqid\":" + (uploadFileArrayPtr + 1000) + ",\"path\":\"" + uploadRemotePath + "\",\"name\":\"" + localFileName + "\",\"size\":" + uploadFileSize + "}";
@@ -1081,7 +1084,7 @@ namespace MeshCentralRouter
if (overWriteCount > 0)
{
FileConfirmOverwriteForm f = new FileConfirmOverwriteForm();
if (overWriteCount == 1) { f.mainTextLabel = String.Format("Overwrite 1 file?", overWriteCount); } else { f.mainTextLabel = String.Format("Overwrite {0} files?", overWriteCount); }
if (overWriteCount == 1) { f.mainTextLabel = String.Format(Translate.T(Properties.Resources.OverwriteOneFile), overWriteCount); } else { f.mainTextLabel = String.Format(Translate.T(Properties.Resources.OverwriteXfiles), overWriteCount); }
if (f.ShowDialog(this) == DialogResult.OK) { performFileDownload(); }
}
else
@@ -1123,6 +1126,7 @@ namespace MeshCentralRouter
try { downloadFileStream = File.OpenWrite(localFilePath); } catch (Exception) { return; }
downloadFileSize = (int)downloadFileSizeArray[downloadFileArrayPtr];
downloadFilePtr = 0;
downloadFileStartTime = DateTime.Now;
string r;
if (downloadRemotePath.EndsWith("/")) { r = downloadRemotePath + downloadFileArray[downloadFileArrayPtr]; } else { r = downloadRemotePath + "/" + downloadFileArray[downloadFileArrayPtr]; }

View File

@@ -87,6 +87,15 @@ namespace MeshCentralRouter.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Almost done.
/// </summary>
internal static string Almostdone {
get {
return ResourceManager.GetString("Almostdone", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to AMT.
/// </summary>
@@ -272,6 +281,15 @@ namespace MeshCentralRouter.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Estimating....
/// </summary>
internal static string EstimatingDotDotDot {
get {
return ResourceManager.GetString("EstimatingDotDotDot", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Failed to start remote desktop session.
/// </summary>
@@ -572,6 +590,24 @@ namespace MeshCentralRouter.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to Overwrite 1 file?.
/// </summary>
internal static string OverwriteOneFile {
get {
return ResourceManager.GetString("OverwriteOneFile", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Overwrite {0} files?.
/// </summary>
internal static string OverwriteXfiles {
get {
return ResourceManager.GetString("OverwriteXfiles", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Port {0} to {1}:{2}.
/// </summary>
@@ -888,6 +924,33 @@ namespace MeshCentralRouter.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to {0} bytes/sec.
/// </summary>
internal static string XbytesPersec {
get {
return ResourceManager.GetString("XbytesPersec", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} Gbytes/sec.
/// </summary>
internal static string XGbytesPersec {
get {
return ResourceManager.GetString("XGbytesPersec", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} hours left.
/// </summary>
internal static string xhoursleft {
get {
return ResourceManager.GetString("xhoursleft", resourceCulture);
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>
@@ -898,6 +961,42 @@ namespace MeshCentralRouter.Properties {
}
}
/// <summary>
/// Looks up a localized string similar to {0} Kbytes/sec.
/// </summary>
internal static string XKbytesPersec {
get {
return ResourceManager.GetString("XKbytesPersec", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} Mbytes/sec.
/// </summary>
internal static string XMbytesPersec {
get {
return ResourceManager.GetString("XMbytesPersec", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} minutes left.
/// </summary>
internal static string xminutesleft {
get {
return ResourceManager.GetString("xminutesleft", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to {0} seconds left.
/// </summary>
internal static string xsecondsleft {
get {
return ResourceManager.GetString("xsecondsleft", resourceCulture);
}
}
/// <summary>
/// Looks up a localized resource of type System.Drawing.Bitmap.
/// </summary>

View File

@@ -394,4 +394,37 @@
<data name="NoToolsAllowed" xml:space="preserve">
<value>No tools allowed</value>
</data>
<data name="Almostdone" xml:space="preserve">
<value>Almost done</value>
</data>
<data name="EstimatingDotDotDot" xml:space="preserve">
<value>Estimating...</value>
</data>
<data name="OverwriteOneFile" xml:space="preserve">
<value>Overwrite 1 file?</value>
</data>
<data name="OverwriteXfiles" xml:space="preserve">
<value>Overwrite {0} files?</value>
</data>
<data name="XbytesPersec" xml:space="preserve">
<value>{0} bytes/sec</value>
</data>
<data name="XGbytesPersec" xml:space="preserve">
<value>{0} Gbytes/sec</value>
</data>
<data name="xhoursleft" xml:space="preserve">
<value>{0} hours left</value>
</data>
<data name="XKbytesPersec" xml:space="preserve">
<value>{0} Kbytes/sec</value>
</data>
<data name="XMbytesPersec" xml:space="preserve">
<value>{0} Mbytes/sec</value>
</data>
<data name="xminutesleft" xml:space="preserve">
<value>{0} minutes left</value>
</data>
<data name="xsecondsleft" xml:space="preserve">
<value>{0} seconds left</value>
</data>
</root>