From 8c36cc8b8c1b3c431fd419933ec4a94a9a09b83b Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Mon, 29 Jul 2019 14:14:23 +0200 Subject: [PATCH] improved error handling --- Changelog.md | 2 +- extensions/ScriptingExtension/ScriptingExtension.cs | 2 +- mpv.net/Misc/Extension.cs | 2 +- mpv.net/Misc/Misc.cs | 5 +++++ mpv.net/mpv/mp.cs | 6 ++---- 5 files changed, 10 insertions(+), 7 deletions(-) diff --git a/Changelog.md b/Changelog.md index ca249ee..b0dedcd 100644 --- a/Changelog.md +++ b/Changelog.md @@ -14,7 +14,7 @@ it has now a feature to add and remove mpv.net to and from the Path environment variable and the OS default apps settings can be opened (Win 10 only) - Error messages are shown when unknown scripts and extensions are found in the startup folder - because user scripts are supposed to be located in the config folder instead + because user scripts and extensions are supposed to be located in the config folder instead ### 5.0 diff --git a/extensions/ScriptingExtension/ScriptingExtension.cs b/extensions/ScriptingExtension/ScriptingExtension.cs index 4d1e5c7..e472981 100644 --- a/extensions/ScriptingExtension/ScriptingExtension.cs +++ b/extensions/ScriptingExtension/ScriptingExtension.cs @@ -31,7 +31,7 @@ namespace ScriptingExtension // the file name of extensions must end with 'Exten if (Directory.Exists(Application.StartupPath + "\\scripts")) foreach (string file in Directory.GetFiles(Application.StartupPath + "\\scripts", "*.cs")) - Msg.ShowError("Failed to load script.", "Only scripts that ship with mpv.net are allowed in \\scripts.\n\nUser scripts have to use \\scripts.\n\nNever copy a new mpv.net version over a old mpv.net version.\n\nNever install a new mpv.net version on top of a old mpv.net version.\n\n" + file); + App.UnknownModule(file); if (scriptFiles.Count == 0) return; CSScriptLibrary.CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom; diff --git a/mpv.net/Misc/Extension.cs b/mpv.net/Misc/Extension.cs index ff2fb58..c82aac3 100644 --- a/mpv.net/Misc/Extension.cs +++ b/mpv.net/Misc/Extension.cs @@ -31,7 +31,7 @@ namespace mpvnet if (knownExtensions.Contains(Path.GetFileName(path))) catalog.Catalogs.Add(new DirectoryCatalog(path, "*Extension.dll")); else - Msg.ShowError("Failed to load extension", "Only extensions that ship with mpv.net are allowed in \\extensions.\n\nUser extensions have to use \\extensions.\n\nNever copy a new mpv.net version over a old mpv.net version.\n\nNever install a new mpv.net version on top of a old mpv.net version.\n\n" + path); + App.UnknownModule(path); } } diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index e2a1522..a136d99 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -84,6 +84,11 @@ namespace mpvnet } } + public static void UnknownModule(string path) + { + Msg.ShowError("Failed to load script or extension", "Only scripts and extensions that ship with mpv.net are allowed in \\scripts or \\extensions.\n\nUser scripts or extensions have to use \\scripts or \\extensions.\n\nNever copy a new mpv.net version over a old mpv.net version.\n\nNever install a new mpv.net version on top of a old mpv.net version.\n\n" + path); + } + public static bool ProcessProperty(string name, string value) { switch (name) // return true instead of break! diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index 3f84e37..47f2c1b 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -213,8 +213,6 @@ namespace mpvnet } } - public static void UnknownScriptError(string path) => Msg.ShowError("Failed to load script", "Only scripts that ship with mpv.net are allowed in \\scripts.\n\nUser scripts have to use \\scripts.\n\nNever copy a new mpv.net version over a old mpv.net version.\n\nNever install a new mpv.net version on top of a old mpv.net version.\n\n" + path); - public static void LoadMpvScripts() { string[] startupScripts = Directory.GetFiles(Application.StartupPath + "\\Scripts"); @@ -224,7 +222,7 @@ namespace mpvnet if (KnownScripts.Contains(Path.GetFileName(path))) commandv("load-script", $"{path}"); else - UnknownScriptError(path); + App.UnknownModule(path); } public static string[] KnownScripts { get; } = { "osc-visibility.js", "show-playlist.js", "seek-show-position.py" }; @@ -243,7 +241,7 @@ namespace mpvnet PowerShellScript.Init(path); } else - UnknownScriptError(path); + App.UnknownModule(path); } }