Allow replacing multiple files in a folder

This commit is contained in:
Fierelier 2022-06-11 00:20:04 +02:00
parent a1000bb782
commit 3b5caff621
1 changed files with 31 additions and 8 deletions

View File

@ -596,30 +596,53 @@ namespace RPFTool
private void btn_replace_Click(object sender, EventArgs e) private void btn_replace_Click(object sender, EventArgs e)
{ {
if (filelistview.SelectedObjects.Count < 1 || filelistview.SelectedObjects.Count > 1) /*if (filelistview.SelectedObjects.Count < 1 || filelistview.SelectedObjects.Count > 1)
{ {
MessageBox.Show("Only 1 file can be selected for replacing", "Replace", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Only 1 file can be selected for replacing", "Replace", MessageBoxButtons.OK, MessageBoxIcon.Information);
return; return;
} }
if (filelistview.SelectedObject is RPFLib.Common.Directory) if (filelistview.SelectedObject is RPFLib.Common.Directory)
{ {
MessageBox.Show("Cannot replace directories", "Replace", MessageBoxButtons.OK, MessageBoxIcon.Information); MessageBox.Show("Cannot replace directories", "Replace", MessageBoxButtons.OK, MessageBoxIcon.Information);
return; return;
} }*/
try try
{ {
var file = filelistview.SelectedObject as RPFLib.Common.File;
using (var ofrm = new OpenFileDialog()) using (var ofrm = new OpenFileDialog())
{ {
ofrm.Multiselect = true;
var files = 0;
if (ofrm.ShowDialog(this) == DialogResult.OK) if (ofrm.ShowDialog(this) == DialogResult.OK)
{ {
byte[] filebytes = System.IO.File.ReadAllBytes(ofrm.FileName); foreach (String file in ofrm.FileNames)
file.SetData(filebytes); {
var index = 0;
foreach (Object obj in filelistview.Objects)
{
if ((obj is RPFLib.Common.Directory) == false)
{
var listItem = filelistview.Items[index];
if (listItem.Text == Path.GetFileName(file))
{
var rpfFile = obj as RPFLib.Common.File;
byte[] filebytes = System.IO.File.ReadAllBytes(file);
rpfFile.SetData(filebytes);
++files;
}
}
index++;
}
}
} }
MessageBox.Show("Replaced " + files as string + " files.");
filelistview.RefreshSelectedObjects();
if (!this.Text.Contains("*"))
this.Text += this.Text + "*";
} }
filelistview.RefreshSelectedObjects();
if (!this.Text.Contains("*"))
this.Text += this.Text + "*";
} }
catch (Exception ex) catch (Exception ex)
{ {