1
0
mirror of synced 2024-11-28 01:10:51 +01:00

Adjust program to use one instance for loading files (can be disabled in config)

This commit is contained in:
KillzXGaming 2019-08-11 11:10:32 -04:00
parent 9a70890924
commit e15e00c2c0
10 changed files with 78 additions and 18 deletions

Binary file not shown.

View File

@ -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
}
}
}

View File

@ -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()));

View File

@ -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(); }

View File

@ -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)
{
}

View File

@ -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

View File

@ -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<string> openedFiles = new List<string>();
public List<string> OpenedFiles = new List<string>();
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
{

View File

@ -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<string> args = new List<string>();
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()