From 3b8dc168b474282e633af1a70223f79d47128b35 Mon Sep 17 00:00:00 2001 From: Blake <6874208+StudentBlake@users.noreply.github.com> Date: Mon, 11 Nov 2019 16:05:17 -0500 Subject: [PATCH] Added edge-case error handling, reverted game revision display change, disable trim button if XCI is already trimmed --- Properties/AssemblyInfo.cs | 4 +-- XCI_Explorer/MainForm.cs | 58 ++++++++++++++++++++++++-------------- 2 files changed, 39 insertions(+), 23 deletions(-) diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index fd99a23..6375465 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -15,5 +15,5 @@ using System.Runtime.InteropServices; [assembly: AssemblyTrademark("")] [assembly: ComVisible(false)] [assembly: Guid("206c6c47-87b1-477f-b6e6-f7e7c1a92f8f")] -[assembly: AssemblyFileVersion("1.4.8.1")] -[assembly: AssemblyVersion("1.4.8.1")] +[assembly: AssemblyFileVersion("1.4.9")] +[assembly: AssemblyVersion("1.4.9")] diff --git a/XCI_Explorer/MainForm.cs b/XCI_Explorer/MainForm.cs index bb3e71e..a6a0c7b 100644 --- a/XCI_Explorer/MainForm.cs +++ b/XCI_Explorer/MainForm.cs @@ -160,31 +160,39 @@ namespace XCI_Explorer LB_ActualHash.Text = ""; B_Extract.Enabled = false; - if (CheckNSP()) + try { - B_TrimXCI.Enabled = false; - B_ExportCert.Enabled = false; - B_ImportCert.Enabled = false; - B_ViewCert.Enabled = false; - B_ClearCert.Enabled = false; + if (CheckNSP()) + { + B_TrimXCI.Enabled = false; + B_ExportCert.Enabled = false; + B_ImportCert.Enabled = false; + B_ViewCert.Enabled = false; + B_ClearCert.Enabled = false; - LoadNSP(); - } - else if (CheckXCI()) - { - B_TrimXCI.Enabled = true; - B_ExportCert.Enabled = true; - B_ImportCert.Enabled = true; - B_ViewCert.Enabled = true; - B_ClearCert.Enabled = true; + LoadNSP(); + } + else if (CheckXCI()) + { + B_TrimXCI.Enabled = true; + B_ExportCert.Enabled = true; + B_ImportCert.Enabled = true; + B_ViewCert.Enabled = true; + B_ClearCert.Enabled = true; - LoadXCI(); + LoadXCI(); + } + else + { + TB_File.Text = null; + MessageBox.Show("File is corrupt or unsupported."); + } } - else + catch(Exception e) { - TB_File.Text = null; - MessageBox.Show("Unsupported file."); + MessageBox.Show("Error: " + e.ToString() + "\nFile is corrupt or unsupported."); } + } private void B_LoadROM_Click(object sender, EventArgs e) @@ -230,6 +238,9 @@ namespace XCI_Explorer LoadPartitions(); LoadNCAData(); LoadGameInfos(); + + if (isTrimmed()) + B_TrimXCI.Enabled = false; } // Giba's better implementation (more native) @@ -560,7 +571,7 @@ namespace XCI_Explorer } else { - TB_GameRev.Text = NACP.NACP_Datas[0].GameVer.Replace("\0", "") + " (" + xmlVersion + ")"; + TB_GameRev.Text = xmlVersion + " (" + NACP.NACP_Datas[0].GameVer.Replace("\0", "") + ")"; } TB_ProdCode.Text = NACP.NACP_Datas[0].GameProd.Replace("\0", ""); if (TB_ProdCode.Text == "") @@ -870,6 +881,11 @@ namespace XCI_Explorer return ByteArrayToString(hashValue); } + public bool isTrimmed() + { + return TB_ROMExactSize.Text == TB_ExactUsedSpace.Text; + } + private void LoadPartitions() { string actualHash; @@ -1301,7 +1317,7 @@ namespace XCI_Explorer { if (MessageBox.Show("Trim XCI?", "XCI Explorer", MessageBoxButtons.YesNo) == DialogResult.Yes) { - if (!TB_ROMExactSize.Text.Equals(TB_ExactUsedSpace.Text)) + if (!isTrimmed()) { FileStream fileStream = new FileStream(TB_File.Text, FileMode.Open, FileAccess.Write); fileStream.SetLength((long)UsedSize);