diff --git a/mpv.net/Scripting/PythonScript.cs b/mpv.net/Scripting/PythonScript.cs index 5c56e93..5742c31 100644 --- a/mpv.net/Scripting/PythonScript.cs +++ b/mpv.net/Scripting/PythonScript.cs @@ -1,4 +1,5 @@ using System; +using System.IO; using System.Reflection; using Microsoft.Scripting; @@ -15,7 +16,7 @@ namespace mpvnet ScriptEngine engine; ScriptScope scope; - public PythonScript(string code) + public PythonScript(string scriptPath) { try { @@ -26,14 +27,14 @@ namespace mpvnet engine.Execute("clr.AddReference(\"mpvnet\")", scope); engine.Execute("import mpvnet", scope); engine.Execute("from mpvnet import *", scope); - engine.Execute(code, scope); + engine.Execute(File.ReadAllText(scriptPath), scope); } catch (Exception ex) { if (ex is SyntaxErrorException e) - Msg.ShowError($"{e.Line}, {e.Column}: " + ex.Message); + Msg.ShowError(e.GetType().Name,$"{e.Line}, {e.Column}: " + e.Message + "\n\n" + Path.GetFileName(scriptPath)); else - Msg.ShowException(ex); + Msg.ShowError(ex.GetType().Name, ex.Message + "\n\n" + Path.GetFileName(scriptPath)); } } } diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index 9110c00..26271c2 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -252,24 +252,24 @@ namespace mpvnet { if (Directory.Exists(PathHelp.StartupPath + "Scripts")) { - foreach (string path in Directory.GetFiles(PathHelp.StartupPath + "Scripts")) + foreach (string scriptPath in Directory.GetFiles(PathHelp.StartupPath + "Scripts")) { - if (KnownScripts.Contains(Path.GetFileName(path))) + if (KnownScripts.Contains(Path.GetFileName(scriptPath))) { - if (path.EndsWith(".py")) - Task.Run(() => PythonScripts.Add(new PythonScript(File.ReadAllText(path)))); - else if (path.EndsWith(".ps1")) - Task.Run(() => PowerShellScript.Init(path)); + if (scriptPath.EndsWith(".py")) + Task.Run(() => PythonScripts.Add(new PythonScript(scriptPath))); + else if (scriptPath.EndsWith(".ps1")) + Task.Run(() => PowerShellScript.Init(scriptPath)); } else - Msg.ShowError("Failed to load script", path + "\n\nOnly scripts that ship with mpv.net are allowed in \\scripts\n\nUser scripts have to use \\scripts\n\nNever copy or install a new mpv.net version over a old mpv.net version."); + Msg.ShowError("Failed to load script", scriptPath + "\n\nOnly scripts that ship with mpv.net are allowed in \\scripts\n\nUser scripts have to use \\scripts\n\nNever copy or install a new mpv.net version over a old mpv.net version."); } } if (Directory.Exists(ConfigFolder + "scripts")) foreach (string scriptPath in Directory.GetFiles(ConfigFolder + "scripts")) if (scriptPath.EndsWith(".py")) - Task.Run(() => PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath)))); + Task.Run(() => PythonScripts.Add(new PythonScript(scriptPath))); else if (scriptPath.EndsWith(".ps1")) Task.Run(() => PowerShellScript.Init(scriptPath)); }