1
0
mirror of https://github.com/Ylianst/MeshCentralRouter synced 2025-12-10 13:23:49 +00:00

Added file transfer skip if file already exists.

This commit is contained in:
Ylian Saint-Hilaire
2021-08-05 10:50:26 -07:00
parent 3dd4c24b41
commit f2d23d75c3
3 changed files with 139 additions and 16 deletions

View File

@@ -32,6 +32,7 @@
this.mainLabel = new System.Windows.Forms.Label(); this.mainLabel = new System.Windows.Forms.Label();
this.okButton = new System.Windows.Forms.Button(); this.okButton = new System.Windows.Forms.Button();
this.cancelButton = new System.Windows.Forms.Button(); this.cancelButton = new System.Windows.Forms.Button();
this.skipCheckBox = new System.Windows.Forms.CheckBox();
this.mainGroupBox.SuspendLayout(); this.mainGroupBox.SuspendLayout();
this.SuspendLayout(); this.SuspendLayout();
// //
@@ -40,10 +41,11 @@
this.mainGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) this.mainGroupBox.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right))); | System.Windows.Forms.AnchorStyles.Right)));
this.mainGroupBox.Controls.Add(this.skipCheckBox);
this.mainGroupBox.Controls.Add(this.mainLabel); this.mainGroupBox.Controls.Add(this.mainLabel);
this.mainGroupBox.Location = new System.Drawing.Point(12, 12); this.mainGroupBox.Location = new System.Drawing.Point(12, 12);
this.mainGroupBox.Name = "mainGroupBox"; this.mainGroupBox.Name = "mainGroupBox";
this.mainGroupBox.Size = new System.Drawing.Size(315, 48); this.mainGroupBox.Size = new System.Drawing.Size(315, 73);
this.mainGroupBox.TabIndex = 6; this.mainGroupBox.TabIndex = 6;
this.mainGroupBox.TabStop = false; this.mainGroupBox.TabStop = false;
this.mainGroupBox.Text = "Confirm Overwrite"; this.mainGroupBox.Text = "Confirm Overwrite";
@@ -64,7 +66,7 @@
this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.okButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.okButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.okButton.ImeMode = System.Windows.Forms.ImeMode.NoControl; this.okButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.okButton.Location = new System.Drawing.Point(171, 66); this.okButton.Location = new System.Drawing.Point(171, 91);
this.okButton.Name = "okButton"; this.okButton.Name = "okButton";
this.okButton.Size = new System.Drawing.Size(75, 23); this.okButton.Size = new System.Drawing.Size(75, 23);
this.okButton.TabIndex = 4; this.okButton.TabIndex = 4;
@@ -77,7 +79,7 @@
this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right))); this.cancelButton.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel; this.cancelButton.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.cancelButton.ImeMode = System.Windows.Forms.ImeMode.NoControl; this.cancelButton.ImeMode = System.Windows.Forms.ImeMode.NoControl;
this.cancelButton.Location = new System.Drawing.Point(252, 66); this.cancelButton.Location = new System.Drawing.Point(252, 91);
this.cancelButton.Name = "cancelButton"; this.cancelButton.Name = "cancelButton";
this.cancelButton.Size = new System.Drawing.Size(75, 23); this.cancelButton.Size = new System.Drawing.Size(75, 23);
this.cancelButton.TabIndex = 5; this.cancelButton.TabIndex = 5;
@@ -85,13 +87,23 @@
this.cancelButton.UseVisualStyleBackColor = true; this.cancelButton.UseVisualStyleBackColor = true;
this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click); this.cancelButton.Click += new System.EventHandler(this.cancelButton_Click);
// //
// skipCheckBox
//
this.skipCheckBox.AutoSize = true;
this.skipCheckBox.Location = new System.Drawing.Point(17, 44);
this.skipCheckBox.Name = "skipCheckBox";
this.skipCheckBox.Size = new System.Drawing.Size(106, 17);
this.skipCheckBox.TabIndex = 2;
this.skipCheckBox.Text = "Skip existing files";
this.skipCheckBox.UseVisualStyleBackColor = true;
//
// FileConfirmOverwriteForm // FileConfirmOverwriteForm
// //
this.AcceptButton = this.okButton; this.AcceptButton = this.okButton;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.CancelButton = this.cancelButton; this.CancelButton = this.cancelButton;
this.ClientSize = new System.Drawing.Size(339, 101); this.ClientSize = new System.Drawing.Size(339, 126);
this.Controls.Add(this.mainGroupBox); this.Controls.Add(this.mainGroupBox);
this.Controls.Add(this.okButton); this.Controls.Add(this.okButton);
this.Controls.Add(this.cancelButton); this.Controls.Add(this.cancelButton);
@@ -100,6 +112,7 @@
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "File Operation"; this.Text = "File Operation";
this.mainGroupBox.ResumeLayout(false); this.mainGroupBox.ResumeLayout(false);
this.mainGroupBox.PerformLayout();
this.ResumeLayout(false); this.ResumeLayout(false);
} }
@@ -110,5 +123,6 @@
private System.Windows.Forms.Label mainLabel; private System.Windows.Forms.Label mainLabel;
private System.Windows.Forms.Button okButton; private System.Windows.Forms.Button okButton;
private System.Windows.Forms.Button cancelButton; private System.Windows.Forms.Button cancelButton;
private System.Windows.Forms.CheckBox skipCheckBox;
} }
} }

