Allow replacing multiple files in a folder
This commit is contained in:
parent
a1000bb782
commit
3b5caff621
|
@ -596,30 +596,53 @@ namespace RPFTool
|
|||
|
||||
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);
|
||||
return;
|
||||
}
|
||||
|
||||
if (filelistview.SelectedObject is RPFLib.Common.Directory)
|
||||
{
|
||||
MessageBox.Show("Cannot replace directories", "Replace", MessageBoxButtons.OK, MessageBoxIcon.Information);
|
||||
return;
|
||||
}
|
||||
}*/
|
||||
|
||||
try
|
||||
{
|
||||
var file = filelistview.SelectedObject as RPFLib.Common.File;
|
||||
using (var ofrm = new OpenFileDialog())
|
||||
{
|
||||
ofrm.Multiselect = true;
|
||||
var files = 0;
|
||||
if (ofrm.ShowDialog(this) == DialogResult.OK)
|
||||
{
|
||||
byte[] filebytes = System.IO.File.ReadAllBytes(ofrm.FileName);
|
||||
file.SetData(filebytes);
|
||||
foreach (String file in ofrm.FileNames)
|
||||
{
|
||||
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)
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue