Skip to content

Commit

Permalink
Fixed #2
Browse files Browse the repository at this point in the history
Made the program respond while the Yaz0 Encoding process is happening to prevent the program from "Not Responding"
Fixed a bug where Folders couldn't be organized
  • Loading branch information
SuperHackio committed Nov 13, 2020
1 parent be00d54 commit 2e7744e
Show file tree
Hide file tree
Showing 7 changed files with 158 additions and 108 deletions.
6 changes: 6 additions & 0 deletions WiiExplorer.sln
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ VisualStudioVersion = 15.0.28307.902
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "WiiExplorer", "WiiExplorer\WiiExplorer.csproj", "{3711A74A-B9FB-4C8F-A7AB-E1198ACB19B9}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Hack.io.RARC", "..\Hack.io\Hack.io.RARC\Hack.io.RARC.csproj", "{4F4162CC-70FF-4EB9-AB34-D5FF98490C34}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand All @@ -15,6 +17,10 @@ Global
{3711A74A-B9FB-4C8F-A7AB-E1198ACB19B9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{3711A74A-B9FB-4C8F-A7AB-E1198ACB19B9}.Release|Any CPU.ActiveCfg = Release|Any CPU
{3711A74A-B9FB-4C8F-A7AB-E1198ACB19B9}.Release|Any CPU.Build.0 = Release|Any CPU
{4F4162CC-70FF-4EB9-AB34-D5FF98490C34}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4F4162CC-70FF-4EB9-AB34-D5FF98490C34}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4F4162CC-70FF-4EB9-AB34-D5FF98490C34}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4F4162CC-70FF-4EB9-AB34-D5FF98490C34}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
31 changes: 17 additions & 14 deletions WiiExplorer/ArcUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,34 +20,37 @@ public static TreeNode[] ToTreeNode(this RARC Arc, int FolderClosedID, ImageList
return Nodes.ToArray();
}

private static TreeNode ToTreeNode(this RARCDirectory Dir, int FolderClosedID, ImageList images)
private static TreeNode ToTreeNode(this RARC.Directory Dir, int FolderClosedID, ImageList images)
{
TreeNode Final = new TreeNode(Dir.Name) { ImageIndex = FolderClosedID, SelectedImageIndex = FolderClosedID };
for (int i = 0; i < Dir.SubDirectories.Count; i++)
Final.Nodes.Add(Dir.SubDirectories[i].ToTreeNode(FolderClosedID, images));
for (int i = 0; i < Dir.Files.Count; i++)
foreach (KeyValuePair<string, object> item in Dir.Items)
{
FileInfo fi = new FileInfo(Dir.Files[i].Name);
int imageindex = 2;
if (images.Images.ContainsKey("*" + fi.Extension))
imageindex = images.Images.IndexOfKey("*" + fi.Extension);
Final.Nodes.Add(new TreeNode(Dir.Files[i].Name) { Tag = Dir.Files[i], ImageIndex = imageindex, SelectedImageIndex = imageindex });
if (item.Value is RARC.Directory dir)
Final.Nodes.Add(dir.ToTreeNode(FolderClosedID, images));
else if (item.Value is RARC.File file)
{
FileInfo fi = new FileInfo(file.Name);
int imageindex = 2;
if (images.Images.ContainsKey("*" + fi.Extension))
imageindex = images.Images.IndexOfKey("*" + fi.Extension);
Final.Nodes.Add(new TreeNode(file.Name) { Tag = file, ImageIndex = imageindex, SelectedImageIndex = imageindex });
}
}
return Final;
}

public static void FromTreeNode(this RARC Arc, TreeNode Root) => Arc.Root = FromTreeNode(Root);

