diff --git a/Changelog.md b/Changelog.md index fe26fd4..d902433 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,3 +1,12 @@ +### + +- clipboard-monitoring was replaced by url-whitelist: + Domain whitelist to monitor the clipboard for URLs to play. + Default: youtube ard zdf +- some settings like colors didn't work because enclosing quotes were missing +- the playlist is never cleared whenever the control key is down but + files and URLs are appended instead + ### 4.3.1 - there was a old bug setting the screen property diff --git a/mpv.net/DynamicGUI/DynamicGUI.cs b/mpv.net/DynamicGUI/DynamicGUI.cs index c95178a..8946da1 100644 --- a/mpv.net/DynamicGUI/DynamicGUI.cs +++ b/mpv.net/DynamicGUI/DynamicGUI.cs @@ -45,11 +45,11 @@ namespace DynamicGUI optionSetting.Options.Add(opt); } } - else if (setting["default"].IsString) + else { StringSetting stringSetting = new StringSetting(); baseSetting = stringSetting; - stringSetting.Default = setting["default"]; + stringSetting.Default = setting.HasKey("default") ? setting["default"].ToString() : ""; } baseSetting.Name = setting["name"]; diff --git a/mpv.net/DynamicGUI/StringSettingControl.xaml.cs b/mpv.net/DynamicGUI/StringSettingControl.xaml.cs index bfdec93..00b4c86 100644 --- a/mpv.net/DynamicGUI/StringSettingControl.xaml.cs +++ b/mpv.net/DynamicGUI/StringSettingControl.xaml.cs @@ -64,7 +64,8 @@ namespace DynamicGUI { d.FullOpen = true; try { - d.Color = System.Drawing.ColorTranslator.FromHtml(ValueTextBox.Text); + Color col = GetColor(ValueTextBox.Text); + d.Color = System.Drawing.Color.FromArgb(col.A, col.R, col.G, col.B); } catch { } if (d.ShowDialog() == WinForms.DialogResult.OK) ValueTextBox.Text = System.Drawing.ColorTranslator.ToHtml(d.Color); @@ -75,29 +76,31 @@ namespace DynamicGUI private void ValueTextBox_TextChanged(object sender, TextChangedEventArgs e) => Update(); + Color GetColor(string value) + { + if (value.Contains("/")) + { + string[] a = value.Split('/'); + + if (a.Length == 3) + return Color.FromRgb(ToByte(a[0]), ToByte(a[1]), ToByte(a[2])); + else if (a.Length == 4) + return Color.FromArgb(ToByte(a[3]), ToByte(a[0]), ToByte(a[1]), ToByte(a[2])); + } + + return (Color)ColorConverter.ConvertFromString(value); + + Byte ToByte(string val) => Convert.ToByte(Convert.ToSingle(val, CultureInfo.InvariantCulture) * 255); + } + public void Update() { if (StringSetting.Type == "color") { Color c = Colors.Transparent; - if (ValueTextBox.Text != "") - { - try { - if (ValueTextBox.Text.Contains("/")) - { - string[] a = ValueTextBox.Text.Split('/'); - if (a.Length == 3) - c = Color.FromRgb(ToByte(a[0]), ToByte(a[1]), ToByte(a[2])); - else if (a.Length == 4) - c = Color.FromArgb(ToByte(a[3]), ToByte(a[0]), ToByte(a[1]), ToByte(a[2])); - } - else - c = (Color)ColorConverter.ConvertFromString(ValueTextBox.Text); - } catch {} - } + if (ValueTextBox.Text != "") try { c = GetColor(ValueTextBox.Text); } catch {} ValueTextBox.Background = new SolidColorBrush(c); } - Byte ToByte(string val) => Convert.ToByte(Convert.ToSingle(val, CultureInfo.InvariantCulture) * 255); } } } \ No newline at end of file diff --git a/mpv.net/Misc/Command.cs b/mpv.net/Misc/Command.cs index 057477b..2b6dfb3 100644 --- a/mpv.net/Misc/Command.cs +++ b/mpv.net/Misc/Command.cs @@ -48,7 +48,7 @@ namespace mpvnet MainForm.Instance.Invoke(new Action(() => { using (var d = new OpenFileDialog() { Multiselect = true }) if (d.ShowDialog() == DialogResult.OK) - mp.Load(d.FileNames); + mp.Load(d.FileNames, true, Control.ModifierKeys.HasFlag(Keys.Control)); })); } @@ -183,9 +183,9 @@ namespace mpvnet public static void execute_mpv_command(string[] args) { MainForm.Instance.Invoke(new Action(() => { - string command = VB.Interaction.InputBox("Enter a mpv command to be executed.", "Execute Command", RegistryHelp.GetString(App.RegPath, "RecentExecutedCommand")); + string command = VB.Interaction.InputBox("Enter a mpv command to be executed.", "Execute Command", RegHelp.GetString(App.RegPath, "RecentExecutedCommand")); if (string.IsNullOrEmpty(command)) return; - RegistryHelp.SetObject(App.RegPath, "RecentExecutedCommand", command); + RegHelp.SetObject(App.RegPath, "RecentExecutedCommand", command); mp.command_string(command, false); })); } @@ -195,7 +195,7 @@ namespace mpvnet MainForm.Instance.Invoke(new Action(() => { string command = VB.Interaction.InputBox("Enter URL to be opened."); if (string.IsNullOrEmpty(command)) return; - mp.Load(command); + mp.Load(new [] { command }, false, Control.ModifierKeys.HasFlag(Keys.Control)); })); } diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index 5a12ada..e52709c 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -13,22 +13,20 @@ using System.Runtime.Serialization; using System.Windows.Forms; using Microsoft.Win32; -using VB = Microsoft.VisualBasic; namespace mpvnet { public class App { public static string ConfFilePath { get; } = mp.ConfFolder + "\\mpvnet.conf"; - public static string RegPath { get; } = "HKCU\\Software\\" + Application.ProductName; - public static string ClipboardMonitoring { get; set; } = "yes"; + public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName; + public static string DarkMode { get; set; } = "always"; + public static string ProcessInstance { get; set; } = "single"; public static string[] VideoTypes { get; } = "mkv mp4 mpg avi mov webm vob wmv flv avs 264 h264 asf webm mpeg mpv y4m avc hevc 265 h265 m2v m2ts vpy mts m4v".Split(' '); public static string[] AudioTypes { get; } = "mp3 mp2 ac3 ogg opus flac wav w64 m4a dts dtsma dtshr dtshd eac3 thd thd+ac3 mka aac mpa".Split(' '); public static string[] SubtitleTypes { get; } = "srt ass idx sup ttxt ssa smi".Split(' '); - - public static string DarkMode { get; set; } = "always"; - public static string ProcessInstance { get; set; } = "single"; + public static string[] UrlWhitelist { get; set; } = { "youtube", "ard", "zdf" }; public static bool DebugMode { get; set; } = false; @@ -85,10 +83,12 @@ namespace mpvnet { switch (name) { - case "clipboard-monitoring": ClipboardMonitoring = value; break; case "process-instance": ProcessInstance = value; break; case "dark-mode": DarkMode = value; break; case "debug-mode": DebugMode = value == "yes"; break; + case "url-whitelist": + UrlWhitelist = value.Split(' ', ',', ';'); + break; } } @@ -171,49 +171,49 @@ namespace mpvnet { Types = types; - RegistryHelp.SetObject(@"HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename, null, ExePath); - RegistryHelp.SetObject($"HKCR\\Applications\\{ExeFilename}", "FriendlyAppName", "mpv.net media player"); - RegistryHelp.SetObject($"HKCR\\Applications\\{ExeFilename}\\shell\\open\\command", null, $"\"{ExePath}\" \"%1\""); - RegistryHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv\Capabilities", "ApplicationDescription", "mpv.net media player"); - RegistryHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv\Capabilities", "ApplicationName", "mpv.net"); - RegistryHelp.SetObject($"HKCR\\SystemFileAssociations\\video\\OpenWithList\\{ExeFilename}", null, ""); - RegistryHelp.SetObject($"HKCR\\SystemFileAssociations\\audio\\OpenWithList\\{ExeFilename}", null, ""); + RegHelp.SetObject(@"HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename, null, ExePath); + RegHelp.SetObject($"HKCR\\Applications\\{ExeFilename}", "FriendlyAppName", "mpv.net media player"); + RegHelp.SetObject($"HKCR\\Applications\\{ExeFilename}\\shell\\open\\command", null, $"\"{ExePath}\" \"%1\""); + RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv\Capabilities", "ApplicationDescription", "mpv.net media player"); + RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv\Capabilities", "ApplicationName", "mpv.net"); + RegHelp.SetObject($"HKCR\\SystemFileAssociations\\video\\OpenWithList\\{ExeFilename}", null, ""); + RegHelp.SetObject($"HKCR\\SystemFileAssociations\\audio\\OpenWithList\\{ExeFilename}", null, ""); foreach (string ext in Types) { - RegistryHelp.SetObject($"HKCR\\Applications\\{ExeFilename}\\SupportedTypes", "." + ext, ""); - RegistryHelp.SetObject($"HKCR\\" + "." + ext, null, ExeFilenameNoExt + "." + ext); - RegistryHelp.SetObject($"HKCR\\" + "." + ext + "\\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, ""); + RegHelp.SetObject($"HKCR\\Applications\\{ExeFilename}\\SupportedTypes", "." + ext, ""); + RegHelp.SetObject($"HKCR\\" + "." + ext, null, ExeFilenameNoExt + "." + ext); + RegHelp.SetObject($"HKCR\\" + "." + ext + "\\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, ""); if (App.VideoTypes.Contains(ext)) - RegistryHelp.SetObject($"HKCR\\" + "." + ext, "PerceivedType", "video"); + RegHelp.SetObject($"HKCR\\" + "." + ext, "PerceivedType", "video"); if (App.AudioTypes.Contains(ext)) - RegistryHelp.SetObject($"HKCR\\" + "." + ext, "PerceivedType", "audio"); - RegistryHelp.SetObject($"HKCR\\" + ExeFilenameNoExt + "." + ext + "\\shell\\open", null, "Play with " + Application.ProductName); - RegistryHelp.SetObject($"HKCR\\" + ExeFilenameNoExt + "." + ext + "\\shell\\open\\command", null, $"\"{ExePath}\" \"%1\""); - RegistryHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities\FileAssociations", "." + ext, ExeFilenameNoExt + "." + ext); + RegHelp.SetObject($"HKCR\\" + "." + ext, "PerceivedType", "audio"); + RegHelp.SetObject($"HKCR\\" + ExeFilenameNoExt + "." + ext + "\\shell\\open", null, "Play with " + Application.ProductName); + RegHelp.SetObject($"HKCR\\" + ExeFilenameNoExt + "." + ext + "\\shell\\open\\command", null, $"\"{ExePath}\" \"%1\""); + RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities\FileAssociations", "." + ext, ExeFilenameNoExt + "." + ext); } } public static void Unregister() { - RegistryHelp.RemoveKey(@"HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename); - RegistryHelp.RemoveKey($"HKCR\\Applications\\{ExeFilename}"); - RegistryHelp.RemoveKey(@"HKLM\SOFTWARE\Clients\Media\mpv.net"); - RegistryHelp.RemoveKey($"HKCR\\SystemFileAssociations\\video\\OpenWithList\\{ExeFilename}"); - RegistryHelp.RemoveKey($"HKCR\\SystemFileAssociations\\audio\\OpenWithList\\{ExeFilename}"); + RegHelp.RemoveKey(@"HKCU\SOFTWARE\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename); + RegHelp.RemoveKey($"HKCR\\Applications\\{ExeFilename}"); + RegHelp.RemoveKey(@"HKLM\SOFTWARE\Clients\Media\mpv.net"); + RegHelp.RemoveKey($"HKCR\\SystemFileAssociations\\video\\OpenWithList\\{ExeFilename}"); + RegHelp.RemoveKey($"HKCR\\SystemFileAssociations\\audio\\OpenWithList\\{ExeFilename}"); foreach (string id in Registry.ClassesRoot.GetSubKeyNames()) { if (id.StartsWith(ExeFilenameNoExt + ".")) Registry.ClassesRoot.DeleteSubKeyTree(id); - RegistryHelp.RemoveValue($"HKCR\\Software\\Classes\\" + id + "\\OpenWithProgIDs", ExeFilenameNoExt + id); - RegistryHelp.RemoveValue($"HKLM\\Software\\Classes\\" + id + "\\OpenWithProgIDs", ExeFilenameNoExt + id); + RegHelp.RemoveValue($"HKCR\\Software\\Classes\\" + id + "\\OpenWithProgIDs", ExeFilenameNoExt + id); + RegHelp.RemoveValue($"HKLM\\Software\\Classes\\" + id + "\\OpenWithProgIDs", ExeFilenameNoExt + id); } } } - public class RegistryHelp + public class RegHelp { public static void SetObject(string path, string name, object value) { diff --git a/mpv.net/Misc/Program.cs b/mpv.net/Misc/Program.cs index 2f04e82..d1ea95c 100644 --- a/mpv.net/Misc/Program.cs +++ b/mpv.net/Misc/Program.cs @@ -37,9 +37,9 @@ namespace mpvnet files.Add(arg); if (files.Count > 0) - RegistryHelp.SetObject(App.RegPath, "ShellFiles", files.ToArray()); + RegHelp.SetObject(App.RegPath, "ShellFiles", files.ToArray()); - RegistryHelp.SetObject(App.RegPath, "ProcessInstanceMode", App.ProcessInstance); + RegHelp.SetObject(App.RegPath, "ProcessInstanceMode", App.ProcessInstance); foreach(Process process in Process.GetProcessesByName("mpvnet")) { diff --git a/mpv.net/Properties/Resources.Designer.cs b/mpv.net/Properties/Resources.Designer.cs index 9969b0c..250f7fe 100644 --- a/mpv.net/Properties/Resources.Designer.cs +++ b/mpv.net/Properties/Resources.Designer.cs @@ -106,9 +106,9 @@ namespace mpvnet.Properties { /// /// Looks up a localized string similar to - ///# mpv manual: https://mpv.io/manual/master/ + ///# manual: https://mpv.io/manual/master/ /// - ///# mpv.net mpv.conf defaults: https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpvConf.txt + ///# defaults: https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpvConf.txt /// ///input-ar-delay = 500 ///input-ar-rate = 20 @@ -164,12 +164,15 @@ namespace mpvnet.Properties { /// { name = "never" }] /// ///[[settings]] - ///name = "clipboard-monitoring" - ///default = "yes" + ///name = "url-whitelist" ///filter = "mpv.net" - ///help = "Monitors the clipboard for URLs to play." - ///options = [{ name = "yes" }, - /// { name = "no" }]. + ///help = "Domain whitelist to monitor the clipboard for URLs to play.\n\nDefault: youtube ard zdf" + /// + ///[[settings]] + ///name = "process-instance" + ///default = "single" + ///filter = "mpv.net" + ///help = "Defines if more then [rest of string was truncated]";. /// internal static string mpvNetConfToml { get { diff --git a/mpv.net/Resources/inputConf.txt b/mpv.net/Resources/inputConf.txt index 40eeacb..8bcee34 100644 --- a/mpv.net/Resources/inputConf.txt +++ b/mpv.net/Resources/inputConf.txt @@ -179,5 +179,6 @@ Wheel_Down add volume -10 Prev playlist-prev Next playlist-next - + Ctrl+Wheel_Up no-osd seek 7 + Ctrl+Wheel_Down no-osd seek -7 MBTN_LEFT_DBL cycle fullscreen \ No newline at end of file diff --git a/mpv.net/Resources/mpvConf.txt b/mpv.net/Resources/mpvConf.txt index 25e416b..de9e80b 100644 --- a/mpv.net/Resources/mpvConf.txt +++ b/mpv.net/Resources/mpvConf.txt @@ -1,7 +1,7 @@  -# mpv manual: https://mpv.io/manual/master/ +# manual: https://mpv.io/manual/master/ -# mpv.net mpv.conf defaults: https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpvConf.txt +# defaults: https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/mpvConf.txt input-ar-delay = 500 input-ar-rate = 20 diff --git a/mpv.net/Resources/mpvConfToml.txt b/mpv.net/Resources/mpvConfToml.txt index 7285d66..cbc9a2f 100644 --- a/mpv.net/Resources/mpvConfToml.txt +++ b/mpv.net/Resources/mpvConfToml.txt @@ -147,8 +147,8 @@ help = "Set the startup volume. 0 means silence, 100 means no volume reduction o [[settings]] name = "alang" -default = "" filter = "Audio" +type = "string" help = "Specify a priority list of audio languages to use. Different container formats employ different language codes. DVDs use ISO 639-1 two-letter language codes, Matroska, MPEG-TS and NUT use ISO 639-2 three-letter language codes, while OGM uses a free-form identifier. See also aid.\n\nExamples\n\nmpv dvd://1 alang=hu,en chooses the Hungarian language track on a DVD and falls back on English if Hungarian is not available.\n\nmpv alang=jpn example.mkv plays a Matroska file with Japanese audio." [[settings]] @@ -163,8 +163,8 @@ options = [{ name = "no", help = "Don't automatically load external audio fil [[settings]] name = "slang" -default = "" filter = "Subtitle" +type = "string" help = "Specify a priority list of subtitle languages to use. Different container formats employ different language codes. DVDs use ISO 639-1 two letter language codes, Matroska uses ISO 639-2 three letter language codes while OGM uses a free-form identifier. See also sid." [[settings]] @@ -179,48 +179,43 @@ options = [{ name = "no", help = "Don't automatically load external subtitle [[settings]] name = "sub-font" -default = "" filter = "Subtitle" +type = "string" help = "Specify font to use for subtitles that do not themselves specify a particular font. The default is sans-serif." [[settings]] name = "sub-font-size" -default = "" filter = "Subtitle" help = "Specify the sub font size. The unit is the size in scaled pixels at a window height of 720. The actual pixel size is scaled with the window height: if the window height is larger or smaller than 720, the actual size of the text increases or decreases as well. Default: 55" [[settings]] name = "sub-color" -default = "" type = "color" filter = "Subtitle" help = "Specify the color used for unstyled text subtitles.\n\nThe color is specified in the form r/g/b, where each color component is specified as number in the range 0.0 to 1.0. It's also possible to specify the transparency by using r/g/b/a, where the alpha value 0 means fully transparent, and 1.0 means opaque. If the alpha component is not given, the color is 100% opaque.\n\nPassing a single number to the option sets the sub to gray, and the form gray/a lets you specify alpha additionally.\n\nExamples\n\n1.0/0.0/0.0 set sub to opaque red\n1.0/0.0/0.0/0.75 set sub to opaque red with 75% alpha\n0.5/0.75 set sub to 50% gray with 75% alpha\n\nAlternatively, the color can be specified as a RGB hex triplet in the form #RRGGBB, where each 2-digit group expresses a color value in the range 0 (00) to 255 (FF). For example, #FF0000 is red. This is similar to web colors. Alpha is given with #AARRGGBB.\n\nExamples\n\n#FF0000 set sub to opaque red\n#C0808080 set sub to 50% gray with 75% alpha" [[settings]] name = "sub-border-color" -default = "" type = "color" filter = "Subtitle" help = "See sub-color. Color used for the sub font border. Ignored when sub-back-color is specified (or more exactly: when that option is not set to completely transparent)." [[settings]] name = "sub-back-color" -default = "" type = "color" filter = "Subtitle" help = "See sub-color. Color used for sub text background. You can use sub-shadow-offset to change its size relative to the text." [[settings]] name = "screen" -default = "" filter = "Screen" help = "<0-32> In multi-monitor configurations (i.e. a single desktop that spans across multiple displays), this option tells mpv which screen to display the video on." [[settings]] name = "osd-playing-msg" -default = "" width = 300 filter = "Screen" +type = "string" help = "Show a message on OSD when playback starts. The string is expanded for properties, e.g. osd-playing-msg='file: ${filename}' will show the message file: followed by a space and the currently played filename. For more information visit:" helpurl = "https://mpv.io/manual/master/#property-expansion" @@ -240,7 +235,6 @@ options = [{ name = "yes" }, [[settings]] name = "screenshot-directory" -default = "" width = 500 type = "folder" filter = "Screen" @@ -271,7 +265,6 @@ options = [{ name = "yes", help = "Don't terminate if the current file is the [[settings]] name = "loop-file" -default = "" filter = "Playback" help = "Loop a single file N times. inf means forever, no means normal playback.\n\nThe difference to loop-playlist is that this doesn't loop the playlist, just the file itself. If the playlist contains only a single file, the difference between the two option is that this option performs a seek on loop, instead of reloading the file. loop is an alias for this option." @@ -285,13 +278,11 @@ options = [{ name = "yes" }, [[settings]] name = "input-ar-delay" -default = "" filter = "Input" help = "Delay in milliseconds before we start to autorepeat a key (0 to disable)." [[settings]] name = "input-ar-rate" -default = "" filter = "Input" help = "Number of key presses to generate per second on autorepeat." @@ -315,6 +306,5 @@ options = [{ name = "yes" }, [[settings]] name = "loop-playlist" -default = "" filter = "Playback" help = " Loops playback N times. A value of 1 plays it one time (default), 2 two times, etc. inf means forever. no is the same as 1 and disables looping. If several files are specified on command line, the entire playlist is looped. The force mode is like inf, but does not skip playlist entries which have been marked as failing. This means the player might waste CPU time trying to loop a file that doesn't exist. But it might be useful for playing webradios under very bad network conditions." \ No newline at end of file diff --git a/mpv.net/Resources/mpvNetConfToml.txt b/mpv.net/Resources/mpvNetConfToml.txt index 86836fe..139c8dc 100644 --- a/mpv.net/Resources/mpvNetConfToml.txt +++ b/mpv.net/Resources/mpvNetConfToml.txt @@ -8,12 +8,10 @@ options = [{ name = "always" }, { name = "never" }] [[settings]] -name = "clipboard-monitoring" -default = "yes" +name = "url-whitelist" filter = "mpv.net" -help = "Monitors the clipboard for URLs to play." -options = [{ name = "yes" }, - { name = "no" }] +type = "string" +help = "Domain whitelist to monitor the clipboard for URLs to play.\n\nDefault: youtube ard zdf" [[settings]] name = "process-instance" diff --git a/mpv.net/WPF/ConfWindow.xaml.cs b/mpv.net/WPF/ConfWindow.xaml.cs index 0f5d86c..4c9b211 100644 --- a/mpv.net/WPF/ConfWindow.xaml.cs +++ b/mpv.net/WPF/ConfWindow.xaml.cs @@ -28,7 +28,7 @@ namespace mpvnet SearchControl.SearchTextBox.TextChanged += SearchTextBox_TextChanged; LoadSettings(SettingsDefinitions, Conf); LoadSettings(NetSettingsDefinitions, NetConf); - SearchControl.Text = RegistryHelp.GetString(@"HKCU\Software\mpv.net", "config editor search"); + SearchControl.Text = RegHelp.GetString(App.RegPath, "config editor search"); if (App.IsDarkMode) { @@ -49,7 +49,7 @@ namespace mpvnet private void LoadSettings(List settingsDefinitions, Dictionary confSettings) { - foreach (var setting in settingsDefinitions) + foreach (SettingBase setting in settingsDefinitions) { if (!FilterStrings.Contains(setting.Filter)) FilterStrings.Add(setting.Filter); @@ -58,7 +58,7 @@ namespace mpvnet { if (setting.Name == pair.Key) { - setting.Value = pair.Value; + setting.Value = pair.Value.Trim('\'', '"'); setting.StartValue = pair.Value; continue; } @@ -132,7 +132,7 @@ namespace mpvnet { base.OnClosed(e); WriteToDisk(); - RegistryHelp.SetObject(@"HKCU\Software\mpv.net", "config editor search", SearchControl.Text); + RegHelp.SetObject(App.RegPath, "config editor search", SearchControl.Text); } void WriteToDisk() @@ -165,17 +165,22 @@ namespace mpvnet foreach (var i in Comments[filePath]) content += $"#{i.Key} = {i.Value}\r\n"; - foreach (var setting in settings) + foreach (SettingBase setting in settings) { if ((setting.Value ?? "") != setting.Default) - confSettings[setting.Name] = setting.Value; + if (setting.Type == "string" || + setting.Type == "folder" || + setting.Type == "color") + + confSettings[setting.Name] = "'" + setting.Value + "'"; + else + confSettings[setting.Name] = setting.Value; if (confSettings.ContainsKey(setting.Name) && (setting.Value ?? "") == setting.Default || (setting.Value ?? "") == "") - { + confSettings.Remove(setting.Name); - } } foreach (var i in confSettings) diff --git a/mpv.net/WPF/EverythingWindow.xaml.cs b/mpv.net/WPF/EverythingWindow.xaml.cs index d384ac5..e3910f8 100644 --- a/mpv.net/WPF/EverythingWindow.xaml.cs +++ b/mpv.net/WPF/EverythingWindow.xaml.cs @@ -95,12 +95,8 @@ namespace mpvnet ListView.ScrollIntoView(ListView.SelectedItem); } break; - case Key.Escape: - Close(); - break; - case Key.Enter: - Execute(); - break; + case Key.Escape: Close(); break; + case Key.Enter: Execute(); break; } } @@ -113,14 +109,11 @@ namespace mpvnet void Execute() { if (ListView.SelectedItem != null) - mp.Load(ListView.SelectedItem as string); + mp.Load(new[] { ListView.SelectedItem as string }, true, Keyboard.Modifiers == ModifierKeys.Control); Keyboard.Focus(FilterTextBox); } - private void ListView_MouseUp(object sender, MouseButtonEventArgs e) - { - Execute(); - } + private void ListView_MouseUp(object sender, MouseButtonEventArgs e) => Execute(); private void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e) { diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index c81484d..eea3802 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -40,7 +40,7 @@ namespace mpvnet MinimumSize = new Size(FontHeight * 16, FontHeight * 9); Text += " " + Application.ProductVersion; - object recent = RegistryHelp.GetObject(App.RegPath, "Recent"); + object recent = RegHelp.GetObject(App.RegPath, "Recent"); if (recent is string[] r) RecentFiles = new List(r); @@ -150,7 +150,7 @@ namespace mpvnet recent.DropDownItems.Clear(); foreach (string path in RecentFiles) - MenuItem.Add(recent.DropDownItems, path, () => mp.Load(path)); + MenuItem.Add(recent.DropDownItems, path, () => mp.Load(new[] { path }, true, Control.ModifierKeys.HasFlag(Keys.Control))); recent.DropDownItems.Add(new ToolStripSeparator()); MenuItem mi = new MenuItem("Clear List"); @@ -377,14 +377,14 @@ namespace mpvnet if (m.Msg == SingleProcess.Message) { - object filesObject = RegistryHelp.GetObject(App.RegPath, "ShellFiles"); + object filesObject = RegHelp.GetObject(App.RegPath, "ShellFiles"); if (filesObject is string[] files) { - switch (RegistryHelp.GetString(App.RegPath, "ProcessInstanceMode")) + switch (RegHelp.GetString(App.RegPath, "ProcessInstanceMode")) { case "single": - mp.Load(files); + mp.Load(files, true, Control.ModifierKeys.HasFlag(Keys.Control)); break; case "queue": foreach (string file in files) @@ -393,7 +393,7 @@ namespace mpvnet } } - RegistryHelp.RemoveValue(App.RegPath, "ShellFiles"); + RegHelp.RemoveValue(App.RegPath, "ShellFiles"); Activate(); return; } @@ -412,9 +412,9 @@ namespace mpvnet { base.OnDragDrop(e); if (e.Data.GetDataPresent(DataFormats.FileDrop)) - mp.Load(e.Data.GetData(DataFormats.FileDrop) as String[]); + mp.Load(e.Data.GetData(DataFormats.FileDrop) as String[], true, Control.ModifierKeys.HasFlag(Keys.Control)); if (e.Data.GetDataPresent(DataFormats.Text)) - mp.Load(e.Data.GetData(DataFormats.Text).ToString()); + mp.Load(new[] { e.Data.GetData(DataFormats.Text).ToString() }, true, Control.ModifierKeys.HasFlag(Keys.Control)); } protected override void OnMouseDown(MouseEventArgs e) @@ -487,7 +487,7 @@ namespace mpvnet BuildMenu(); ContextMenuStrip = ContextMenu; IgnoreDpiChanged = false; - CheckURLinClipboard(); + CheckUrlInClipboard(); } protected override void OnResize(EventArgs e) @@ -499,7 +499,7 @@ namespace mpvnet protected override void OnFormClosed(FormClosedEventArgs e) { base.OnFormClosed(e); - RegistryHelp.SetObject(App.RegPath, "Recent", RecentFiles.ToArray()); + RegHelp.SetObject(App.RegPath, "Recent", RecentFiles.ToArray()); App.Exit(); mp.commandv("quit"); mp.AutoResetEvent.WaitOne(3000); @@ -514,20 +514,24 @@ namespace mpvnet protected override void OnActivated(EventArgs e) { base.OnActivated(e); - CheckURLinClipboard(); + CheckUrlInClipboard(); } - void CheckURLinClipboard() + void CheckUrlInClipboard() { - if (App.ClipboardMonitoring != "yes") return; string clipboard = Clipboard.GetText(); - if (clipboard.StartsWith("http") && RegistryHelp.GetString(App.RegPath, "LastURL") != clipboard && Visible) + foreach (string url in App.UrlWhitelist) { - RegistryHelp.SetObject(App.RegPath, "LastURL", clipboard); + if (clipboard.Contains("://") && !clipboard.Contains("\n") && + clipboard.Contains(url.ToLower()) && + RegHelp.GetString(App.RegPath, "LastURL") != clipboard && Visible) + { + RegHelp.SetObject(App.RegPath, "LastURL", clipboard); - if (Msg.ShowQuestion("Play URL?", clipboard) == MsgResult.OK) - mp.Load(clipboard); + if (Msg.ShowQuestion("Play URL?", clipboard) == MsgResult.OK) + mp.Load(new[] { clipboard }, true, Control.ModifierKeys.HasFlag(Keys.Control)); + } } } } diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index 560cfd6..fa91c4c 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -538,11 +538,11 @@ namespace mpvnet { files.Add(i); if (i.StartsWith("http")) - RegistryHelp.SetObject(App.RegPath, "LastURL", i); + RegHelp.SetObject(App.RegPath, "LastURL", i); } } - mp.Load(files.ToArray()); + mp.Load(files.ToArray(), App.ProcessInstance != "queue", Control.ModifierKeys.HasFlag(Keys.Control)); foreach (string i in args) { @@ -560,7 +560,7 @@ namespace mpvnet } } - public static void Load(params string[] files) + public static void Load(string[] files, bool loadFolder, bool append) { if (files is null || files.Length == 0) return; HideLogo(); @@ -569,12 +569,12 @@ namespace mpvnet if (App.SubtitleTypes.Contains(Path.GetExtension(files[i]).TrimStart('.').ToLower())) mp.commandv("sub-add", files[i]); else - if (i == 0) + if (i == 0 && !append) mp.commandv("loadfile", files[i]); else mp.commandv("loadfile", files[i], "append"); - Task.Run(() => LoadFolder()); // user reported race condition + if (loadFolder && !append) Task.Run(() => LoadFolder()); // user reported race condition } static void LoadFolder()