diff --git a/.vs/Toolbox/v15/.suo b/.vs/Toolbox/v15/.suo index ff3b6d1b..332c03d4 100644 Binary files a/.vs/Toolbox/v15/.suo and b/.vs/Toolbox/v15/.suo differ diff --git a/File_Format_Library/FileFormats/Message/MSBT.cs b/File_Format_Library/FileFormats/Message/MSBT.cs index 312db0af..8e298d55 100644 --- a/File_Format_Library/FileFormats/Message/MSBT.cs +++ b/File_Format_Library/FileFormats/Message/MSBT.cs @@ -460,7 +460,7 @@ namespace FirstPlugin for (int i = 0; i < Entries.Count; i++) { writer.Write(Entries[i].Item1); //MessageID - writer.Write(Entries[i].Item2); //MessageIndex + writer.Write(Entries[i].Item2); //MessageIndex } } } diff --git a/Switch_Toolbox_Library/Config.cs b/Switch_Toolbox_Library/Config.cs index 544ffa4d..ab65088a 100644 --- a/Switch_Toolbox_Library/Config.cs +++ b/Switch_Toolbox_Library/Config.cs @@ -244,6 +244,9 @@ namespace Toolbox.Library case "CustomPicureBoxBGColor": TryParseHexColor(node, ref Runtime.CustomPicureBoxBGColor); break; + case "UseSingleInstance": + bool.TryParse(node.InnerText, out Runtime.UseSingleInstance); + break; } } @@ -368,6 +371,8 @@ namespace Toolbox.Library XmlNode mainSettingsNode = doc.CreateElement("MAINFORM"); parentNode.AppendChild(mainSettingsNode); + + mainSettingsNode.AppendChild(createNode(doc, "UseSingleInstance", Runtime.UseSingleInstance.ToString())); mainSettingsNode.AppendChild(createNode(doc, "UseDirectXTexDecoder", Runtime.UseDirectXTexDecoder.ToString())); mainSettingsNode.AppendChild(createNode(doc, "AlwaysCompressOnSave", Runtime.AlwaysCompressOnSave.ToString())); mainSettingsNode.AppendChild(createNode(doc, "DisplayViewport", Runtime.DisplayViewport.ToString())); diff --git a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs index a0544446..a958e380 100644 --- a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs +++ b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditor.cs @@ -106,6 +106,7 @@ namespace Toolbox.Library.Forms } public void SelectFirstNode() { if (ObjectTree != null) ObjectTree.SelectFirstNode(); } + public void SelectNode(TreeNode node) { if (ObjectTree != null) ObjectTree.SelectNode(node); } public void SortTreeAscending() { if (ObjectTree != null) ObjectTree.SortTreeAscending(); } diff --git a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs index b23cdf51..8fce4b12 100644 --- a/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs +++ b/Switch_Toolbox_Library/Forms/Editors/Object Editor/ObjectEditorTree.cs @@ -58,6 +58,8 @@ namespace Toolbox.Library.Forms FileRoot.Nodes.Add(n); } + SelectNode(FileRoot); + for (int i = 0; i < FileRoot.FileNodes.Count; i++) { if (FileRoot.FileNodes[i].Item1.OpenFileFormatOnLoad) @@ -563,6 +565,11 @@ namespace Toolbox.Library.Forms treeViewCustom1.Sort(); } + public void SelectNode(TreeNode node) + { + treeViewCustom1.SelectedNode = node; + } + private void splitter1_Resize(object sender, EventArgs e) { } diff --git a/Switch_Toolbox_Library/Runtime.cs b/Switch_Toolbox_Library/Runtime.cs index 686a01fb..07be7c16 100644 --- a/Switch_Toolbox_Library/Runtime.cs +++ b/Switch_Toolbox_Library/Runtime.cs @@ -15,10 +15,9 @@ namespace Toolbox.Library public class Runtime { + public static bool UseSingleInstance = true; public static bool UseDirectXTexDecoder = true; - public static bool DEVELOPER_DEBUG_MODE = false; - public static bool AlwaysCompressOnSave = false; public static class ResourceTables diff --git a/Switch_Toolbox_Library/Toolbox.Library.dll b/Switch_Toolbox_Library/Toolbox.Library.dll index 882e5e0b..1cd438e4 100644 Binary files a/Switch_Toolbox_Library/Toolbox.Library.dll and b/Switch_Toolbox_Library/Toolbox.Library.dll differ diff --git a/Switch_Toolbox_Library/Toolbox.Library.pdb b/Switch_Toolbox_Library/Toolbox.Library.pdb index e763e82c..45555206 100644 Binary files a/Switch_Toolbox_Library/Toolbox.Library.pdb and b/Switch_Toolbox_Library/Toolbox.Library.pdb differ diff --git a/Toolbox/MainForm.cs b/Toolbox/MainForm.cs index 4b0c57db..4ebb9515 100644 --- a/Toolbox/MainForm.cs +++ b/Toolbox/MainForm.cs @@ -51,8 +51,6 @@ namespace Toolbox FormThemes.ActivePreset = FormThemes.Preset.Dark; InitializeComponent(); - - LoadConfig(); } public void UpdateForm() @@ -65,7 +63,7 @@ namespace Toolbox } //Use for files opened with program - public List openedFiles = new List(); + public List OpenedFiles = new List(); private void Form1_Load(object sender, EventArgs e) { @@ -122,13 +120,13 @@ namespace Toolbox ReloadFiles(); LoadPluginFileContextMenus(); - foreach (string file in openedFiles) + foreach (string file in OpenedFiles) { if (File.Exists(file)) OpenFile(file); } - openedFiles.Clear(); + OpenedFiles.Clear(); if (Runtime.UseDebugDomainExceptionHandler) { @@ -137,6 +135,17 @@ namespace Toolbox } } + public void OpenFiles() + { + foreach (string file in OpenedFiles) + { + if (File.Exists(file)) + OpenFile(file); + } + + OpenedFiles.Clear(); + } + private void ReloadFiles() { SupportedFormats = FileManager.GetFileFormats(); @@ -324,8 +333,6 @@ namespace Toolbox } SetFormatSettings(GetActiveIFileFormat()); - - ((ObjectEditor)editor).SelectFirstNode(); } private void AddObjectEditorFile(TreeNode file, ObjectEditor editor, bool ClearFiles) @@ -333,6 +340,7 @@ namespace Toolbox TabDupeIndex = 0; editor.MdiParent = this; editor.AddNode(file, ClearFiles); + editor.SelectNode(file); if (file is TreeNodeFile) { @@ -558,7 +566,7 @@ namespace Toolbox #region Form Settings and plugin menus - private void LoadConfig() + public static void LoadConfig() { try { diff --git a/Toolbox/Program.cs b/Toolbox/Program.cs index bb0072e9..9635f41a 100644 --- a/Toolbox/Program.cs +++ b/Toolbox/Program.cs @@ -6,6 +6,7 @@ using System.Windows.Forms; using System.IO; using System.Runtime.InteropServices; using System.Reflection; +using Microsoft.VisualBasic.ApplicationServices; namespace Toolbox { @@ -35,23 +36,62 @@ namespace Toolbox var domain = AppDomain.CurrentDomain; domain.AssemblyResolve += LoadAssembly; - MainForm form = new MainForm(); - form.openedFiles = Files; - - bool LoadedDX = TryLoadDirectXTex(); if (!LoadedDX && !Toolbox.Library.Runtime.UseDirectXTexDecoder) { - var result = MessageBox.Show("Direct X Tex Failed to load! Make sure to install Visual C++ and Direct X Tex. Do you want to go to the install sites?", "", MessageBoxButtons.YesNo); + var result = MessageBox.Show("Direct X Tex Failed to load! Make sure to install Visual C++ and Direct X Tex. Do you want to go to the install sites?", "", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { System.Diagnostics.Process.Start("https://support.microsoft.com/en-us/help/2977003/the-latest-supported-visual-c-downloads"); System.Diagnostics.Process.Start("https://www.microsoft.com/en-us/download/details.aspx?id=35"); } } - Toolbox.Library.Runtime.UseDirectXTexDecoder= LoadedDX; - Application.Run(form); + MainForm.LoadConfig(); + + if (Toolbox.Library.Runtime.UseSingleInstance) + { + SingleInstanceController controller = new SingleInstanceController(); + controller.Run(args); + } + else + { + MainForm form = new MainForm(); + form.OpenedFiles = Files; + Application.Run(form); + } + } + + public class SingleInstanceController : WindowsFormsApplicationBase + { + public SingleInstanceController() + { + IsSingleInstance = true; + Startup += OnStart; + StartupNextInstance += Program_StartupNextInstance; + } + + private void OnStart(object sender, StartupEventArgs e) + { + List args = new List(); + foreach (string arg in e.CommandLine) + args.Add(arg); + + Toolbox.MainForm.Instance.OpenedFiles = args; + } + + void Program_StartupNextInstance(object sender, StartupNextInstanceEventArgs e) + { + e.BringToForeground = true; + MainForm form = MainForm as MainForm; + form.OpenedFiles = e.CommandLine.ToList(); + form.OpenFiles(); + } + + protected override void OnCreateMainForm() + { + MainForm = new MainForm(); + } } private static bool TryLoadZSTD()