mirror of
https://github.com/Ylianst/MeshCentralRouter
synced 2025-12-26 05:03:22 +00:00
Added upload/download error handling.
This commit is contained in:
30
FileTransferStatusForm.Designer.cs
generated
30
FileTransferStatusForm.Designer.cs
generated
@@ -32,12 +32,15 @@
|
||||
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(FileTransferStatusForm));
|
||||
this.cancelButton = new System.Windows.Forms.Button();
|
||||
this.mainGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.errorsTextBox = new System.Windows.Forms.TextBox();
|
||||
this.mainLabel2 = new System.Windows.Forms.Label();
|
||||
this.progressBar2 = new System.Windows.Forms.ProgressBar();
|
||||
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.errorsGroupBox = new System.Windows.Forms.GroupBox();
|
||||
this.mainGroupBox.SuspendLayout();
|
||||
this.errorsGroupBox.SuspendLayout();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// cancelButton
|
||||
@@ -58,6 +61,18 @@
|
||||
this.mainGroupBox.Name = "mainGroupBox";
|
||||
this.mainGroupBox.TabStop = false;
|
||||
//
|
||||
// errorsTextBox
|
||||
//
|
||||
resources.ApplyResources(this.errorsTextBox, "errorsTextBox");
|
||||
this.errorsTextBox.BorderStyle = System.Windows.Forms.BorderStyle.None;
|
||||
this.errorsTextBox.Name = "errorsTextBox";
|
||||
this.errorsTextBox.ReadOnly = true;
|
||||
//
|
||||
// mainLabel2
|
||||
//
|
||||
resources.ApplyResources(this.mainLabel2, "mainLabel2");
|
||||
this.mainLabel2.Name = "mainLabel2";
|
||||
//
|
||||
// progressBar2
|
||||
//
|
||||
resources.ApplyResources(this.progressBar2, "progressBar2");
|
||||
@@ -78,16 +93,19 @@
|
||||
this.updateTimer.Interval = 500;
|
||||
this.updateTimer.Tick += new System.EventHandler(this.updateTimer_Tick);
|
||||
//
|
||||
// mainLabel2
|
||||
// errorsGroupBox
|
||||
//
|
||||
resources.ApplyResources(this.mainLabel2, "mainLabel2");
|
||||
this.mainLabel2.Name = "mainLabel2";
|
||||
this.errorsGroupBox.Controls.Add(this.errorsTextBox);
|
||||
resources.ApplyResources(this.errorsGroupBox, "errorsGroupBox");
|
||||
this.errorsGroupBox.Name = "errorsGroupBox";
|
||||
this.errorsGroupBox.TabStop = false;
|
||||
//
|
||||
// FileTransferStatusForm
|
||||
//
|
||||
resources.ApplyResources(this, "$this");
|
||||
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
|
||||
this.CancelButton = this.cancelButton;
|
||||
this.Controls.Add(this.errorsGroupBox);
|
||||
this.Controls.Add(this.mainGroupBox);
|
||||
this.Controls.Add(this.cancelButton);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
|
||||
@@ -97,6 +115,8 @@
|
||||
this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.FileTransferStatusForm_FormClosing);
|
||||
this.Load += new System.EventHandler(this.FileTransferStatusForm_Load);
|
||||
this.mainGroupBox.ResumeLayout(false);
|
||||
this.errorsGroupBox.ResumeLayout(false);
|
||||
this.errorsGroupBox.PerformLayout();
|
||||
this.ResumeLayout(false);
|
||||
|
||||
}
|
||||
@@ -110,5 +130,7 @@
|
||||
private System.Windows.Forms.Label mainLabel1;
|
||||
private System.Windows.Forms.Timer updateTimer;
|
||||
private System.Windows.Forms.Label mainLabel2;
|
||||
private System.Windows.Forms.TextBox errorsTextBox;
|
||||
private System.Windows.Forms.GroupBox errorsGroupBox;
|
||||
}
|
||||
}
|
||||
@@ -15,6 +15,7 @@ limitations under the License.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Drawing;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace MeshCentralRouter
|
||||
@@ -22,6 +23,12 @@ namespace MeshCentralRouter
|
||||
public partial class FileTransferStatusForm : Form
|
||||
{
|
||||
private FileViewer fileViewer;
|
||||
private bool loaded = false;
|
||||
public bool showingError = false;
|
||||
private string errors = "";
|
||||
private bool done = false;
|
||||
private Point mainBoxLocation;
|
||||
private Point errorBoxLocation;
|
||||
|
||||
public FileTransferStatusForm(FileViewer fileViewer)
|
||||
{
|
||||
@@ -30,6 +37,8 @@ namespace MeshCentralRouter
|
||||
Translate.TranslateControl(this);
|
||||
updateInfo();
|
||||
updateTimer.Enabled = true;
|
||||
mainBoxLocation = mainGroupBox.Location;
|
||||
errorBoxLocation = errorsGroupBox.Location;
|
||||
}
|
||||
|
||||
private void updateTimer_Tick(object sender, EventArgs e)
|
||||
@@ -37,6 +46,31 @@ namespace MeshCentralRouter
|
||||
updateInfo();
|
||||
}
|
||||
|
||||
public delegate void updateErrorMessageshandler();
|
||||
|
||||
public void addErrorMessage(string msg)
|
||||
{
|
||||
lock (this)
|
||||
{
|
||||
errors += (msg + "\r\n");
|
||||
showingError = true;
|
||||
}
|
||||
if (loaded == false) return;
|
||||
if (this.InvokeRequired) { this.Invoke(new updateErrorMessageshandler(updateErrorMessages)); } else { updateErrorMessages(); }
|
||||
}
|
||||
|
||||
public void updateErrorMessages()
|
||||
{
|
||||
showDialogParts(!done, showingError);
|
||||
lock (this) { errorsTextBox.Text = errors; }
|
||||
}
|
||||
|
||||
public void transferCompleted()
|
||||
{
|
||||
done = true;
|
||||
showDialogParts(!done, showingError);
|
||||
}
|
||||
|
||||
private void updateInfo()
|
||||
{
|
||||
if (fileViewer.uploadActive)
|
||||
@@ -87,7 +121,11 @@ namespace MeshCentralRouter
|
||||
if (x > (int)fileViewer.downloadFileArray.Count) { x = fileViewer.downloadFileArray.Count; }
|
||||
progressBar2.Value = fileViewer.downloadFileArrayPtr;
|
||||
}
|
||||
else { Close(); }
|
||||
else
|
||||
{
|
||||
done = true;
|
||||
if (showingError == false) { Close(); } else { cancelButton.Text = Translate.T(Properties.Resources.Close); }
|
||||
}
|
||||
}
|
||||
|
||||
private string secondsLeftToString(double x)
|
||||
@@ -114,12 +152,60 @@ namespace MeshCentralRouter
|
||||
|
||||
private void cancelButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
if (done)
|
||||
{
|
||||
fileViewer.transferStatusForm = null;
|
||||
Close();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Cancel file transfer
|
||||
if (fileViewer.uploadActive) { fileViewer.uploadCancel(); }
|
||||
if (fileViewer.downloadActive) { fileViewer.downloadCancel(); }
|
||||
}
|
||||
}
|
||||
|
||||
private void FileTransferStatusForm_Load(object sender, EventArgs e)
|
||||
{
|
||||
CenterToParent();
|
||||
lock (this) { errorsTextBox.Text = errors; }
|
||||
loaded = true;
|
||||
showDialogParts(!done, showingError);
|
||||
}
|
||||
|
||||
private void showDialogParts(bool status, bool errors)
|
||||
{
|
||||
mainGroupBox.Visible = status;
|
||||
errorsGroupBox.Visible = errors;
|
||||
if (errors == false)
|
||||
{
|
||||
if (status == false)
|
||||
{
|
||||
// Show nothing
|
||||
this.Height = 109;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show only status box
|
||||
this.Height = mainGroupBox.Height + 99;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (status == false)
|
||||
{
|
||||
// Show only error box
|
||||
this.Height = errorsGroupBox.Height + 99;
|
||||
errorsGroupBox.Location = mainBoxLocation;
|
||||
}
|
||||
else
|
||||
{
|
||||
// Show both status and error box
|
||||
this.Height = mainGroupBox.Height + errorsGroupBox.Height + 109;
|
||||
errorsGroupBox.Location = errorBoxLocation;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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, 130</value>
|
||||
<value>277, 244</value>
|
||||
</data>
|
||||
<data name="cancelButton.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>75, 23</value>
|
||||
@@ -145,11 +145,110 @@
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>cancelButton.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
<value>2</value>
|
||||
</data>
|
||||
<data name="mainGroupBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
<value>Top, Left, Right</value>
|
||||
</data>
|
||||
<data name=">>mainLabel2.Name" xml:space="preserve">
|
||||
<value>mainLabel2</value>
|
||||
</data>
|
||||
<data name=">>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=">>mainLabel2.Parent" xml:space="preserve">
|
||||
<value>mainGroupBox</value>
|
||||
</data>
|
||||
<data name=">>mainLabel2.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name=">>progressBar2.Name" xml:space="preserve">
|
||||
<value>progressBar2</value>
|
||||
</data>
|
||||
<data name=">>progressBar2.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.ProgressBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>progressBar2.Parent" xml:space="preserve">
|
||||
<value>mainGroupBox</value>
|
||||
</data>
|
||||
<data name=">>progressBar2.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name=">>progressBar1.Name" xml:space="preserve">
|
||||
<value>progressBar1</value>
|
||||
</data>
|
||||
<data name=">>progressBar1.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.ProgressBar, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>progressBar1.Parent" xml:space="preserve">
|
||||
<value>mainGroupBox</value>
|
||||
</data>
|
||||
<data name=">>progressBar1.ZOrder" xml:space="preserve">
|
||||
<value>2</value>
|
||||
</data>
|
||||
<data name=">>mainLabel1.Name" xml:space="preserve">
|
||||
<value>mainLabel1</value>
|
||||
</data>
|
||||
<data name=">>mainLabel1.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=">>mainLabel1.Parent" xml:space="preserve">
|
||||
<value>mainGroupBox</value>
|
||||
</data>
|
||||
<data name=">>mainLabel1.ZOrder" xml:space="preserve">
|
||||
<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, 109</value>
|
||||
</data>
|
||||
<data name="mainGroupBox.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>4</value>
|
||||
</data>
|
||||
<data name="mainGroupBox.Text" xml:space="preserve">
|
||||
<value>Transfer Progress</value>
|
||||
</data>
|
||||
<data name=">>mainGroupBox.Name" xml:space="preserve">
|
||||
<value>mainGroupBox</value>
|
||||
</data>
|
||||
<data name=">>mainGroupBox.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>mainGroupBox.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>mainGroupBox.ZOrder" xml:space="preserve">
|
||||
<value>1</value>
|
||||
</data>
|
||||
<data name="errorsTextBox.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
<value>Top, Bottom, Left, Right</value>
|
||||
</data>
|
||||
<data name="errorsTextBox.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>17, 19</value>
|
||||
</data>
|
||||
<data name="errorsTextBox.Multiline" type="System.Boolean, mscorlib">
|
||||
<value>True</value>
|
||||
</data>
|
||||
<data name="errorsTextBox.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>306, 84</value>
|
||||
</data>
|
||||
<data name="errorsTextBox.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>6</value>
|
||||
</data>
|
||||
<data name=">>errorsTextBox.Name" xml:space="preserve">
|
||||
<value>errorsTextBox</value>
|
||||
</data>
|
||||
<data name=">>errorsTextBox.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.TextBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>errorsTextBox.Parent" xml:space="preserve">
|
||||
<value>errorsGroupBox</value>
|
||||
</data>
|
||||
<data name=">>errorsTextBox.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<data name="mainLabel2.Anchor" type="System.Windows.Forms.AnchorStyles, System.Windows.Forms">
|
||||
<value>Top, Left, Right</value>
|
||||
</data>
|
||||
@@ -255,33 +354,33 @@
|
||||
<data name=">>mainLabel1.ZOrder" xml:space="preserve">
|
||||
<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, 112</value>
|
||||
</data>
|
||||
<data name="mainGroupBox.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>4</value>
|
||||
</data>
|
||||
<data name="mainGroupBox.Text" xml:space="preserve">
|
||||
<value>Transfer Progress</value>
|
||||
</data>
|
||||
<data name=">>mainGroupBox.Name" xml:space="preserve">
|
||||
<value>mainGroupBox</value>
|
||||
</data>
|
||||
<data name=">>mainGroupBox.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>mainGroupBox.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>mainGroupBox.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<metadata name="updateTimer.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>17, 17</value>
|
||||
</metadata>
|
||||
<data name="errorsGroupBox.Location" type="System.Drawing.Point, System.Drawing">
|
||||
<value>12, 127</value>
|
||||
</data>
|
||||
<data name="errorsGroupBox.Size" type="System.Drawing.Size, System.Drawing">
|
||||
<value>340, 109</value>
|
||||
</data>
|
||||
<data name="errorsGroupBox.TabIndex" type="System.Int32, mscorlib">
|
||||
<value>7</value>
|
||||
</data>
|
||||
<data name="errorsGroupBox.Text" xml:space="preserve">
|
||||
<value>Transfer Errors</value>
|
||||
</data>
|
||||
<data name=">>errorsGroupBox.Name" xml:space="preserve">
|
||||
<value>errorsGroupBox</value>
|
||||
</data>
|
||||
<data name=">>errorsGroupBox.Type" xml:space="preserve">
|
||||
<value>System.Windows.Forms.GroupBox, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</data>
|
||||
<data name=">>errorsGroupBox.Parent" xml:space="preserve">
|
||||
<value>$this</value>
|
||||
</data>
|
||||
<data name=">>errorsGroupBox.ZOrder" xml:space="preserve">
|
||||
<value>0</value>
|
||||
</data>
|
||||
<metadata name="$this.Localizable" type="System.Boolean, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
|
||||
<value>True</value>
|
||||
</metadata>
|
||||
@@ -289,7 +388,7 @@
|
||||
<value>6, 13</value>
|
||||
</data>
|
||||
<data name="$this.ClientSize" type="System.Drawing.Size, System.Drawing">
|
||||
<value>364, 165</value>
|
||||
<value>364, 279</value>
|
||||
</data>
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
<value>
|
||||
@@ -1985,6 +2084,9 @@
|
||||
AADAPwAAwD8AAMA/AADAPwAA
|
||||
</value>
|
||||
</data>
|
||||
<data name="$this.ImeMode" type="System.Windows.Forms.ImeMode, System.Windows.Forms">
|
||||
<value>NoControl</value>
|
||||
</data>
|
||||
<data name="$this.StartPosition" type="System.Windows.Forms.FormStartPosition, System.Windows.Forms">
|
||||
<value>CenterParent</value>
|
||||
</data>
|
||||
|
||||
207
FileViewer.cs
207
FileViewer.cs
@@ -60,6 +60,7 @@ namespace MeshCentralRouter
|
||||
public long uploadFilePtr = 0;
|
||||
public long uploadFileSize = 0;
|
||||
public DateTime uploadFileStartTime = DateTime.MinValue;
|
||||
public string uploadFileName = null;
|
||||
|
||||
// Download state
|
||||
public bool downloadActive = false;
|
||||
@@ -445,8 +446,35 @@ namespace MeshCentralRouter
|
||||
}
|
||||
else if (sub == "cancel")
|
||||
{
|
||||
// Cancel the download
|
||||
downloadCancel();
|
||||
// Unable to download this file
|
||||
if (transferStatusForm != null) { transferStatusForm.addErrorMessage(String.Format(Translate.T(Properties.Resources.ErrorDownloadingFileX), downloadFileArray[downloadFileArrayPtr].ToString())); }
|
||||
|
||||
// Send DOWNLOAD command
|
||||
string cmd = "{\"action\":\"download\",\"sub\":\"stop\",\"id\":" + (downloadFileArrayPtr + 1000) + "}";
|
||||
byte[] bincmd = UTF8Encoding.UTF8.GetBytes(cmd);
|
||||
wc.SendBinary(bincmd, 0, bincmd.Length);
|
||||
if (downloadFileStream != null) { downloadFileStream.Close(); downloadFileStream = null; } // Close the file
|
||||
try { File.Delete(Path.Combine(downloadLocalPath.FullName, downloadFileArray[downloadFileArrayPtr].ToString())); } catch (Exception) { }
|
||||
|
||||
// Go to next file
|
||||
if (downloadFileArray.Count > downloadFileArrayPtr + 1)
|
||||
{
|
||||
// Download the next file
|
||||
downloadFileArrayPtr++;
|
||||
downloadNextFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Done with all files
|
||||
downloadActive = false;
|
||||
downloadStop = false;
|
||||
downloadFileArrayPtr = -1;
|
||||
downloadFileArray = null;
|
||||
downloadLocalPath = null;
|
||||
downloadRemotePath = null;
|
||||
closeTransferDialog();
|
||||
localRefresh();
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
@@ -511,13 +539,16 @@ namespace MeshCentralRouter
|
||||
if (uploadStop) { uploadCancel(); return; }
|
||||
uploadNextPart(false);
|
||||
}
|
||||
else if (action == "uploaddone")
|
||||
else if ((action == "uploaddone") || (action == "uploaderror"))
|
||||
{
|
||||
// Clean up current upload
|
||||
uploadFilePtr = 0;
|
||||
uploadFileSize = 0;
|
||||
if (uploadFileStream != null) { uploadFileStream.Close(); uploadFileStream = null; }
|
||||
|
||||
// If this is an error, show it in the dialog
|
||||
if ((action == "uploaderror") && (transferStatusForm != null)) { transferStatusForm.addErrorMessage(String.Format(Translate.T(Properties.Resources.ErrorUploadingFileX), uploadFileName)); }
|
||||
|
||||
// Check if another file needs to be uploaded
|
||||
if (uploadFileArray.Count > uploadFileArrayPtr + 1)
|
||||
{
|
||||
@@ -536,14 +567,11 @@ namespace MeshCentralRouter
|
||||
uploadRemotePath = null;
|
||||
uploadFilePtr = 0;
|
||||
uploadFileSize = 0;
|
||||
uploadFileName = null;
|
||||
closeTransferDialog();
|
||||
remoteRefresh();
|
||||
}
|
||||
}
|
||||
else if (action == "uploaderror")
|
||||
{
|
||||
uploadCancel();
|
||||
}
|
||||
else if (reqid == 1)
|
||||
{
|
||||
// Result of a LS command
|
||||
@@ -765,13 +793,7 @@ namespace MeshCentralRouter
|
||||
string r = remoteFolder;
|
||||
if (r.EndsWith("/")) { r = r.Substring(0, r.Length - 1); }
|
||||
int i = r.LastIndexOf("/");
|
||||
if (i >= 0)
|
||||
{
|
||||
r = r.Substring(0, i + 1);
|
||||
} else
|
||||
{
|
||||
r = "";
|
||||
}
|
||||
if (i >= 0) { r = r.Substring(0, i + 1); } else { r = ""; }
|
||||
requestRemoteFolder(r);
|
||||
}
|
||||
|
||||
@@ -948,7 +970,7 @@ namespace MeshCentralRouter
|
||||
private void uploadButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
// If a transfer is currently active, ignore this.
|
||||
if (uploadActive || downloadActive) return;
|
||||
if (uploadActive || downloadActive || (transferStatusForm != null)) return;
|
||||
|
||||
// If any files are going to be overwritten
|
||||
int overWriteCount = 0;
|
||||
@@ -989,11 +1011,12 @@ namespace MeshCentralRouter
|
||||
uploadRemotePath = remoteFolder;
|
||||
uploadActive = true;
|
||||
uploadStop = false;
|
||||
uploadNextFile();
|
||||
|
||||
// Show transfer status dialog
|
||||
transferStatusForm = new FileTransferStatusForm(this);
|
||||
transferStatusForm.Show(this);
|
||||
|
||||
uploadNextFile();
|
||||
}
|
||||
|
||||
private void uploadNextFile()
|
||||
@@ -1011,10 +1034,40 @@ namespace MeshCentralRouter
|
||||
localFilePath = (string)uploadFileArray[uploadFileArrayPtr];
|
||||
localFileName = Path.GetFileName(localFilePath);
|
||||
}
|
||||
uploadFileStream = File.OpenRead(localFilePath);
|
||||
try { uploadFileStream = File.OpenRead(localFilePath); } catch (Exception ex)
|
||||
{
|
||||
// Display the error
|
||||
if (transferStatusForm != null) { transferStatusForm.addErrorMessage(String.Format(Translate.T(Properties.Resources.UnableToOpenFileX), localFileName)); }
|
||||
|
||||
// Skip to the next file
|
||||
// Check if another file needs to be uploaded
|
||||
if (uploadFileArray.Count > uploadFileArrayPtr + 1)
|
||||
{
|
||||
// Upload the next file
|
||||
uploadFileArrayPtr++;
|
||||
uploadNextFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Done with all files
|
||||
uploadActive = false;
|
||||
uploadStop = false;
|
||||
uploadFileArrayPtr = -1;
|
||||
uploadFileArray = null;
|
||||
uploadLocalPath = null;
|
||||
uploadRemotePath = null;
|
||||
uploadFilePtr = 0;
|
||||
uploadFileSize = 0;
|
||||
uploadFileName = null;
|
||||
closeTransferDialog();
|
||||
remoteRefresh();
|
||||
}
|
||||
return;
|
||||
}
|
||||
uploadFileSize = new FileInfo(localFilePath).Length;
|
||||
uploadFilePtr = 0;
|
||||
uploadFileStartTime = DateTime.Now;
|
||||
uploadFileName = localFileName;
|
||||
|
||||
// Send UPLOAD command
|
||||
string cmd = "{\"action\":\"upload\",\"reqid\":" + (uploadFileArrayPtr + 1000) + ",\"path\":\"" + uploadRemotePath + "\",\"name\":\"" + localFileName + "\",\"size\":" + uploadFileSize + "}";
|
||||
@@ -1071,13 +1124,21 @@ namespace MeshCentralRouter
|
||||
{
|
||||
if (transferStatusForm == null) return;
|
||||
if (this.InvokeRequired) { this.Invoke(new closeTransferDialogHandler(closeTransferDialog)); return; }
|
||||
transferStatusForm.Close(); transferStatusForm = null;
|
||||
if (transferStatusForm.showingError == false)
|
||||
{
|
||||
// Everything was succesful, close the form
|
||||
transferStatusForm.Close();
|
||||
transferStatusForm = null;
|
||||
} else {
|
||||
// Error are displayed, keep the form open
|
||||
transferStatusForm.transferCompleted();
|
||||
}
|
||||
}
|
||||
|
||||
private void downloadButton_Click(object sender, EventArgs e)
|
||||
{
|
||||
// If a transfer is currently active, ignore this.
|
||||
if (uploadActive || downloadActive) return;
|
||||
if (uploadActive || downloadActive || (transferStatusForm != null)) return;
|
||||
|
||||
// If any files are going to be overwritten
|
||||
int overWriteCount = 0;
|
||||
@@ -1103,16 +1164,10 @@ namespace MeshCentralRouter
|
||||
{
|
||||
FileConfirmOverwriteForm f = new FileConfirmOverwriteForm();
|
||||
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
|
||||
{
|
||||
performFileDownload();
|
||||
}
|
||||
if (f.ShowDialog(this) != DialogResult.OK) return;
|
||||
}
|
||||
|
||||
private void performFileDownload()
|
||||
{
|
||||
// Perform the download
|
||||
downloadFileArrayPtr = 0;
|
||||
downloadFileArray = new ArrayList();
|
||||
downloadFileSizeArray = new ArrayList();
|
||||
@@ -1128,11 +1183,12 @@ namespace MeshCentralRouter
|
||||
downloadRemotePath = remoteFolder;
|
||||
downloadActive = true;
|
||||
downloadStop = false;
|
||||
downloadNextFile();
|
||||
|
||||
// Show transfer status dialog
|
||||
transferStatusForm = new FileTransferStatusForm(this);
|
||||
transferStatusForm.Show(this);
|
||||
|
||||
downloadNextFile();
|
||||
}
|
||||
|
||||
private void downloadNextFile()
|
||||
@@ -1141,7 +1197,32 @@ namespace MeshCentralRouter
|
||||
|
||||
string localFilePath;
|
||||
localFilePath = Path.Combine(downloadLocalPath.FullName, (string)downloadFileArray[downloadFileArrayPtr]);
|
||||
try { downloadFileStream = File.OpenWrite(localFilePath); } catch (Exception) { return; }
|
||||
try { downloadFileStream = File.OpenWrite(localFilePath); } catch (Exception) {
|
||||
// Download error, show it in the dialog
|
||||
FileInfo f = new FileInfo(localFilePath);
|
||||
if (transferStatusForm != null) { transferStatusForm.addErrorMessage(String.Format(Translate.T(Properties.Resources.UnableToWriteFileX), f.Name)); }
|
||||
|
||||
// Unable to download the file, skip it.
|
||||
if (downloadFileArray.Count > downloadFileArrayPtr + 1)
|
||||
{
|
||||
// Download the next file
|
||||
downloadFileArrayPtr++;
|
||||
downloadNextFile();
|
||||
}
|
||||
else
|
||||
{
|
||||
// Done with all files
|
||||
downloadActive = false;
|
||||
downloadStop = false;
|
||||
downloadFileArrayPtr = -1;
|
||||
downloadFileArray = null;
|
||||
downloadLocalPath = null;
|
||||
downloadRemotePath = null;
|
||||
closeTransferDialog();
|
||||
localRefresh();
|
||||
}
|
||||
return;
|
||||
}
|
||||
downloadFileSize = (int)downloadFileSizeArray[downloadFileArrayPtr];
|
||||
downloadFilePtr = 0;
|
||||
downloadFileStartTime = DateTime.Now;
|
||||
@@ -1199,7 +1280,6 @@ namespace MeshCentralRouter
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void downloadCancel()
|
||||
{
|
||||
if (downloadActive == false) return;
|
||||
@@ -1259,28 +1339,54 @@ namespace MeshCentralRouter
|
||||
|
||||
private void rightListView_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (uploadActive || downloadActive) return;
|
||||
if (uploadActive || downloadActive || (transferStatusForm != null)) return;
|
||||
if ((node.agentid < 5) && ((remoteFolder == null) || (remoteFolder == ""))) { return; }
|
||||
if (e.Data.GetDataPresent(DataFormats.FileDrop)) e.Effect = DragDropEffects.Copy;
|
||||
}
|
||||
|
||||
private void rightListView_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (uploadActive || downloadActive) return;
|
||||
if (uploadActive || downloadActive || (transferStatusForm != null)) return;
|
||||
if ((node.agentid < 5) && ((remoteFolder == null) || (remoteFolder == ""))) { return; }
|
||||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
|
||||
// If any files are going to be overwritten
|
||||
int overWriteCount = 0;
|
||||
foreach (string file in files)
|
||||
{
|
||||
FileInfo f = new FileInfo(file);
|
||||
string filename = f.Name;
|
||||
foreach (ListViewItem l2 in rightListView.Items)
|
||||
{
|
||||
if (l2.ImageIndex == 2)
|
||||
{
|
||||
string filename2 = l2.Text;
|
||||
if (node.agentid < 5) { filename = filename.ToLower(); filename2 = filename2.ToLower(); }
|
||||
if (filename.Equals(filename2)) { overWriteCount++; }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (overWriteCount > 0)
|
||||
{
|
||||
FileConfirmOverwriteForm f = new FileConfirmOverwriteForm();
|
||||
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) return;
|
||||
}
|
||||
|
||||
// Perform the upload
|
||||
uploadFileArrayPtr = 0;
|
||||
uploadFileArray = new ArrayList();
|
||||
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
|
||||
foreach (string file in files) { uploadFileArray.Add(file); }
|
||||
uploadLocalPath = null;
|
||||
uploadRemotePath = remoteFolder;
|
||||
uploadActive = true;
|
||||
uploadStop = false;
|
||||
uploadNextFile();
|
||||
|
||||
// Show transfer status dialog
|
||||
transferStatusForm = new FileTransferStatusForm(this);
|
||||
transferStatusForm.Show(this);
|
||||
|
||||
uploadNextFile();
|
||||
}
|
||||
|
||||
private void leftListView_MouseMove(object sender, MouseEventArgs e)
|
||||
@@ -1324,14 +1430,40 @@ namespace MeshCentralRouter
|
||||
|
||||
private void leftListView_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if (uploadActive || downloadActive || (localFolder == null)) return;
|
||||
if (uploadActive || downloadActive || (localFolder == null) || (transferStatusForm != null)) return;
|
||||
if ((e.Data.GetDataPresent("Type") == true) && ((string)e.Data.GetData("Type") == ("MeshCentralRouterRemoteFiles-" + rndString))) { e.Effect = DragDropEffects.Copy; }
|
||||
}
|
||||
|
||||
private void leftListView_DragDrop(object sender, DragEventArgs e)
|
||||
{
|
||||
if (uploadActive || downloadActive) return;
|
||||
if (uploadActive || downloadActive || (transferStatusForm != null)) return;
|
||||
if ((e.Data.GetDataPresent("Type") == false) || ((string)e.Data.GetData("Type") != ("MeshCentralRouterRemoteFiles-" + rndString))) return;
|
||||
|
||||
ArrayList files = (ArrayList)e.Data.GetData("RemoteFiles");
|
||||
|
||||
// If any files are going to be overwritten
|
||||
int overWriteCount = 0;
|
||||
foreach (string file in files)
|
||||
{
|
||||
string filename = file;
|
||||
foreach (ListViewItem l2 in leftListView.Items)
|
||||
{
|
||||
if (l2.ImageIndex == 2)
|
||||
{
|
||||
string filename2 = l2.Text;
|
||||
if (node.agentid < 5) { filename = filename.ToLower(); filename2 = filename2.ToLower(); }
|
||||
if (filename.Equals(filename2)) { overWriteCount++; }
|
||||
}
|
||||
}
|
||||
}
|
||||
if (overWriteCount > 0)
|
||||
{
|
||||
FileConfirmOverwriteForm f = new FileConfirmOverwriteForm();
|
||||
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) return;
|
||||
}
|
||||
|
||||
// Perform downloads
|
||||
downloadFileArrayPtr = 0;
|
||||
downloadFileArray = (ArrayList)e.Data.GetData("RemoteFiles");
|
||||
downloadFileSizeArray = (ArrayList)e.Data.GetData("RemoteSizes");
|
||||
@@ -1339,11 +1471,12 @@ namespace MeshCentralRouter
|
||||
downloadRemotePath = (string)e.Data.GetData("RemoteFolder");
|
||||
downloadActive = true;
|
||||
downloadStop = false;
|
||||
downloadNextFile();
|
||||
|
||||
// Show transfer status dialog
|
||||
transferStatusForm = new FileTransferStatusForm(this);
|
||||
transferStatusForm.Show(this);
|
||||
|
||||
downloadNextFile();
|
||||
}
|
||||
private static string getRandomString(int length)
|
||||
{
|
||||
|
||||
45
Properties/Resources.Designer.cs
generated
45
Properties/Resources.Designer.cs
generated
@@ -143,6 +143,15 @@ namespace MeshCentralRouter.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Close.
|
||||
/// </summary>
|
||||
internal static string Close {
|
||||
get {
|
||||
return ResourceManager.GetString("Close", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized resource of type System.Drawing.Bitmap.
|
||||
/// </summary>
|
||||
@@ -281,6 +290,24 @@ namespace MeshCentralRouter.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error downloading file: {0}.
|
||||
/// </summary>
|
||||
internal static string ErrorDownloadingFileX {
|
||||
get {
|
||||
return ResourceManager.GetString("ErrorDownloadingFileX", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Error uploading file: {0}.
|
||||
/// </summary>
|
||||
internal static string ErrorUploadingFileX {
|
||||
get {
|
||||
return ResourceManager.GetString("ErrorUploadingFileX", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Estimating....
|
||||
/// </summary>
|
||||
@@ -879,6 +906,24 @@ namespace MeshCentralRouter.Properties {
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unable to open file: {0}.
|
||||
/// </summary>
|
||||
internal static string UnableToOpenFileX {
|
||||
get {
|
||||
return ResourceManager.GetString("UnableToOpenFileX", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Unable to write file: {0}.
|
||||
/// </summary>
|
||||
internal static string UnableToWriteFileX {
|
||||
get {
|
||||
return ResourceManager.GetString("UnableToWriteFileX", resourceCulture);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Looks up a localized string similar to Updating....
|
||||
/// </summary>
|
||||
|
||||
@@ -427,4 +427,19 @@
|
||||
<data name="xsecondsleft" xml:space="preserve">
|
||||
<value>{0} seconds left</value>
|
||||
</data>
|
||||
<data name="Close" xml:space="preserve">
|
||||
<value>Close</value>
|
||||
</data>
|
||||
<data name="ErrorDownloadingFileX" xml:space="preserve">
|
||||
<value>Error downloading file: {0}</value>
|
||||
</data>
|
||||
<data name="ErrorUploadingFileX" xml:space="preserve">
|
||||
<value>Error uploading file: {0}</value>
|
||||
</data>
|
||||
<data name="UnableToOpenFileX" xml:space="preserve">
|
||||
<value>Unable to open file: {0}</value>
|
||||
</data>
|
||||
<data name="UnableToWriteFileX" xml:space="preserve">
|
||||
<value>Unable to write file: {0}</value>
|
||||
</data>
|
||||
</root>
|
||||
Reference in New Issue
Block a user