Added background worker for extracting NCAs

This commit is contained in:
StudentBlake 2018-06-30 13:18:40 -04:00
parent 690fcc70a7
commit ed5c20000d
3 changed files with 109 additions and 56 deletions

View file

@ -16,5 +16,5 @@ using System.Runtime.Versioning;
[assembly: AssemblyTrademark("")] [assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)] [assembly: ComVisible(false)]
[assembly: Guid("206c6c47-87b1-477f-b6e6-f7e7c1a92f8f")] [assembly: Guid("206c6c47-87b1-477f-b6e6-f7e7c1a92f8f")]
[assembly: AssemblyFileVersion("1.2.2.0")] [assembly: AssemblyFileVersion("1.2.2.1")]
[assembly: AssemblyVersion("1.2.2.0")] [assembly: AssemblyVersion("1.2.2.1")]

View file

@ -99,6 +99,7 @@ namespace XCI_Explorer
private Label LB_ExpectedHash; private Label LB_ExpectedHash;
private Label LB_ActualHash; private Label LB_ActualHash;
private Label LB_HashedRegionSize; private Label LB_HashedRegionSize;
private BackgroundWorker backgroundWorker1;
private Button B_TrimXCI; private Button B_TrimXCI;
public MainForm() public MainForm()
@ -511,7 +512,10 @@ namespace XCI_Explorer
LB_DataOffset.Text = "Offset: 0x" + selectedOffset.ToString("X"); LB_DataOffset.Text = "Offset: 0x" + selectedOffset.ToString("X");
LB_SelectedData.Text = e.Node.Text; LB_SelectedData.Text = e.Node.Text;
if (backgroundWorker1.IsBusy != true)
{
B_Extract.Enabled = true; B_Extract.Enabled = true;
}
string[] array = new string[5] string[] array = new string[5]
{ {
"B", "B",
@ -684,23 +688,16 @@ namespace XCI_Explorer
saveFileDialog.FileName = LB_SelectedData.Text; saveFileDialog.FileName = LB_SelectedData.Text;
if (saveFileDialog.ShowDialog() == DialogResult.OK) if (saveFileDialog.ShowDialog() == DialogResult.OK)
{ {
using (FileStream fileStream = File.OpenRead(TB_File.Text)) if (backgroundWorker1.IsBusy != true)
{ {
using (FileStream fileStream2 = File.OpenWrite(saveFileDialog.FileName)) B_Extract.Enabled = false;
{ B_LoadROM.Enabled = false;
new BinaryReader(fileStream); B_TrimXCI.Enabled = false;
new BinaryWriter(fileStream2);
fileStream.Position = selectedOffset; // Start the asynchronous operation.
byte[] buffer = new byte[8192]; backgroundWorker1.RunWorkerAsync(saveFileDialog.FileName);
long num = selectedSize;
int num2; MessageBox.Show("Extracting NCA\nPlease wait...");
while ((num2 = fileStream.Read(buffer, 0, 8192)) > 0 && num > 0)
{
fileStream2.Write(buffer, 0, num2);
num -= num2;
}
fileStream.Close();
}
} }
} }
} }
@ -787,6 +784,90 @@ namespace XCI_Explorer
} }
} }
private void LB_ExpectedHash_DoubleClick(object sender, EventArgs e)
{
BetterTreeNode betterTreeNode = (BetterTreeNode)TV_Partitions.SelectedNode;
if (betterTreeNode.Offset != -1)
{
Clipboard.SetText(betterTreeNode.ExpectedHash);
}
}
private void LB_ActualHash_DoubleClick(object sender, EventArgs e)
{
BetterTreeNode betterTreeNode = (BetterTreeNode)TV_Partitions.SelectedNode;
if (betterTreeNode.Offset != -1)
{
Clipboard.SetText(betterTreeNode.ActualHash);
}
}
private void TB_File_DragDrop(object sender, DragEventArgs e)
{
if (backgroundWorker1.IsBusy != true)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
TB_File.Text = files[0];
ProcessFile();
}
}
private void TB_File_DragEnter(object sender, DragEventArgs e)
{
if (backgroundWorker1.IsBusy != true)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
}
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
{
BackgroundWorker worker = sender as BackgroundWorker;
string fileName = (string)e.Argument;
using (FileStream fileStream = File.OpenRead(TB_File.Text))
{
using (FileStream fileStream2 = File.OpenWrite(fileName))
{
new BinaryReader(fileStream);
new BinaryWriter(fileStream2);
fileStream.Position = selectedOffset;
byte[] buffer = new byte[8192];
long num = selectedSize;
int num2;
while ((num2 = fileStream.Read(buffer, 0, 8192)) > 0 && num > 0)
{
fileStream2.Write(buffer, 0, num2);
num -= num2;
}
fileStream.Close();
}
}
}
private void backgroundWorker1_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
B_Extract.Enabled = true;
B_LoadROM.Enabled = true;
B_TrimXCI.Enabled = true;
if (e.Error != null)
{
MessageBox.Show("Error: " + e.Error.Message);
}
else
{
MessageBox.Show("Done extracting NCA!");
}
}
protected override void Dispose(bool disposing) protected override void Dispose(bool disposing)
{ {
if (disposing && components != null) if (disposing && components != null)
@ -842,6 +923,7 @@ namespace XCI_Explorer
this.LB_DataOffset = new System.Windows.Forms.Label(); this.LB_DataOffset = new System.Windows.Forms.Label();
this.LB_SelectedData = new System.Windows.Forms.Label(); this.LB_SelectedData = new System.Windows.Forms.Label();
this.TV_Partitions = new System.Windows.Forms.TreeView(); this.TV_Partitions = new System.Windows.Forms.TreeView();
this.backgroundWorker1 = new System.ComponentModel.BackgroundWorker();
this.TABC_Main.SuspendLayout(); this.TABC_Main.SuspendLayout();
this.TABP_XCI.SuspendLayout(); this.TABP_XCI.SuspendLayout();
this.groupBox2.SuspendLayout(); this.groupBox2.SuspendLayout();
@ -1290,6 +1372,11 @@ namespace XCI_Explorer
this.TV_Partitions.TabIndex = 0; this.TV_Partitions.TabIndex = 0;
this.TV_Partitions.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.TV_Partitions_AfterSelect); this.TV_Partitions.AfterSelect += new System.Windows.Forms.TreeViewEventHandler(this.TV_Partitions_AfterSelect);
// //
// backgroundWorker1
//
this.backgroundWorker1.DoWork += new System.ComponentModel.DoWorkEventHandler(this.backgroundWorker1_DoWork);
this.backgroundWorker1.RunWorkerCompleted += new System.ComponentModel.RunWorkerCompletedEventHandler(this.backgroundWorker1_RunWorkerCompleted);
//
// MainForm // MainForm
// //
this.AllowDrop = true; this.AllowDrop = true;
@ -1316,42 +1403,5 @@ namespace XCI_Explorer
this.PerformLayout(); this.PerformLayout();
} }
private void LB_ExpectedHash_DoubleClick(object sender, EventArgs e)
{
BetterTreeNode betterTreeNode = (BetterTreeNode)TV_Partitions.SelectedNode;
if (betterTreeNode.Offset != -1)
{
Clipboard.SetText(betterTreeNode.ExpectedHash);
}
}
private void LB_ActualHash_DoubleClick(object sender, EventArgs e)
{
BetterTreeNode betterTreeNode = (BetterTreeNode)TV_Partitions.SelectedNode;
if (betterTreeNode.Offset != -1)
{
Clipboard.SetText(betterTreeNode.ActualHash);
}
}
private void TB_File_DragDrop(object sender, DragEventArgs e)
{
string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
TB_File.Text = files[0];
ProcessFile();
}
private void TB_File_DragEnter(object sender, DragEventArgs e)
{
if (e.Data.GetDataPresent(DataFormats.FileDrop))
{
e.Effect = DragDropEffects.Copy;
}
else
{
e.Effect = DragDropEffects.None;
}
}
} }
} }

View file

@ -117,4 +117,7 @@
<resheader name="writer"> <resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value> <value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader> </resheader>
<metadata name="backgroundWorker1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
<value>17, 17</value>
</metadata>
</root> </root>