public static RARCDirectory FromTreeNode(this TreeNode TN)
public static RARC.Directory FromTreeNode(this TreeNode TN)
{
RARCDirectory Dir = new RARCDirectory() { Name = TN.Text };
RARC.Directory Dir = new RARC.Directory() { Name = TN.Text };
for (int i = 0; i < TN.Nodes.Count; i++)
if (TN.Nodes[i].Tag == null)
Dir.SubDirectories.Add(FromTreeNode(TN.Nodes[i]));
Dir.Items.Add(TN.Nodes[i].Text, FromTreeNode(TN.Nodes[i]));
else
{
Dir.Files.Add((RARCFile)TN.Nodes[i].Tag);
Dir.Files[Dir.Files.Count - 1].Name = TN.Nodes[i].Text;
((RARC.File)TN.Nodes[i].Tag).Name = TN.Nodes[i].Text;
Dir.Items.Add(TN.Nodes[i].Text, (RARC.File)TN.Nodes[i].Tag);
}
return Dir;
}
Expand Down
6 changes: 6 additions & 0 deletions WiiExplorer/MainForm.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

95 changes: 61 additions & 34 deletions WiiExplorer/MainForm.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
using System.Text;
using System.Windows.Forms;
using Microsoft.WindowsAPICodePack.Dialogs;
using System.Diagnostics;

namespace WiiExplorer
{
Expand Down Expand Up @@ -43,8 +44,8 @@ private void MainForm_Load(object sender, EventArgs e)
OpenWith = null;
}

OpenFileDialog ofd = new OpenFileDialog() { Filter = "Revolution Archives|*.arc|All Files|*.*" };
SaveFileDialog sfd = new SaveFileDialog() { Filter = "Revolution Archives|*.arc|All Files|*.*" };
OpenFileDialog ofd = new OpenFileDialog() { Filter = "All Supported Files|*.arc;*.szs|Revolution Archives|*.arc|YAZ0 Identified Revolution Archives|*.szs|All Files|*.*" };
SaveFileDialog sfd = new SaveFileDialog() { Filter = "All Supported Files|*.arc;*.szs|Revolution Archives|*.arc|YAZ0 Identified Revolution Archives|*.szs|All Files|*.*" };

