diff --git a/FileTransferStatusForm.Designer.cs b/FileTransferStatusForm.Designer.cs index a02e856..aeb794b 100644 --- a/FileTransferStatusForm.Designer.cs +++ b/FileTransferStatusForm.Designer.cs @@ -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; } } \ No newline at end of file diff --git a/FileTransferStatusForm.cs b/FileTransferStatusForm.cs index e94255e..cd6494e 100644 --- a/FileTransferStatusForm.cs +++ b/FileTransferStatusForm.cs @@ -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; } diff --git a/FileTransferStatusForm.resx b/FileTransferStatusForm.resx index 1fa2cb7..5de3228 100644 --- a/FileTransferStatusForm.resx +++ b/FileTransferStatusForm.resx @@ -123,7 +123,7 @@ - 277, 113 + 277, 130 75, 23 @@ -150,11 +150,41 @@ Top, Bottom, Left, Right + + Top, Left, Right + + + NoControl + + + 14, 42 + + + 309, 13 + + + 5 + + + --- + + + mainLabel2 + + + System.Windows.Forms.Label, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + mainGroupBox + + + 0 + Top, Left, Right - 17, 64 + 17, 83 306, 16 @@ -172,13 +202,13 @@ mainGroupBox - 0 + 1 Top, Left, Right - 17, 42 + 17, 61 306, 16 @@ -196,7 +226,7 @@ mainGroupBox - 1 + 2 Top, Left, Right @@ -223,13 +253,13 @@ mainGroupBox - 2 + 3 12, 12 - 340, 95 + 340, 112 4 @@ -259,7 +289,7 @@ 6, 13 - 364, 148 + 364, 165 diff --git a/FileViewer.cs b/FileViewer.cs index c3db568..a3e8ee5 100644 --- a/FileViewer.cs +++ b/FileViewer.cs @@ -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]; } diff --git a/Properties/Resources.Designer.cs b/Properties/Resources.Designer.cs index 0fbc661..6d4c8d1 100644 --- a/Properties/Resources.Designer.cs +++ b/Properties/Resources.Designer.cs @@ -87,6 +87,15 @@ namespace MeshCentralRouter.Properties { } } + /// + /// Looks up a localized string similar to Almost done. + /// + internal static string Almostdone { + get { + return ResourceManager.GetString("Almostdone", resourceCulture); + } + } + /// /// Looks up a localized string similar to AMT. /// @@ -272,6 +281,15 @@ namespace MeshCentralRouter.Properties { } } + /// + /// Looks up a localized string similar to Estimating.... + /// + internal static string EstimatingDotDotDot { + get { + return ResourceManager.GetString("EstimatingDotDotDot", resourceCulture); + } + } + /// /// Looks up a localized string similar to Failed to start remote desktop session. /// @@ -572,6 +590,24 @@ namespace MeshCentralRouter.Properties { } } + /// + /// Looks up a localized string similar to Overwrite 1 file?. + /// + internal static string OverwriteOneFile { + get { + return ResourceManager.GetString("OverwriteOneFile", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Overwrite {0} files?. + /// + internal static string OverwriteXfiles { + get { + return ResourceManager.GetString("OverwriteXfiles", resourceCulture); + } + } + /// /// Looks up a localized string similar to Port {0} to {1}:{2}. /// @@ -888,6 +924,33 @@ namespace MeshCentralRouter.Properties { } } + /// + /// Looks up a localized string similar to {0} bytes/sec. + /// + internal static string XbytesPersec { + get { + return ResourceManager.GetString("XbytesPersec", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} Gbytes/sec. + /// + internal static string XGbytesPersec { + get { + return ResourceManager.GetString("XGbytesPersec", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} hours left. + /// + internal static string xhoursleft { + get { + return ResourceManager.GetString("xhoursleft", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// @@ -898,6 +961,42 @@ namespace MeshCentralRouter.Properties { } } + /// + /// Looks up a localized string similar to {0} Kbytes/sec. + /// + internal static string XKbytesPersec { + get { + return ResourceManager.GetString("XKbytesPersec", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} Mbytes/sec. + /// + internal static string XMbytesPersec { + get { + return ResourceManager.GetString("XMbytesPersec", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} minutes left. + /// + internal static string xminutesleft { + get { + return ResourceManager.GetString("xminutesleft", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to {0} seconds left. + /// + internal static string xsecondsleft { + get { + return ResourceManager.GetString("xsecondsleft", resourceCulture); + } + } + /// /// Looks up a localized resource of type System.Drawing.Bitmap. /// diff --git a/Properties/Resources.resx b/Properties/Resources.resx index 3826a5f..afceb7c 100644 --- a/Properties/Resources.resx +++ b/Properties/Resources.resx @@ -394,4 +394,37 @@ No tools allowed + + Almost done + + + Estimating... + + + Overwrite 1 file? + + + Overwrite {0} files? + + + {0} bytes/sec + + + {0} Gbytes/sec + + + {0} hours left + + + {0} Kbytes/sec + + + {0} Mbytes/sec + + + {0} minutes left + + + {0} seconds left + \ No newline at end of file