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
This commit is contained in:
stax76
2024-07-15 02:10:30 +02:00
parent ae9c69e469
commit ae80076f36
10 changed files with 64 additions and 551 deletions

View File

@@ -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)

View File

@@ -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.

View File

@@ -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 @@ public class GuiCommand
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 @@ public class GuiCommand
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 @@ public class GuiCommand
// 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();
// });
//}

View File

@@ -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<CommandPaletteItem> 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
});
}
}

View File

@@ -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; }
}

View File

@@ -1,127 +0,0 @@
<UserControl
x:Class="MpvNet.Windows.WPF.Controls.CommandPaletteControl"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:MpvNet.Windows.WPF.Controls"
mc:Ignorable="d"
FontSize="13"
Loaded="OnLoaded"
Background="#111111"
>
<UserControl.InputBindings>
<KeyBinding Gesture="Esc" Command="{Binding EscapeCommand}"/>
<KeyBinding Gesture="Enter" Command="{Binding ExecuteCommand}"/>
</UserControl.InputBindings>
<Border Name="MainBorder"
BorderThickness="1,0,1,1"
CornerRadius="0,0,5,5"
Padding="0,0,0,5"
BorderBrush="{Binding Theme.MenuHighlight}"
Background="{Binding Theme.Background}"
SnapsToDevicePixels="True"
>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto" />
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Border BorderBrush="{Binding Theme.Heading}"
BorderThickness="1"
CornerRadius="3"
Margin="7"
>
<controls:SearchControl
HintText="Search"
x:Name="SearchControl"
Grid.ColumnSpan="2"
Padding="1,1,1,0"
/>
</Border>
<ListView
Name="MainListView"
Grid.Row="1"
Foreground="{Binding Theme.Foreground}"
Background="{Binding Theme.Background}"
BorderThickness="0"
MaxHeight="202"
SizeChanged="MainListView_SizeChanged"
MouseUp="MainListView_MouseUp"
>
<ListView.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
<Setter Property="Height" Value="25"></Setter>
<Setter Property="BorderThickness" Value="0"></Setter>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ListBoxItem}">
<Border x:Name="BD"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Background="{TemplateBinding Background}"
Padding="{TemplateBinding Padding}"
SnapsToDevicePixels="true">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
<ControlTemplate.Triggers>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="BD" Value="{DynamicResource HighlightBrush}" />
</MultiTrigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="Selector.IsSelectionActive" Value="False" />
<Condition Property="IsSelected" Value="True" />
</MultiTrigger.Conditions>
<Setter Property="Background" TargetName="BD" Value="{DynamicResource BorderBrush}" />
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Resources>
<Style TargetType="Border">
<Setter Property="CornerRadius" Value="3"/>
</Style>
</Style.Resources>
</Style>
</ListView.ItemContainerStyle>
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition />
</Grid.ColumnDefinitions>
<TextBlock Text="{Binding Text}"></TextBlock>
<TextBlock
Grid.Column="1"
Text="{Binding SecondaryText}"
HorizontalAlignment="Right"
/>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Grid>
</Border>
</UserControl>

View File

@@ -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<CommandPaletteItem> Items { get; } = new ObservableCollection<CommandPaletteItem>();
public CommandPaletteControl()
{
InitializeComponent();
DataContext = this;
CollectionViewSource = new CollectionViewSource() { Source = Items };
CollectionView = CollectionViewSource.View;
CollectionView.Filter = new Predicate<object>(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<CommandPaletteItem> 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);
}
}

View File

@@ -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 @@ public partial class MainForm : Form
pos.Y > ClientSize.Height * 0.78;
}
bool IsCommandPaletteVissible() => CommandPaletteHost != null && CommandPaletteHost.Visible;
void UpdateMenu()
{
Player.UpdateExternalTracks();
@@ -1254,8 +1251,7 @@ public partial class MainForm : Form
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 partial class MainForm : Form
[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;
//}
}

View File

@@ -117,20 +117,31 @@ public static class InputHelp
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 class InputHelp
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 class InputHelp
return defaults;
}
// only used by dead command palette
public static List<Binding> GetBindingsFromContent(string content)
{
var bindings = new List<Binding>();
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<string, Binding> GetActiveBindings(List<Binding> bindings)
{
Dictionary<string, Binding> ret = new();

View File

@@ -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
Write-Host 'Script finished successfully' -ForegroundColor Green
$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)
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.'
}