OpenFileDialog Fileofd = new OpenFileDialog() { Multiselect = true };
SaveFileDialog Exportsfd = new SaveFileDialog();
Expand Down Expand Up @@ -467,21 +468,30 @@ private void ArchiveTreeView_BeforeCollapse(object sender, TreeViewCancelEventAr

#endregion

private void EnableControls()
{
EditToolStripMenuItem.Enabled = true;
AddFileToolStripMenuItem.Enabled = true;
AddFolderToolStripMenuItem.Enabled = true;
DeleteSelectedToolStripMenuItem.Enabled = true;
RenameSelectedToolStripMenuItem.Enabled = true;
ExportSelectedToolStripMenuItem.Enabled = true;
ExportAllToolStripMenuItem.Enabled = true;
ReplaceSelectedToolStripMenuItem.Enabled = true;
ImportFolderToolStripMenuItem.Enabled = true;
ArchiveTreeView.Enabled = true;
RootNameTextBox.Enabled = true;
SaveToolStripMenuItem.Enabled = true;
SaveAsToolStripMenuItem.Enabled = true;
private void SetControlsEnabled(bool toggle = true, bool affectall = false)
{
EditToolStripMenuItem.Enabled = toggle;
AddFileToolStripMenuItem.Enabled = toggle;
AddFolderToolStripMenuItem.Enabled = toggle;
DeleteSelectedToolStripMenuItem.Enabled = toggle;
RenameSelectedToolStripMenuItem.Enabled = toggle;
ExportSelectedToolStripMenuItem.Enabled = toggle;
ExportAllToolStripMenuItem.Enabled = toggle;
ReplaceSelectedToolStripMenuItem.Enabled = toggle;
ImportFolderToolStripMenuItem.Enabled = toggle;
ArchiveTreeView.Enabled = toggle;
RootNameTextBox.Enabled = toggle;
SaveToolStripMenuItem.Enabled = toggle;
SaveAsToolStripMenuItem.Enabled = toggle;

if (affectall)
{
FileToolStripMenuItem.Enabled = toggle;
NewToolStripMenuItem.Enabled = toggle;
NewFromFolderToolStripMenuItem.Enabled = toggle;
OpenToolStripMenuItem.Enabled = toggle;
Yaz0ToolStripComboBox.Enabled = toggle;
}
}

private void NewToolStripMenuItem_Click(object sender, EventArgs e)
Expand All @@ -493,7 +503,7 @@ private void NewToolStripMenuItem_Click(object sender, EventArgs e)
RootNameTextBox.Text = "New Archive";

Edited = false;
EnableControls();
SetControlsEnabled();
MainToolStripProgressBar.Value = 100;
MainToolStripStatusLabel.Text = "Created a new Archive.";
Text = $"WiiExplorer {Application.ProductVersion} - New Archive";
Expand All @@ -520,8 +530,10 @@ private void OpenArchive(string Filename)
ArchiveTreeView.Nodes.AddRange(Archive.ToTreeNode(0, ArchiveImageList));
RootNameTextBox.Text = Archive.Root.Name;

RARC.File InitSensor = Archive["AirBubble/ActorInfo/InitSensor.bcsv"] as RARC.File;
Archive["AirBubble/ActorInfo/InitSensor.bcsv"] = InitSensor;
Edited = false;
EnableControls();
SetControlsEnabled();
MainToolStripProgressBar.Value = 100;
MainToolStripStatusLabel.Text = $"Archive loaded successfully!";
Text = $"WiiExplorer {Application.ProductVersion} - {new FileInfo(Filename).Name}";
Expand Down Expand Up @@ -564,12 +576,23 @@ private void SaveArchive(string Filename)
Archive.FromTreeNode(RootNode);
MainToolStripProgressBar.Value = 80;
Archive.Save(Filename);
YAZ0.Compress(Filename, Program.Yaz0Mode == 2);
Stopwatch timer = new Stopwatch();
timer.Start();
if (Program.Yaz0Mode != 0)
Yaz0BackgroundWorker.RunWorkerAsync(Filename);
SetControlsEnabled(false, true);
while (Yaz0BackgroundWorker.IsBusy)
{
MainToolStripStatusLabel.Text = $"{(Program.Yaz0Mode == 2 ? "Fast ":"")}Yaz0 Encoding, Please Wait. ({timer.Elapsed.ToString("mm\\:ss")} Elapsed)";
Application.DoEvents();
}
timer.Stop();
ArchiveTreeView.Nodes.AddRange(Archive.ToTreeNode(0, ArchiveImageList));

Edited = false;
MainToolStripProgressBar.Value = 100;
MainToolStripStatusLabel.Text = $"Archive saved successfully!";
MainToolStripStatusLabel.Text = $"Archive saved successfully!{(Program.Yaz0Mode != 0 ? $"({timer.Elapsed.ToString("mm\\:ss")} Elapsed)":"")}";
SetControlsEnabled(affectall:true);
Text = $"WiiExplorer {Application.ProductVersion} - {new FileInfo(Filename).Name}";
Properties.Settings.Default.PreviousOpenArchivePath = new FileInfo(Filename).DirectoryName;
Properties.Settings.Default.Save();
Expand All @@ -583,7 +606,6 @@ private void AddFileToolStripMenuItem_Click(object sender, EventArgs e)
return;
}


TreeNode tmp = ArchiveTreeView.SelectedNode;
Fileofd.InitialDirectory = Properties.Settings.Default.PreviousAddFilePath;
if (Fileofd.ShowDialog() == DialogResult.OK && Fileofd.FileName != "")
Expand All @@ -596,21 +618,21 @@ private void AddFileToolStripMenuItem_Click(object sender, EventArgs e)
if (ArchiveImageList.Images.ContainsKey("*" + fi.Extension))
imageindex = ArchiveImageList.Images.IndexOfKey("*" + fi.Extension);
if (ArchiveTreeView.SelectedNode == null)
ArchiveTreeView.Nodes.Add(new TreeNode(fi.Name) { Tag = new RARCFile(Fileofd.FileNames[i]), ImageIndex = imageindex, SelectedImageIndex = imageindex });
ArchiveTreeView.Nodes.Add(new TreeNode(fi.Name) { Tag = new RARC.File(Fileofd.FileNames[i]), ImageIndex = imageindex, SelectedImageIndex = imageindex });
else
{
//Add file to directory
if (ArchiveTreeView.SelectedNode.Tag is null)
{
ArchiveTreeView.SelectedNode.Nodes.Add(new TreeNode(fi.Name) { Tag = new RARCFile(Fileofd.FileNames[i]), ImageIndex = imageindex, SelectedImageIndex = imageindex });
ArchiveTreeView.SelectedNode.Nodes.Add(new TreeNode(fi.Name) { Tag = new RARC.File(Fileofd.FileNames[i]), ImageIndex = imageindex, SelectedImageIndex = imageindex });
}
else if (ArchiveTreeView.SelectedNode.Parent == null)
{
ArchiveTreeView.Nodes.Add(new TreeNode(fi.Name) { Tag = new RARCFile(Fileofd.FileNames[i]), ImageIndex = imageindex, SelectedImageIndex = imageindex });
ArchiveTreeView.Nodes.Add(new TreeNode(fi.Name) { Tag = new RARC.File(Fileofd.FileNames[i]), ImageIndex = imageindex, SelectedImageIndex = imageindex });
}
else
{
ArchiveTreeView.SelectedNode.Parent.Nodes.Add(new TreeNode(fi.Name) { Tag = new RARCFile(Fileofd.FileNames[i]), ImageIndex = imageindex, SelectedImageIndex = imageindex });
ArchiveTreeView.SelectedNode.Parent.Nodes.Add(new TreeNode(fi.Name) { Tag = new RARC.File(Fileofd.FileNames[i]), ImageIndex = imageindex, SelectedImageIndex = imageindex });
}
}
}
Expand Down Expand Up @@ -725,7 +747,7 @@ private void ReplaceSelectedToolStripMenuItem_Click(object sender, EventArgs e)
if (Fileofd.ShowDialog() == DialogResult.OK && Fileofd.FileName != "")
{
string oldname = ArchiveTreeView.SelectedNode.Text;
RARCFile file = new RARCFile(ofd.FileName);
RARC.File file = new RARC.File(ofd.FileName);
TreeNode ParentNode = ArchiveTreeView.SelectedNode.Parent;
int selectindex = ArchiveTreeView.SelectedNode.Index;
ArchiveTreeView.SelectedNode.Remove();
Expand All @@ -734,9 +756,9 @@ private void ReplaceSelectedToolStripMenuItem_Click(object sender, EventArgs e)
if (ArchiveImageList.Images.ContainsKey("*" + fi.Extension))
imageindex = ArchiveImageList.Images.IndexOfKey("*" + fi.Extension);
if (ParentNode == null)
ArchiveTreeView.Nodes.Insert(selectindex, new TreeNode(fi.Name) { Tag = new RARCFile(Fileofd.FileName), ImageIndex = imageindex, SelectedImageIndex = imageindex });
ArchiveTreeView.Nodes.Insert(selectindex, new TreeNode(fi.Name) { Tag = new RARC.File(Fileofd.FileName), ImageIndex = imageindex, SelectedImageIndex = imageindex });
else
ParentNode.Nodes.Insert(selectindex, new TreeNode(fi.Name) { Tag = new RARCFile(Fileofd.FileName), ImageIndex = imageindex, SelectedImageIndex = imageindex });
ParentNode.Nodes.Insert(selectindex, new TreeNode(fi.Name) { Tag = new RARC.File(Fileofd.FileName), ImageIndex = imageindex, SelectedImageIndex = imageindex });


Properties.Settings.Default.PreviousAddFilePath = new FileInfo(Fileofd.FileName).DirectoryName;
Expand All @@ -746,7 +768,7 @@ private void ReplaceSelectedToolStripMenuItem_Click(object sender, EventArgs e)
}
}

