From ae80076f36d7a2939d5cfa39ac3a48dd7c0ebf08 Mon Sep 17 00:00:00 2001 From: stax76 Date: Mon, 15 Jul 2024 02:10:30 +0200 Subject: [PATCH] Full support for select.lua select.lua is a new simple command palette script embedded into mpv/libmpv. In the context menu select.lua features can be found under 'View > On Screen Menu'. https://github.com/mpv-player/mpv/blob/master/player/lua/select.lua --- docs/changelog.md | 5 + docs/manual.md | 9 -- src/MpvNet.Windows/GuiCommand.cs | 45 +----- src/MpvNet.Windows/UI/CommandPalette.cs | 22 --- src/MpvNet.Windows/UI/CommandPaletteItem.cs | 25 --- .../WPF/Controls/CommandPaletteControl.xaml | 127 --------------- .../Controls/CommandPaletteControl.xaml.cs | 150 ------------------ src/MpvNet.Windows/WinForms/MainForm.cs | 105 +----------- src/MpvNet/InputHelp.cs | 67 ++------ src/Tools/update-mpv-and-libmpv.ps1 | 60 ++++--- 10 files changed, 64 insertions(+), 551 deletions(-) delete mode 100644 src/MpvNet.Windows/UI/CommandPalette.cs delete mode 100644 src/MpvNet.Windows/UI/CommandPaletteItem.cs delete mode 100644 src/MpvNet.Windows/WPF/Controls/CommandPaletteControl.xaml delete mode 100644 src/MpvNet.Windows/WPF/Controls/CommandPaletteControl.xaml.cs diff --git a/docs/changelog.md b/docs/changelog.md index bca3edd4..d20240ab 100644 --- a/docs/changelog.md +++ b/docs/changelog.md @@ -3,6 +3,11 @@ - Korean, Russian and Turkish translation added, Japanese translation fixed. Thanks to the translation team! - Auto build update. +- Full support for select.lua which is a new simple command palette script embedded into mpv/libmpv. + In the context menu select.lua features can be found under 'View > On Screen Menu'. + https://github.com/mpv-player/mpv/blob/master/player/lua/select.lua +- The helper script 'Tools\update-mpv-and-libmpv.ps1' no longer uses command line arguments, + it uses now the Path environment variable to find mpv and mpv.net. # v7.1.1.0 (2024-02-03) diff --git a/docs/manual.md b/docs/manual.md index a77120db..b64ba4db 100644 --- a/docs/manual.md +++ b/docs/manual.md @@ -313,15 +313,6 @@ Shows media info with raw property names. ### show-menu Shows the context menu. -### show-playlist -Shows the playlist in a message box. For a playlist menu -the following user scripts exist: - -- https://github.com/stax76/mpv-scripts#command_palette -- https://github.com/stax76/mpv-scripts#search_menu -- https://github.com/tomasklaen/uosc -- https://github.com/jonniek/mpv-playlistmanager - ### show-profiles Shows available profiles with a message box. diff --git a/src/MpvNet.Windows/GuiCommand.cs b/src/MpvNet.Windows/GuiCommand.cs index afd70704..42771591 100644 --- a/src/MpvNet.Windows/GuiCommand.cs +++ b/src/MpvNet.Windows/GuiCommand.cs @@ -55,19 +55,19 @@ public class GuiCommand ["show-media-info"] = ShowMediaInfo, ["show-menu"] = args => ShowMenu?.Invoke(), ["show-profiles"] = args => Msg.ShowInfo(Player.GetProfiles()), - ["show-properties"] = args => ShowProperties(), + ["show-properties"] = args => Player.Command("script-binding select/show-properties"), ["show-protocols"] = args => ShowProtocols(), ["window-scale"] = args => WindowScaleNet?.Invoke(float.Parse(args[0], CultureInfo.InvariantCulture)), // deprecated ["show-recent"] = args => ShowRemoved(), // deprecated - ["show-playlist"] = args => ShowPlaylist(), // deprecated ["quick-bookmark"] = args => QuickBookmark(), // deprecated ["show-history"] = args => ShowHistory(), // deprecated - ["show-command-palette"] = args => ShowCommandPalette(), // deprecated - ["show-audio-tracks"] = args => ShowTracks(), // deprecated - ["show-subtitle-tracks"] = args => ShowTracks(), // deprecated + ["show-playlist"] = args => Player.Command("script-binding select/select-playlist"), // deprecated + ["show-command-palette"] = args => Player.Command("script-binding select/select-binding"), // deprecated + ["show-audio-tracks"] = args => Player.Command("script-binding select/select-aid"), // deprecated + ["show-subtitle-tracks"] = args => Player.Command("script-binding select/select-sid"), // deprecated }; void ShowDialog(Type winType) @@ -161,9 +161,6 @@ void ShowCommands() ShowTextWithEditor("Input Commands", header + sb.ToString()); } - void ShowProperties() => - ShowTextWithEditor("Properties", Core.GetPropertyString("property-list").Replace(",", BR)); - void ShowKeys() => ShowTextWithEditor("Keys", Core.GetPropertyString("input-key-list").Replace(",", BR)); @@ -384,28 +381,6 @@ void RemoveFromPath() Msg.ShowInfo(_("mpv.net was successfully removed from the Path environment variable.")); } - // deprecated - void ShowTracks() => - Msg.ShowInfo(_("This feature was removed, but there are user scripts:") + BR2 + - "https://github.com/stax76/mpv-scripts#command_palette" + BR + - "https://github.com/stax76/mpv-scripts#search_menu" + BR + - "https://github.com/tomasklaen/uosc"); - - // deprecated - void ShowPlaylist() => - Msg.ShowInfo(_("This feature was removed, but there are user scripts:") + BR2 + - "https://github.com/stax76/mpv-scripts#command_palette" + BR + - "https://github.com/stax76/mpv-scripts#search_menu" + BR + - "https://github.com/tomasklaen/uosc" + BR + - "https://github.com/jonniek/mpv-playlistmanager"); - - // deprecated - void ShowCommandPalette() => - Msg.ShowInfo(_("This feature was removed, but there are user scripts:") + BR2 + - "https://github.com/stax76/mpv-scripts#command_palette" + BR + - "https://github.com/stax76/mpv-scripts#search_menu" + BR + - "https://github.com/tomasklaen/uosc"); - // deprecated void QuickBookmark() => Msg.ShowInfo(_("This feature was removed, but there are user scripts:") + BR2 + @@ -419,13 +394,3 @@ void ShowHistory() => // deprecated void ShowRemoved() => Msg.ShowInfo(_("This feature was removed.")); } - - -//public void ShowCommandPalette() -//{ -// MainForm.Instance?.BeginInvoke(() => { -// CommandPalette.Instance.SetItems(CommandPalette.GetItems()); -// MainForm.Instance.ShowCommandPalette(); -// CommandPalette.Instance.SelectFirst(); -// }); -//} diff --git a/src/MpvNet.Windows/UI/CommandPalette.cs b/src/MpvNet.Windows/UI/CommandPalette.cs deleted file mode 100644 index c3c4804c..00000000 --- a/src/MpvNet.Windows/UI/CommandPalette.cs +++ /dev/null @@ -1,22 +0,0 @@ - -using MpvNet.Windows.WPF.Controls; - -namespace MpvNet.Windows.UI; - -public class CommandPalette -{ - public static CommandPaletteControl Instance { get; } = new CommandPaletteControl(); - - public static IEnumerable GetItems() - { - return InputHelp.GetBindingsFromContent(App.InputConf.GetContent()) - .Where(i => i.Command != "") - .Select(i => new CommandPaletteItem() - { - Text = i.Comment, - SecondaryText = i.Input, - Action = () => Core.Command(i.Command), - Binding = i - }); - } -} diff --git a/src/MpvNet.Windows/UI/CommandPaletteItem.cs b/src/MpvNet.Windows/UI/CommandPaletteItem.cs deleted file mode 100644 index f157ee55..00000000 --- a/src/MpvNet.Windows/UI/CommandPaletteItem.cs +++ /dev/null @@ -1,25 +0,0 @@ - -namespace MpvNet.Windows.UI; - -public class CommandPaletteItem -{ - public CommandPaletteItem() { } - - public CommandPaletteItem(string text, Action action) - { - Text = text; - Action = action; - } - - public CommandPaletteItem(string text, string secondaryText, Action action) - { - Text = text; - Action = action; - SecondaryText = secondaryText; - } - - public string Text { get; set; } = ""; - public string SecondaryText { get; set; } = ""; - public Action? Action { get; set; } - public Binding? Binding { get; set; } -} diff --git a/src/MpvNet.Windows/WPF/Controls/CommandPaletteControl.xaml b/src/MpvNet.Windows/WPF/Controls/CommandPaletteControl.xaml deleted file mode 100644 index be9fadb7..00000000 --- a/src/MpvNet.Windows/WPF/Controls/CommandPaletteControl.xaml +++ /dev/null @@ -1,127 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/MpvNet.Windows/WPF/Controls/CommandPaletteControl.xaml.cs b/src/MpvNet.Windows/WPF/Controls/CommandPaletteControl.xaml.cs deleted file mode 100644 index e4f1fe37..00000000 --- a/src/MpvNet.Windows/WPF/Controls/CommandPaletteControl.xaml.cs +++ /dev/null @@ -1,150 +0,0 @@ - -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Windows; -using System.Windows.Controls; -using System.Windows.Data; -using System.Windows.Input; - -using CommunityToolkit.Mvvm.Input; - -using MpvNet.Windows.UI; -using MpvNet.Windows.WinForms; - -namespace MpvNet.Windows.WPF.Controls; - -public partial class CommandPaletteControl : UserControl -{ - public ICollectionView CollectionView { get; set; } - public CollectionViewSource CollectionViewSource { get; } - public ObservableCollection Items { get; } = new ObservableCollection(); - - public CommandPaletteControl() - { - InitializeComponent(); - DataContext = this; - CollectionViewSource = new CollectionViewSource() { Source = Items }; - CollectionView = CollectionViewSource.View; - CollectionView.Filter = new Predicate(item => Filter((CommandPaletteItem)item)); - MainListView.ItemsSource = CollectionView; - - SearchControl.SearchTextBox.PreviewKeyDown += SearchTextBox_PreviewKeyDown; - SearchControl.SearchTextBox.TextChanged += SearchTextBox_TextChanged; - SearchControl.HideClearButton = true; - - if (Environment.OSVersion.Version < new Version(10, 0)) - MainBorder.CornerRadius = new CornerRadius(0); - } - - void SearchTextBox_TextChanged(object sender, TextChangedEventArgs e) - { - CollectionView.Refresh(); - SelectFirst(); - } - - void SearchTextBox_PreviewKeyDown(object sender, KeyEventArgs e) - { - switch (e.Key) - { - case Key.Up: - { - int index = MainListView.SelectedIndex; - index -= 1; - - if (index < 0) - index = 0; - - MainListView.SelectedIndex = index; - MainListView.ScrollIntoView(MainListView.SelectedItem); - } - break; - case Key.Down: - { - int index = MainListView.SelectedIndex; - - if (++index > MainListView.Items.Count - 1) - index = MainListView.Items.Count - 1; - - MainListView.SelectedIndex = index; - MainListView.ScrollIntoView(MainListView.SelectedItem); - } - break; - } - } - - void MainListView_SizeChanged(object sender, SizeChangedEventArgs e) => AdjustHeight(); - - void MainListView_MouseUp(object sender, MouseButtonEventArgs e) => ExecuteInternal(); - - [RelayCommand] - void Escape(object param) => MainForm.Instance?.HideCommandPalette(); - - [RelayCommand] - void Execute() => ExecuteInternal(); - - void OnLoaded(object sender, RoutedEventArgs e) => Keyboard.Focus(SearchControl.SearchTextBox); - - public Theme Theme => Theme.Current!; - - bool Filter(CommandPaletteItem item) - { - string filter = SearchControl.SearchTextBox.Text.ToLower(); - - if (item.Binding != null) - { - //if (item.CommandItem.Alias.ContainsEx(filter)) - // return true; - - if (filter.Length == 1) - return item.Binding.Input.ToLower() - .Replace("ctrl+", "") - .Replace("shift+", "") - .Replace("alt+", "") == filter.ToLower(); - - if (item.Binding.Command.ToLower().Contains(filter)) - return true; - } - - if (filter == "" || item.Text.ToLower().Contains(filter) || - item.SecondaryText.ToLower().Contains(filter)) - - return true; - - return false; - } - - public void SelectFirst() - { - if (MainListView.Items.Count > 0) - { - MainListView.SelectedIndex = 0; - MainListView.ScrollIntoView(MainListView.SelectedItem); - } - } - - void ExecuteInternal() - { - if (MainListView.SelectedItem != null) - { - CommandPaletteItem? item = MainListView.SelectedItem as CommandPaletteItem; - MainForm.Instance?.HideCommandPalette(); - item?.Action?.Invoke(); - //MainForm.Instance.Voodoo(); //TODO: Voodoo - } - } - - public void SetItems(IEnumerable items) - { - Items.Clear(); - - foreach (var i in items) - Items.Add(i); - } - - public void AdjustHeight() - { - double actualHeight = SearchControl.ActualHeight + MainListView.ActualHeight + 5 + 16; - int dpi = MainForm.GetDpi(MainForm.Instance!.Handle); - MainForm.Instance.CommandPaletteHost.Height = (int)(actualHeight / 96.0 * dpi); - } -} diff --git a/src/MpvNet.Windows/WinForms/MainForm.cs b/src/MpvNet.Windows/WinForms/MainForm.cs index 64553865..ea06240e 100644 --- a/src/MpvNet.Windows/WinForms/MainForm.cs +++ b/src/MpvNet.Windows/WinForms/MainForm.cs @@ -27,7 +27,6 @@ public partial class MainForm : Form { public SnapManager SnapManager = new SnapManager(); public IntPtr MpvWindowHandle { get; set; } - public ElementHost? CommandPaletteHost { get; set; } public bool WasShown { get; set; } public static MainForm? Instance { get; set; } WpfControls.ContextMenu ContextMenu { get; } = new WpfControls.ContextMenu(); @@ -280,8 +279,6 @@ bool IsMouseInOsc() pos.Y > ClientSize.Height * 0.78; } - bool IsCommandPaletteVissible() => CommandPaletteHost != null && CommandPaletteHost.Visible; - void UpdateMenu() { Player.UpdateExternalTracks(); @@ -1254,8 +1251,7 @@ void CursorTimer_Tick(object sender, EventArgs e) else if ((Environment.TickCount - _lastCursorChanged > 1500 || Environment.TickCount - _lastCursorChanged > 5000) && ClientRectangle.Contains(PointToClient(MousePosition)) && - ActiveForm == this && !ContextMenu.IsVisible && !IsMouseInOsc() && - !IsCommandPaletteVissible()) + ActiveForm == this && !ContextMenu.IsVisible && !IsMouseInOsc()) HideCursor(); } @@ -1515,103 +1511,4 @@ public static int GetDpi(IntPtr hwnd) [DllImport("DwmApi")] static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, int[] attrValue, int attrSize); - - //protected override void OnLayout(LayoutEventArgs args) - //{ - // base.OnLayout(args); - // AdjustCommandPaletteLeftAndWidth(); - //} - - //class ElementHostEx : ElementHost - //{ - // protected override void OnHandleCreated(EventArgs e) - // { - // base.OnHandleCreated(e); - // const int LWA_ColorKey = 1; - - // if (Environment.OSVersion.Version > new Version(10, 0)) - // SetLayeredWindowAttributes(Handle, 0x111111, 255, LWA_ColorKey); - // } - - // protected override CreateParams CreateParams - // { - // get - // { - // CreateParams cp = base.CreateParams; - - // if (Environment.OSVersion.Version > new Version(10, 0)) - // cp.ExStyle |= 0x00080000; // WS_EX_LAYERED - - // cp.ExStyle |= 0x00000008; // WS_EX_TOPMOST - - // cp.Style |= 0x04000000; //WS_CLIPSIBLINGS - // cp.Style |= 0x02000000; //WS_CLIPCHILDREN - - // return cp; - // } - // } - - // protected override bool ProcessCmdKey(ref Message msg, Keys keyData) - // { - // try - // { - // return base.ProcessCmdKey(ref msg, keyData); - // } - // catch (Exception) - // { - // return true; - // } - // } - - // [DllImport("user32.dll")] - // public static extern bool SetLayeredWindowAttributes(IntPtr hWnd, int crKey, byte alpha, int dwFlags); - //} - - //public void ShowCommandPalette() - //{ - // if (CommandPaletteHost == null) - // { - // CommandPaletteHost = new ElementHostEx(); - // CommandPaletteHost.Dock = DockStyle.Fill; - // CommandPaletteHost.BackColor = Color.FromArgb(0x111111); - - // AdjustCommandPaletteLeftAndWidth(); - // CommandPaletteHost.Child = CommandPalette.Instance; - // CommandPalette.Instance.AdjustHeight(); - // Controls.Add(CommandPaletteHost); - // CommandPaletteHost.BringToFront(); - // } - //} - - public void HideCommandPalette() - { - if (CommandPaletteHost != null) - { - CommandPaletteHost.Visible = false; - - CommandPalette.Instance.Items.Clear(); - CommandPalette.Instance.SearchControl.SearchTextBox.Text = ""; - CommandPalette.Instance.UpdateLayout(); - - ActiveControl = null; - Controls.Remove(CommandPaletteHost); - - CommandPaletteHost.Child = null; - CommandPaletteHost.Dispose(); - CommandPaletteHost = null; - } - } - - //void AdjustCommandPaletteLeftAndWidth() - //{ - // if (CommandPaletteHost == null) - // return; - - // CommandPaletteHost.Width = FontHeight * 26; - - // if (CommandPaletteHost.Width > ClientSize.Width) - // CommandPaletteHost.Width = ClientSize.Width; - - // CommandPaletteHost.Left = (ClientSize.Width - CommandPaletteHost.Size.Width) / 2; - //} } diff --git a/src/MpvNet/InputHelp.cs b/src/MpvNet/InputHelp.cs index dab3ef79..06d64cc2 100644 --- a/src/MpvNet/InputHelp.cs +++ b/src/MpvNet/InputHelp.cs @@ -117,20 +117,31 @@ public static List GetDefaults() new (_("Speed"), "-"), new (_("Speed"), _("Reset"), "set speed 1", "BS"), - new (_("View"), _("Show Playlist"), "script-message-to mpvnet show-playlist", "F8"), new (_("View"), _("Toggle Statistics"), "script-binding stats/display-stats-toggle", "t"), new (_("View"), _("Toggle OSC Visibility"), "script-binding osc/visibility", "Del"), new (_("View"), _("Show Media Info On-Screen"), "script-message-to mpvnet show-media-info osd", "i"), new (_("View"), _("Show Media Info Message Box"), "script-message-to mpvnet show-media-info msgbox", "Ctrl+m"), new (_("View"), _("Show Progress"), "show-progress", "p"), + + new (_("View") + " > " + _("On Screen Menu"), _("Playlist"), "script-binding select/select-playlist", "F8"), + new (_("View") + " > " + _("On Screen Menu"), _("Bindings"), "script-binding select/select-binding", "F1"), + new (_("View") + " > " + _("On Screen Menu"), _("Properties"), "script-binding select/show-properties", "F3"), + new (_("View") + " > " + _("On Screen Menu"), _("Chapters"), "script-binding select/select-chapter", "Alt+c"), + new (_("View") + " > " + _("On Screen Menu"), _("Tracks"), "script-binding select/select-track", "Alt+t"), + new (_("View") + " > " + _("On Screen Menu"), _("Audio Tracks"), "script-binding select/select-aid"), + new (_("View") + " > " + _("On Screen Menu"), _("Subtitle Tracks"), "script-binding select/select-sid"), + new (_("View") + " > " + _("On Screen Menu"), _("Secondary Subtitle"), "script-binding select/select-secondary-sid", "Alt+F2"), + new (_("View") + " > " + _("On Screen Menu"), _("Video Tracks"), "script-binding select/select-vid", "Alt+v"), + new (_("View") + " > " + _("On Screen Menu"), _("Subtitle Lines"), "script-binding select/select-subtitle-line", "Alt+l"), + new (_("View") + " > " + _("On Screen Menu"), _("Audio Devices"), "script-binding select/select-audio-device", "Alt+d"), + new (_("View") + " > " + _("More"), _("Show Console"), "script-binding console/enable", "`"), new (_("View") + " > " + _("More"), _("Show Audio Devices"), "script-message-to mpvnet show-audio-devices"), new (_("View") + " > " + _("More"), _("Show Commands"), "script-message-to mpvnet show-commands", "F2"), new (_("View") + " > " + _("More"), _("Show Bindings"), "script-message-to mpvnet show-bindings"), - new (_("View") + " > " + _("More"), _("Show Properties"), "script-message-to mpvnet show-properties", "F3"), new (_("View") + " > " + _("More"), _("Show Keys"), "script-message-to mpvnet show-keys", "Alt+k"), new (_("View") + " > " + _("More"), _("Show Protocols"), "script-message-to mpvnet show-protocols", "Alt+p"), - new (_("View") + " > " + _("More"), _("Show Decoders"), "script-message-to mpvnet show-decoders", "Alt+d"), + new (_("View") + " > " + _("More"), _("Show Decoders"), "script-message-to mpvnet show-decoders"), new (_("View") + " > " + _("More"), _("Show Demuxers"), "script-message-to mpvnet show-demuxers"), new (_("Window"), _("Fullscreen"), "cycle fullscreen", "Enter"), @@ -216,8 +227,6 @@ public static List GetDefaults() new ("", "", "no-osd seek 5", "Ctrl+Wheel_Up", _("Seek Forward")), new ("", "", "no-osd seek -5", "Ctrl+Wheel_Down", _("Seek Backward")), new ("", "", "quit", "Power", _("Exit")), - - //new (_("Command Palette"), _("Commands"), "script-message-to mpvnet show-command-palette", "F1"), }; return bindings; @@ -413,54 +422,6 @@ public static List GetEditorBindings(string content) return defaults; } - // only used by dead command palette - public static List GetBindingsFromContent(string content) - { - var bindings = new List(); - - if (!string.IsNullOrEmpty(content)) - { - foreach (string line in content.Split('\r', '\n')) - { - string value = line.Trim(); - - if (value.StartsWith("#")) - continue; - - if (!value.Contains(' ')) - continue; - - Binding binding = new Binding(); - binding.Input = value[..value.IndexOf(" ")]; - - if (binding.Input == "_") - binding.Input = ""; - - value = value[(value.IndexOf(" ") + 1)..]; - - if (value.Contains(App.MenuSyntax)) - { - binding.Comment = value[(value.IndexOf(App.MenuSyntax) + App.MenuSyntax.Length)..].Trim(); - value = value[..value.IndexOf(App.MenuSyntax)]; - - if (binding.Comment.Contains(';')) - binding.Comment = binding.Comment[(binding.Comment.IndexOf(";") + 1)..].Trim(); - } - - binding.Command = value.Trim(); - - if (binding.Command == "") - continue; - - if (binding.Command.ToLower() == "ignore") - binding.Command = ""; - - bindings.Add(binding); - } - } - return bindings; - } - public static Dictionary GetActiveBindings(List bindings) { Dictionary ret = new(); diff --git a/src/Tools/update-mpv-and-libmpv.ps1 b/src/Tools/update-mpv-and-libmpv.ps1 index fecc9014..ce733832 100644 --- a/src/Tools/update-mpv-and-libmpv.ps1 +++ b/src/Tools/update-mpv-and-libmpv.ps1 @@ -1,21 +1,14 @@ <# -This script updates mpv and libmpv using github.com/zhongfly/mpv-winbuild - -Two positional command line arguments need to be passed into the script: - -1. The directory containing libmpv to be updated. -2. The directory containing mpv to be updated. - -To skip one of both pass 'no' instead of the path. - -Requires 7zip being installed at 'C:\Program Files\7-Zip\7z.exe' +Updates mpv and libmpv used by mpv.net. +It uses the Path environment variable to find mpv and mpv.net. +Files are downloaded from github.com/zhongfly/mpv-winbuild. +Requires 7zip being installed at 'C:\Program Files\7-Zip\7z.exe'. #> -$zip7Path = 'C:\Program Files\7-Zip\7z.exe' -$ScriptArgs = $args +$Zip7Path = 'C:\Program Files\7-Zip\7z.exe' # Stop when the first error occurs $ErrorActionPreference = 'Stop' @@ -42,13 +35,12 @@ function Download($pattern) { function Unpack($archieveFile, $outputRootDir) { $outputDir = Join-Path $outputRootDir $archieveFile.BaseName if (Test-Path $outputDir) { Remove-Item $outputDir -Recurse } - $process = Start-Process (Test $zip7Path) @('x', $archieveFile.FullName, "-o$outputDir") -NoNewWindow -Wait + $process = Start-Process (Test $Zip7Path) @('x', $archieveFile.FullName, "-o$outputDir") -NoNewWindow -Wait if ($process.ExitCode) { throw $process.ExitCode } return Test $outputDir } -function UpdateLibmpv { - $targetFolder = $ScriptArgs[0] +function UpdateLibmpv($targetFolder) { if ($targetFolder -eq 'no') { return } $archiveFile = Get-Item (Download "mpv-dev-x86_64-[0-9]{8}") $archiveDir = Unpack $archiveFile $env:TEMP @@ -57,17 +49,43 @@ function UpdateLibmpv { Remove-Item $archiveDir -Recurse } -function UpdateMpv() { - $targetFolder = $ScriptArgs[1] +function UpdateMpv($targetFolder) { if ($targetFolder -eq 'no') { return } $archiveFile = Get-Item (Download "mpv-x86_64-[0-9]{8}") $archiveDir = Unpack $archiveFile $env:TEMP - Copy-Item "$archiveDir\mpv\*" $targetFolder -Force -Recurse + Copy-Item "$archiveDir\*" $targetFolder -Force -Recurse Remove-Item $archiveFile.FullName Remove-Item $archiveDir -Recurse } -UpdateLibmpv -UpdateMpv +# Update mpv + +$MpvLocations = @() + (cmd /c where mpv.exe) + +if ($MpvLocations.Length -gt 0) { + $mpvDir = Split-Path ($MpvLocations[0]) + ''; 'mpv found at:'; $mpvDir + $result = Read-Host 'Update mpv? [y/n]' + + if ($result -eq 'y') { + UpdateMpv $mpvDir + } +} else { + 'mpv location not found.' +} + +# Update libmpv used by mpv.net + +$MpvNetLocations = @() + (cmd /c where mpvnet.exe) -Write-Host 'Script finished successfully' -ForegroundColor Green +if ($MpvNetLocations.Length -gt 0) { + $mpvNetDir = Split-Path ($MpvNetLocations[0]) + ''; 'mpv.net found at:'; $mpvNetDir + $result = Read-Host 'Update libmpv? [y/n]' + + if ($result -eq 'y') { + UpdateLibmpv $mpvNetDir + } +} else { + 'mpv.net location not found.' +}