From 1e9893977d9352a517c2977be139b5f6e41d9998 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sat, 27 Jul 2019 19:23:42 +0200 Subject: [PATCH] refactoring --- Changelog.md | 4 +++ README.md | 29 +++++++------------ mpv.net/Misc/Misc.cs | 50 ++++++++------------------------- mpv.net/Resources/inputConf.txt | 22 ++++++++++----- mpv.net/WinForms/MainForm.cs | 2 -- mpv.net/mpv/mp.cs | 25 +++++++++++++---- 6 files changed, 60 insertions(+), 72 deletions(-) diff --git a/Changelog.md b/Changelog.md index 1208bea..91cd6f6 100644 --- a/Changelog.md +++ b/Changelog.md @@ -2,6 +2,10 @@ - 'Tools > Execute mpv command' was removed, [mpv-repl](https://github.com/rossy/mpv-repl) is currently the best choice +- many [wiki pages](https://github.com/stax76/mpv.net/wiki) were improved +- the logo/icon had a very small cosmetic change +- the help in the context menu was improved +- config options specific to mpv.net are now available from the command line ### 5.0 diff --git a/README.md b/README.md index 581acb4..a541238 100644 --- a/README.md +++ b/README.md @@ -219,40 +219,31 @@ Third party components: [Support thread in VideoHelp forum](https://forum.videohelp.com/threads/392514-mpv-net-a-extendable-media-player-for-windows) -[Issue tracker to report bugs and request features](https://github.com/stax76/mpv.net/issues) +[Issue tracker, feel free to use for anything mpv.net related](https://github.com/stax76/mpv.net/issues) [frank.skare.de@gmail.com](mailto:frank.skare.de@gmail.com?Subject=mpv.net%20support) Please click on the star at the top of the page and like mpv.net at [alternativeto.net](https://alternativeto.net/software/mpv-net/). -If you like you can express your appreciation for my player by sending little beer money with paypal. +If you want to support the development of mpv.net you can do so with a donation. ### Links -mpv manual: - -mpv wiki: - mpv.net wiki: - -mpv apps: - -mpv user scripts: - -mpv default key bindings: - mpv.net default key bindings: - -mpv download: - mpv.net download: - -mpv bugs and requests: - mpv.net bugs and requests: +mpv manual: +mpv wiki: +mpv apps: +mpv user scripts: +mpv default key bindings: +mpv download: +mpv bugs and requests: + ### Changelog [Changelog](Changelog.md) diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index 0101b7f..f5d8398 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -84,50 +84,24 @@ namespace mpvnet } } - public static void ProcessProperty(string name, string value) + public static bool ProcessProperty(string name, string value) { - switch (name) + switch (name) // return true instead of break! { - case "remember-position": RememberPosition = value == "yes"; break; - case "start-size": RememberHeight = value == "previous"; break; - case "process-instance": ProcessInstance = value; break; - case "dark-mode": DarkMode = value; break; - case "debug-mode": DebugMode = value == "yes"; break; - case "dark-color": DarkColor = value.Trim('\'', '"'); break; - case "light-color": LightColor = value.Trim('\'', '"'); break; - case "url-whitelist": - UrlWhitelist = value.Split(' ', ',', ';'); - break; + case "remember-position": RememberPosition = value == "yes"; return true; + case "start-size": RememberHeight = value == "previous"; return true; + case "process-instance": ProcessInstance = value; return true; + case "dark-mode": DarkMode = value; return true; + case "debug-mode": DebugMode = value == "yes"; return true; + case "dark-color": DarkColor = value.Trim('\'', '"'); return true; + case "light-color": LightColor = value.Trim('\'', '"'); return true; + case "url-whitelist": UrlWhitelist = value.Split(' ', ',', ';'); return true; case "start-threshold": int.TryParse(value, out int result); StartThreshold = result; - break; - } - } - - public static void ProcessCommandLineEarly() - { - var args = Environment.GetCommandLineArgs().Skip(1); - - foreach (string i in args) - { - if (i.StartsWith("--")) - { - if (i.Contains("=")) - { - string left = i.Substring(2, i.IndexOf("=") - 2); - string right = i.Substring(left.Length + 3); - mp.ProcessProperty(left, right); - ProcessProperty(left, right); - } - else - { - string name = i.Substring(2); - mp.ProcessProperty(name, "yes"); - ProcessProperty(name, "yes"); - } - } + return true; } + return false; } } diff --git a/mpv.net/Resources/inputConf.txt b/mpv.net/Resources/inputConf.txt index eb40ac6..104d577 100644 --- a/mpv.net/Resources/inputConf.txt +++ b/mpv.net/Resources/inputConf.txt @@ -155,13 +155,21 @@ 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 shell-execute https://mpv.io/manual/stable/ #menu: Help > Show mpv manual - _ script-message mpv.net shell-execute https://github.com/mpv-player/mpv/blob/master/etc/input.conf #menu: Help > Show mpv default keys - _ script-message mpv.net shell-execute https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/inputConf.txt #menu: Help > Show mpv.net default keys - _ script-message mpv.net shell-execute https://mpv-net.github.io/mpv.net-web-site/ #menu: Help > Show mpv.net web site - _ script-message mpv.net shell-execute https://github.com/stax76/mpv.net/blob/master/Manual.md #menu: Help > Show mpv.net manual - _ ignore #menu: Help > - - _ script-message mpv.net show-about #menu: Help > About mpv.net + _ 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 + _ script-message mpv.net shell-execute https://github.com/stax76/mpv.net/wiki #menu: Help > mpv.net Wiki + _ script-message mpv.net shell-execute https://github.com/stax76/mpv.net#support #menu: Help > mpv.net Support + _ script-message mpv.net shell-execute https://github.com/stax76/mpv.net/releases #menu: Help > mpv.net Download + _ script-message mpv.net shell-execute https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/inputConf.txt #menu: Help > mpv.net Default Key Bindings + _ ignore #menu: Help > - + _ script-message mpv.net shell-execute https://mpv.io/manual/stable/ #menu: Help > mpv Manual + _ script-message mpv.net shell-execute https://github.com/mpv-player/mpv/wiki #menu: Help > mpv Wiki + _ script-message mpv.net shell-execute https://github.com/mpv-player/mpv/wiki/User-Scripts #menu: Help > mpv User Scripts + _ script-message mpv.net shell-execute https://mpv.io/bug-reports/ #menu: Help > mpv Bugs and Requests + _ script-message mpv.net shell-execute https://mpv.io/installation/ #menu: Help > mpv Download + _ script-message mpv.net shell-execute https://github.com/mpv-player/mpv/blob/master/etc/input.conf #menu: Help > mpv Default Key Bindings + _ ignore #menu: Help > - + _ script-message mpv.net show-about #menu: Help > About mpv.net _ ignore #menu: - Esc quit #menu: Exit diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index 9e7a037..0d3f822 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -50,8 +50,6 @@ namespace mpvnet ContextMenu.Opened += ContextMenu_Opened; ContextMenu.Opening += ContextMenu_Opening; - App.ProcessCommandLineEarly(); - if (mp.Screen == -1) mp.Screen = Array.IndexOf(Screen.AllScreens, Screen.PrimaryScreen); int targetIndex = mp.Screen; Screen[] screens = Screen.AllScreens; diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index d868c33..3c35f0b 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -104,6 +104,7 @@ namespace mpvnet set_property_string("input-media-keys", "yes"); mpv_initialize(Handle); ShowLogo(); + LoadMpvScripts(); ProcessCommandLine(); Task.Run(() => { EventLoop(); }); } @@ -213,6 +214,15 @@ namespace mpvnet } } + 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}"); + } + public static void LoadScripts() { @@ -220,10 +230,6 @@ namespace mpvnet { 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 scriptPath in startupScripts) if (Path.GetExtension(scriptPath) == ".py") PythonScripts.Add(new PythonScript(File.ReadAllText(scriptPath))); @@ -562,10 +568,17 @@ namespace mpvnet { string left = i.Substring(2, i.IndexOf("=") - 2); string right = i.Substring(left.Length + 3); - set_property_string(left, right, true); + mp.ProcessProperty(left, right); + if (!App.ProcessProperty(left, right)) + set_property_string(left, right, true); } else - set_property_string(i.Substring(2), "yes", true); + { + string name = i.Substring(2); + mp.ProcessProperty(name, "yes"); + if (!App.ProcessProperty(name, "yes")) + set_property_string(name, "yes", true); + } } catch (Exception e) {