From a5f4d848d42b0598464c5904a1a7ecae0bd3a4ed Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sun, 10 Nov 2019 23:22:20 +0100 Subject: [PATCH] changelog and update check --- Changelog.md | 3 + mpv.net/Misc/App.cs | 20 +++--- mpv.net/Misc/Command.cs | 8 ++- mpv.net/Misc/Misc.cs | 108 +++++++---------------------- mpv.net/Misc/Program.cs | 3 +- mpv.net/Misc/RegistryHelp.cs | 70 +++++++++++++++++++ mpv.net/Misc/UpdateCheck.cs | 78 +++++++++++++++++++++ mpv.net/Native/TaskDialog.cs | 3 +- mpv.net/Properties/AssemblyInfo.cs | 4 +- mpv.net/Resources/ConfToml.txt | 9 +++ mpv.net/Resources/inputConf.txt | 25 +++---- mpv.net/WPF/ConfWindow.xaml.cs | 4 +- mpv.net/WPF/SetupWindow.xaml.cs | 2 +- mpv.net/WinForms/MainForm.cs | 102 +++++++++++++++------------ mpv.net/mpv.net.csproj | 3 + mpv.net/mpv/mp.cs | 7 +- 16 files changed, 283 insertions(+), 166 deletions(-) create mode 100644 mpv.net/Misc/RegistryHelp.cs create mode 100644 mpv.net/Misc/UpdateCheck.cs diff --git a/Changelog.md b/Changelog.md index 47d1d60..dcdd498 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,8 @@ +- new: install via Scoop and Chocolatey added to readme/website (Restia666Ashdoll) + - fix: often the OSC was shown when fullscreen was entered + or on app startup, this is now suppressed ### 5.4.3.0 diff --git a/mpv.net/Misc/App.cs b/mpv.net/Misc/App.cs index cf68a99..6318f1a 100644 --- a/mpv.net/Misc/App.cs +++ b/mpv.net/Misc/App.cs @@ -29,6 +29,7 @@ namespace mpvnet public static bool RememberVolume { get; set; } = true; public static bool AutoLoadFolder { get; set; } = true; public static bool Queue { get; set; } + public static bool UpdateCheck { get; set; } public static int StartThreshold { get; set; } = 1500; public static int RecentCount { get; set; } = 15; @@ -83,8 +84,8 @@ namespace mpvnet { if (RememberVolume) { - mp.set_property_int("volume", RegHelp.GetInt(App.RegPath, "Volume", 70)); - mp.set_property_string("mute", RegHelp.GetString(App.RegPath, "Mute", "no")); + mp.set_property_int("volume", RegistryHelp.GetInt(App.RegPath, "Volume", 70)); + mp.set_property_string("mute", RegistryHelp.GetString(App.RegPath, "Mute", "no")); } } @@ -92,8 +93,8 @@ namespace mpvnet { if (RememberVolume) { - RegHelp.SetObject(App.RegPath, "Volume", mp.get_property_int("volume")); - RegHelp.SetObject(App.RegPath, "Mute", mp.get_property_string("mute")); + RegistryHelp.SetValue(App.RegPath, "Volume", mp.get_property_int("volume")); + RegistryHelp.SetValue(App.RegPath, "Mute", mp.get_property_string("mute")); } } @@ -120,16 +121,17 @@ namespace mpvnet { case "remember-position": RememberPosition = value == "yes"; return true; case "maximized": Maximized = value == "yes"; return true; + case "debug-mode": DebugMode = value == "yes"; return true; + case "remember-volume": RememberVolume = value == "yes"; return true; + case "queue": Queue = value == "yes"; return true; + case "auto-load-folder": AutoLoadFolder = value == "yes"; return true; + case "update-check": UpdateCheck = 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 "remember-volume": RememberVolume = value == "yes"; return true; case "start-threshold": StartThreshold = value.Int(); return true; - case "minimum-aspect-ratio": MinimumAspectRatio = value.Float(); return true; - case "auto-load-folder": AutoLoadFolder = value == "yes"; return true; case "recent-count": RecentCount = value.Int(); return true; - case "queue": Queue = value == "yes"; return true; + case "minimum-aspect-ratio": MinimumAspectRatio = value.Float(); return true; case "dark-theme": DarkTheme = value.Trim('\'', '"'); return true; case "light-theme": LightTheme = value.Trim('\'', '"'); return true; } diff --git a/mpv.net/Misc/Command.cs b/mpv.net/Misc/Command.cs index c66dd6e..6aaca4d 100644 --- a/mpv.net/Misc/Command.cs +++ b/mpv.net/Misc/Command.cs @@ -1,4 +1,5 @@ -using System; + +using System; using System.Diagnostics; using System.IO; using System.Linq; @@ -17,6 +18,7 @@ namespace mpvnet switch (id) { case "open-files": OpenFiles(args); break; + case "update-check": UpdateCheck.CheckOnline(true); break; case "open-url": OpenURL(); break; case "open-optical-media": Open_DVD_Or_BD_Folder(); break; case "manage-file-associations": // deprecated 2019 @@ -201,9 +203,9 @@ namespace mpvnet public static void ExecuteMpvCommand() // deprecated 2019 { InvokeOnMainThread(new Action(() => { - string command = VB.Interaction.InputBox("Enter a mpv command to be executed.", "Execute Command", RegHelp.GetString(App.RegPath, "RecentExecutedCommand")); + string command = VB.Interaction.InputBox("Enter a mpv command to be executed.", "Execute Command", RegistryHelp.GetString(App.RegPath, "RecentExecutedCommand")); if (string.IsNullOrEmpty(command)) return; - RegHelp.SetObject(App.RegPath, "RecentExecutedCommand", command); + RegistryHelp.SetValue(App.RegPath, "RecentExecutedCommand", command); mp.command(command, false); })); } diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index 9975514..2ce88d7 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -66,108 +66,52 @@ namespace mpvnet { Types = types; - 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.net\Capabilities", "ApplicationDescription", "mpv.net media player"); - RegHelp.SetObject(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationName", "mpv.net"); - RegHelp.SetObject(@"HKCR\SystemFileAssociations\video\OpenWithList\" + ExeFilename, null, ""); - RegHelp.SetObject(@"HKCR\SystemFileAssociations\audio\OpenWithList\" + ExeFilename, null, ""); - RegHelp.SetObject(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net", @"SOFTWARE\Clients\Media\mpv.net\Capabilities"); + RegistryHelp.SetValue(@"HKCU\Software\Microsoft\Windows\CurrentVersion\App Paths\" + ExeFilename, null, ExePath); + RegistryHelp.SetValue(@"HKCR\Applications\" + ExeFilename, "FriendlyAppName", "mpv.net media player"); + RegistryHelp.SetValue($@"HKCR\Applications\{ExeFilename}\shell\open\command", null, $"\"{ExePath}\" \"%1\""); + RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationDescription", "mpv.net media player"); + RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities", "ApplicationName", "mpv.net"); + RegistryHelp.SetValue(@"HKCR\SystemFileAssociations\video\OpenWithList\" + ExeFilename, null, ""); + RegistryHelp.SetValue(@"HKCR\SystemFileAssociations\audio\OpenWithList\" + ExeFilename, null, ""); + RegistryHelp.SetValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net", @"SOFTWARE\Clients\Media\mpv.net\Capabilities"); foreach (string ext in Types) { - RegHelp.SetObject($@"HKCR\Applications\{ExeFilename}\SupportedTypes", "." + ext, ""); - RegHelp.SetObject($@"HKCR\" + "." + ext, null, ExeFilenameNoExt + "." + ext); - RegHelp.SetObject($@"HKCR\" + "." + ext + @"\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, ""); + RegistryHelp.SetValue($@"HKCR\Applications\{ExeFilename}\SupportedTypes", "." + ext, ""); + RegistryHelp.SetValue($@"HKCR\" + "." + ext, null, ExeFilenameNoExt + "." + ext); + RegistryHelp.SetValue($@"HKCR\" + "." + ext + @"\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, ""); if (App.VideoTypes.Contains(ext)) - RegHelp.SetObject(@"HKCR\" + "." + ext, "PerceivedType", "video"); + RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "video"); if (App.AudioTypes.Contains(ext)) - RegHelp.SetObject(@"HKCR\" + "." + ext, "PerceivedType", "audio"); + RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "audio"); if (App.ImageTypes.Contains(ext)) - RegHelp.SetObject(@"HKCR\" + "." + ext, "PerceivedType", "image"); + RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "image"); - 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); + RegistryHelp.SetValue($@"HKCR\" + ExeFilenameNoExt + "." + ext + @"\shell\open", null, "Play with " + Application.ProductName); + RegistryHelp.SetValue($@"HKCR\" + ExeFilenameNoExt + "." + ext + @"\shell\open\command", null, $"\"{ExePath}\" \"%1\""); + RegistryHelp.SetValue(@"HKLM\SOFTWARE\Clients\Media\mpv.net\Capabilities\FileAssociations", "." + ext, ExeFilenameNoExt + "." + ext); } } public static void Unregister() { - 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); - RegHelp.RemoveValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net"); + 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); + RegistryHelp.RemoveValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net"); foreach (string id in Registry.ClassesRoot.GetSubKeyNames()) { if (id.StartsWith(ExeFilenameNoExt + ".")) Registry.ClassesRoot.DeleteSubKeyTree(id); - RegHelp.RemoveValue($@"HKCR\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id); - RegHelp.RemoveValue($@"HKLM\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id); - } - } - } - - public class RegHelp - { - public static void SetObject(string path, string name, object value) - { - using (RegistryKey regKey = GetRootKey(path).CreateSubKey(path.Substring(5), RegistryKeyPermissionCheck.ReadWriteSubTree)) - regKey.SetValue(name, value); - } - - public static string GetString(string path, string name, string defaultValue = "") - { - object value = GetObject(path, name, defaultValue); - return !(value is string) ? defaultValue : value.ToString(); - } - - public static int GetInt(string path, string name, int defaultValue = 0) - { - object value = GetObject(path, name, defaultValue); - return !(value is int) ? defaultValue : (int)value; - } - - public static object GetObject(string path, string name, object defaultValue = null) - { - using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5))) - return regKey == null ? null : regKey.GetValue(name, defaultValue); - } - - public static void RemoveKey(string path) - { - try - { - GetRootKey(path).DeleteSubKeyTree(path.Substring(5), false); - } catch { } - } - - public static void RemoveValue(string path, string name) - { - try - { - using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5), true)) - if (regKey != null) - regKey.DeleteValue(name, false); - } catch {} - } - - static RegistryKey GetRootKey(string path) - { - switch (path.Substring(0, 4)) - { - case "HKLM": return Registry.LocalMachine; - case "HKCU": return Registry.CurrentUser; - case "HKCR": return Registry.ClassesRoot; - default: throw new Exception(); + RegistryHelp.RemoveValue($@"HKCR\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id); + RegistryHelp.RemoveValue($@"HKLM\Software\Classes\{id}\OpenWithProgIDs", ExeFilenameNoExt + id); } } } @@ -316,7 +260,7 @@ namespace mpvnet public class Folder { - public static string Startup { get; } = Application.StartupPath + "\\"; + public static string Startup { get; } = Application.StartupPath + @"\"; } public class PathHelp diff --git a/mpv.net/Misc/Program.cs b/mpv.net/Misc/Program.cs index b947c3d..35c9045 100644 --- a/mpv.net/Misc/Program.cs +++ b/mpv.net/Misc/Program.cs @@ -1,4 +1,5 @@ -using System; + +using System; using System.Windows.Forms; using System.Linq; using System.Collections.Generic; diff --git a/mpv.net/Misc/RegistryHelp.cs b/mpv.net/Misc/RegistryHelp.cs new file mode 100644 index 0000000..e943ae9 --- /dev/null +++ b/mpv.net/Misc/RegistryHelp.cs @@ -0,0 +1,70 @@ + +using System; +using Microsoft.Win32; +using System.Windows.Forms; + +public class RegistryHelp +{ + public static string ApplicationKey { get; } = @"HKCU\Software\" + Application.ProductName; + + public static void SetValue(string path, string name, object value) + { + using (RegistryKey regKey = GetRootKey(path).CreateSubKey(path.Substring(5), RegistryKeyPermissionCheck.ReadWriteSubTree)) + regKey.SetValue(name, value); + } + + public static string GetString(string path, string name, string defaultValue = "") + { + object value = GetValue(path, name, defaultValue); + return !(value is string) ? defaultValue : value.ToString(); + } + + public static int GetInt(string path, string name, int defaultValue = 0) + { + object value = GetValue(path, name, defaultValue); + return !(value is int) ? defaultValue : (int)value; + } + + public static bool GetBool(string path, string name, bool defaultValue = false) + { + object val = GetValue(path, name, defaultValue); + return val is bool ? (bool)val : defaultValue; + } + + public static object GetValue(string path, string name, object defaultValue = null) + { + using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5))) + return regKey == null ? null : regKey.GetValue(name, defaultValue); + } + + public static void RemoveKey(string path) + { + try + { + GetRootKey(path).DeleteSubKeyTree(path.Substring(5), false); + } + catch { } + } + + public static void RemoveValue(string path, string name) + { + try + { + using (RegistryKey regKey = GetRootKey(path).OpenSubKey(path.Substring(5), true)) + if (regKey != null) + regKey.DeleteValue(name, false); + } + catch { } + } + + static RegistryKey GetRootKey(string path) + { + switch (path.Substring(0, 4)) + { + case "HKLM": return Registry.LocalMachine; + case "HKCU": return Registry.CurrentUser; + case "HKCR": return Registry.ClassesRoot; + default: throw new Exception(); + } + } +} \ No newline at end of file diff --git a/mpv.net/Misc/UpdateCheck.cs b/mpv.net/Misc/UpdateCheck.cs new file mode 100644 index 0000000..efc1f2e --- /dev/null +++ b/mpv.net/Misc/UpdateCheck.cs @@ -0,0 +1,78 @@ + +using System; +using System.Diagnostics; +using System.IO; +using System.Net.Http; +using System.Reflection; +using System.Text.RegularExpressions; +using System.Windows.Forms; + +namespace mpvnet +{ + class UpdateCheck + { + public static void DailyCheck() + { + if (App.UpdateCheck && RegistryHelp.GetInt(RegistryHelp.ApplicationKey, "LastUpdateCheck") + != DateTime.Now.DayOfYear) + + CheckOnline(); + } + + public static async void CheckOnline(bool showUpToDateMessage = false) + { + try + { + using (HttpClient client = new HttpClient()) + { + RegistryHelp.SetValue(RegistryHelp.ApplicationKey, "LastUpdateCheck", DateTime.Now.DayOfYear); + client.DefaultRequestHeaders.Add("User-Agent", "mpv.net"); + var response = await client.GetAsync("https://api.github.com/repos/stax76/mpv.net/releases/latest"); + response.EnsureSuccessStatusCode(); + string content = await response.Content.ReadAsStringAsync(); + Match match = Regex.Match(content, $@"""mpv\.net-portable-x64-([\d\.]+)\.7z"""); + Version onlineVersion = Version.Parse(match.Groups[1].Value); + Version currentVersion = Assembly.GetEntryAssembly().GetName().Version; + + //if (onlineVersion == currentVersion) + //{ + // if (showUpToDateMessage) + // Msg.Show($"{Application.ProductName} is up to date."); + // return; + //} + + if (Msg.ShowQuestion($"New version {onlineVersion} is available, update now?") == MsgResult.OK) + { + string arch = IntPtr.Size == 8 ? "64" : "86"; + string url = $"https://github.com/stax76/mpv.net/releases/download/{onlineVersion}/mpv.net-portable-x{arch}-{onlineVersion}.7z"; + bool asAdmin = false; + + try { + File.WriteAllText(Folder.Startup + @"write access test", ""); + } catch { + asAdmin = true; + } + + //using (Process proc = new Process()) + //{ + // proc.StartInfo.FileName = "PowerShell"; + // proc.StartInfo.Arguments = $"-File \"{Folder.Startup + "Update.ps1"}\" \"{url}\" \"{Application.StartupPath}\""; + + // if (asAdmin) + // proc.StartInfo.Verb = "runas"; + + // proc.Start(); + //} + + //mp.command("quit"); + } + } + } + catch (Exception ex) + { + if (showUpToDateMessage) + Msg.ShowException(ex); + } + } + } +} \ No newline at end of file diff --git a/mpv.net/Native/TaskDialog.cs b/mpv.net/Native/TaskDialog.cs index 878935e..14a73a7 100644 --- a/mpv.net/Native/TaskDialog.cs +++ b/mpv.net/Native/TaskDialog.cs @@ -1,4 +1,5 @@ -using System; + +using System; using System.Runtime.InteropServices; using System.Text; using System.Collections.Generic; diff --git a/mpv.net/Properties/AssemblyInfo.cs b/mpv.net/Properties/AssemblyInfo.cs index e93fb9a..89eb4c2 100644 --- a/mpv.net/Properties/AssemblyInfo.cs +++ b/mpv.net/Properties/AssemblyInfo.cs @@ -6,11 +6,11 @@ using System.Runtime.InteropServices; // set of attributes. Change these attribute values to modify the information // associated with an assembly. [assembly: AssemblyTitle("mpv.net")] -[assembly: AssemblyDescription("media player")] +[assembly: AssemblyDescription("mpv based media player")] [assembly: AssemblyConfiguration("")] [assembly: AssemblyCompany("Frank Skare (stax76)")] [assembly: AssemblyProduct("mpv.net")] -[assembly: AssemblyCopyright("Copyright 2017-2019 Frank Skare (stax76)")] +[assembly: AssemblyCopyright("Copyright © 2017-2019 Frank Skare (stax76)")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] diff --git a/mpv.net/Resources/ConfToml.txt b/mpv.net/Resources/ConfToml.txt index 2d88ac0..f6c5a20 100644 --- a/mpv.net/Resources/ConfToml.txt +++ b/mpv.net/Resources/ConfToml.txt @@ -502,6 +502,15 @@ file = "mpv" filter = "Input" help = "Number of key presses to generate per second on autorepeat." +[[settings]] +name = "update-check" +file = "mpvnet" +default = "no" +filter = "General" +help = "Daily check for new version. (mpv.net specific setting)" +options = [{ name = "yes" }, + { name = "no" }] + [[settings]] name = "process-instance" file = "mpvnet" diff --git a/mpv.net/Resources/inputConf.txt b/mpv.net/Resources/inputConf.txt index 69f74a1..9db3cfc 100644 --- a/mpv.net/Resources/inputConf.txt +++ b/mpv.net/Resources/inputConf.txt @@ -14,7 +14,7 @@ # space character to make it easier to do a text search, so if you want to know # if 'o' has already a binding you can make a text search on ' o '. - # mpv input commands: https://github.com/stax76/mpv.net/wiki/mpv-input-commands + # mpv input commands: https://mpv.io/manual/master/#list-of-input-commands # mpv input keys: https://github.com/stax76/mpv.net/wiki/mpv-input-keys @@ -157,21 +157,14 @@ Ctrl+h cycle-values hwdec "auto" "no" #menu: Tools > Toggle Hardware Decoding _ 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 - _ 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 + _ script-message mpv.net shell-execute https://mpv.io #menu: Help > Website mpv + _ script-message mpv.net shell-execute https://github.com/stax76/mpv.net #menu: Help > Website mpv.net + _ ignore #menu: Help > - + _ script-message mpv.net shell-execute https://mpv.io/manual/stable/ #menu: Help > Manual mpv + _ script-message mpv.net shell-execute https://github.com/stax76/mpv.net/blob/master/Manual.md #menu: Help > Manual mpv.net + _ ignore #menu: Help > - + _ script-message mpv.net update-check #menu: Help > Check for Updates + _ script-message mpv.net show-about #menu: Help > About mpv.net _ ignore #menu: - Esc quit #menu: Exit diff --git a/mpv.net/WPF/ConfWindow.xaml.cs b/mpv.net/WPF/ConfWindow.xaml.cs index 0e4e4d0..18f8617 100644 --- a/mpv.net/WPF/ConfWindow.xaml.cs +++ b/mpv.net/WPF/ConfWindow.xaml.cs @@ -30,7 +30,7 @@ namespace mpvnet LoadConf(App.ConfPath); LoadSettings(); InitialContent = GetCompareString(); - SearchControl.Text = RegHelp.GetString(App.RegPath, "ConfigEditorSearch"); + SearchControl.Text = RegistryHelp.GetString(App.RegPath, "ConfigEditorSearch"); } private void LoadSettings() @@ -68,7 +68,7 @@ namespace mpvnet protected override void OnClosed(EventArgs e) { base.OnClosed(e); - RegHelp.SetObject(App.RegPath, "ConfigEditorSearch", SearchControl.Text); + RegistryHelp.SetValue(App.RegPath, "ConfigEditorSearch", SearchControl.Text); if (InitialContent == GetCompareString()) return; diff --git a/mpv.net/WPF/SetupWindow.xaml.cs b/mpv.net/WPF/SetupWindow.xaml.cs index 744fd00..1ea60d5 100644 --- a/mpv.net/WPF/SetupWindow.xaml.cs +++ b/mpv.net/WPF/SetupWindow.xaml.cs @@ -15,7 +15,7 @@ namespace mpvnet { try { - using (var proc = new Process()) + using (Process proc = new Process()) { proc.StartInfo.FileName = WinForms.Application.ExecutablePath; proc.StartInfo.Arguments = "--reg-file-assoc " + value; diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index 3654ca0..4c21d72 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -34,7 +34,7 @@ namespace mpvnet try { - object recent = RegHelp.GetObject(App.RegPath, "Recent"); + object recent = RegistryHelp.GetValue(App.RegPath, "Recent"); if (recent is string[] r) RecentFiles = new List(r); @@ -91,8 +91,8 @@ namespace mpvnet Left = target.X + (target.Width - Width) / 2; Top = target.Y + (target.Height - Height) / 2; - int posX = RegHelp.GetInt(App.RegPath, "PosX"); - int posY = RegHelp.GetInt(App.RegPath, "PosY"); + int posX = RegistryHelp.GetInt(App.RegPath, "PosX"); + int posY = RegistryHelp.GetInt(App.RegPath, "PosY"); if (posX != 0 && posY != 0 && App.RememberPosition) { @@ -472,7 +472,7 @@ namespace mpvnet break; case 0x0200: // WM_MOUSEMOVE { - if ((DateTime.Now - LastCycleFullscreen).TotalMilliseconds > 100) + if ((DateTime.Now - LastCycleFullscreen).TotalMilliseconds > 500) { Point pos = PointToClient(Cursor.Position); mp.command($"mouse {pos.X} {pos.Y}"); @@ -483,61 +483,69 @@ namespace mpvnet } break; case 0x2a3: // WM_MOUSELEAVE - mp.command("mouse 1 1"); // osc won't always auto hide + // osc won't always auto hide + mp.command("mouse 1 1"); break; - case 0x203: // Native.WM.LBUTTONDBLCLK + case 0x203: // WM_LBUTTONDBLCLK { Point pos = PointToClient(Cursor.Position); mp.command($"mouse {pos.X} {pos.Y} 0 double"); } break; case 0x02E0: // WM_DPICHANGED - if (!WasShown) - break; - var r2 = Marshal.PtrToStructure(m.LParam); - Native.SetWindowPos(Handle, IntPtr.Zero, r2.Left, r2.Top, r2.Width, r2.Height, 0); + { + if (!WasShown) + break; + + Native.RECT rect = Marshal.PtrToStructure(m.LParam); + Native.SetWindowPos(Handle, IntPtr.Zero, rect.Left, rect.Top, rect.Width, rect.Height, 0); + } break; case 0x0214: // WM_SIZING - var rc = Marshal.PtrToStructure(m.LParam); - var r = rc; - NativeHelp.SubtractWindowBorders(Handle, ref r); - int c_w = r.Right - r.Left, c_h = r.Bottom - r.Top; - Size s = mp.VideoSize; + { + var rc = Marshal.PtrToStructure(m.LParam); + var r = rc; + NativeHelp.SubtractWindowBorders(Handle, ref r); + int c_w = r.Right - r.Left, c_h = r.Bottom - r.Top; + Size s = mp.VideoSize; - if (s == Size.Empty) - s = new Size(16, 9); + if (s == Size.Empty) + s = new Size(16, 9); - float aspect = s.Width / (float)s.Height; - int d_w = Convert.ToInt32(c_h * aspect - c_w); - int d_h = Convert.ToInt32(c_w / aspect - c_h); - int[] d_corners = { d_w, d_h, -d_w, -d_h }; - int[] corners = { rc.Left, rc.Top, rc.Right, rc.Bottom }; - int corner = NativeHelp.GetResizeBorder(m.WParam.ToInt32()); + float aspect = s.Width / (float)s.Height; + int d_w = Convert.ToInt32(c_h * aspect - c_w); + int d_h = Convert.ToInt32(c_w / aspect - c_h); + int[] d_corners = { d_w, d_h, -d_w, -d_h }; + int[] corners = { rc.Left, rc.Top, rc.Right, rc.Bottom }; + int corner = NativeHelp.GetResizeBorder(m.WParam.ToInt32()); - if (corner >= 0) - corners[corner] -= d_corners[corner]; + if (corner >= 0) + corners[corner] -= d_corners[corner]; - Marshal.StructureToPtr(new Native.RECT(corners[0], corners[1], corners[2], corners[3]), m.LParam, false); - m.Result = new IntPtr(1); + Marshal.StructureToPtr(new Native.RECT(corners[0], corners[1], corners[2], corners[3]), m.LParam, false); + m.Result = new IntPtr(1); + } return; case 0x004A: // WM_COPYDATA - var copyData = (Native.COPYDATASTRUCT)m.GetLParam(typeof(Native.COPYDATASTRUCT)); - string[] files = copyData.lpData.Split('\n'); - string mode = files[0]; - files = files.Skip(1).ToArray(); - - switch (mode) { - case "single": - mp.Load(files, true, Control.ModifierKeys.HasFlag(Keys.Control)); - break; - case "queue": - foreach (string file in files) - mp.commandv("loadfile", file, "append"); - break; - } + var copyData = (Native.COPYDATASTRUCT)m.GetLParam(typeof(Native.COPYDATASTRUCT)); + string[] files = copyData.lpData.Split('\n'); + string mode = files[0]; + files = files.Skip(1).ToArray(); - Activate(); + switch (mode) + { + case "single": + mp.Load(files, true, Control.ModifierKeys.HasFlag(Keys.Control)); + break; + case "queue": + foreach (string file in files) + mp.commandv("loadfile", file, "append"); + break; + } + + Activate(); + } return; } @@ -624,6 +632,7 @@ namespace mpvnet if (mp.GPUAPI != "vulkan") mp.VideoSizeAutoResetEvent.WaitOne(App.StartThreshold); + LastCycleFullscreen = DateTime.Now; SetFormPosAndSize(); } @@ -645,9 +654,10 @@ namespace mpvnet WPF.WPF.Init(); System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown; Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y); - WasShown = true; + UpdateCheck.DailyCheck(); mp.LoadScripts(); Task.Run(() => App.Extension = new Extension()); + WasShown = true; } protected override void OnResize(EventArgs e) @@ -664,11 +674,11 @@ namespace mpvnet if (WindowState == FormWindowState.Normal) { - RegHelp.SetObject(App.RegPath, "PosX", Left + Width / 2); - RegHelp.SetObject(App.RegPath, "PosY", Top + Height / 2); + RegistryHelp.SetValue(App.RegPath, "PosX", Left + Width / 2); + RegistryHelp.SetValue(App.RegPath, "PosY", Top + Height / 2); } - RegHelp.SetObject(App.RegPath, "Recent", RecentFiles.ToArray()); + RegistryHelp.SetValue(App.RegPath, "Recent", RecentFiles.ToArray()); if (mp.IsQuitNeeded) mp.commandv("quit"); diff --git a/mpv.net/mpv.net.csproj b/mpv.net/mpv.net.csproj index c511049..5b990df 100644 --- a/mpv.net/mpv.net.csproj +++ b/mpv.net/mpv.net.csproj @@ -108,6 +108,7 @@ ..\packages\Microsoft.PowerShell.5.ReferenceAssemblies.1.1.0\lib\net4\System.Management.Automation.dll + @@ -142,6 +143,8 @@ MSBuild:Compile + + SearchTextBoxUserControl.xaml diff --git a/mpv.net/mpv/mp.cs b/mpv.net/mpv/mp.cs index 5342e31..0ef96e7 100644 --- a/mpv.net/mpv/mp.cs +++ b/mpv.net/mpv/mp.cs @@ -1,4 +1,5 @@ -using System; + +using System; using System.Collections.Generic; using System.Diagnostics; using System.Drawing; @@ -155,7 +156,7 @@ namespace mpvnet _ConfigFolder = portableFolder; if (!Directory.Exists(_ConfigFolder)) - _ConfigFolder = RegHelp.GetString(App.RegPath, "ConfigFolder"); + _ConfigFolder = RegistryHelp.GetString(App.RegPath, "ConfigFolder"); if (!Directory.Exists(_ConfigFolder)) { @@ -202,7 +203,7 @@ namespace mpvnet Directory.CreateDirectory(_ConfigFolder); if (!_ConfigFolder.Contains("portable_config")) - RegHelp.SetObject(App.RegPath, "ConfigFolder", _ConfigFolder); + RegistryHelp.SetValue(App.RegPath, "ConfigFolder", _ConfigFolder); if (!File.Exists(_ConfigFolder + "input.conf")) File.WriteAllText(_ConfigFolder + "input.conf", Properties.Resources.inputConf);