From efbe49b4390900ed40bb0854c2566974b06d60d3 Mon Sep 17 00:00:00 2001 From: Yako Date: Mon, 16 Jun 2025 18:37:36 +0200 Subject: [PATCH] Prevent DSPRE from opening if required tools can not be found and print appropriate error --- DS_Map/Main Window.Designer.cs | 1 + DS_Map/Main Window.cs | 58 ++++++++++++++++++++++++++++++++-- 2 files changed, 56 insertions(+), 3 deletions(-) diff --git a/DS_Map/Main Window.Designer.cs b/DS_Map/Main Window.Designer.cs index 17f8123..3862b53 100644 --- a/DS_Map/Main Window.Designer.cs +++ b/DS_Map/Main Window.Designer.cs @@ -11006,6 +11006,7 @@ this.Name = "MainProgram"; this.Text = "DS Pokémon Rom Editor Reloaded 1.11.1 (Nømura, AdAstra/LD3005, Mixone)"; this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.MainProgram_FormClosing); + this.Shown += new System.EventHandler(this.MainProgram_Shown); this.mainTabControl.ResumeLayout(false); this.headerEditorTabPage.ResumeLayout(false); this.headerEditorTabPage.PerformLayout(); diff --git a/DS_Map/Main Window.cs b/DS_Map/Main Window.cs index 7f3d202..cbc8809 100644 --- a/DS_Map/Main Window.cs +++ b/DS_Map/Main Window.cs @@ -78,11 +78,20 @@ namespace DSPRE { #region Subroutines private void MainProgram_FormClosing(object sender, FormClosingEventArgs e) { - if (MessageBox.Show("Are you sure you want to quit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { + if (e.CloseReason != CloseReason.ApplicationExitCall && MessageBox.Show("Are you sure you want to quit?", "Exit", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No) { e.Cancel = true; } Properties.Settings.Default.Save(); } + + private void MainProgram_Shown(object sender, EventArgs e) { + if (!DetectRequiredTools()) + { + BeginInvoke(new Action(() => Application.Exit())); + return; + } + } + private string[] GetBuildingsList(bool interior) { List names = new List(); string path = romInfo.GetBuildingModelsDirPath(interior); @@ -698,9 +707,52 @@ namespace DSPRE { { MessageBox.Show("Unpacking will not be possible without a valid work directory.", "Unpacking aborted", MessageBoxButtons.OK, MessageBoxIcon.Error); return false; - } - + } + } + private bool DetectRequiredTools() + { + bool toolsMissing = false; + List missingToolsList = new List(); + + if (!File.Exists(@"Tools\ndstool.exe")) + { + toolsMissing = true; + missingToolsList.Add("ndstool.exe"); + } + if (!File.Exists(@"Tools\blz.exe")) + { + toolsMissing = true; + missingToolsList.Add("blz.exe"); + } + if (!File.Exists(@"Tools\apicula.exe")) + { + toolsMissing = true; + missingToolsList.Add("apicula.exe"); + } + + if (toolsMissing) + { + string message = "The following required tools are missing from the DSPRE Tools folder:\n-" + + string.Join("\n-", missingToolsList) + "\n\n" + + "Please ensure that the Tools folder is intact and contains all necessary files.\n" + + "Common causes for this issue are:\n" + + " - DSPRE is stored in OneDrive\n" + + " - You opened DSPRE from Windows search\n" + + " - Your Antivirus software has removed critical files\n\n" + + "DSPRE will now close."; + MessageBox.Show(message, "Missing Tools", MessageBoxButtons.OK, MessageBoxIcon.Error); + + // If the program somehow doesn't close after this, we also disable the buttons and hope this is enough to dissuade the user from using it. + this.loadRomButton.Enabled = false; // Disable Load ROM button + this.readDataFromFolderButton.Enabled = false; // Disable Read Data from Folder button + this.fileToolStripMenuItem.DropDownItems[0].Enabled = false; // Disable Open ROM menu item + this.fileToolStripMenuItem.DropDownItems[1].Enabled = false; // Disable Open Folder menu item + + return false; + } + + return true; } private void CheckROMLanguage() {