diff --git a/Changelog.md b/Changelog.md index ea0bfff..ca249ee 100644 --- a/Changelog.md +++ b/Changelog.md @@ -10,6 +10,11 @@ - the input editor no longer as known limitations, 'alt gr' and ctrl+alt are working now - the help in the input editor was simplified and the filter logic was improved - fixed issue in file associations causing mpv.net not to appear in OS default apps +- 'Tools > Manage File Associations' was replaced by 'Tools > OS Setup', + 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 ### 5.0 diff --git a/extensions/ScriptingExtension/ScriptingExtension.cs b/extensions/ScriptingExtension/ScriptingExtension.cs index 30849d2..4d1e5c7 100644 --- a/extensions/ScriptingExtension/ScriptingExtension.cs +++ b/extensions/ScriptingExtension/ScriptingExtension.cs @@ -1,11 +1,9 @@ // This extension implements the C# scripting feature of mpv.net which // is based on CS-Script (https://www.cs-script.net). -// Furthermore I use this extension to code and debug scripts -// because writing script code without debugger is not much fun. - -// Once the code was developed and debugged, I move the code -// from the extension to a standalone script. +// I also use this extension to code scripts in order to have full +// code completion and debugger support, once the script code is +// finished I move it from the extension to a standalone script. using System; using System.ComponentModel.Composition; @@ -21,7 +19,7 @@ namespace ScriptingExtension // the file name of extensions must end with 'Exten [Export(typeof(IExtension))] public class ScriptingExtension : IExtension { - Script Script; + //Script Script; public ScriptingExtension() { @@ -32,7 +30,8 @@ namespace ScriptingExtension // the file name of extensions must end with 'Exten scriptFiles.AddRange(Directory.GetFiles(mp.ConfigFolder + "scripts", "*.cs")); if (Directory.Exists(Application.StartupPath + "\\scripts")) - scriptFiles.AddRange(Directory.GetFiles(Application.StartupPath + "\\scripts", "*.cs")); + 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); if (scriptFiles.Count == 0) return; CSScriptLibrary.CSScript.EvaluatorConfig.Engine = EvaluatorEngine.CodeDom; @@ -47,4 +46,4 @@ namespace ScriptingExtension // the file name of extensions must end with 'Exten } } } -} +} \ No newline at end of file diff --git a/mpv.net/Misc/Command.cs b/mpv.net/Misc/Command.cs index 73107c4..0e7a762 100644 --- a/mpv.net/Misc/Command.cs +++ b/mpv.net/Misc/Command.cs @@ -28,6 +28,7 @@ namespace mpvnet case "show-about": ShowDialog(typeof(AboutWindow)); break; case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break; case "show-input-editor": ShowDialog(typeof(InputWindow)); break; + case "show-setup-dialog": ShowDialog(typeof(SetupWindow)); break; case "open-conf-folder": Process.Start(mp.ConfigFolder); break; case "open-files": OpenFiles(args); break; case "shell-execute": Process.Start(args[0]); break; @@ -230,31 +231,6 @@ namespace mpvnet } } - public static void ManageFileAssociations() - { - using (var td = new TaskDialog()) - { - td.MainInstruction = "Choose an option."; - td.MainIcon = MsgIcon.Shield; - - td.AddCommandLink("Register video file extensions", "video"); - td.AddCommandLink("Register audio file extensions", "audio"); - td.AddCommandLink("Register image file extensions", "image"); - td.AddCommandLink("Unregister file extensions", "unreg"); - - string result = td.Show(); - - if (!string.IsNullOrEmpty(result)) - { - using (var proc = new Process()) - { - proc.StartInfo.FileName = System.Windows.Forms.Application.ExecutablePath; - proc.StartInfo.Arguments = "--reg-file-assoc " + result; - proc.StartInfo.Verb = "runas"; - try { proc.Start(); } catch { } - } - } - } - } + public static void ManageFileAssociations() => ShowDialog(typeof(SetupWindow)); // deprecated 2019 } -} +} \ No newline at end of file diff --git a/mpv.net/Misc/Extension.cs b/mpv.net/Misc/Extension.cs index f7d3843..ff2fb58 100644 --- a/mpv.net/Misc/Extension.cs +++ b/mpv.net/Misc/Extension.cs @@ -4,6 +4,7 @@ using System.ComponentModel.Composition; using System.ComponentModel.Composition.Hosting; using System.IO; using System.Windows.Forms; +using System.Linq; namespace mpvnet { @@ -19,12 +20,20 @@ namespace mpvnet try { AggregateCatalog catalog = new AggregateCatalog(); - string dir = Application.StartupPath + "\\Extensions"; if (Directory.Exists(dir)) - foreach (string i in Directory.GetDirectories(dir)) - catalog.Catalogs.Add(new DirectoryCatalog(i, "*Extension.dll")); + { + string[] knownExtensions = { "RatingExtension", "ScriptingExtension" }; + + foreach (string path in Directory.GetDirectories(dir)) + { + 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); + } + } dir = mp.ConfigFolder + "\\Extensions"; diff --git a/mpv.net/Resources/inputConf.txt b/mpv.net/Resources/inputConf.txt index 104d577..e204c53 100644 --- a/mpv.net/Resources/inputConf.txt +++ b/mpv.net/Resources/inputConf.txt @@ -153,7 +153,7 @@ l ab-loop #menu: Tools > Set/clear A-B loop points L cycle-values loop-file "inf" "no" #menu: Tools > Toggle infinite file looping Ctrl+h cycle-values hwdec "auto" "no" #menu: Tools > Toggle Hardware Decoding - _ script-message mpv.net manage-file-associations #menu: Tools > Manage File Associations... + _ script-message mpv.net show-setup-dialog #menu: Tools > OS Setup... _ script-message mpv.net shell-execute https://github.com/stax76/mpv.net/blob/master/Manual.md #menu: Help > mpv.net Manual _ script-message mpv.net shell-execute https://github.com/stax76/mpv.net #menu: Help > mpv.net GitHub diff --git a/mpv.net/WPF/SetupWindow.xaml b/mpv.net/WPF/SetupWindow.xaml new file mode 100644 index 0000000..a982133 --- /dev/null +++ b/mpv.net/WPF/SetupWindow.xaml @@ -0,0 +1,19 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/mpv.net/WPF/SetupWindow.xaml.cs b/mpv.net/WPF/SetupWindow.xaml.cs new file mode 100644 index 0000000..bcab40f --- /dev/null +++ b/mpv.net/WPF/SetupWindow.xaml.cs @@ -0,0 +1,57 @@ +using System; +using System.Diagnostics; +using System.Windows; +using WF = System.Windows.Forms; + +namespace mpvnet +{ + public partial class SetupWindow : Window + { + public SetupWindow() => InitializeComponent(); + + void RegisterFileAssociations(string value) + { + using (var proc = new Process()) + { + proc.StartInfo.FileName = System.Windows.Forms.Application.ExecutablePath; + proc.StartInfo.Arguments = "--reg-file-assoc " + value; + proc.StartInfo.Verb = "runas"; + try { proc.Start(); } catch { } + } + } + + private void RegisterVideo_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("video"); + private void RegisterAudio_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("audio"); + private void RegisterImage_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("image"); + private void UnregisterFileAssociations_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("unreg"); + private void ManageDefaultApps_Click(object sender, RoutedEventArgs e) => Process.Start("ms-settings:defaultapps"); + + private void AddToPathEnvVar_Click(object sender, RoutedEventArgs e) + { + string var = WF.Application.StartupPath + ";"; + string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User); + + if (path.Contains(var)) + Msg.ShowWarning("Path was already containing mpv.net."); + else + { + Environment.SetEnvironmentVariable("Path", var + path, EnvironmentVariableTarget.User); + Msg.Show("mpv.net was successfully added to Path.", (var + path).Replace(";","\n")); + } + } + + private void RemoveFromPathEnvVar_Click(object sender, RoutedEventArgs e) + { + string var = WF.Application.StartupPath + ";"; + string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User); + + if (path.Contains(var)) + { + Environment.SetEnvironmentVariable("Path", path.Replace(var, ""), EnvironmentVariableTarget.User); + Msg.Show("mpv.net was successfully removed from Path."); + } + else + Msg.ShowWarning("Path was not containing mpv.net."); + } + } +} \ No newline at end of file diff --git a/mpv.net/mpv.net.csproj b/mpv.net/mpv.net.csproj index 183e06f..8872699 100644 --- a/mpv.net/mpv.net.csproj +++ b/mpv.net/mpv.net.csproj @@ -119,6 +119,10 @@ MSBuild:Compile Designer + + MSBuild:Compile + Designer + MSBuild:Compile Designer @@ -172,6 +176,9 @@ + + SetupWindow.xaml + EverythingWindow.xaml diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index 3c35f0b..3f84e37 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -156,7 +156,6 @@ namespace mpvnet td.AddCommandLink(@"AppData\Roaming\mpv.net", appdataFolder, appdataFolder); td.AddCommandLink(@"AppData\Roaming\mpv", appdataFolderMpv, appdataFolderMpv); td.AddCommandLink("\\portable_config", portableFolder, portableFolder); - td.AddCommandLink("", startupFolder, startupFolder); td.AddCommandLink("Choose custom folder", "custom"); td.AllowCancel = false; _ConfigFolder = td.Show(); @@ -214,36 +213,45 @@ 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"); - foreach (string scriptPath in startupScripts) - if (scriptPath.EndsWith(".lua") || scriptPath.EndsWith(".js")) - commandv("load-script", $"{scriptPath}"); + foreach (string path in startupScripts) + if (path.EndsWith(".lua") || path.EndsWith(".js")) + if (KnownScripts.Contains(Path.GetFileName(path))) + commandv("load-script", $"{path}"); + else + UnknownScriptError(path); } + public static string[] KnownScripts { get; } = { "osc-visibility.js", "show-playlist.js", "seek-show-position.py" }; + public static void LoadScripts() { - if (Directory.Exists(Application.StartupPath + "\\Scripts")) { - string[] startupScripts = Directory.GetFiles(Application.StartupPath + "\\Scripts"); - - foreach (string scriptPath in startupScripts) - if (Path.GetExtension(scriptPath) == ".py") - PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath))); - - foreach (string scriptPath in startupScripts) - if (Path.GetExtension(scriptPath) == ".ps1") - PowerShellScript.Init(scriptPath); + foreach (string path in Directory.GetFiles(Application.StartupPath + "\\Scripts")) + { + if (KnownScripts.Contains(Path.GetFileName(path))) + { + if (path.EndsWith(".py")) + PythonScripts.Add(new PythonScript(File.ReadAllText(path))); + else if (path.EndsWith(".ps1")) + PowerShellScript.Init(path); + } + else + UnknownScriptError(path); + } } if (Directory.Exists(ConfigFolder + "Scripts")) foreach (string scriptPath in Directory.GetFiles(ConfigFolder + "Scripts")) - if (Path.GetExtension(scriptPath) == ".py") + if (scriptPath.EndsWith(".py")) PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath))); - else if (Path.GetExtension(scriptPath) == ".ps1") + else if (scriptPath.EndsWith(".ps1")) PowerShellScript.Init(scriptPath); }