View File

@@ -8,12 +8,15 @@ namespace MeshCentralRouter
public FileConfirmOverwriteForm() public FileConfirmOverwriteForm()
{ {
InitializeComponent(); InitializeComponent();
skipCheckBox.Checked = (Settings.GetRegValue("skipExistingFiles", "0") == "1");
} }
public string mainTextLabel { get { return mainLabel.Text; } set { mainLabel.Text = value; } } public string mainTextLabel { get { return mainLabel.Text; } set { mainLabel.Text = value; } }
public bool skipExistingFiles { get { return skipCheckBox.Checked; } set { skipCheckBox.Checked = value; } }
private void okButton_Click(object sender, EventArgs e) private void okButton_Click(object sender, EventArgs e)
{ {
Settings.SetRegValue("skipExistingFiles", skipCheckBox.Checked ? "1" : "0");
DialogResult = DialogResult.OK; DialogResult = DialogResult.OK;
} }

View File

@@ -41,6 +41,7 @@ namespace MeshCentralRouter
public string remoteFolder = null; public string remoteFolder = null;
public ArrayList remoteFolderList = null; public ArrayList remoteFolderList = null;
private static string rndString = getRandomString(12); private static string rndString = getRandomString(12);
private bool skipExistingFiles = false;
// Stats // Stats
public long bytesIn = 0; public long bytesIn = 0;
@@ -990,23 +991,43 @@ namespace MeshCentralRouter
} }
} }
skipExistingFiles = true;
if (overWriteCount > 0) if (overWriteCount > 0)
{ {
FileConfirmOverwriteForm f = new FileConfirmOverwriteForm(); 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 (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(); } if (f.ShowDialog(this) != DialogResult.OK) return;
skipExistingFiles = f.skipExistingFiles;
}
uploadFileArrayPtr = 0;
uploadFileArray = new ArrayList();
if (skipExistingFiles == true)
{
foreach (ListViewItem l in leftListView.SelectedItems) {
if (l.ImageIndex == 2) {
bool overwrite = false;
string filename = l.Text;
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)) { overwrite = true; }
}
}
if (overwrite == false) { uploadFileArray.Add(l.Text); }
}
}
} }
else else
{ {
performFileUpload(); foreach (ListViewItem l in leftListView.SelectedItems) { if (l.ImageIndex == 2) { uploadFileArray.Add(l.Text); } }
} }
}
private void performFileUpload() if (uploadFileArray.Count == 0) return;
{
uploadFileArrayPtr = 0;
uploadFileArray = new ArrayList();
foreach (ListViewItem l in leftListView.SelectedItems) { if (l.ImageIndex == 2) { uploadFileArray.Add(l.Text); } }
uploadLocalPath = localFolder; uploadLocalPath = localFolder;
uploadRemotePath = remoteFolder; uploadRemotePath = remoteFolder;
uploadActive = true; uploadActive = true;
@@ -1160,11 +1181,13 @@ namespace MeshCentralRouter
} }
} }
skipExistingFiles = true;
if (overWriteCount > 0) if (overWriteCount > 0)
{ {
FileConfirmOverwriteForm f = new FileConfirmOverwriteForm(); 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 (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; if (f.ShowDialog(this) != DialogResult.OK) return;
skipExistingFiles = f.skipExistingFiles;
} }
// Perform the download // Perform the download
@@ -1175,10 +1198,33 @@ namespace MeshCentralRouter
{ {
if (l.ImageIndex == 2) if (l.ImageIndex == 2)
{ {
downloadFileArray.Add(l.Text); if (skipExistingFiles == false)
downloadFileSizeArray.Add(int.Parse(l.SubItems[1].Text)); {
downloadFileArray.Add(l.Text);
downloadFileSizeArray.Add(int.Parse(l.SubItems[1].Text));
}
else
{
bool overwrite = false;
string filename = l.Text;
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)) { overwrite = true; }
}
}
if (overwrite == false)
{
downloadFileArray.Add(l.Text);
downloadFileSizeArray.Add(int.Parse(l.SubItems[1].Text));
}
}
} }
} }
if (downloadFileArray.Count == 0) return;
downloadLocalPath = localFolder; downloadLocalPath = localFolder;
downloadRemotePath = remoteFolder; downloadRemotePath = remoteFolder;
downloadActive = true; downloadActive = true;
@@ -1366,17 +1412,43 @@ namespace MeshCentralRouter
} }
} }
} }
skipExistingFiles = true;
if (overWriteCount > 0) if (overWriteCount > 0)
{ {
FileConfirmOverwriteForm f = new FileConfirmOverwriteForm(); 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 (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; if (f.ShowDialog(this) != DialogResult.OK) return;
skipExistingFiles = f.skipExistingFiles;
} }
// Perform the upload // Perform the upload
uploadFileArrayPtr = 0; uploadFileArrayPtr = 0;
uploadFileArray = new ArrayList(); uploadFileArray = new ArrayList();
foreach (string file in files) { uploadFileArray.Add(file); }
if (skipExistingFiles == true)
{
foreach (string file in files)
{
bool overwrite = false;
string filename = file;
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)) { overwrite = true; }
}
}
if (overwrite == false) { uploadFileArray.Add(file); }
}
}
else
{
foreach (string file in files) { uploadFileArray.Add(file); }
}
if (uploadFileArray.Count == 0) return;
uploadLocalPath = null; uploadLocalPath = null;
uploadRemotePath = remoteFolder; uploadRemotePath = remoteFolder;
uploadActive = true; uploadActive = true;
@@ -1456,17 +1528,51 @@ namespace MeshCentralRouter
} }
} }
} }
skipExistingFiles = true;
if (overWriteCount > 0) if (overWriteCount > 0)
{ {
FileConfirmOverwriteForm f = new FileConfirmOverwriteForm(); 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 (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; if (f.ShowDialog(this) != DialogResult.OK) return;
skipExistingFiles = f.skipExistingFiles;
} }
// Perform downloads // Perform downloads
downloadFileArrayPtr = 0; downloadFileArrayPtr = 0;
downloadFileArray = (ArrayList)e.Data.GetData("RemoteFiles"); downloadFileArray = (ArrayList)e.Data.GetData("RemoteFiles");
downloadFileSizeArray = (ArrayList)e.Data.GetData("RemoteSizes"); downloadFileSizeArray = (ArrayList)e.Data.GetData("RemoteSizes");
if (skipExistingFiles == true)
{
ArrayList downloadFileArray2 = new ArrayList();
ArrayList downloadFileSizeArray2 = new ArrayList();
for (int i = 0; i < downloadFileArray.Count; i++)
{
bool overwrite = false;
string filename = (string)downloadFileArray[i];
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)) { overwrite = true; }
}
}
if (overwrite == false)
{
downloadFileArray2.Add(downloadFileArray[i]);
downloadFileSizeArray2.Add(downloadFileSizeArray[i]);
}
}
downloadFileArray = downloadFileArray2;
downloadFileSizeArray = downloadFileSizeArray2;
}
if (downloadFileArray.Count == 0) return;
downloadLocalPath = localFolder; downloadLocalPath = localFolder;
downloadRemotePath = (string)e.Data.GetData("RemoteFolder"); downloadRemotePath = (string)e.Data.GetData("RemoteFolder");
downloadActive = true; downloadActive = true;