private void MainForm_FormClosing(object sender, FormClosingEventArgs e) => e.Cancel = (e.CloseReason == CloseReason.UserClosing & Edited) && MessageBox.Show("You have unsaved changes.\nAre you sure you want to quit?", "Unsaved Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No;
private void MainForm_FormClosing(object sender, FormClosingEventArgs e) => e.Cancel = Yaz0BackgroundWorker.IsBusy || (e.CloseReason == CloseReason.UserClosing & Edited) && MessageBox.Show("You have unsaved changes.\nAre you sure you want to quit?", "Unsaved Changes", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.No;

private void Yaz0ToolStripComboBox_SelectedIndexChanged(object sender, EventArgs e) => Program.Yaz0Mode = (byte)Yaz0ToolStripComboBox.SelectedIndex;

Expand All @@ -767,7 +789,7 @@ private void ExportArchiveFile(TreeNode TN)
else if (Directory.Exists(Exportsfd.FileName))
Directory.Delete(Exportsfd.FileName, true);

RARCDirectory test = TN.FromTreeNode();
RARC.Directory test = TN.FromTreeNode();
Directory.CreateDirectory(Exportsfd.FileName);
test.Export(Exportsfd.FileName);
MainToolStripStatusLabel.Text = $"\"{TN.Text}\" has been saved!";
Expand All @@ -791,7 +813,7 @@ private void ExportArchiveFile(TreeNode TN)
Exportsfd.InitialDirectory = Properties.Settings.Default.PreviousExportPath;
if (Exportsfd.ShowDialog() == DialogResult.OK && Exportsfd.FileName != "")
{
File.WriteAllBytes(Exportsfd.FileName, ((RARCFile)TN.Tag).FileData);
File.WriteAllBytes(Exportsfd.FileName, ((RARC.File)TN.Tag).FileData);
MainToolStripStatusLabel.Text = $"\"{TN.Text}\" has been saved!";

Properties.Settings.Default.PreviousExportPath = new FileInfo(Exportsfd.FileName).DirectoryName;
Expand All @@ -807,7 +829,7 @@ private void ArchiveTreeView_AfterSelect(object sender, TreeViewEventArgs e)
else if (ArchiveTreeView.SelectedNode.Tag == null)
MainToolStripStatusLabel.Text = $"Folder \"{ArchiveTreeView.SelectedNode.Text}\" ({ArchiveTreeView.SelectedNode.Nodes.Count} Item{(ArchiveTreeView.SelectedNode.Nodes.Count > 1 ? "s":"")})";
else
MainToolStripStatusLabel.Text = $"File \"{ArchiveTreeView.SelectedNode.Text}\" ({((RARCFile)ArchiveTreeView.SelectedNode.Tag).FileData.Length} Bytes)";
MainToolStripStatusLabel.Text = $"File \"{ArchiveTreeView.SelectedNode.Text}\" ({((RARC.File)ArchiveTreeView.SelectedNode.Tag).FileData.Length} Bytes)";
}

private void ImportFolderToolStripMenuItem_Click(object sender, EventArgs e)
Expand Down Expand Up @@ -854,7 +876,7 @@ private void NewFromFolderToolStripMenuItem_Click(object sender, EventArgs e)
Properties.Settings.Default.Save();

Edited = true;
EnableControls();
SetControlsEnabled();
MainToolStripProgressBar.Value = 100;
MainToolStripStatusLabel.Text = $"Created a new Archive from \"{BFB.FileName}\"";
Text = $"WiiExplorer {Application.ProductVersion} - New Archive";
Expand All @@ -868,5 +890,10 @@ private void ArchiveTreeView_NodeMouseClick(object sender, TreeNodeMouseClickEve
ArchiveContextMenuStrip.Show(ArchiveTreeView, e.Location);
}
}

private void Yaz0BackgroundWorker_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e)
{
YAZ0.Compress((string)e.Argument, Program.Yaz0Mode == 2);
}
}
}
Loading

0 comments on commit 2e7744e

Please sign in to comment.