From f8acf02daeb190a8cd1dd7564d8ac230e9619691 Mon Sep 17 00:00:00 2001 From: Kythyria Tieran Date: Sun, 17 Jul 2022 23:24:17 +0100 Subject: [PATCH] Use the script location as the working directory when calling mscripts from the GUI --- PD2ModelParser/Modelscript/Script.cs | 6 +++--- PD2ModelParser/UI/ObjectsPanel.cs | 6 ++++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/PD2ModelParser/Modelscript/Script.cs b/PD2ModelParser/Modelscript/Script.cs index 3f82c1f..b83de66 100644 --- a/PD2ModelParser/Modelscript/Script.cs +++ b/PD2ModelParser/Modelscript/Script.cs @@ -17,7 +17,7 @@ public static bool ExecuteFileWithMsgBox(ref FullModelData data, string file) { XElement root = XElement.Parse(File.ReadAllText(file)); var script = ParseXml(root); - data = ExecuteItems(script, Directory.GetCurrentDirectory(), data); + data = ExecuteItems(script, System.IO.Path.GetDirectoryName(file), data); return true; } catch (Exception exc) @@ -29,11 +29,11 @@ public static bool ExecuteFileWithMsgBox(ref FullModelData data, string file) } } - public static bool ExecuteWithMsgBox(IEnumerable items, ref FullModelData initialModel) + public static bool ExecuteWithMsgBox(IEnumerable items, string workDir, ref FullModelData initialModel) { try { - initialModel = ExecuteItems(items, Directory.GetCurrentDirectory(), initialModel); + initialModel = ExecuteItems(items, workDir, initialModel); return true; } catch (Exception exc) diff --git a/PD2ModelParser/UI/ObjectsPanel.cs b/PD2ModelParser/UI/ObjectsPanel.cs index 147e6a5..5e0ee62 100644 --- a/PD2ModelParser/UI/ObjectsPanel.cs +++ b/PD2ModelParser/UI/ObjectsPanel.cs @@ -5,6 +5,8 @@ using System.Linq; using System.Windows.Forms; +using Directory = System.IO.Directory; + namespace PD2ModelParser.UI { public partial class ObjectsPanel : UserControl @@ -57,7 +59,7 @@ private void Reload() } // TODO: There must be a better way to deal with errors. - bool success = Modelscript.Script.ExecuteWithMsgBox(script, ref data); + bool success = Modelscript.Script.ExecuteWithMsgBox(script, Directory.GetCurrentDirectory(), ref data); if (!success) return; @@ -157,7 +159,7 @@ private void btnSave_Click(object sender, EventArgs e) new Modelscript.SaveModel() { File = modelFile.Selected } }; // TODO: There must be a better way to deal with errors. - bool success = Modelscript.Script.ExecuteWithMsgBox(script, ref data); + bool success = Modelscript.Script.ExecuteWithMsgBox(script, Directory.GetCurrentDirectory(), ref data); if (!success) return; }