Skip to content

Commit

Permalink
Use the script location as the working directory when calling mscript…
Browse files Browse the repository at this point in the history
…s from the GUI
  • Loading branch information
kythyria committed Jul 17, 2022
1 parent 509d55a commit f8acf02
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 3 additions & 3 deletions PD2ModelParser/Modelscript/Script.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -29,11 +29,11 @@ public static bool ExecuteFileWithMsgBox(ref FullModelData data, string file)
}
}

public static bool ExecuteWithMsgBox(IEnumerable<IScriptItem> items, ref FullModelData initialModel)
public static bool ExecuteWithMsgBox(IEnumerable<IScriptItem> items, string workDir, ref FullModelData initialModel)
{
try
{
initialModel = ExecuteItems(items, Directory.GetCurrentDirectory(), initialModel);
initialModel = ExecuteItems(items, workDir, initialModel);
return true;
}
catch (Exception exc)
Expand Down
6 changes: 4 additions & 2 deletions PD2ModelParser/UI/ObjectsPanel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Linq;
using System.Windows.Forms;

using Directory = System.IO.Directory;

namespace PD2ModelParser.UI
{
public partial class ObjectsPanel : UserControl
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit f8acf02

Please sign in to comment.