diff --git a/Changelog.md b/Changelog.md index a7298f4..2126936 100644 --- a/Changelog.md +++ b/Changelog.md @@ -4,8 +4,9 @@ - Load AviSynth DLL from environment variable AviSynthDLL in order to support AviSynth portable mode. -- New option global-media-keys (next, previous, play/pause, stop) -- libmpv shinshiro 2020-11-22 +- New option global-media-keys (next, previous, play/pause, stop). +- Improved setup dialog. +- libmpv updated to shinshiro 2020-11-22. 5.4.8.4 Beta diff --git a/mpv.net/Misc/Help.cs b/mpv.net/Misc/Help.cs index 63a8a6a..8b66a00 100644 --- a/mpv.net/Misc/Help.cs +++ b/mpv.net/Misc/Help.cs @@ -6,6 +6,33 @@ using System.Windows.Forms; namespace mpvnet { + public static class ProcessHelp + { + public static void Execute(string file, string arguments = null) + { + using (Process proc = new Process()) + { + proc.StartInfo.FileName = file; + proc.StartInfo.Arguments = arguments; + // default is true in .NET Framework and false in .NET Core + proc.StartInfo.UseShellExecute = false; + proc.Start(); + } + } + + public static void ShellExecute(string file, string arguments = null) + { + using (Process proc = new Process()) + { + proc.StartInfo.FileName = file; + proc.StartInfo.Arguments = arguments; + // default is true in .NET Framework and false in .NET Core + proc.StartInfo.UseShellExecute = true; + proc.Start(); + } + } + } + public static class ConsoleHelp { public static int Padding { get; set; } diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index 3696eec..4d39905 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -80,25 +80,6 @@ namespace mpvnet RegistryHelp.SetValue(@"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); - RegistryHelp.RemoveValue(@"HKLM\SOFTWARE\RegisteredApplications", "mpv.net"); - - 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); - } - } } public class MediaTrack diff --git a/mpv.net/Misc/Program.cs b/mpv.net/Misc/Program.cs index d60ec64..e7ac2fc 100644 --- a/mpv.net/Misc/Program.cs +++ b/mpv.net/Misc/Program.cs @@ -33,7 +33,6 @@ namespace mpvnet if (args[1] == "audio") FileAssociation.Register(App.AudioTypes); if (args[1] == "video") FileAssociation.Register(App.VideoTypes); if (args[1] == "image") FileAssociation.Register(App.ImageTypes); - if (args[1] == "unreg") FileAssociation.Unregister(); return; } diff --git a/mpv.net/Misc/UpdateCheck.cs b/mpv.net/Misc/UpdateCheck.cs index ea89bee..fdd5ddf 100644 --- a/mpv.net/Misc/UpdateCheck.cs +++ b/mpv.net/Misc/UpdateCheck.cs @@ -1,6 +1,7 @@  using System; using System.Diagnostics; +using System.IO; using System.Net.Http; using System.Reflection; using System.Text.RegularExpressions; @@ -55,7 +56,7 @@ namespace mpvnet proc.StartInfo.UseShellExecute = true; proc.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); proc.StartInfo.FileName = "PowerShell"; - proc.StartInfo.Arguments = $"-NoLogo -NoExit -File \"{Folder.Startup + "Update.ps1"}\" \"{url}\" \"{Application.StartupPath.TrimEnd('\\')}\""; + proc.StartInfo.Arguments = $"-NoLogo -NoExit -File \"{Folder.Startup + "Update.ps1"}\" \"{url}\" \"{Folder.Startup.TrimEnd(Path.DirectorySeparatorChar)}\""; if (Folder.Startup.Contains("Program Files")) proc.StartInfo.Verb = "runas"; diff --git a/mpv.net/WPF/SetupWindow.xaml b/mpv.net/WPF/SetupWindow.xaml index b4dc788..ef27e38 100644 --- a/mpv.net/WPF/SetupWindow.xaml +++ b/mpv.net/WPF/SetupWindow.xaml @@ -19,27 +19,51 @@ + + - - - - - - - - + + + Start Menu Shortcut + + + + + File Extensions + + + + + + + + Path Environment Variable + + + + \ No newline at end of file diff --git a/mpv.net/WPF/SetupWindow.xaml.cs b/mpv.net/WPF/SetupWindow.xaml.cs index 7c5d24a..a6677d7 100644 --- a/mpv.net/WPF/SetupWindow.xaml.cs +++ b/mpv.net/WPF/SetupWindow.xaml.cs @@ -1,9 +1,10 @@  using System; using System.Diagnostics; -using System.Windows; -using System.Windows.Media.Imaging; +using System.IO; using System.Windows.Interop; +using System.Windows.Media.Imaging; +using System.Windows; using WinForms = System.Windows.Forms; @@ -39,22 +40,38 @@ namespace mpvnet proc.StartInfo.FileName = WinForms.Application.ExecutablePath; proc.StartInfo.Arguments = "--reg-file-assoc " + value; proc.StartInfo.Verb = "runas"; + proc.StartInfo.UseShellExecute = true; proc.Start(); } - Process.Start("ms-settings:defaultapps"); + Msg.Show(value[0].ToString().ToUpper() + value.Substring(1) + + " file associations successfully created."); } catch {} } - void RegisterVideo_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("video"); - void RegisterAudio_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("audio"); - void RegisterImage_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("image"); + void AddVideo_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("video"); + void AddAudio_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("audio"); + void AddImage_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("image"); - void UnregisterFileAssociations_Click(object sender, RoutedEventArgs e) => RegisterFileAssociations("unreg"); + void RemoveFileAssociations_Click(object sender, RoutedEventArgs e) + { + try + { + using (Process proc = new Process()) + { + proc.StartInfo.FileName = "powershell.exe"; + proc.StartInfo.Arguments = "-NoLogo -NoExit -ExecutionPolicy Unrestricted -File \"" + + Folder.Startup + "Setup\\uninstall.ps1\""; + proc.StartInfo.Verb = "runas"; + proc.StartInfo.UseShellExecute = true; + proc.Start(); + } + } catch { } + } void AddToPathEnvVar_Click(object sender, RoutedEventArgs e) { - string var = WinForms.Application.StartupPath + ";"; + string var = Folder.Startup.TrimEnd(Path.DirectorySeparatorChar) + ";"; string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User); if (path.Contains(var)) @@ -68,7 +85,7 @@ namespace mpvnet void RemoveFromPathEnvVar_Click(object sender, RoutedEventArgs e) { - string var = WinForms.Application.StartupPath + ";"; + string var = Folder.Startup.TrimEnd(Path.DirectorySeparatorChar) + ";"; string path = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User); if (path.Contains(var)) @@ -80,17 +97,29 @@ namespace mpvnet Msg.ShowWarning("Path was not containing mpv.net."); } - void aaa() + void AddStartMenuShortcut_Click(object sender, RoutedEventArgs e) { - BitmapSource shieldSource = null; - IntPtr icon = GetIcon(SHSTOCKICONID.Shield, SHSTOCKICONFLAGS.SHGSI_LARGEICON); - shieldSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon( - icon, Int32Rect.Empty, BitmapSizeOptions.FromEmptyOptions()); - DestroyIcon(icon); - //shieldSource = System.Windows.Interop.Imaging.CreateBitmapSourceFromHIcon( - // System.Drawing.SystemIcons.Shield.Handle, - // Int32Rect.Empty, - // BitmapSizeOptions.FromEmptyOptions()); + ExecutePowerShellScript(Folder.Startup + "Setup\\create start menu shortcut.ps1"); + } + + void RemoveStartMenuShortcut_Click(object sender, RoutedEventArgs e) + { + ExecutePowerShellScript(Folder.Startup + "Setup\\remove start menu shortcut.ps1"); + } + + void ShowEnvVarEditor_Click(object sender, RoutedEventArgs e) + { + ProcessHelp.Execute("rundll32.exe", "sysdm.cpl,EditEnvironmentVariables"); + } + + void ExecutePowerShellScript(string file) + { + ProcessHelp.Execute("powershell.exe", "-NoLogo -NoExit -ExecutionPolicy Unrestricted -File \"" + file + "\""); + } + + private void EditDefaultApp_Click(object sender, RoutedEventArgs e) + { + ProcessHelp.ShellExecute("ms-settings:defaultapps"); } } } diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index be3e426..27b63d5 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -814,9 +814,6 @@ namespace mpvnet core.LoadScripts(); Task.Run(() => App.Extension = new Extension()); ShownTickCount = Environment.TickCount; - - SetupWindow win = new SetupWindow(); - win.Show(); } protected override void OnActivated(EventArgs e)