Compare commits

...

20 Commits

Author SHA1 Message Date
Frank Skare
7d31237d5f fix release script 2020-05-11 17:14:23 +02:00
Frank Skare
3705e2abbf 5.4.8.0 2020-05-11 17:08:01 +02:00
Frank Skare
7d73529c83 fix beep sound when closed from taskbar 2020-05-11 12:16:40 +02:00
Frank Skare
2e59d49ad1 2 bugs fixed 2020-05-11 03:51:52 +02:00
Frank Skare
f61eef8961 5.4.7.4 Beta 2020-05-10 07:01:59 +02:00
Frank Skare
efb4c085d5 fix release script 2020-05-08 15:56:54 +02:00
Frank Skare
4a045d6a91 setting media-keys added 2020-05-08 15:32:47 +02:00
Frank Skare
da1a78cfa3 5.4.7.2 Beta 2020-05-08 09:22:19 +02:00
Frank Skare
5b3697fbde built-in WM_APPCOMMAND support 2020-05-08 08:26:44 +02:00
Frank Skare
726d759589 misc 2020-05-07 13:32:23 +02:00
Frank Skare
ed614332f7 misc 2020-05-07 13:21:59 +02:00
Frank Skare
9d46064dca 5.4.7.1 Beta 2020-05-07 11:47:09 +02:00
Frank Skare
407b49b3ad 5.4.7.0 2020-05-06 18:51:38 +02:00
Frank Skare
0e92d4ec0c 5.4.7.0 2020-05-06 18:43:20 +02:00
Frank Skare
4f96835e19 support avisynth portable 2020-05-06 11:11:09 +02:00
Frank Skare
56d954d94e manual 2020-05-04 16:30:39 +02:00
Frank Skare
a8aeb1e3e9 manual 2020-05-04 16:28:59 +02:00
Frank Skare
415fd266a2 log error fix 2020-05-04 15:15:40 +02:00
Frank Skare
51f9e17380 5.4.6.0 2020-05-04 05:50:29 +02:00
Frank Skare
28045ad33e 5.4.5.1 Beta 2020-05-03 11:10:56 +02:00
62 changed files with 1630 additions and 1354 deletions

View File

@@ -1,8 +1,80 @@
5.4.4.7 Beta (not yet released)
5.4.8.1 Beta (not yet released)
============
-
5.4.8.0
=======
- fix learn window of input editor (much work)
- fix black one pixel bar on right side
- fix beep sound when closed from taskbar
5.4.7.4 Beta (not yet released)
============
- the media key issue should now be fixed!
- libmpv and youtube-dl update
5.4.7.3 Beta
============
- new setting media-keys added, can be found in the config editor in the input tab.
5.4.7.2 Beta
============
- another attempt to fix a app command issue. WM_APPCOMMAND (mpv calls this media keys)
based input is no longer directly passed to mpv but rather handled in mpv.net directly
translating the native commands to mpv keys and sent via keypress input command to mpv
- another attempt to fix a crash caused by powershell 5.1 not being installed
5.4.7.1 Beta
============
- log error fix, mpv.net does now ignore all log messages because libmpv already
prints the log messages to the the terminal
- the release script now also outputs x86 beta versions so x86 users can test betas
5.4.7.0
=======
- log error fix
- workaround to support AviSynth portable (ffmpeg blocks loading AviSynth from path env var)
- attempt to fix not reproducible volume input issue
- attempt to fix exception caused by powershell being not available on Win 7
5.4.6.0
=======
- youtube-dl update
- auto update routine fix
5.4.5.1 Beta
============
- extensions no longer need to end with *Extension.dll but rather
the file name and the directory name must be identical
- text encoding exception fix
- the PowerShell script host is more feature complete, easier to use
and more efficient, there were however many PowerShell and C# breaking
changes requrired to make the core more robust and efficient
- Python 2 script host removed, Python 3 support is planned for summer
5.4.5.0
=======
stable release, no changes since the last beta
5.4.4.6 Beta

View File

@@ -166,7 +166,9 @@ After the file associations were registered, go to the Windows settings under 'S
It's possible to change the default application using the 'Open with' feature of the context menu in File Explorer.
[Open with++](#open-with) can be used to extend the File Explorer context menu to get menu items for 'Play with mpv.net' and 'Add to mpv.net playlist'.
[Open with++](#open-with) can be used to extend the File Explorer context menu to get menu items for [Play with mpv.net](https://github.com/stax76/OpenWithPlusPlus#play-with-mpvnet) and [Add to mpv.net playlist](https://github.com/stax76/OpenWithPlusPlus#add-to-mpvnet-playlist).
When multiple files are selected in File Explorer and enter is pressed then the files are opened in mpv.net in random order, this works with maximum 15 files.
Support
@@ -174,9 +176,9 @@ Support
Before making a support request, please try a newer [beta version](#beta) first.
[Support thread in VideoHelp forum](https://forum.videohelp.com/threads/392514-mpv-net-a-extendable-media-player-for-windows)
Bugs and feature requests can be made on the github [issue tracker](https://github.com/stax76/mpv.net/issues), feel free to use for anything mpv.net related.
[Issue tracker](https://github.com/stax76/mpv.net/issues), feel free to use for anything mpv.net related.
Or use the [support thread](https://forum.videohelp.com/threads/392514-mpv-net-a-extendable-media-player-for-windows) in the VideoHelp forum.
Settings
@@ -272,30 +274,7 @@ Alternatively he Chrome/Firefox extension [Open With](https://github.com/stax76/
### Open with++
Open with++ allows to customize the File Explorer context menu to add menu items 'Play with mpv.net' and 'Add to mpv.net playlist'.
https://github.com/stax76/OpenWithPlusPlus
https://github.com/stax76/OpenWithPlusPlus#mpvnet
https://github.com/stax76/OpenWithPlusPlus#add-to-mpvnet-playlist
### MediaInfo.NET
MediaInfo.NET is a media info GUI.
https://github.com/stax76/MediaInfo.NET
To start a external application mpv has the run input command (it does not use shell execute).
If the path has spaces then it must be enclosed in quotes and then double backslashes must be used for escaping or alternatively forward slashes.
`_ run D:\Software\MediaInfoNET.exe "${path}" #menu: Tools > Open file with MediaInfo.NET`
`_ run "D:\\Soft ware\\MediaInfoNET.exe" "${path}" #menu: Tools > Open file with MediaInfo.NET`
`_ run "D:/Soft ware/MediaInfoNET.exe" "${path}" #menu: Tools > Open file with MediaInfo.NET`
[Open with++](https://github.com/stax76/OpenWithPlusPlus) can be used to extend the File Explorer context menu to get menu items for [Play with mpv.net](https://github.com/stax76/OpenWithPlusPlus#play-with-mpvnet) and [Add to mpv.net playlist](https://github.com/stax76/OpenWithPlusPlus#add-to-mpvnet-playlist).
Scripting
@@ -341,7 +320,7 @@ The PowerShell scripting host is like extensions not initialized before media fi
mpv.net does not define scripting interfaces but instead exposed its complete internals, there are no compatibility guaranties.
[Example Scripts](scripts/examples)
[Example Scripts](scripts)
#### C#
@@ -358,16 +337,16 @@ Script code can be written within a C# [extension](#extensions), that way full c
The C# scripting host is like [extensions](#extensions) not initialized before media files are loaded.
[Example Scripts](scripts/examples)
[Example Scripts](scripts)
Extensions
----------
Extensions are located in the config folder and the filename must end with 'Extension.dll':
Extensions are located in a subfolder _extensions_ in the config folder and the filename must have the same name as the directory:
```Text
<config folder>\Extensions\ExampleExtension\ExampleExtension.dll
<config folder>\extensions\ExampleExtension\ExampleExtension.dll
```
mpv.net does not define extension interfaces but instead exposed its complete internals, there are no compatibility guaranties.
@@ -442,7 +421,7 @@ Selecting multiple files in File Explorer and pressing enter will open the files
Whenever the control key is pressed when files or URLs are opened, the playlist is not cleared but the files or URLs are appended to the playlist. This works in all mpv.net features that open files or URLs.
Pressing the shift key while opening a single file will suppress loading all files in the folder.
Pressing the shift key while opening a single file will suppress loading all files of the folder into the playlist.
In fullscreen mode clicking the top right corner closes the player.
@@ -538,9 +517,7 @@ input.conf defines mpvs key and mouse bindings and mpv.net uses comments to defi
The Open Files menu entry is one way to open files in mpv.net, it supports multi selection.
Another way to open files is the command line, it is used by the File Explorer if file associations exist.
When mpv.net is started from a terminal, mpv.net outputs status and debug messages on the terminal.
Another way to open files is the command line which is used by File Explorer for existing associations.
A third way is to drag and drop files on the main window.

View File

@@ -1,40 +1,6 @@
$ErrorActionPreference = 'Stop'
$include = @(
'*.cs',
'*.csproj',
'*.iss',
'*.js',
'*.lua',
'*.md',
'*.ps1',
'*.resx',
'*.sln',
'*.txt',
'*.xaml'
)
$files = Get-ChildItem -Path $PSScriptRoot -Recurse -File -Include $include
foreach ($file in $files)
{
$lines = Get-Content $file
foreach ($line in $lines)
{
foreach ($char in $line.ToCharArray())
{
$codePoint = [int]$char
if ($codePoint -gt 127)
{
throw "Non ASCII char $char in file '$($file.FullName)' in line: $line"
}
}
}
}
$desktopDir = [Environment]::GetFolderPath('Desktop')
$exePath = $PSScriptRoot + '\mpv.net\bin\x64\mpvnet.exe'
$versionInfo = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath)
@@ -43,6 +9,29 @@ $msBuild = $vsDir + '\Community\MSBuild\Current\Bin\MSBuild.exe'
$inno = 'C:\Program Files (x86)\Inno Setup 6\ISCC.exe'
$7z = 'C:\Program Files\7-Zip\7z.exe'
$cloudDirectories = 'C:\Users\frank\OneDrive\Public\mpv.net\',
'C:\Users\frank\Dropbox\Public\mpv.net\'
function UploadBeta($sourceFile)
{
foreach ($cloudDirectory in $cloudDirectories)
{
if (-not (Test-Path $cloudDirectory))
{
throw $cloudDirectory
}
$targetFile = $cloudDirectory + (Split-Path $sourceFile -Leaf)
if (Test-Path $targetFile)
{
throw $targetFile
}
Copy-Item $sourceFile $targetFile
}
}
if ($versionInfo.FilePrivatePart -eq 0)
{
& $msBuild mpv.net.sln -t:Rebuild -p:Configuration=Debug -p:Platform=x64
@@ -59,56 +48,50 @@ if ($versionInfo.FilePrivatePart -eq 0)
$targetDir = $desktopDir + "\mpv.net-portable-x64-$($versionInfo.FileVersion)"
Copy-Item .\mpv.net\bin\x64 $targetDir -Recurse -Exclude System.Management.Automation.xml
& $7z a -t7z -mx9 "$targetDir.7z" -r "$targetDir\*"
if ($LastExitCode) { throw $LastExitCode }
& $7z a -tzip -mx9 "$targetDir.zip" -r "$targetDir\*"
if ($LastExitCode) { throw $LastExitCode }
$targetDir = $desktopDir + "\mpv.net-portable-x86-$($versionInfo.FileVersion)"
Copy-Item .\mpv.net\bin\x86 $targetDir -Recurse -Exclude System.Management.Automation.xml
& $7z a -t7z -mx9 "$targetDir.7z" -r "$targetDir\*"
if ($LastExitCode) { throw $LastExitCode }
& $7z a -tzip -mx9 "$targetDir.zip" -r "$targetDir\*"
if ($LastExitCode) { throw $LastExitCode }
Set-Clipboard ($versionInfo.FileVersion + "`n`nChangelog:`n`n" +
'https://github.com/stax76/mpv.net/blob/master/Changelog.md' + "`n`nDownload:`n`n" +
'https://github.com/stax76/mpv.net/blob/master/Manual.md#stable')
}
else
{
& $msBuild mpv.net.sln -t:Rebuild -p:Configuration=Debug -p:Platform=x64
if ($LastExitCode) { throw $LastExitCode }
& $msBuild mpv.net.sln -t:Rebuild -p:Configuration=Debug -p:Platform=x86
if ($LastExitCode) { throw $LastExitCode }
$targetDir = "$desktopDir\mpv.net-portable-x64-$($versionInfo.FileVersion)-beta"
Copy-Item .\mpv.net\bin\x64 $targetDir -Recurse -Exclude System.Management.Automation.xml
& $7z a -t7z -mx9 "$targetDir.7z" -r "$targetDir\*"
if ($LastExitCode) { throw $LastExitCode }
UploadBeta "$targetDir.7z"
$cloudDirectories = 'C:\Users\frank\OneDrive\Public\mpv.net\',
'C:\Users\frank\Dropbox\Public\mpv.net\'
$targetDir = $desktopDir + "\mpv.net-portable-x86-$($versionInfo.FileVersion)-beta"
Copy-Item .\mpv.net\bin\x86 $targetDir -Recurse -Exclude System.Management.Automation.xml
& $7z a -t7z -mx9 "$targetDir.7z" -r "$targetDir\*"
if ($LastExitCode) { throw $LastExitCode }
UploadBeta "$targetDir.7z"
foreach ($cloudDirectory in $cloudDirectories)
{
if (-not (Test-Path $cloudDirectory))
{
throw $cloudDirectory
}
$targetFile = $cloudDirectory + (Split-Path $targetDir -Leaf) + '.7z'
if (Test-Path $targetFile)
{
throw $targetFile
}
Copy-Item ($targetDir + '.7z') $targetFile
Invoke-Item $cloudDirectory
}
Set-Clipboard ($versionInfo.FileVersion + " Beta`n`nChangelog:`n`n" +
'https://github.com/stax76/mpv.net/blob/master/Changelog.md' + "`n`nDownload:`n`n" +
'https://github.com/stax76/mpv.net/blob/master/Manual.md#beta')
}
Set-Clipboard ($versionInfo.FileVersion + "`n`n" +
'https://github.com/stax76/mpv.net/blob/master/Changelog.md' + "`n`n" +
'https://github.com/stax76/mpv.net#download')
Write-Host 'successfully finished' -ForegroundColor Green

View File

@@ -8,6 +8,7 @@ using System.Collections.Generic;
using System.IO;
using mpvnet;
using static mpvnet.Core;
namespace RatingExtension // the assembly name must end with 'Extension'
{
@@ -19,8 +20,8 @@ namespace RatingExtension // the assembly name must end with 'Extension'
public RatingExtension() // plugin initialization
{
mp.ClientMessage += ClientMessage; //handles keys defined in input.conf
mp.Shutdown += Shutdown; // handles MPV_EVENT_SHUTDOWN
core.ClientMessage += ClientMessage; //handles keys defined in input.conf
core.Shutdown += Shutdown; // handles MPV_EVENT_SHUTDOWN
}
// handles MPV_EVENT_SHUTDOWN
@@ -53,10 +54,10 @@ namespace RatingExtension // the assembly name must end with 'Extension'
if (int.TryParse(args[1], out int rating))
{
string path = mp.get_property_string("path");
string path = core.get_property_string("path");
if (!File.Exists(path)) return;
Dic[path] = rating;
mp.commandv("show-text", $"Rating: {rating}");
core.commandv("show-text", $"Rating: {rating}");
}
else if (args[1] == "about")
Msg.Show("Rating Extension", "This extension writes a rating to the filename of rated videos when mpv.net shuts down.\n\nThe input.conf defaults contain key bindings for this extension to set ratings.");

View File

@@ -13,6 +13,7 @@ using System.IO;
using mpvnet;
using CSScriptLibrary;
using static mpvnet.Core;
// the file name of extensions must end with 'Extension'
namespace ScriptingExtension
@@ -27,8 +28,8 @@ namespace ScriptingExtension
//Script = new Script();
List<string> files = new List<string>();
if (Directory.Exists(mp.ConfigFolder + "scripts-cs"))
files.AddRange(Directory.GetFiles(mp.ConfigFolder + "scripts-cs", "*.cs"));
if (Directory.Exists(core.ConfigFolder + "scripts-cs"))
files.AddRange(Directory.GetFiles(core.ConfigFolder + "scripts-cs", "*.cs"));
if (Directory.Exists(Folder.Startup + "scripts"))
foreach (string path in Directory.GetFiles(Folder.Startup + "scripts", "*.cs"))

View File

@@ -2,12 +2,13 @@
using System.IO;
using mpvnet;
using static mpvnet.Core;
class Script
{
public Script()
{
mp.Shutdown += Shutdown;
core.Shutdown += Shutdown;
}
void Shutdown()

View File

@@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DynamicGUI"
xmlns:UI="clr-namespace:UI"
xmlns:mpvnet="clr-namespace:mpvnet"
mc:Ignorable="d"
d:DesignHeight="450"
@@ -17,8 +17,8 @@
Margin="0,10"
BorderThickness="0"
IsReadOnly="True"
Foreground="{x:Static UI:Theme.Heading}"
Background="{x:Static UI:Theme.Background}" />
Foreground="{x:Static mpvnet:Theme.Heading}"
Background="{x:Static mpvnet:Theme.Background}" />
<ItemsControl x:Name="ItemsControl">
<ItemsControl.ItemTemplate>
@@ -32,7 +32,7 @@
FontSize="16"
FontWeight="Normal"
VerticalAlignment="Top"
Foreground="{x:Static UI:Theme.Foreground}"/>
Foreground="{x:Static mpvnet:Theme.Foreground}"/>
<TextBox x:Name="ItemHelpTextBox"
TextWrapping="WrapWithOverflow"
@@ -41,8 +41,8 @@
Margin="10,0,0,0" BorderThickness="0"
IsReadOnly="True" Padding="7,0,0,0"
MinHeight="0"
Foreground="{x:Static UI:Theme.Foreground2}"
Background="{x:Static UI:Theme.Background}"/>
Foreground="{x:Static mpvnet:Theme.Foreground2}"
Background="{x:Static mpvnet:Theme.Background}"/>
</WrapPanel>
</DataTemplate>
@@ -54,8 +54,8 @@
BorderThickness="0"
IsReadOnly="True"
Margin="0,10,0,0"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}"/>
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}"/>
<TextBlock x:Name="LinkTextBlock" Margin="0,10">
<local:HyperlinkEx x:Name="Link"></local:HyperlinkEx>
</TextBlock>

View File

@@ -4,7 +4,7 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DynamicGUI"
xmlns:UI="clr-namespace:UI"
xmlns:mpvnet="clr-namespace:mpvnet"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800">
@@ -16,8 +16,8 @@
Margin="0,10"
BorderThickness="0"
IsReadOnly="True"
Foreground="{x:Static UI:Theme.Heading}"
Background="{x:Static UI:Theme.Background}"/>
Foreground="{x:Static mpvnet:Theme.Heading}"
Background="{x:Static mpvnet:Theme.Background}"/>
<Grid Margin="0,0,0,10">
<Grid.ColumnDefinitions>
@@ -29,9 +29,9 @@
Width="150"
Height="20"
HorizontalAlignment="Left"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}"
CaretBrush="{x:Static UI:Theme.Foreground}"
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}"
CaretBrush="{x:Static mpvnet:Theme.Foreground}"
TextChanged="ValueTextBox_TextChanged"/>
<Button x:Name="Button"
@@ -47,8 +47,8 @@
TextWrapping="WrapWithOverflow"
BorderThickness="0"
IsReadOnly="True"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}"/>
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}"/>
<TextBlock x:Name="LinkTextBlock" Margin="0,10">
<local:HyperlinkEx x:Name="Link"></local:HyperlinkEx>

Binary file not shown.

View File

@@ -4,13 +4,10 @@ using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Windows.Forms;
using UI;
using static libmpv;
using System.Threading.Tasks;
using static mpvnet.Core;
namespace mpvnet
{
public static class App
@@ -21,7 +18,7 @@ namespace mpvnet
public static string[] SubtitleTypes { get; } = { "srt", "ass", "idx", "sup", "ttxt", "ssa", "smi" };
public static string RegPath { get; } = @"HKCU\Software\" + Application.ProductName;
public static string ConfPath { get => mp.ConfigFolder + "mpvnet.conf"; }
public static string ConfPath { get => core.ConfigFolder + "mpvnet.conf"; }
public static string ProcessInstance { get; set; } = "single";
public static string DarkMode { get; set; } = "always";
public static string DarkTheme { get; set; } = "dark";
@@ -49,8 +46,8 @@ namespace mpvnet
public static void Init()
{
string dummy = mp.ConfigFolder;
var dummy2 = mp.Conf;
string dummy = core.ConfigFolder;
var dummy2 = core.Conf;
foreach (var i in Conf)
ProcessProperty(i.Key, i.Value, true);
@@ -59,7 +56,7 @@ namespace mpvnet
{
try
{
string filePath = mp.ConfigFolder + "mpvnet-debug.log";
string filePath = core.ConfigFolder + "mpvnet-debug.log";
if (File.Exists(filePath))
File.Delete(filePath);
@@ -78,23 +75,16 @@ namespace mpvnet
string themeContent = null;
if (File.Exists(mp.ConfigFolder + "theme.conf"))
themeContent = File.ReadAllText(mp.ConfigFolder + "theme.conf");
if (File.Exists(core.ConfigFolder + "theme.conf"))
themeContent = File.ReadAllText(core.ConfigFolder + "theme.conf");
Theme.Init(
themeContent,
Properties.Resources.theme,
IsDarkMode ? DarkTheme : LightTheme);
mp.Shutdown += Shutdown;
mp.Initialized += Initialized;
mp.LogMessage += ShowFatalError;
}
static void ShowFatalError(mpv_log_level level, string msg)
{
if (!App.IsStartedFromTerminal && level == mpv_log_level.MPV_LOG_LEVEL_FATAL)
Msg.ShowError(msg);
core.Shutdown += Shutdown;
core.Initialized += Initialized;
}
public static void RunAction(Action action)
@@ -103,6 +93,7 @@ namespace mpvnet
try
{
action.Invoke();
Debug.WriteLine(Environment.TickCount);
}
catch (Exception e)
{
@@ -116,25 +107,36 @@ namespace mpvnet
if (obj is Exception e)
{
if (App.IsStartedFromTerminal)
ConsoleHelp.WriteError(e.ToString(), "mpv.net");
ConsoleHelp.WriteError(e.ToString());
else
Msg.ShowException(e);
}
else
{
if (App.IsStartedFromTerminal)
ConsoleHelp.WriteError(obj.ToString(), "mpv.net");
ConsoleHelp.WriteError(obj.ToString());
else
Msg.ShowError(obj.ToString());
}
}
public static void ShowError(string title, string msg)
{
if (App.IsStartedFromTerminal)
{
ConsoleHelp.WriteError(title);
ConsoleHelp.WriteError(msg);
}
else
Msg.ShowError(title, msg);
}
static void Initialized()
{
if (RememberVolume)
{
mp.set_property_int("volume", RegistryHelp.GetInt(App.RegPath, "Volume", 70));
mp.set_property_string("mute", RegistryHelp.GetString(App.RegPath, "Mute", "no"));
core.set_property_int("volume", RegistryHelp.GetInt(App.RegPath, "Volume", 70));
core.set_property_string("mute", RegistryHelp.GetString(App.RegPath, "Mute", "no"));
}
}
@@ -142,8 +144,8 @@ namespace mpvnet
{
if (RememberVolume)
{
RegistryHelp.SetValue(App.RegPath, "Volume", mp.get_property_int("volume"));
RegistryHelp.SetValue(App.RegPath, "Mute", mp.get_property_string("mute"));
RegistryHelp.SetValue(App.RegPath, "Volume", core.get_property_int("volume"));
RegistryHelp.SetValue(App.RegPath, "Mute", core.get_property_string("mute"));
}
}
@@ -184,7 +186,7 @@ namespace mpvnet
case "light-theme": LightTheme = value.Trim('\'', '"'); return true;
default:
if (writeError)
ConsoleHelp.WriteError($"unknown mpvnet.conf property: {name}", "mpv.net");
ConsoleHelp.WriteError($"unknown mpvnet.conf property: {name}");
return false;
}
}

View File

@@ -8,13 +8,13 @@ using System.Windows.Forms;
using System.Windows.Interop;
using VB = Microsoft.VisualBasic;
using ScriptHost;
using static NewLine;
using static mpvnet.Core;
namespace mpvnet
{
public class Command
public class Commands
{
public static void Execute(string id, string[] args)
{
@@ -36,7 +36,7 @@ namespace mpvnet
case "show-about": ShowDialog(typeof(AboutWindow)); break;
case "show-conf-editor": ShowDialog(typeof(ConfWindow)); break;
case "show-input-editor": ShowDialog(typeof(InputWindow)); break;
case "open-conf-folder": Process.Start(mp.ConfigFolder); break;
case "open-conf-folder": Process.Start(core.ConfigFolder); break;
case "shell-execute": Process.Start(args[0]); break;
case "show-info": ShowInfo(); break;
case "playlist-first": PlaylistFirst(); break;
@@ -49,7 +49,7 @@ namespace mpvnet
}
}
public static void InvokeOnMainThread(Action action) => MainForm.Instance.Invoke(action);
public static void InvokeOnMainThread(Action action) => MainForm.Instance.BeginInvoke(action);
public static void ShowDialog(Type winType)
{
@@ -74,7 +74,7 @@ namespace mpvnet
InvokeOnMainThread(new Action(() => {
using (var d = new OpenFileDialog() { Multiselect = true })
if (d.ShowDialog() == DialogResult.OK)
mp.LoadFiles(d.FileNames, loadFolder, append);
core.LoadFiles(d.FileNames, loadFolder, append);
}));
}
@@ -90,13 +90,13 @@ namespace mpvnet
{
if (Directory.Exists(d.SelectedPath + "\\BDMV"))
{
mp.set_property_string("bluray-device", d.SelectedPath);
mp.LoadFiles(new[] { @"bd://" }, false, false);
core.set_property_string("bluray-device", d.SelectedPath);
core.LoadFiles(new[] { @"bd://" }, false, false);
}
else
{
mp.set_property_string("dvd-device", d.SelectedPath);
mp.LoadFiles(new[] { @"dvd://" }, false, false);
core.set_property_string("dvd-device", d.SelectedPath);
core.LoadFiles(new[] { @"dvd://" }, false, false);
}
}
}
@@ -105,31 +105,31 @@ namespace mpvnet
public static void PlaylistFirst()
{
int pos = mp.get_property_int("playlist-pos");
int pos = core.get_property_int("playlist-pos");
if (pos != 0)
mp.set_property_int("playlist-pos", 0);
core.set_property_int("playlist-pos", 0);
}
public static void PlaylistLast()
{
int pos = mp.get_property_int("playlist-pos");
int count = mp.get_property_int("playlist-count");
int pos = core.get_property_int("playlist-pos");
int count = core.get_property_int("playlist-count");
if (pos < count - 1)
mp.set_property_int("playlist-pos", count - 1);
core.set_property_int("playlist-pos", count - 1);
}
public static void ShowHistory()
{
if (File.Exists(mp.ConfigFolder + "history.txt"))
Process.Start(mp.ConfigFolder + "history.txt");
if (File.Exists(core.ConfigFolder + "history.txt"))
Process.Start(core.ConfigFolder + "history.txt");
else
{
if (Msg.ShowQuestion("Create history.txt file in config folder?",
"mpv.net will write the date, time and filename of opened files to it.") == MsgResult.OK)
File.WriteAllText(mp.ConfigFolder + "history.txt", "");
File.WriteAllText(core.ConfigFolder + "history.txt", "");
}
}
@@ -139,13 +139,13 @@ namespace mpvnet
{
string performer, title, album, genre, date, duration, text = "";
long fileSize = 0;
string path = mp.get_property_string("path");
string path = core.get_property_string("path");
if (path.Contains("://"))
path = mp.get_property_string("media-title");
path = core.get_property_string("media-title");
int width = mp.get_property_int("video-params/w");
int height = mp.get_property_int("video-params/h");
int width = core.get_property_int("video-params/w");
int height = core.get_property_int("video-params/h");
if (File.Exists(path))
{
@@ -171,7 +171,7 @@ namespace mpvnet
text += "Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n";
text += "Type: " + path.ShortExt().ToUpper();
mp.commandv("show-text", text, "5000");
core.commandv("show-text", text, "5000");
return;
}
}
@@ -185,16 +185,16 @@ namespace mpvnet
"Size: " + mediaInfo.GetInfo(MediaInfoStreamKind.General, "FileSize/String") + "\n" +
"Type: " + path.ShortExt().ToUpper();
mp.commandv("show-text", text, "5000");
core.commandv("show-text", text, "5000");
return;
}
}
}
TimeSpan position = TimeSpan.FromSeconds(mp.get_property_number("time-pos"));
TimeSpan duration2 = TimeSpan.FromSeconds(mp.get_property_number("duration"));
string videoFormat = mp.get_property_string("video-format").ToUpper();
string audioCodec = mp.get_property_string("audio-codec-name").ToUpper();
TimeSpan position = TimeSpan.FromSeconds(core.get_property_number("time-pos"));
TimeSpan duration2 = TimeSpan.FromSeconds(core.get_property_number("duration"));
string videoFormat = core.get_property_string("video-format").ToUpper();
string audioCodec = core.get_property_string("audio-codec-name").ToUpper();
text = path.FileName() + "\n" +
FormatTime(position.TotalMinutes) + ":" +
@@ -208,12 +208,12 @@ namespace mpvnet
text += $"{videoFormat}\n{audioCodec}";
mp.commandv("show-text", text, "5000");
core.commandv("show-text", text, "5000");
string FormatTime(double value) => ((int)value).ToString("00");
}
catch (Exception e)
{
Msg.ShowException(e);
App.ShowException(e);
}
}
@@ -221,9 +221,12 @@ namespace mpvnet
{
InvokeOnMainThread(new Action(() => {
string command = VB.Interaction.InputBox("Enter a mpv command to be executed.", "Execute Command", RegistryHelp.GetString(App.RegPath, "RecentExecutedCommand"));
if (string.IsNullOrEmpty(command)) return;
if (string.IsNullOrEmpty(command))
return;
RegistryHelp.SetValue(App.RegPath, "RecentExecutedCommand", command);
mp.command(command, false);
core.command(command, false);
}));
}
@@ -231,12 +234,14 @@ namespace mpvnet
{
InvokeOnMainThread(new Action(() => {
string clipboard = System.Windows.Forms.Clipboard.GetText();
if (string.IsNullOrEmpty(clipboard) || (!clipboard.Contains("://") && !File.Exists(clipboard)) || clipboard.Contains("\n"))
{
Msg.ShowError("The clipboard does not contain a valid URL or file, URLs have to contain :// and are not allowed to contain a newline character.");
App.ShowError("No URL found", "The clipboard does not contain a valid URL or file.");
return;
}
mp.LoadFiles(new [] { clipboard }, false, Control.ModifierKeys.HasFlag(Keys.Control));
core.LoadFiles(new [] { clipboard }, false, Control.ModifierKeys.HasFlag(Keys.Control));
}));
}
@@ -245,7 +250,7 @@ namespace mpvnet
InvokeOnMainThread(new Action(() => {
using (var d = new OpenFileDialog())
{
string path = mp.get_property_string("path");
string path = core.get_property_string("path");
if (File.Exists(path))
d.InitialDirectory = Path.GetDirectoryName(path);
@@ -254,7 +259,7 @@ namespace mpvnet
if (d.ShowDialog() == DialogResult.OK)
foreach (string filename in d.FileNames)
mp.commandv("sub-add", filename);
core.commandv("sub-add", filename);
}
}));
}
@@ -264,40 +269,40 @@ namespace mpvnet
InvokeOnMainThread(new Action(() => {
using (var d = new OpenFileDialog())
{
string path = mp.get_property_string("path");
string path = core.get_property_string("path");
if (File.Exists(path))
d.InitialDirectory = Path.GetDirectoryName(path);
d.Multiselect = true;
if (d.ShowDialog() == DialogResult.OK)
foreach (string i in d.FileNames)
mp.commandv("audio-add", i);
core.commandv("audio-add", i);
}
}));
}
public static void CycleAudio()
{
string path = mp.get_property_string("path");
string path = core.get_property_string("path");
if (!File.Exists(path))
return;
using (MediaInfo mi = new MediaInfo(path))
{
MediaTrack[] audTracks = mp.MediaTracks.Where(track => track.Type == "a").ToArray();
MediaTrack[] audTracks = core.MediaTracks.Where(track => track.Type == "a").ToArray();
if (audTracks.Length < 2)
return;
int aid = mp.get_property_int("aid");
int aid = core.get_property_int("aid");
aid += 1;
if (aid > audTracks.Length)
aid = 1;
mp.commandv("set", "aid", aid.ToString());
mp.commandv("show-text", audTracks[aid - 1].Text.Substring(3), "5000");
core.commandv("set", "aid", aid.ToString());
core.commandv("show-text", audTracks[aid - 1].Text.Substring(3), "5000");
}
}
@@ -317,7 +322,7 @@ namespace mpvnet
''
}";
string json = mp.get_property_string("profile-list");
string json = core.get_property_string("profile-list");
string file = Path.GetTempPath() + @"\mpv profile-list.txt";
File.WriteAllText(file, BR + PowerShell.InvokeAndReturnString(code, "json", json));
Process.Start(file);
@@ -344,7 +349,7 @@ namespace mpvnet
}
}";
string json = mp.get_property_string("command-list");
string json = core.get_property_string("command-list");
string file = Path.GetTempPath() + @"\mpv command-list.txt";
File.WriteAllText(file, PowerShell.InvokeAndReturnString(code, "json", json) + BR);
Process.Start(file);
@@ -353,7 +358,7 @@ namespace mpvnet
static void ShowProperties()
{
string file = Path.GetTempPath() + @"\mpv property-list.txt";
var props = mp.get_property_string("property-list").Split(',').OrderBy(prop => prop);
var props = core.get_property_string("property-list").Split(',').OrderBy(prop => prop);
File.WriteAllText(file, BR + string.Join(BR, props) + BR);
Process.Start(file);
}

View File

@@ -1,10 +1,13 @@
using System;

using System;
using System.Collections.Generic;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;
using System.IO;
using System.Linq;
using static mpvnet.Core;
namespace mpvnet
{
public class Extension
@@ -25,20 +28,23 @@ namespace mpvnet
{
string[] knownExtensions = { "RatingExtension", "ScriptingExtension" };
foreach (string path in Directory.GetDirectories(dir))
foreach (string extDir in Directory.GetDirectories(dir))
{
if (knownExtensions.Contains(Path.GetFileName(path)))
catalog.Catalogs.Add(new DirectoryCatalog(path, "*Extension.dll"));
if (knownExtensions.Contains(Path.GetFileName(extDir)))
catalog.Catalogs.Add(new DirectoryCatalog(extDir, Path.GetFileName(extDir) + ".dll"));
else
Msg.ShowError("Failed to load extension", path + "\n\nOnly extensions that ship with mpv.net are allowed in <startup>\\extensions\n\nUser extensions have to use <config folder>\\extensions\n\nNever copy or install a new mpv.net version over a old mpv.net version.");
ConsoleHelp.WriteError("Failed to load extension:\n\n" + extDir +
"\n\nOnly extensions that ship with mpv.net are allowed in <startup>\\extensions" +
"\n\nUser extensions have to use <config folder>\\extensions" +
"\n\nNever copy or install a new mpv.net version over a old mpv.net version.");
}
}
dir = mp.ConfigFolder + "extensions";
dir = core.ConfigFolder + "extensions";
if (Directory.Exists(dir))
foreach (string i in Directory.GetDirectories(dir))
catalog.Catalogs.Add(new DirectoryCatalog(i, "*Extension.dll"));
foreach (string extDir in Directory.GetDirectories(dir))
catalog.Catalogs.Add(new DirectoryCatalog(extDir, Path.GetFileName(extDir) + ".dll"));
if (catalog.Catalogs.Count > 0)
{
@@ -48,7 +54,7 @@ namespace mpvnet
}
catch (Exception ex)
{
Msg.ShowException(ex);
App.ShowException(ex);
}
}
}

View File

@@ -1,45 +1,111 @@

using System;
using System.Diagnostics;
using System.Drawing;
using System.Windows.Forms;
public static class ConsoleHelp
namespace mpvnet
{
public static int Padding { get; set; }
public static void WriteError(object obj, string module = null) => Write(obj, module, ConsoleColor.Red, false);
public static void Write(object obj, string module = "mpv.net")
public static class ConsoleHelp
{
Write(obj, module, ConsoleColor.Black, true);
}
public static int Padding { get; set; }
public static void Write(object obj, string module, ConsoleColor color)
{
Write(obj, module, color, false);
}
public static void WriteError(object obj, string module = "mpv.net")
{
Write(obj, module, ConsoleColor.Red, false);
}
public static void Write(object obj, string module, ConsoleColor color, bool useDefaultColor)
{
if (obj == null)
return;
public static void Write(object obj, string module = "mpv.net")
{
Write(obj, module, ConsoleColor.Black, true);
}
string value = obj.ToString();
public static void Write(object obj, string module, ConsoleColor color)
{
Write(obj, module, color, false);
}
if (!string.IsNullOrEmpty(module))
module = "[" + module + "] ";
public static void Write(object obj, string module, ConsoleColor color, bool useDefaultColor)
{
if (obj == null)
return;
if (useDefaultColor)
string value = obj.ToString();
if (!string.IsNullOrEmpty(module))
module = "[" + module + "] ";
if (useDefaultColor)
Console.ResetColor();
else
Console.ForegroundColor = color;
value = module + value;
if (Padding > 0 && value.Length < Padding)
value = value.PadRight(Padding);
Console.WriteLine(value);
Console.ResetColor();
else
Console.ForegroundColor = color;
Trace.WriteLine(obj);
}
}
value = module + value;
public class CursorHelp
{
static bool IsVisible = true;
if (Padding > 0 && value.Length < Padding)
value = value.PadRight(Padding);
public static void Show()
{
if (!IsVisible)
{
Cursor.Show();
IsVisible = true;
}
}
Console.WriteLine(value);
Console.ResetColor();
Trace.WriteLine(obj);
public static void Hide()
{
if (IsVisible)
{
Cursor.Hide();
IsVisible = false;
}
}
public static bool IsPosDifferent(Point screenPos)
{
return
Math.Abs(screenPos.X - Control.MousePosition.X) > 10 ||
Math.Abs(screenPos.Y - Control.MousePosition.Y) > 10;
}
}
public class mpvHelp
{
public static string WM_APPCOMMAND_to_mpv_key(int value)
{
switch (value)
{
case 5: return "SEARCH"; // BROWSER_SEARCH
case 6: return "FAVORITES"; // BROWSER_FAVORITES
case 7: return "HOMEPAGE"; // BROWSER_HOME
case 15: return "MAIL"; // LAUNCH_MAIL
case 33: return "PRINT"; // PRINT
case 11: return "NEXT"; // MEDIA_NEXTTRACK
case 12: return "PREV"; // MEDIA_PREVIOUSTRACK
case 13: return "STOP"; // MEDIA_STOP
case 14: return "PLAYPAUSE"; // MEDIA_PLAY_PAUSE
case 46: return "PLAY"; // MEDIA_PLAY
case 47: return "PAUSE"; // MEDIA_PAUSE
case 48: return "RECORD"; // MEDIA_RECORD
case 49: return "FORWARD"; // MEDIA_FAST_FORWARD
case 50: return "REWIND"; // MEDIA_REWIND
case 51: return "CHANNEL_UP"; // MEDIA_CHANNEL_UP
case 52: return "CHANNEL_DOWN"; // MEDIA_CHANNEL_DOWN
}
return null;
}
}
}

View File

@@ -1,10 +1,8 @@

using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Runtime.CompilerServices;
@@ -14,6 +12,8 @@ using System.Windows.Forms;
using Microsoft.Win32;
using static mpvnet.Core;
namespace mpvnet
{
public class Sys
@@ -186,43 +186,13 @@ namespace mpvnet
public static ObservableCollection<CommandItem> Items {
get {
if (_Items is null)
_Items = GetItems(File.ReadAllText(mp.InputConfPath));
_Items = GetItems(File.ReadAllText(core.InputConfPath));
return _Items;
}
}
}
public class CursorHelp
{
static bool IsVisible = true;
public static void Show()
{
if (!IsVisible)
{
Cursor.Show();
IsVisible = true;
}
}
public static void Hide()
{
if (IsVisible)
{
Cursor.Hide();
IsVisible = false;
}
}
public static bool IsPosDifferent(Point screenPos)
{
return
Math.Abs(screenPos.X - Control.MousePosition.X) > 10 ||
Math.Abs(screenPos.Y - Control.MousePosition.Y) > 10;
}
}
public class Folder
{
public static string Startup { get; } = Application.StartupPath + @"\";

244
mpv.net/Misc/PowerShell.cs Normal file
View File

@@ -0,0 +1,244 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Threading;
using System.Threading.Tasks;
using static mpvnet.Core;
using static NewLine;
namespace mpvnet
{
public class PowerShell
{
public Runspace Runspace { get; set; }
public Pipeline Pipeline { get; set; }
public string Module { get; set; }
public bool Print { get; set; }
public List<string> Scripts { get; } = new List<string>();
public List<KeyValuePair<string, object>> Variables = new List<KeyValuePair<string, object>>();
public string[] Parameters { get; }
public event Action<string, object[]> Event;
public event Action<string, object> PropertyChanged;
public List<KeyValuePair<string, ScriptBlock>> EventHandlers = new List<KeyValuePair<string, ScriptBlock>>();
public List<KeyValuePair<string, ScriptBlock>> PropChangedHandlers = new List<KeyValuePair<string, ScriptBlock>>();
public static List<PowerShell> Instances { get; } = new List<PowerShell>();
public object Invoke() => Invoke(null, null);
public object Invoke(string variable, object obj)
{
try
{
Runspace = RunspaceFactory.CreateRunspace();
Runspace.ApartmentState = ApartmentState.STA;
Runspace.Open();
Pipeline = Runspace.CreatePipeline();
foreach (string script in Scripts)
Pipeline.Commands.AddScript(script);
if (Parameters != null)
foreach (string param in Parameters)
foreach (Command command in Pipeline.Commands)
command.Parameters.Add(null, param);
Runspace.SessionStateProxy.SetVariable("mp", this);
foreach (var i in Variables)
Runspace.SessionStateProxy.SetVariable(i.Key, i.Value);
if (!string.IsNullOrEmpty(variable))
Runspace.SessionStateProxy.SetVariable(variable, obj);
if (Print)
{
Pipeline.Output.DataReady += Output_DataReady;
Pipeline.Error.DataReady += Error_DataReady;
}
return Pipeline.Invoke();
}
catch (RuntimeException e)
{
string message = e.Message + BR + BR + e.ErrorRecord.ScriptStackTrace.Replace(
" <ScriptBlock>, <No file>", "") + BR + BR + Module + BR;
throw new PowerShellException(message);
}
catch (Exception e)
{
throw e;
}
}
public static string InvokeAndReturnString(string code, string varName, object varValue)
{
PowerShell ps = new PowerShell() { Print = false };
ps.Scripts.Add(code);
string ret = string.Join(Environment.NewLine, (ps.Invoke(varName, varValue)
as IEnumerable<object>).Select(item => item.ToString())).ToString();
ps.Runspace.Dispose();
return ret;
}
public void Output_DataReady(object sender, EventArgs e)
{
var output = sender as PipelineReader<PSObject>;
while (output.Count > 0)
ConsoleHelp.Write(output.Read(), Module);
}
public void Error_DataReady(object sender, EventArgs e)
{
var output = sender as PipelineReader<Object>;
while (output.Count > 0)
ConsoleHelp.WriteError(output.Read(), Module);
}
public void RedirectStreams(PSEventJob job)
{
if (Print)
{
job.Output.DataAdded += Output_DataAdded;
job.Error.DataAdded += Error_DataAdded;
}
}
public void commandv(params string[] args) => core.commandv(args);
public void command(string command) => core.command(command);
public bool get_property_bool(string name) => core.get_property_bool(name);
public void set_property_bool(string name, bool value) => core.set_property_bool(name, value);
public int get_property_int(string name) => core.get_property_int(name);
public void set_property_int(string name, int value) => core.set_property_int(name, value);
public double get_property_number(string name) => core.get_property_number(name);
public void set_property_number(string name, double value) => core.set_property_number(name, value);
public string get_property_string(string name) => core.get_property_string(name);
public void set_property_string(string name, string value) => core.set_property_string(name, value);
public void observe_property(string name, string type, ScriptBlock sb)
{
PropChangedHandlers.Add(new KeyValuePair<string, ScriptBlock>(name, sb));
switch (type)
{
case "bool": case "boolean":
core.observe_property_bool(name, (value) => Task.Run(() => PropertyChanged.Invoke(name, value)));
break;
case "string":
core.observe_property_string(name, (value) => Task.Run(() => PropertyChanged.Invoke(name, value)));
break;
case "int": case "integer":
core.observe_property_int(name, (value) => Task.Run(() => PropertyChanged.Invoke(name, value)));
break;
case "float": case "double":
core.observe_property_double(name, (value) => Task.Run(() => PropertyChanged.Invoke(name, value)));
break;
case "nil": case "none": case "native":
core.observe_property(name, () => Task.Run(() => PropertyChanged.Invoke(name, null)));
break;
default:
App.ShowError("Invalid Type", "Valid types are: bool or boolean, string, int or integer, float or double, nil or none or native");
break;
}
}
public void register_event(string name, ScriptBlock sb)
{
EventHandlers.Add(new KeyValuePair<string, ScriptBlock>(name, sb));
switch (name)
{
case "log-message":
core.LogMessageAsync += (level, msg) => Event.Invoke("log-message", new object[] { level, msg });
break;
case "end-file":
core.EndFileAsync += (reason) => Event.Invoke("end-file", new object[] { reason });
break;
case "client-message":
core.ClientMessageAsync += (args) => Event.Invoke("client-message", args);
break;
case "shutdown":
core.Shutdown += () => Event.Invoke("shutdown", null);
break;
case "get-property-reply":
core.GetPropertyReplyAsync += () => Event.Invoke("get-property-reply", null);
break;
case "set-property-reply":
core.SetPropertyReplyAsync += () => Event.Invoke("set-property-reply", null);
break;
case "command-reply":
core.CommandReplyAsync += () => Event.Invoke("command-reply", null);
break;
case "start-file":
core.StartFileAsync += () => Event.Invoke("start-file", null);
break;
case "file-loaded":
core.FileLoadedAsync += () => Event.Invoke("file-loaded", null);
break;
case "idle":
core.IdleAsync += () => Event.Invoke("idle", null);
break;
case "video-reconfig":
core.VideoReconfigAsync += () => Event.Invoke("video-reconfig", null);
break;
case "audio-reconfig":
core.AudioReconfigAsync += () => Event.Invoke("audio-reconfig", null);
break;
case "seek":
core.SeekAsync += () => Event.Invoke("seek", null);
break;
case "playback-restart":
core.PlaybackRestartAsync += () => Event.Invoke("playback-restart", null);
break;
}
}
void Output_DataAdded(object sender, DataAddedEventArgs e)
{
var output = sender as PSDataCollection<PSObject>;
ConsoleHelp.Write(output[e.Index], Module);
}
void Error_DataAdded(object sender, DataAddedEventArgs e)
{
var error = sender as PSDataCollection<ErrorRecord>;
ConsoleHelp.WriteError(error[e.Index], Module);
}
}
public class PowerShellException : Exception
{
public PowerShellException(string message) : base(message)
{
}
}
}

View File

@@ -6,6 +6,8 @@ using System.Collections.Generic;
using System.Threading;
using System.Diagnostics;
using static mpvnet.Core;
namespace mpvnet
{
static class Program
@@ -21,7 +23,7 @@ namespace mpvnet
if (App.IsStartedFromTerminal)
WinAPI.AttachConsole(-1 /*ATTACH_PARENT_PROCESS*/);
if (mp.ConfigFolder == "")
if (core.ConfigFolder == "")
return;
string[] args = Environment.GetCommandLineArgs().Skip(1).ToArray();

View File

@@ -2,7 +2,7 @@
using System.Collections.Generic;
using System.Windows.Media;
namespace UI
namespace mpvnet
{
public class Theme
{
@@ -45,7 +45,7 @@ namespace UI
if (!theme.Dictionary.ContainsKey(key))
{
isKeyMissing = true;
ConsoleHelp.WriteError($"Theme '{activeTheme}' misses '{key}'", "mpv.net");
ConsoleHelp.WriteError($"Theme '{activeTheme}' misses '{key}'");
break;
}
}

View File

@@ -6,6 +6,8 @@ using System.Reflection;
using System.Text.RegularExpressions;
using System.Windows.Forms;
using static mpvnet.Core;
namespace mpvnet
{
class UpdateCheck
@@ -61,7 +63,7 @@ namespace mpvnet
proc.Start();
}
mp.command("quit");
core.command("quit");
}
RegistryHelp.SetValue(RegistryHelp.ApplicationKey, "UpdateCheckVersion", onlineVersion.ToString());

View File

@@ -1,4 +1,5 @@
using System;

using System;
namespace mpvnet
{

View File

@@ -32,5 +32,5 @@ using System.Runtime.InteropServices;
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("5.4.5.0")]
[assembly: AssemblyFileVersion("5.4.5.0")]
[assembly: AssemblyVersion("5.4.8.0")]
[assembly: AssemblyFileVersion("5.4.8.0")]

View File

@@ -314,7 +314,7 @@ options = [{ name = "yes" },
name = "autofit"
file = "mpv"
filter = "Screen"
help = "<int> Initial window height in percent. Default: 50"
help = "<int> Initial window height in percent. Default: 60"
[[settings]]
name = "autofit-smaller"
@@ -348,7 +348,7 @@ help = "Threshold in milliseconds to wait for libmpv returning the video resolut
name = "minimum-aspect-ratio"
file = "mpvnet"
filter = "Screen"
help = "<float> Minimum aspect ratio for the window. Default: 1.2 (mpv.net specific setting)"
help = "<float> Minimum aspect ratio, if the AR is smaller than the defined value then the window AR is set to 16/9. This avoids a square window for Music with cover art. Default: 1.2 (mpv.net specific setting)"
[[settings]]
name = "remember-position"

View File

@@ -1,22 +1,31 @@
# This file defines the key and mouse bindings and the context menu
# of mpv.net. A input and config editor can be found in mpv.nets
# context menu under 'Settings'. The defaults of this file can be found at:
# This file defines the key and mouse bindings and the context menu of mpv.net.
# https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt
# A convenient input and config editor can be found in the context menu of mpv.net
# under 'Settings'.
# The defaults of mpv can be found at:
# https://github.com/mpv-player/mpv/blob/master/etc/input.conf
# mpv.net's defaults of mpv.conf contain: 'input-default-bindings = no'
# which disables mpv's input defaults. Every line in this file begins with a
# The mpv.conf defaults of mpv.net contain: 'input-default-bindings = no'
# which disables the input defaults of mpv. Every line in this file begins with a
# 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 do a text search on ' o '.
# mpv input commands: https://mpv.io/manual/master/#list-of-input-commands
# input test mode:
# mpvnet --input-test
# run mpv.net in input test mode with: mpvnet --input-test
# input key list:
# mpv --input-keylist
# mpv.net input.conf defaults:
# https://github.com/stax76/mpv.net/blob/master/mpv.net/Resources/input.conf.txt
# mpv input.conf defaults:
# https://github.com/mpv-player/mpv/blob/master/etc/input.conf
# mpv input commands:
# https://mpv.io/manual/master/#list-of-input-commands
# mpv input options:
# https://mpv.io/manual/master/#input
o script-message mpv.net open-files #menu: Open > Open Files...
u script-message mpv.net open-url #menu: Open > Open URL or file path from clipboard
@@ -180,9 +189,6 @@
Stop stop
Forward seek 60
Rewind seek -60
Mute cycle mute
Volume_Up add volume 10
Volume_Down add volume -10
Wheel_Up add volume 10
Wheel_Down add volume -10
Wheel_Left add volume -10

View File

@@ -1,61 +0,0 @@

using System;
using System.IO;
using System.Reflection;
using Microsoft.Scripting;
using Microsoft.Scripting.Hosting;
using IronPython.Hosting;
using IronPython.Runtime;
using IronPython.Runtime.Operations;
namespace mpvnet
{
public class PythonScript
{
ScriptEngine engine;
ScriptScope scope;
public PythonScript(string scriptPath)
{
try
{
engine = Python.CreateEngine();
scope = engine.CreateScope();
scope.ImportModule("clr");
engine.Execute("import clr", scope);
engine.Execute("clr.AddReference(\"mpvnet\")", scope);
engine.Execute("import mpvnet", scope);
engine.Execute("from mpvnet import *", scope);
engine.Execute(File.ReadAllText(scriptPath), scope);
}
catch (Exception ex)
{
if (ex is SyntaxErrorException e)
Msg.ShowError(e.GetType().Name,$"{e.Line}, {e.Column}: " + e.Message + "\n\n" + Path.GetFileName(scriptPath));
else
Msg.ShowError(ex.GetType().Name, ex.Message + "\n\n" + Path.GetFileName(scriptPath));
}
}
}
public class PythonEventObject
{
public PythonFunction PythonFunction { get; set; }
public EventInfo EventInfo { get; set; }
public Delegate Delegate { get; set; }
public void Invoke() => PythonCalls.Call(PythonFunction);
public void InvokeEndFileEventMode(EndFileEventMode arg)
{
PythonCalls.Call(PythonFunction, new[] { arg });
}
public void InvokeStrings(string[] arg)
{
PythonCalls.Call(PythonFunction, new[] { arg });
}
}
}

View File

@@ -1,123 +0,0 @@

using System;
using System.Collections.Generic;
using System.Linq;
using System.Management.Automation;
using System.Management.Automation.Runspaces;
using System.Threading;
namespace ScriptHost
{
public class PowerShell
{
public Runspace Runspace { get; set; }
public Pipeline Pipeline { get; set; }
public string Module { get; set; }
public bool Print { get; set; }
public List<string> Scripts { get; } = new List<string>();
public string[] Parameters { get; }
public static List<PowerShell> Instances { get; } = new List<PowerShell>();
string NL = Environment.NewLine;
public object Invoke() => Invoke(null, null);
public object Invoke(string variable, object obj)
{
try
{
Runspace = RunspaceFactory.CreateRunspace();
Runspace.ApartmentState = ApartmentState.STA;
Runspace.Open();
Pipeline = Runspace.CreatePipeline();
foreach (string script in Scripts)
Pipeline.Commands.AddScript(script);
if (Parameters != null)
foreach (string param in Parameters)
foreach (Command command in Pipeline.Commands)
command.Parameters.Add(null, param);
Runspace.SessionStateProxy.SetVariable("ScriptHost", this);
if (!string.IsNullOrEmpty(variable))
Runspace.SessionStateProxy.SetVariable(variable, obj);
if (Print)
{
Pipeline.Output.DataReady += Output_DataReady;
Pipeline.Error.DataReady += Error_DataReady;
}
return Pipeline.Invoke();
}
catch (RuntimeException e)
{
string message = e.Message + NL + NL + e.ErrorRecord.ScriptStackTrace.Replace(
" <ScriptBlock>, <No file>", "") + NL + NL + Module + NL;
throw new PowerShellException(message);
}
catch (Exception e)
{
throw e;
}
}
public static string InvokeAndReturnString(string code, string varName, object varValue)
{
PowerShell ps = new PowerShell() { Print = false };
ps.Scripts.Add(code);
string ret = string.Join(Environment.NewLine, (ps.Invoke(varName, varValue)
as IEnumerable<object>).Select(item => item.ToString())).ToString();
ps.Runspace.Dispose();
return ret;
}
public void Output_DataReady(object sender, EventArgs e)
{
var output = sender as PipelineReader<PSObject>;
while (output.Count > 0)
ConsoleHelp.Write(output.Read(), Module);
}
public void Error_DataReady(object sender, EventArgs e)
{
var output = sender as PipelineReader<Object>;
while (output.Count > 0)
ConsoleHelp.WriteError(output.Read(), Module);
}
public void RedirectEventJobStreams(PSEventJob job)
{
if (Print)
{
job.Output.DataAdded += Output_DataAdded;
job.Error.DataAdded += Error_DataAdded;
}
}
void Output_DataAdded(object sender, DataAddedEventArgs e)
{
var output = sender as PSDataCollection<PSObject>;
ConsoleHelp.Write(output[e.Index], Module);
}
void Error_DataAdded(object sender, DataAddedEventArgs e)
{
var error = sender as PSDataCollection<ErrorRecord>;
ConsoleHelp.WriteError(error[e.Index], Module);
}
}
public class PowerShellException : Exception
{
public PowerShellException(string message) : base(message)
{
}
}
}

View File

@@ -1,23 +1,67 @@
$ErrorActionPreference = 'Stop'
$targetDir = (Split-Path $args[1]) + "\new version"
if ($args.Length -ne 2) {
Write-Host 'Invalid arguments' -ForegroundColor Red
exit
}
if (-not (Get-Command curl.exe)) {
Write-Host 'Error using curl.exe' -ForegroundColor Red
exit
}
if ($PSVersionTable.PSVersion.Major -lt 5) {
Write-Host 'PowerShell 5.1 not found' -ForegroundColor Red
exit
}
Add-Type -AssemblyName Microsoft.VisualBasic
# Delete directory using recycle bin
function Remove-Directory($directory) {
if (Test-Path $directory) {
[Microsoft.VisualBasic.FileIO.FileSystem]::
DeleteDirectory($directory, 'OnlyErrorDialogs', 'SendToRecycleBin')
}
}
$currentDir = $args[1];
$targetDir = (Split-Path $currentDir) + "\new version"
Remove-Directory $targetDir
$targetFile = $targetDir + '.7z'
Remove-Item $targetFile -Force -ErrorAction Ignore
Write-Host 'Download new version' -ForegroundColor Green
curl.exe $args[0] --location --output $targetFile
if ($LastExitCode) { throw $LastExitCode }
Write-Host 'Unpack new version' -ForegroundColor Green
& ($args[1] + '\7z\7za.exe') x -y $targetFile -o"$targetDir"
& ($currentDir + '\7z\7za.exe') x -y $targetFile -o"$targetDir"
if ($LastExitCode) { throw $LastExitCode }
Write-Host 'Delete downloaded file' -ForegroundColor Green
Remove-Item $targetFile -Force -Recurse
$portableConfigDir = $currentDir + '\portable_config'
$portableConfigTempDir = (Split-Path $currentDir) + '\portable config dir temp'
Remove-Item $portableConfigTempDir -Force -ErrorAction Ignore
if (Test-Path $portableConfigDir) {
Write-Host 'Backup portable config' -ForegroundColor Green
Copy-Item $portableConfigDir $portableConfigTempDir -Recurse -Force
}
Write-Host 'Delete current version' -ForegroundColor Green
Remove-Item $args[1] -Force -Recurse
Remove-Directory $currentDir
Write-Host 'Rename directory' -ForegroundColor Green
Rename-Item $targetDir (Split-Path $args[1] -Leaf)
Rename-Item $targetDir (Split-Path $currentDir -Leaf)
if (Test-Path $portableConfigTempDir) {
Write-Host 'Restore portable config' -ForegroundColor Green
Move-Item $portableConfigTempDir $portableConfigDir -Force
}
Write-Host 'Update is complete' -ForegroundColor Green

View File

@@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:UI="clr-namespace:UI"
xmlns:mpvnet="clr-namespace:mpvnet"
mc:Ignorable="d"
Title="About mpv.net"
@@ -13,8 +13,8 @@
ShowInTaskbar="False"
WindowStartupLocation="CenterOwner"
ResizeMode="NoResize"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}">
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}">
<Grid>
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">

View File

@@ -1,7 +1,10 @@
using System.IO;

using System.IO;
using System.Windows;
using System.Windows.Input;
using static mpvnet.Core;
namespace mpvnet
{
public partial class AboutWindow : Window
@@ -10,7 +13,7 @@ namespace mpvnet
{
InitializeComponent();
Version.Text = $"mpv.net Version {System.Windows.Forms.Application.ProductVersion} ({File.GetLastWriteTime(System.Windows.Forms.Application.ExecutablePath).ToShortDateString()})";
mpvVersion.Text = $"{mp.get_property_string("mpv-version")} ({File.GetLastWriteTime(Folder.Startup + "mpv-1.dll").ToShortDateString()})";
mpvVersion.Text = $"{core.get_property_string("mpv-version")} ({File.GetLastWriteTime(Folder.Startup + "mpv-1.dll").ToShortDateString()})";
}
protected override void OnPreviewKeyDown(KeyEventArgs e) => Close();

View File

@@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:UI="clr-namespace:UI"
xmlns:mpvnet="clr-namespace:mpvnet"
mc:Ignorable="d"
Title="Command Palette"
@@ -21,15 +21,15 @@
</Grid.RowDefinitions>
<TextBox Name="FilterTextBox"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}"
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}"
PreviewKeyDown="FilterTextBox_PreviewKeyDown"
TextChanged="FilterTextBox_TextChanged"/>
<ListView Name="ListView"
Grid.Row="1"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}"
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}"
MouseUp="ListView_MouseUp">
<ListView.ItemContainerStyle>

View File

@@ -6,6 +6,8 @@ using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Interop;
using static mpvnet.Core;
namespace mpvnet
{
public partial class CommandPaletteWindow : Window
@@ -106,7 +108,7 @@ namespace mpvnet
{
CommandItem item = ListView.SelectedItem as CommandItem;
Close();
mp.command(item.Command);
core.command(item.Command);
}
}

View File

@@ -3,14 +3,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:UI="clr-namespace:UI"
xmlns:mpvnet="clr-namespace:mpvnet"
mc:Ignorable="d"
Title="Config Editor"
Height="530"
Width="700"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}"
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}"
ShowInTaskbar="False"
WindowStartupLocation="CenterScreen"
Loaded="ConfWindow1_Loaded">
@@ -47,8 +47,8 @@
ItemsSource="{Binding FilterStrings}"
BorderThickness="0"
SelectionChanged="FilterListBox_SelectionChanged"
Foreground="{x:Static UI:Theme.Heading}"
Background="{x:Static UI:Theme.Background}">
Foreground="{x:Static mpvnet:Theme.Heading}"
Background="{x:Static mpvnet:Theme.Background}">
<ListBox.ItemTemplate>
<DataTemplate>
@@ -57,10 +57,10 @@
</ListBox.ItemTemplate>
</ListBox>
<TextBlock Name="OpenSettingsTextBlock" Margin="0,30,0,0" Cursor="Hand" TextWrapping="WrapWithOverflow" Foreground="{x:Static UI:Theme.Heading}" MouseUp="OpenSettingsTextBlock_MouseUp">Open config folder</TextBlock>
<TextBlock Name="PreviewTextBlock" Margin="0,15,0,0" Cursor="Hand" TextWrapping="WrapWithOverflow" Foreground="{x:Static UI:Theme.Heading}" MouseUp="PreviewTextBlock_MouseUp">Preview mpv.conf</TextBlock>
<TextBlock Name="ShowManualTextBlock" Margin="0,15,0,0" Cursor="Hand" TextWrapping="WrapWithOverflow" Foreground="{x:Static UI:Theme.Heading}" MouseUp="ShowManualTextBlock_MouseUp">Show mpv manual</TextBlock>
<TextBlock Name="SupportTextBlock" Margin="0,15,0,0" Cursor="Hand" TextWrapping="WrapWithOverflow" Foreground="{x:Static UI:Theme.Heading}" MouseUp="SupportTextBlock_MouseUp">Show support forum</TextBlock>
<TextBlock Name="OpenSettingsTextBlock" Margin="0,30,0,0" Cursor="Hand" TextWrapping="WrapWithOverflow" Foreground="{x:Static mpvnet:Theme.Heading}" MouseUp="OpenSettingsTextBlock_MouseUp">Open config folder</TextBlock>
<TextBlock Name="PreviewTextBlock" Margin="0,15,0,0" Cursor="Hand" TextWrapping="WrapWithOverflow" Foreground="{x:Static mpvnet:Theme.Heading}" MouseUp="PreviewTextBlock_MouseUp">Preview mpv.conf</TextBlock>
<TextBlock Name="ShowManualTextBlock" Margin="0,15,0,0" Cursor="Hand" TextWrapping="WrapWithOverflow" Foreground="{x:Static mpvnet:Theme.Heading}" MouseUp="ShowManualTextBlock_MouseUp">Show mpv manual</TextBlock>
<TextBlock Name="SupportTextBlock" Margin="0,15,0,0" Cursor="Hand" TextWrapping="WrapWithOverflow" Foreground="{x:Static mpvnet:Theme.Heading}" MouseUp="SupportTextBlock_MouseUp">Show support forum</TextBlock>
</StackPanel>
</Grid>
</Window>

View File

@@ -11,6 +11,7 @@ using System.Windows.Controls;
using System.Windows.Input;
using DynamicGUI;
using static mpvnet.Core;
namespace mpvnet
{
@@ -26,7 +27,7 @@ namespace mpvnet
InitializeComponent();
DataContext = this;
SearchControl.SearchTextBox.TextChanged += SearchTextBox_TextChanged;
LoadConf(mp.ConfPath);
LoadConf(core.ConfPath);
LoadConf(App.ConfPath);
LoadSettings();
InitialContent = GetCompareString();
@@ -74,7 +75,7 @@ namespace mpvnet
if (InitialContent == GetCompareString())
return;
File.WriteAllText(mp.ConfPath, GetContent("mpv"));
File.WriteAllText(core.ConfPath, GetContent("mpv"));
File.WriteAllText(App.ConfPath, GetContent("mpvnet"));
Msg.Show("Changes will be available on next mpv.net startup.");
}
@@ -293,7 +294,7 @@ namespace mpvnet
void OpenSettingsTextBlock_MouseUp(object sender, MouseButtonEventArgs e)
{
Process.Start(Path.GetDirectoryName(mp.ConfPath));
Process.Start(Path.GetDirectoryName(core.ConfPath));
}
void PreviewTextBlock_MouseUp(object sender, MouseButtonEventArgs e)

View File

@@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:UI="clr-namespace:UI"
xmlns:mpvnet="clr-namespace:mpvnet"
mc:Ignorable="d"
Title="Media File Search"
@@ -21,14 +21,14 @@
</Grid.RowDefinitions>
<TextBox Name="FilterTextBox"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}"
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}"
PreviewKeyDown="FilterTextBox_PreviewKeyDown"
TextChanged="FilterTextBox_TextChanged"/>
<ListView Name="ListView"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}"
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}"
Grid.Row="1"
MouseUp="ListView_MouseUp"
PreviewKeyDown="ListView_PreviewKeyDown">

View File

@@ -10,6 +10,8 @@ using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Interop;
using static mpvnet.Core;
namespace mpvnet
{
public partial class EverythingWindow : Window
@@ -103,7 +105,7 @@ namespace mpvnet
void Execute()
{
if (ListView.SelectedItem != null)
mp.LoadFiles(new[] { ListView.SelectedItem as string }, true, Keyboard.Modifiers == ModifierKeys.Control);
core.LoadFiles(new[] { ListView.SelectedItem as string }, true, Keyboard.Modifiers == ModifierKeys.Control);
Keyboard.Focus(FilterTextBox);
}

View File

@@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:UI="clr-namespace:UI"
xmlns:mpvnet="clr-namespace:mpvnet"
mc:Ignorable="d"
Title="Input Editor"
@@ -11,8 +11,8 @@
Width="750"
FontSize="13"
ShowInTaskbar="False"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}"
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}"
Loaded="Window_Loaded"
Closed="Window_Closed">

View File

@@ -8,6 +8,8 @@ using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using static mpvnet.Core;
namespace mpvnet
{
public partial class InputWindow : Window
@@ -123,7 +125,7 @@ namespace mpvnet
void Window_Closed(object sender, EventArgs e)
{
if (InitialInputConfContent == GetInputConfContent()) return;
File.WriteAllText(mp.InputConfPath, GetInputConfContent());
File.WriteAllText(core.InputConfPath, GetInputConfContent());
Msg.Show("Changes will be available on next mpv.net startup.");
}

View File

@@ -3,7 +3,7 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:UI="clr-namespace:UI"
xmlns:mpvnet="clr-namespace:mpvnet"
mc:Ignorable="d"
Title="Learn Input"
@@ -12,12 +12,11 @@
WindowStartupLocation="CenterOwner"
ResizeMode="NoResize"
Loaded="Window_Loaded"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}"
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}"
MouseWheel="Window_MouseWheel"
MouseUp="Window_MouseUp"
MouseDoubleClick="Window_MouseDoubleClick"
TextInput="Window_TextInput">
MouseDoubleClick="Window_MouseDoubleClick" PreviewKeyDown="Window_PreviewKeyDown">
<Grid>
<Grid.RowDefinitions>

View File

@@ -1,11 +1,12 @@

using System;
using System.Diagnostics;
using System.Runtime.InteropServices;
using System.Text;
using System.Windows;
using System.Windows.Input;
using System.Windows.Interop;
using WinForms = System.Windows.Forms;
using System.Windows.Forms;
namespace mpvnet
{
@@ -13,13 +14,68 @@ namespace mpvnet
{
public CommandItem InputItem { get; set; }
string NewKey = "";
string KeyChar = "";
uint MAPVK_VK_TO_VSC = 0;
int VK_MENU = 0x12;
int VK_LMENU = 0xA4;
int VK_RMENU = 0xA5;
int VK_CONTROL = 0x11;
int VK_LCONTROL = 0xA2;
int VK_RCONTROL = 0xA3;
public LearnWindow() => InitializeComponent();
[DllImport("user32.dll", CharSet = CharSet.Auto)]
static extern short GetKeyState(int keyCode);
[DllImport("user32.dll")]
static extern uint MapVirtualKey(uint uCode, uint uMapType);
[DllImport("user32.dll", CharSet = CharSet.Unicode)]
static extern int ToUnicode(uint wVirtKey, uint wScanCode, byte[] lpKeyState,
StringBuilder pwszBuff, int cchBuff, uint wFlags);
[DllImport("user32.dll")]
static extern bool GetKeyboardState(byte[] lpKeyState);
string ToUnicode(uint vk)
{
byte[] keys = new byte[256];
if (!GetKeyboardState(keys))
return "";
if ((keys[VK_CONTROL] & 0x80) != 0 && (keys[VK_MENU] & 0x80) == 0)
keys[VK_LCONTROL] = keys[VK_RCONTROL] = keys[VK_CONTROL] = 0;
uint scanCode = MapVirtualKey(vk, MAPVK_VK_TO_VSC);
string ret = ToUnicode(vk, scanCode, keys);
if (ret.Length == 1 && (int)ret[0] < 32)
return "";
if (ret == "" && (keys[VK_MENU] & 0x80) != 0)
{
keys[VK_LMENU] = keys[VK_RMENU] = keys[VK_MENU] = 0;
ret = ToUnicode(vk, scanCode, keys);
}
return ret;
}
public string ToUnicode(uint vk, uint scanCode, byte[] keys)
{
StringBuilder sb = new StringBuilder(10);
ToUnicode(vk, scanCode, keys, sb, sb.Capacity, 0);
return sb.ToString();
}
IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
WinForms.Message m = new WinForms.Message();
Message m = new Message();
m.HWnd = hwnd;
m.Msg = msg;
m.WParam = wParam;
@@ -28,298 +84,116 @@ namespace mpvnet
return m.Result;
}
void OnKeyUp(WinForms.KeyEventArgs e)
void OnKeyDown(uint vk)
{
if (e.KeyCode == WinForms.Keys.ControlKey || e.KeyCode == WinForms.Keys.ShiftKey ||
e.KeyCode == WinForms.Keys.Menu || e.KeyCode == WinForms.Keys.None)
Keys key = (Keys)vk;
if (key == Keys.ControlKey || key == Keys.ShiftKey ||
key == Keys.Menu || key == Keys.None)
return;
string text = "";
uint charValue = MapVirtualKey((uint)e.KeyCode, 2);
string text = ToUnicode(vk);
if (charValue == 0 || (charValue & 1 << 31) == 1 << 31)
text = e.KeyCode.ToString().Trim();
else
try {
text = Convert.ToChar(charValue).ToString().ToLower().Trim();
} catch {}
if ((int)key > 111 && (int)key < 136)
text = "F" + ((int)key - 111);
for (int i = 0; i < 13; i++)
if ("D" + i == text)
text = text.Substring(1);
if ((int)key > 95 && (int)key < 106)
text = "KP" + ((int)key - 96);
switch (e.KeyCode)
switch (text)
{
case WinForms.Keys.NumPad0:
case WinForms.Keys.NumPad1:
case WinForms.Keys.NumPad2:
case WinForms.Keys.NumPad3:
case WinForms.Keys.NumPad4:
case WinForms.Keys.NumPad5:
case WinForms.Keys.NumPad6:
case WinForms.Keys.NumPad7:
case WinForms.Keys.NumPad8:
case WinForms.Keys.NumPad9:
text = "KP" + e.KeyCode.ToString()[6]; break;
case WinForms.Keys.Space:
text = "Space"; break;
case WinForms.Keys.Enter:
text = "Enter"; break;
case WinForms.Keys.Tab:
text = "TAB"; break;
case WinForms.Keys.Back:
text = "BS"; break;
case WinForms.Keys.Delete:
text = "DEL"; break;
case WinForms.Keys.Insert:
text = "INS"; break;
case WinForms.Keys.Home:
text = "Home"; break;
case WinForms.Keys.End:
text = "END"; break;
case WinForms.Keys.PageUp:
text = "PGUP"; break;
case WinForms.Keys.PageDown:
text = "PGDWN"; break;
case WinForms.Keys.Escape:
text = "ESC"; break;
case WinForms.Keys.PrintScreen:
text = "Print"; break;
case WinForms.Keys.Play:
text = "Play"; break;
case WinForms.Keys.Pause:
text = "Pause"; break;
case WinForms.Keys.MediaPlayPause:
text = "PlayPause"; break;
case WinForms.Keys.MediaStop:
text = "Stop"; break;
case WinForms.Keys.MediaNextTrack:
text = "Next"; break;
case WinForms.Keys.MediaPreviousTrack:
text = "Prev"; break;
case WinForms.Keys.VolumeUp:
text = "Volume_Up"; break;
case WinForms.Keys.VolumeDown:
text = "Volume_Down"; break;
case WinForms.Keys.VolumeMute:
text = "Mute"; break;
case WinForms.Keys.BrowserHome:
text = "Homepage"; break;
case WinForms.Keys.LaunchMail:
text = "Mail"; break;
case WinForms.Keys.BrowserFavorites:
text = "Favorites"; break;
case WinForms.Keys.BrowserSearch:
text = "Search"; break;
case WinForms.Keys.Sleep:
text = "Sleep"; break;
case WinForms.Keys.Cancel:
text = "Cancel"; break;
case "#": text = "SHARP"; break;
case "´´": text = "´"; break;
case "``": text = "`"; break;
case "^^": text = "^"; break;
}
bool wasModified = false;
bool isAlt = GetKeyState(18) < (short)0;
bool isShift = GetKeyState(16) < (short)0;
bool isCtrl = GetKeyState(17) < (short)0;
if (text.Length == 1 && KeyChar != text)
switch (key)
{
text = KeyChar;
wasModified = true;
case Keys.Left: text = "LEFT"; break;
case Keys.Up: text = "UP"; break;
case Keys.Right: text = "RIGHT"; break;
case Keys.Down: text = "DOWN"; break;
case Keys.Space: text = "SPACE"; break;
case Keys.Enter: text = "ENTER"; break;
case Keys.Tab: text = "TAB"; break;
case Keys.Back: text = "BS"; break;
case Keys.Delete: text = "DEL"; break;
case Keys.Insert: text = "INS"; break;
case Keys.Home: text = "HOME"; break;
case Keys.End: text = "END"; break;
case Keys.PageUp: text = "PGUP"; break;
case Keys.PageDown: text = "PGDWN"; break;
case Keys.Escape: text = "ESC"; break;
case Keys.Sleep: text = "SLEEP"; break;
case Keys.Cancel: text = "CANCEL"; break;
case Keys.PrintScreen: text = "PRINT"; break;
case Keys.BrowserFavorites: text = "FAVORITES"; break;
case Keys.BrowserSearch: text = "SEARCH"; break;
case Keys.BrowserHome: text = "HOMEPAGE"; break;
case Keys.LaunchMail: text = "MAIL"; break;
case Keys.Play: text = "PLAY"; break;
case Keys.Pause: text = "PAUSE"; break;
case Keys.MediaPlayPause: text = "PLAYPAUSE"; break;
case Keys.MediaStop: text = "STOP"; break;
case Keys.MediaNextTrack: text = "NEXT"; break;
case Keys.MediaPreviousTrack: text = "PREV"; break;
case Keys.VolumeUp:
case Keys.VolumeDown:
case Keys.VolumeMute:
text = ""; break;
}
if (text == "#") text = "SHARP";
bool isAlt = GetKeyState(18) < 0;
bool isShift = GetKeyState(16) < 0;
bool isCtrl = GetKeyState(17) < 0;
if (isAlt && !wasModified)
bool isLetter = (int)key > 64 && (int)key < 91;
if (isLetter && isShift)
text = text.ToUpper();
string keyString = ToUnicode(vk);
if (isAlt && !isCtrl)
text = "ALT+" + text;
if (isShift && !wasModified)
if (isShift && keyString == "")
text = "SHIFT+" + text;
if (isCtrl && !wasModified)
if (isCtrl && !(keyString != "" && isCtrl && isAlt))
text = "CTRL+" + text;
if (!string.IsNullOrEmpty(text))
SetKey(text);
}
DateTime LastKeyUp;
void SetKey(string key)
{
NewKey = key;
MenuTextBlock.Text = InputItem.Path;
KeyTextBlock.Text = key;
LastKeyUp = DateTime.Now;
}
[DllImport("user32.dll")]
static extern uint MapVirtualKey(uint uCode, uint uMapType);
public static WinForms.Keys ModifierKeys {
get {
WinForms.Keys keys = WinForms.Keys.None;
if (GetKeyState(17) < (short)0)
keys |= WinForms.Keys.Control;
if (GetKeyState(16) < (short)0)
keys |= WinForms.Keys.Shift;
if (GetKeyState(18) < (short)0)
keys |= WinForms.Keys.Alt;
return keys;
}
}
void ProcessKeyEventArgs(ref WinForms.Message m)
void ProcessKeyEventArgs(ref Message m)
{
int WM_KEYUP = 0x0101, WM_SYSKEYUP = 0x0105, WM_APPCOMMAND = 0x0319;
int WM_KEYDOWN = 0x100;
int WM_SYSKEYDOWN = 0x104;
int WM_APPCOMMAND = 0x319;
if (m.Msg == WM_KEYUP || m.Msg == WM_SYSKEYUP)
OnKeyUp(new WinForms.KeyEventArgs((WinForms.Keys)(unchecked((int)(long)m.WParam)) | ModifierKeys));
if (m.Msg == WM_KEYDOWN || m.Msg == WM_SYSKEYDOWN)
OnKeyDown((uint)m.WParam.ToInt64());
else if (m.Msg == WM_APPCOMMAND)
{
if (!mp.get_property_bool("input-media-keys"))
return;
string value = mpvHelp.WM_APPCOMMAND_to_mpv_key((int)(m.LParam.ToInt64() >> 16 & ~0xf000));
var value = (AppCommand)(m.LParam.ToInt64() >> 16 & ~0xf000);
switch (value)
{
case AppCommand.APPCOMMAND_MEDIA_CHANNEL_DOWN:
SetKey("CHANNEL_DOWN");
break;
case AppCommand.APPCOMMAND_MEDIA_CHANNEL_UP:
SetKey("CHANNEL_UP");
break;
case AppCommand.APPCOMMAND_MEDIA_FAST_FORWARD:
SetKey("FORWARD");
break;
case AppCommand.APPCOMMAND_MEDIA_REWIND:
SetKey("REWIND");
break;
case AppCommand.APPCOMMAND_MEDIA_PAUSE:
SetKey("PAUSE");
break;
case AppCommand.APPCOMMAND_MEDIA_PLAY:
SetKey("PLAY");
break;
case AppCommand.APPCOMMAND_MEDIA_PLAY_PAUSE:
SetKey("PLAYPAUSE");
break;
case AppCommand.APPCOMMAND_MEDIA_NEXTTRACK:
SetKey("NEXT");
break;
case AppCommand.APPCOMMAND_MEDIA_PREVIOUSTRACK:
SetKey("PREV");
break;
case AppCommand.APPCOMMAND_MEDIA_RECORD:
SetKey("RECORD");
break;
case AppCommand.APPCOMMAND_MEDIA_STOP:
SetKey("STOP");
break;
case AppCommand.APPCOMMAND_VOLUME_UP:
SetKey("VOLUME_UP");
break;
case AppCommand.APPCOMMAND_VOLUME_DOWN:
SetKey("VOLUME_DOWN");
break;
case AppCommand.APPCOMMAND_VOLUME_MUTE:
SetKey("MUTE");
break;
case AppCommand.APPCOMMAND_BROWSER_HOME:
SetKey("HOMEPAGE");
break;
case AppCommand.APPCOMMAND_LAUNCH_MAIL:
SetKey("MAIL");
break;
case AppCommand.APPCOMMAND_BROWSER_FAVORITES:
SetKey("FAVORITES");
break;
case AppCommand.APPCOMMAND_BROWSER_SEARCH:
SetKey("SEARCH");
break;
case AppCommand.APPCOMMAND_PRINT:
SetKey("PRINT");
break;
}
if (value != null)
SetKey(value);
}
}
internal enum AppCommand
{
APPCOMMAND_BASS_BOOST = 20,
APPCOMMAND_BASS_DOWN = 19,
APPCOMMAND_BASS_UP = 21,
APPCOMMAND_BROWSER_BACKWARD = 1,
APPCOMMAND_BROWSER_FAVORITES = 6,
APPCOMMAND_BROWSER_FORWARD = 2,
APPCOMMAND_BROWSER_HOME = 7,
APPCOMMAND_BROWSER_REFRESH = 3,
APPCOMMAND_BROWSER_SEARCH = 5,
APPCOMMAND_BROWSER_STOP = 4,
APPCOMMAND_CLOSE = 31,
APPCOMMAND_COPY = 36,
APPCOMMAND_CORRECTION_LIST = 45,
APPCOMMAND_CUT = 37,
APPCOMMAND_DICTATE_OR_COMMAND_CONTROL_TOGGLE = 43,
APPCOMMAND_FIND = 28,
APPCOMMAND_FORWARD_MAIL = 40,
APPCOMMAND_HELP = 27,
APPCOMMAND_LAUNCH_APP1 = 17,
APPCOMMAND_LAUNCH_APP2 = 18,
APPCOMMAND_LAUNCH_MAIL = 15,
APPCOMMAND_LAUNCH_MEDIA_SELECT = 16,
APPCOMMAND_MEDIA_CHANNEL_DOWN = 52,
APPCOMMAND_MEDIA_CHANNEL_UP = 51,
APPCOMMAND_MEDIA_FAST_FORWARD = 49,
APPCOMMAND_MEDIA_NEXTTRACK = 11,
APPCOMMAND_MEDIA_PAUSE = 47,
APPCOMMAND_MEDIA_PLAY = 46,
APPCOMMAND_MEDIA_PLAY_PAUSE = 14,
APPCOMMAND_MEDIA_PREVIOUSTRACK = 12,
APPCOMMAND_MEDIA_RECORD = 48,
APPCOMMAND_MEDIA_REWIND = 50,
APPCOMMAND_MEDIA_STOP = 13,
APPCOMMAND_MIC_ON_OFF_TOGGLE = 44,
APPCOMMAND_MICROPHONE_VOLUME_DOWN = 25,
APPCOMMAND_MICROPHONE_VOLUME_MUTE = 24,
APPCOMMAND_MICROPHONE_VOLUME_UP = 26,
APPCOMMAND_NEW = 29,
APPCOMMAND_OPEN = 30,
APPCOMMAND_PASTE = 38,
APPCOMMAND_PRINT = 33,
APPCOMMAND_REDO = 35,
APPCOMMAND_REPLY_TO_MAIL = 39,
APPCOMMAND_SAVE = 32,
APPCOMMAND_SEND_MAIL = 41,
APPCOMMAND_SPELL_CHECK = 42,
APPCOMMAND_TREBLE_DOWN = 22,
APPCOMMAND_TREBLE_UP = 23,
APPCOMMAND_UNDO = 34,
APPCOMMAND_VOLUME_DOWN = 9,
APPCOMMAND_VOLUME_MUTE = 8,
APPCOMMAND_VOLUME_UP = 10
}
[DllImport("user32.dll", CharSet = CharSet.Auto)]
public static extern short GetKeyState(int keyCode);
[DllImport("user32.dll")]
static extern short VkKeyScan(char c);
[DllImport("user32.dll", SetLastError = true)]
static extern int ToAscii(uint uVirtKey,
uint uScanCode,
byte[] lpKeyState,
out uint lpChar,
uint flags);
void Window_Loaded(object sender, RoutedEventArgs e)
{
HwndSource source = HwndSource.FromHwnd(new WindowInteropHelper(this).Handle);
@@ -380,9 +254,13 @@ namespace mpvnet
}
}
void Window_TextInput(object sender, TextCompositionEventArgs e)
void Window_PreviewKeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
KeyChar = e.Text;
if (e.Key == Key.Tab)
{
OnKeyDown((uint)Keys.Tab);
e.Handled = true;
}
}
}
}

View File

@@ -1,6 +1,6 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:UI="clr-namespace:UI">
xmlns:mpvnet="clr-namespace:mpvnet">
<Style TargetType="TextBox">
<Setter Property="Template">
@@ -26,7 +26,7 @@
<Setter Property="BorderBrush" TargetName="border" Value="#FF7EB4EA"/>
</Trigger>
<Trigger Property="IsFocused" Value="true">
<Setter Property="BorderBrush" TargetName="border" Value="{x:Static UI:Theme.Heading}"/>
<Setter Property="BorderBrush" TargetName="border" Value="{x:Static mpvnet:Theme.Heading}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@@ -49,8 +49,8 @@
x:Name="normal"
Width="18"
Height="18"
Fill="{x:Static UI:Theme.Background}"
Stroke="{x:Static UI:Theme.Heading}"
Fill="{x:Static mpvnet:Theme.Background}"
Stroke="{x:Static mpvnet:Theme.Heading}"
StrokeThickness="2" />
<Ellipse
x:Name="Checked1"

View File

@@ -3,20 +3,20 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:UI="clr-namespace:UI"
xmlns:mpvnet="clr-namespace:mpvnet"
mc:Ignorable="d"
d:DesignHeight="450"
d:DesignWidth="800">
<Grid Name="SearchTextBoxUserControl1"
Background="{x:Static UI:Theme.Background}">
Background="{x:Static mpvnet:Theme.Background}">
<TextBlock Name="HintTextBlock"
Margin="5,2"
Text="Find a setting"
VerticalAlignment="Center"
Foreground="{x:Static UI:Theme.Foreground2}"
Background="{x:Static UI:Theme.Background}" />
Foreground="{x:Static mpvnet:Theme.Foreground2}"
Background="{x:Static mpvnet:Theme.Background}" />
<TextBox Name="SearchTextBox"
Height="25"
@@ -24,8 +24,8 @@
BorderThickness="2"
Background="Transparent"
TextChanged="SearchTextBox_TextChanged"
Foreground="{x:Static UI:Theme.Foreground}"
CaretBrush="{x:Static UI:Theme.Foreground}" />
Foreground="{x:Static mpvnet:Theme.Foreground}"
CaretBrush="{x:Static mpvnet:Theme.Foreground}" />
<Button Name="SearchClearButton"
Background="Transparent"
@@ -40,8 +40,8 @@
<Button.Style>
<Style TargetType="Button">
<Setter Property="Background" Value="{x:Static UI:Theme.Background}"/>
<Setter Property="Foreground" Value="{x:Static UI:Theme.Foreground2}"/>
<Setter Property="Background" Value="{x:Static mpvnet:Theme.Background}"/>
<Setter Property="Foreground" Value="{x:Static mpvnet:Theme.Foreground2}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="Button">
@@ -58,7 +58,7 @@
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Foreground" Value="{x:Static UI:Theme.Heading}"/>
<Setter Property="Foreground" Value="{x:Static mpvnet:Theme.Heading}"/>
</Trigger>
</Style.Triggers>
</Style>

View File

@@ -3,13 +3,13 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:UI="clr-namespace:UI"
xmlns:mpvnet="clr-namespace:mpvnet"
mc:Ignorable="d"
Title="mpv.net Setup"
FontSize="13"
Foreground="{x:Static UI:Theme.Foreground}"
Background="{x:Static UI:Theme.Background}"
Foreground="{x:Static mpvnet:Theme.Foreground}"
Background="{x:Static mpvnet:Theme.Background}"
SizeToContent="WidthAndHeight"
WindowStartupLocation="CenterOwner" >

View File

@@ -11,8 +11,7 @@ using System.Globalization;
using System.Diagnostics;
using System.Threading.Tasks;
using UI;
using ScriptHost;
using static mpvnet.Core;
namespace mpvnet
{
@@ -24,6 +23,7 @@ namespace mpvnet
Point LastCursorPosition;
int LastCursorChanged;
int LastCycleFullscreen;
int LastAppCommand;
int TaskbarButtonCreatedMessage;
int ShownTickCount;
@@ -47,30 +47,30 @@ namespace mpvnet
Instance = this;
Hwnd = Handle;
ConsoleHelp.Padding = 60;
mp.Init();
core.Init();
mp.Shutdown += Shutdown;
mp.VideoSizeChanged += VideoSizeChanged;
mp.FileLoaded += FileLoaded;
mp.Idle += Idle;
mp.Seek += () => UpdateProgressBar();
core.Shutdown += Shutdown;
core.VideoSizeChanged += VideoSizeChanged;
core.FileLoaded += FileLoaded;
core.Idle += Idle;
core.Seek += () => UpdateProgressBar();
mp.observe_property("window-maximized", PropChangeWindowMaximized);
mp.observe_property("window-minimized", PropChangeWindowMinimized);
mp.observe_property_bool("pause", PropChangePause);
mp.observe_property_bool("fullscreen", PropChangeFullscreen);
mp.observe_property_bool("ontop", PropChangeOnTop);
mp.observe_property_bool("border", PropChangeBorder);
core.observe_property("window-maximized", PropChangeWindowMaximized);
core.observe_property("window-minimized", PropChangeWindowMinimized);
core.observe_property_bool("pause", PropChangePause);
core.observe_property_bool("fullscreen", PropChangeFullscreen);
core.observe_property_bool("ontop", PropChangeOnTop);
core.observe_property_bool("border", PropChangeBorder);
mp.observe_property_string("sid", PropChangeSid);
mp.observe_property_string("aid", PropChangeAid);
mp.observe_property_string("vid", PropChangeVid);
core.observe_property_string("sid", PropChangeSid);
core.observe_property_string("aid", PropChangeAid);
core.observe_property_string("vid", PropChangeVid);
mp.observe_property_int("edition", PropChangeEdition);
mp.observe_property_double("window-scale", PropChangeWindowScale);
core.observe_property_int("edition", PropChangeEdition);
core.observe_property_double("window-scale", PropChangeWindowScale);
if (mp.GPUAPI != "vulkan")
mp.ProcessCommandLine(false);
if (core.GPUAPI != "vulkan")
core.ProcessCommandLine(false);
AppDomain.CurrentDomain.UnhandledException += (sender, e) => App.ShowException(e.ExceptionObject);
Application.ThreadException += (sender, e) => App.ShowException(e.Exception);
@@ -82,10 +82,10 @@ namespace mpvnet
ContextMenu.Opened += ContextMenu_Opened;
ContextMenu.Opening += ContextMenu_Opening;
if (mp.Screen == -1)
mp.Screen = Array.IndexOf(Screen.AllScreens, Screen.PrimaryScreen);
if (core.Screen == -1)
core.Screen = Array.IndexOf(Screen.AllScreens, Screen.PrimaryScreen);
int targetIndex = mp.Screen;
int targetIndex = core.Screen;
Screen[] screens = Screen.AllScreens;
if (targetIndex < 0)
@@ -99,7 +99,7 @@ namespace mpvnet
Left = target.X + (target.Width - Width) / 2;
Top = target.Y + (target.Height - Height) / 2;
if (!mp.Border)
if (!core.Border)
FormBorderStyle = FormBorderStyle.None;
int posX = RegistryHelp.GetInt(App.RegPath, "PosX");
@@ -111,13 +111,13 @@ namespace mpvnet
Top = posY - Height / 2;
}
if (mp.WindowMaximized)
if (core.WindowMaximized)
{
SetFormPosAndSize(1, true);
WindowState = FormWindowState.Maximized;
}
if (mp.WindowMinimized)
if (core.WindowMinimized)
{
SetFormPosAndSize(1, true);
WindowState = FormWindowState.Minimized;
@@ -163,7 +163,7 @@ namespace mpvnet
void ContextMenu_Opening(object sender, CancelEventArgs e)
{
lock (mp.MediaTracks)
lock (core.MediaTracks)
{
MenuItem trackMenuItem = FindMenuItem("Track");
@@ -171,16 +171,16 @@ namespace mpvnet
{
trackMenuItem.DropDownItems.Clear();
MediaTrack[] audTracks = mp.MediaTracks.Where(track => track.Type == "a").ToArray();
MediaTrack[] subTracks = mp.MediaTracks.Where(track => track.Type == "s").ToArray();
MediaTrack[] vidTracks = mp.MediaTracks.Where(track => track.Type == "v").ToArray();
MediaTrack[] ediTracks = mp.MediaTracks.Where(track => track.Type == "e").ToArray();
MediaTrack[] audTracks = core.MediaTracks.Where(track => track.Type == "a").ToArray();
MediaTrack[] subTracks = core.MediaTracks.Where(track => track.Type == "s").ToArray();
MediaTrack[] vidTracks = core.MediaTracks.Where(track => track.Type == "v").ToArray();
MediaTrack[] ediTracks = core.MediaTracks.Where(track => track.Type == "e").ToArray();
foreach (MediaTrack track in vidTracks)
{
MenuItem mi = new MenuItem(track.Text);
mi.Action = () => mp.commandv("set", "vid", track.ID.ToString());
mi.Checked = mp.Vid == track.ID.ToString();
mi.Action = () => core.commandv("set", "vid", track.ID.ToString());
mi.Checked = core.Vid == track.ID.ToString();
trackMenuItem.DropDownItems.Add(mi);
}
@@ -190,8 +190,8 @@ namespace mpvnet
foreach (MediaTrack track in audTracks)
{
MenuItem mi = new MenuItem(track.Text);
mi.Action = () => mp.commandv("set", "aid", track.ID.ToString());
mi.Checked = mp.Aid == track.ID.ToString();
mi.Action = () => core.commandv("set", "aid", track.ID.ToString());
mi.Checked = core.Aid == track.ID.ToString();
trackMenuItem.DropDownItems.Add(mi);
}
@@ -201,16 +201,16 @@ namespace mpvnet
foreach (MediaTrack track in subTracks)
{
MenuItem mi = new MenuItem(track.Text);
mi.Action = () => mp.commandv("set", "sid", track.ID.ToString());
mi.Checked = mp.Sid == track.ID.ToString();
mi.Action = () => core.commandv("set", "sid", track.ID.ToString());
mi.Checked = core.Sid == track.ID.ToString();
trackMenuItem.DropDownItems.Add(mi);
}
if (subTracks.Length > 0)
{
MenuItem mi = new MenuItem("S: No subtitles");
mi.Action = () => mp.commandv("set", "sid", "no");
mi.Checked = mp.Sid == "no";
mi.Action = () => core.commandv("set", "sid", "no");
mi.Checked = core.Sid == "no";
trackMenuItem.DropDownItems.Add(mi);
}
@@ -220,14 +220,14 @@ namespace mpvnet
foreach (MediaTrack track in ediTracks)
{
MenuItem mi = new MenuItem(track.Text);
mi.Action = () => mp.commandv("set", "edition", track.ID.ToString());
mi.Checked = mp.Edition == track.ID;
mi.Action = () => core.commandv("set", "edition", track.ID.ToString());
mi.Checked = core.Edition == track.ID;
trackMenuItem.DropDownItems.Add(mi);
}
}
}
lock (mp.Chapters)
lock (core.Chapters)
{
MenuItem chaptersMenuItem = FindMenuItem("Chapters");
@@ -235,11 +235,11 @@ namespace mpvnet
{
chaptersMenuItem.DropDownItems.Clear();
foreach (var i in mp.Chapters)
foreach (var i in core.Chapters)
{
MenuItem mi = new MenuItem(i.Key);
mi.ShortcutKeyDisplayString = TimeSpan.FromSeconds(i.Value).ToString().Substring(0, 8) + " ";
mi.Action = () => mp.commandv("seek", i.Value.ToString(CultureInfo.InvariantCulture), "absolute");
mi.Action = () => core.commandv("seek", i.Value.ToString(CultureInfo.InvariantCulture), "absolute");
chaptersMenuItem.DropDownItems.Add(mi);
}
}
@@ -252,7 +252,7 @@ namespace mpvnet
recent.DropDownItems.Clear();
foreach (string path in RecentFiles)
MenuItem.Add(recent.DropDownItems, path, () => mp.LoadFiles(new[] { path }, true, Control.ModifierKeys.HasFlag(Keys.Control)));
MenuItem.Add(recent.DropDownItems, path, () => core.LoadFiles(new[] { path }, true, Control.ModifierKeys.HasFlag(Keys.Control)));
recent.DropDownItems.Add(new ToolStripSeparator());
MenuItem mi = new MenuItem("Clear List");
@@ -287,7 +287,7 @@ namespace mpvnet
if (WindowState != FormWindowState.Normal)
return;
if (mp.Fullscreen)
if (core.Fullscreen)
{
CycleFullscreen(true);
return;
@@ -295,17 +295,17 @@ namespace mpvnet
}
Screen screen = Screen.FromControl(this);
int autoFitHeight = Convert.ToInt32(screen.WorkingArea.Height * mp.Autofit);
int autoFitHeight = Convert.ToInt32(screen.WorkingArea.Height * core.Autofit);
if (mp.VideoSize.Height == 0 || mp.VideoSize.Width == 0 ||
mp.VideoSize.Width / (float)mp.VideoSize.Height < App.MinimumAspectRatio)
if (core.VideoSize.Height == 0 || core.VideoSize.Width == 0 ||
core.VideoSize.Width / (float)core.VideoSize.Height < App.MinimumAspectRatio)
mp.VideoSize = new Size((int)(autoFitHeight * (16 / 9.0)), autoFitHeight);
core.VideoSize = new Size((int)(autoFitHeight * (16 / 9f)), autoFitHeight);
Size videoSize = mp.VideoSize;
Size videoSize = core.VideoSize;
int height = videoSize.Height;
if (mp.WasInitialSizeSet || scale != 1)
if (core.WasInitialSizeSet || scale != 1)
height = ClientSize.Height;
else
{
@@ -317,30 +317,30 @@ namespace mpvnet
if (App.StartSize != "video")
height = autoFitHeight;
mp.WasInitialSizeSet = true;
core.WasInitialSizeSet = true;
}
height = Convert.ToInt32(height * scale);
int width = Convert.ToInt32(height * videoSize.Width / (double)videoSize.Height);
int width = height * videoSize.Width / videoSize.Height;
int maxHeight = screen.WorkingArea.Height - (Height - ClientSize.Height);
int maxWidth = screen.WorkingArea.Width - (Width - ClientSize.Width);
if (height < maxHeight * mp.AutofitSmaller)
if (height < maxHeight * core.AutofitSmaller)
{
height = Convert.ToInt32(maxHeight * mp.AutofitSmaller);
width = Convert.ToInt32(height * videoSize.Width / (double)videoSize.Height);
height = Convert.ToInt32(maxHeight * core.AutofitSmaller);
width = Convert.ToInt32(height * videoSize.Width / videoSize.Height);
}
if (height > maxHeight * mp.AutofitLarger)
if (height > maxHeight * core.AutofitLarger)
{
height = Convert.ToInt32(maxHeight * mp.AutofitLarger);
width = Convert.ToInt32(height * videoSize.Width / (double)videoSize.Height);
height = Convert.ToInt32(maxHeight * core.AutofitLarger);
width = Convert.ToInt32(height * videoSize.Width / videoSize.Height);
}
if (width > maxWidth)
{
width = maxWidth;
height = Convert.ToInt32(width * videoSize.Height / (double)videoSize.Width);
height = (int)Math.Ceiling(width * videoSize.Height / (double)videoSize.Width);
}
Point middlePos = new Point(Left + Width / 2, Top + Height / 2);
@@ -374,7 +374,7 @@ namespace mpvnet
public void CycleFullscreen(bool enabled)
{
LastCycleFullscreen = Environment.TickCount;
mp.Fullscreen = enabled;
core.Fullscreen = enabled;
if (enabled)
{
@@ -401,7 +401,7 @@ namespace mpvnet
else
WindowState = FormWindowState.Normal;
if (mp.Border)
if (core.Border)
FormBorderStyle = FormBorderStyle.Sizable;
else
FormBorderStyle = FormBorderStyle.None;
@@ -414,7 +414,7 @@ namespace mpvnet
public void BuildMenu()
{
string content = File.ReadAllText(mp.InputConfPath);
string content = File.ReadAllText(core.InputConfPath);
var items = CommandItem.GetItems(content);
if (!content.Contains("#menu:"))
@@ -438,7 +438,7 @@ namespace mpvnet
MenuItem menuItem = ContextMenu.Add(path, () => {
try {
mp.command(item.Command);
core.command(item.Command);
} catch (Exception ex) {
Msg.ShowException(ex);
}
@@ -451,19 +451,24 @@ namespace mpvnet
void FileLoaded()
{
string path = mp.get_property_string("path");
string path = core.get_property_string("path");
BeginInvoke(new Action(() => {
if (path.Contains("://"))
Text = mp.get_property_string("media-title") + " - mpv.net " + Application.ProductVersion;
Text = core.get_property_string("media-title") + " - mpv.net " + Application.ProductVersion;
else if (path.Contains(":\\") || path.StartsWith("\\\\"))
Text = path.FileName() + " - mpv.net " + Application.ProductVersion;
else
Text = "mpv.net " + Application.ProductVersion;
int interval = (int)(mp.Duration.TotalMilliseconds / 100);
if (interval < 100) interval = 100;
if (interval > 1000) interval = 1000;
int interval = (int)(core.Duration.TotalMilliseconds / 100);
if (interval < 100)
interval = 100;
if (interval > 1000)
interval = 1000;
ProgressTimer.Interval = interval;
UpdateProgressBar();
}));
@@ -510,19 +515,34 @@ namespace mpvnet
case 0x20A: // WM_MOUSEWHEEL
case 0x100: // WM_KEYDOWN
case 0x101: // WM_KEYUP
case 0x102: // WM_CHAR
case 0x104: // WM_SYSKEYDOWN
case 0x105: // WM_SYSKEYUP
case 0x106: // WM_SYSCHAR
{
bool skip = m.Msg == 0x100 && LastAppCommand != 0 &&
(Environment.TickCount - LastAppCommand) < 1000;
if (core.WindowHandle != IntPtr.Zero && !skip)
m.Result = WinAPI.SendMessage(core.WindowHandle, m.Msg, m.WParam, m.LParam);
}
break;
case 0x319: // WM_APPCOMMAND
if (mp.WindowHandle != IntPtr.Zero)
m.Result = WinAPI.SendMessage(mp.WindowHandle, m.Msg, m.WParam, m.LParam);
{
string value = mpvHelp.WM_APPCOMMAND_to_mpv_key((int)(m.LParam.ToInt64() >> 16 & ~0xf000));
if (value != null)
{
core.command("keypress " + value);
m.Result = new IntPtr(1);
LastAppCommand = Environment.TickCount;
return;
}
}
break;
case 0x0200: // WM_MOUSEMOVE
if (Environment.TickCount - LastCycleFullscreen > 500)
{
Point pos = PointToClient(Cursor.Position);
mp.command($"mouse {pos.X} {pos.Y}");
core.command($"mouse {pos.X} {pos.Y}");
}
if (CursorHelp.IsPosDifferent(LastCursorPosition))
@@ -530,12 +550,12 @@ namespace mpvnet
break;
case 0x2a3: // WM_MOUSELEAVE
//osc won't auto hide after mouse left window in borderless mode
mp.command($"mouse {ClientSize.Width / 2} {ClientSize.Height / 3}");
core.command($"mouse {ClientSize.Width / 2} {ClientSize.Height / 3}");
break;
case 0x203: // WM_LBUTTONDBLCLK
{
Point pos = PointToClient(Cursor.Position);
mp.command($"mouse {pos.X} {pos.Y} 0 double");
core.command($"mouse {pos.X} {pos.Y} 0 double");
}
break;
case 0x02E0: // WM_DPICHANGED
@@ -553,14 +573,24 @@ namespace mpvnet
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;
Size s = core.VideoSize;
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_w = (int)(c_h * aspect - c_w);
int d_h = (int)(c_w / aspect - c_h);
Debug.WriteLine(d_w);
Debug.WriteLine(d_h);
int d_w2 = (int)(c_h * aspect - c_w);
int d_h2 = (int)(c_w / aspect - c_h);
Debug.WriteLine(d_w2);
Debug.WriteLine(d_h2);
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());
@@ -582,11 +612,11 @@ namespace mpvnet
switch (mode)
{
case "single":
mp.LoadFiles(files, true, Control.ModifierKeys.HasFlag(Keys.Control));
core.LoadFiles(files, true, Control.ModifierKeys.HasFlag(Keys.Control));
break;
case "queue":
foreach (string file in files)
mp.commandv("loadfile", file, "append");
core.commandv("loadfile", file, "append");
break;
}
@@ -595,13 +625,15 @@ namespace mpvnet
return;
}
if (m.Msg == TaskbarButtonCreatedMessage && mp.TaskbarProgress)
if (m.Msg == TaskbarButtonCreatedMessage && core.TaskbarProgress)
{
Taskbar = new Taskbar(Handle);
ProgressTimer.Start();
}
base.WndProc(ref m);
// beep sound when closed using taskbar due to exception
if (!IsDisposed)
base.WndProc(ref m);
}
void CursorTimer_Tick(object sender, EventArgs e)
@@ -622,26 +654,26 @@ namespace mpvnet
void UpdateProgressBar()
{
if (mp.TaskbarProgress && Taskbar != null)
Taskbar.SetValue(mp.get_property_number("time-pos"), mp.Duration.TotalSeconds);
if (core.TaskbarProgress && Taskbar != null)
Taskbar.SetValue(core.get_property_number("time-pos"), core.Duration.TotalSeconds);
}
void PropChangeOnTop(bool value) => BeginInvoke(new Action(() => TopMost = value));
void PropChangeAid(string value) => mp.Aid = value;
void PropChangeAid(string value) => core.Aid = value;
void PropChangeSid(string value) => mp.Sid = value;
void PropChangeSid(string value) => core.Sid = value;
void PropChangeVid(string value) => mp.Vid = value;
void PropChangeVid(string value) => core.Vid = value;
void PropChangeEdition(int value) => mp.Edition = value;
void PropChangeEdition(int value) => core.Edition = value;
void PropChangeWindowScale(double value)
{
if (value != 1)
{
BeginInvoke(new Action(() => SetFormPosAndSize(value)));
mp.command("no-osd set window-scale 1");
core.command("no-osd set window-scale 1");
}
}
@@ -652,11 +684,11 @@ namespace mpvnet
BeginInvoke(new Action(() =>
{
mp.WindowMaximized = mp.get_property_bool("window-maximized");
core.WindowMaximized = core.get_property_bool("window-maximized");
if (mp.WindowMaximized && WindowState != FormWindowState.Maximized)
if (core.WindowMaximized && WindowState != FormWindowState.Maximized)
WindowState = FormWindowState.Maximized;
else if (!mp.WindowMaximized && WindowState == FormWindowState.Maximized)
else if (!core.WindowMaximized && WindowState == FormWindowState.Maximized)
WindowState = FormWindowState.Normal;
}));
}
@@ -668,25 +700,25 @@ namespace mpvnet
BeginInvoke(new Action(() =>
{
mp.WindowMinimized = mp.get_property_bool("window-minimized");
core.WindowMinimized = core.get_property_bool("window-minimized");
if (mp.WindowMinimized && WindowState != FormWindowState.Minimized)
if (core.WindowMinimized && WindowState != FormWindowState.Minimized)
WindowState = FormWindowState.Minimized;
else if (!mp.WindowMinimized && WindowState == FormWindowState.Minimized)
else if (!core.WindowMinimized && WindowState == FormWindowState.Minimized)
WindowState = FormWindowState.Normal;
}));
}
void PropChangeBorder(bool enabled) {
mp.Border = enabled;
core.Border = enabled;
BeginInvoke(new Action(() => {
if (!IsFullscreen)
{
if (mp.Border && FormBorderStyle == FormBorderStyle.None)
if (core.Border && FormBorderStyle == FormBorderStyle.None)
FormBorderStyle = FormBorderStyle.Sizable;
if (!mp.Border && FormBorderStyle == FormBorderStyle.Sizable)
if (!core.Border && FormBorderStyle == FormBorderStyle.Sizable)
FormBorderStyle = FormBorderStyle.None;
}
}));
@@ -694,7 +726,7 @@ namespace mpvnet
void PropChangePause(bool enabled)
{
if (Taskbar != null && mp.TaskbarProgress)
if (Taskbar != null && core.TaskbarProgress)
{
if (enabled)
Taskbar.SetState(TaskbarStates.Paused);
@@ -707,8 +739,8 @@ namespace mpvnet
{
base.OnLoad(e);
if (mp.GPUAPI != "vulkan")
mp.VideoSizeAutoResetEvent.WaitOne(App.StartThreshold);
if (core.GPUAPI != "vulkan")
core.VideoSizeAutoResetEvent.WaitOne(App.StartThreshold);
LastCycleFullscreen = Environment.TickCount;
SetFormPosAndSize();
@@ -718,8 +750,8 @@ namespace mpvnet
{
base.OnShown(e);
if (mp.GPUAPI == "vulkan")
mp.ProcessCommandLine(false);
if (core.GPUAPI == "vulkan")
core.ProcessCommandLine(false);
ToolStripRendererEx.ForegroundColor = Theme.Current.GetWinFormsColor("menu-foreground");
ToolStripRendererEx.BackgroundColor = Theme.Current.GetWinFormsColor("menu-background");
@@ -733,7 +765,7 @@ namespace mpvnet
System.Windows.Application.Current.ShutdownMode = System.Windows.ShutdownMode.OnExplicitShutdown;
Cursor.Position = new Point(Cursor.Position.X + 1, Cursor.Position.Y);
UpdateCheck.DailyCheck();
mp.LoadScripts();
core.LoadScripts();
Task.Run(() => App.Extension = new Extension());
ShownTickCount = Environment.TickCount;
}
@@ -749,8 +781,8 @@ namespace mpvnet
{
base.OnResize(e);
if (mp.IsLogoVisible)
mp.ShowLogo();
if (core.IsLogoVisible)
core.ShowLogo();
if (FormBorderStyle != FormBorderStyle.None)
{
@@ -764,16 +796,16 @@ namespace mpvnet
{
if (WindowState == FormWindowState.Minimized)
{
mp.set_property_string("window-minimized", "yes");
core.set_property_string("window-minimized", "yes");
}
else if (WindowState == FormWindowState.Normal)
{
mp.set_property_string("window-maximized", "no");
mp.set_property_string("window-minimized", "no");
core.set_property_string("window-maximized", "no");
core.set_property_string("window-minimized", "no");
}
else if (WindowState == FormWindowState.Maximized)
{
mp.set_property_string("window-maximized", "yes");
core.set_property_string("window-maximized", "yes");
}
}
}
@@ -784,16 +816,11 @@ namespace mpvnet
SaveWindowProperties();
RegistryHelp.SetValue(App.RegPath, "Recent", RecentFiles.ToArray());
if (mp.IsQuitNeeded)
mp.commandv("quit");
if (core.IsQuitNeeded)
core.commandv("quit");
if (!mp.ShutdownAutoResetEvent.WaitOne(10000))
if (!core.ShutdownAutoResetEvent.WaitOne(10000))
Msg.ShowError("Shutdown thread failed to complete within 10 seconds.");
try { // PowerShell 5.1 might not be available
foreach (PowerShell ps in PowerShell.Instances)
ps.Runspace.Dispose();
} catch {}
}
protected override void OnMouseDown(MouseEventArgs e)
@@ -809,7 +836,7 @@ namespace mpvnet
}
if (Width - e.Location.X < 10 && e.Location.Y < 10)
mp.commandv("quit");
core.commandv("quit");
}
protected override void OnDragEnter(DragEventArgs e)
@@ -825,10 +852,10 @@ namespace mpvnet
base.OnDragDrop(e);
if (e.Data.GetDataPresent(DataFormats.FileDrop))
mp.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as String[], true, Control.ModifierKeys.HasFlag(Keys.Control));
core.LoadFiles(e.Data.GetData(DataFormats.FileDrop) as String[], true, Control.ModifierKeys.HasFlag(Keys.Control));
if (e.Data.GetDataPresent(DataFormats.Text))
mp.LoadFiles(new[] { e.Data.GetData(DataFormats.Text).ToString() }, true, Control.ModifierKeys.HasFlag(Keys.Control));
core.LoadFiles(new[] { e.Data.GetData(DataFormats.Text).ToString() }, true, Control.ModifierKeys.HasFlag(Keys.Control));
}
protected override void OnLostFocus(EventArgs e)
@@ -839,7 +866,10 @@ namespace mpvnet
protected override void OnKeyDown(KeyEventArgs e)
{
e.SuppressKeyPress = true; // prevent beep using alt key
// prevent beep using alt key
if (Control.ModifierKeys == Keys.Alt)
e.SuppressKeyPress = true;
base.OnKeyDown(e);
}
}

View File

@@ -76,29 +76,6 @@
<GenerateSerializationAssemblies>Auto</GenerateSerializationAssemblies>
</PropertyGroup>
<ItemGroup>
<Reference Include="IKVM.Reflection, Version=7.2.4630.5, Culture=neutral, PublicKeyToken=13235d27fcbfff58, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>IronPython\IKVM.Reflection.dll</HintPath>
</Reference>
<Reference Include="IronPython, Version=2.7.9.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>IronPython\IronPython.dll</HintPath>
</Reference>
<Reference Include="IronPython.Modules, Version=2.7.9.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>IronPython\IronPython.Modules.dll</HintPath>
</Reference>
<Reference Include="IronPythonAddon">
<HintPath>IronPython\IronPythonAddon.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Dynamic, Version=1.2.2.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>IronPython\Microsoft.Dynamic.dll</HintPath>
</Reference>
<Reference Include="Microsoft.Scripting, Version=1.2.2.0, Culture=neutral, PublicKeyToken=7f709c5b713576e1, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>IronPython\Microsoft.Scripting.dll</HintPath>
</Reference>
<Reference Include="Microsoft.VisualBasic" />
<Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" />
@@ -156,7 +133,7 @@
<Compile Include="Misc\UpdateCheck.cs" />
<Compile Include="Misc\RegistryHelp.cs" />
<Compile Include="Misc\Theme.cs" />
<Compile Include="Scripting\PowerShell.cs" />
<Compile Include="Misc\PowerShell.cs" />
<Compile Include="WPF\SearchTextBoxUserControl.xaml.cs">
<DependentUpon>SearchTextBoxUserControl.xaml</DependentUpon>
</Compile>
@@ -179,7 +156,6 @@
<DesignTime>True</DesignTime>
<DependentUpon>Resources.resx</DependentUpon>
</Compile>
<Compile Include="Scripting\IronPython.cs" />
<Compile Include="mpv\libmpv.cs" />
<Compile Include="WinForms\MainForm.cs">
<SubType>Form</SubType>
@@ -188,8 +164,8 @@
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Misc\Misc.cs" />
<Compile Include="mpv\mp.cs" />
<Compile Include="Misc\Command.cs" />
<Compile Include="mpv\core.cs" />
<Compile Include="Misc\Commands.cs" />
<Compile Include="Native\Native.cs" />
<Compile Include="Native\NativeHelp.cs" />
<Compile Include="Misc\Program.cs" />

File diff suppressed because it is too large Load Diff

View File

@@ -44,6 +44,9 @@ public class libmpv
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern mpv_error mpv_set_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref Int64 data);
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern mpv_error mpv_set_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref double data);
[DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)]
public static extern mpv_error mpv_observe_property(IntPtr mpvHandle, UInt64 reply_userdata, [MarshalAs(UnmanagedType.LPUTF8Str)] string name, mpv_format format);
@@ -149,9 +152,9 @@ public class libmpv
[StructLayout(LayoutKind.Sequential)]
public struct mpv_event_log_message
{
public string prefix;
public string level;
public string text;
public IntPtr prefix;
public IntPtr level;
public IntPtr text;
public mpv_log_level log_level;
}

View File

@@ -8,9 +8,11 @@ using System.Linq;
class Script
{
MainForm MainForm;
Core core;
public Script()
{
core = Core.core;
MainForm = mpvnet.MainForm.Instance;
MainForm.ContextMenu.Opening += ContextMenu_Opening;
}
@@ -24,13 +26,13 @@ class Script
return;
menuItem.DropDownItems.Clear();
var editionTracks = mp.MediaTracks.Where(track => track.Type == "e");
var editionTracks = core.MediaTracks.Where(track => track.Type == "e");
foreach (MediaTrack track in editionTracks)
{
MenuItem mi = new MenuItem(track.Text);
mi.Action = () => { mp.commandv("set", "edition", track.ID.ToString()); };
mi.Checked = mp.Edition == track.ID;
mi.Action = () => { core.commandv("set", "edition", track.ID.ToString()); };
mi.Checked = core.Edition == track.ID;
menuItem.DropDownItems.Add(mi);
}
}

View File

@@ -11,9 +11,10 @@ class Script
{
string content = "ctrl+w script-message my-message-1 my-argument-1";
string sectionName = Assembly.GetExecutingAssembly().GetName().Name;
mp.commandv("define-section", sectionName, content, "force");
mp.commandv("enable-section", sectionName);
mp.ClientMessage += ClientMessage;
Core core = Core.core;
core.commandv("define-section", sectionName, content, "force");
core.commandv("enable-section", sectionName);
core.ClientMessage += ClientMessage;
}
void ClientMessage(string[] args)

View File

@@ -6,13 +6,16 @@ using mpvnet;
class Script
{
Core core;
public Script()
{
mp.observe_property_bool("fullscreen", FullscreenChange);
core = Core.core;
core.observe_property_bool("fullscreen", FullscreenChange);
}
void FullscreenChange(bool value)
{
mp.commandv("show-text", "fullscreen: " + value);
core.commandv("show-text", "fullscreen: " + value);
}
}

View File

@@ -9,12 +9,14 @@ using mpvnet;
class Script
{
MainForm Form;
Core core;
bool WasPlaying;
bool WasPaused;
public Script()
{
core = Core.core;
Form = MainForm.Instance;
Form.Resize += Form_Resize;
}
@@ -23,11 +25,11 @@ class Script
{
if (Form.WindowState == FormWindowState.Minimized)
{
WasPlaying = !mp.get_property_bool("pause");
WasPlaying = !core.get_property_bool("pause");
if (WasPlaying)
{
mp.set_property_bool("pause", true, true);
core.set_property_bool("pause", true, true);
WasPaused = true;
}
}
@@ -35,7 +37,7 @@ class Script
{
if (WasPaused)
{
mp.set_property_bool("pause", false, true);
core.set_property_bool("pause", false, true);
WasPaused = false;
}
}

View File

@@ -1,4 +0,0 @@
// This script shows a message box using the Msg class of mpv.net.
[Msg]::Show("Hello World")

View File

@@ -1,25 +0,0 @@
# Shows the Open File dialog to open a file without loading its folder into the playlist.
# In input.conf add: <key> script-message load-without-folder
$job = Register-ObjectEvent -InputObject ([mpvnet.mp]) -EventName ClientMessage -Action {
# exit if message does not equal 'load-without-folder'
if ($args.Length -ne 1 -or $args[0] -ne 'load-without-folder')
{
exit
}
$dialog = New-Object Windows.Forms.OpenFileDialog
if ($dialog.ShowDialog() -ne "OK") {
$dialog.Dispose()
exit
}
[mp]::Load($dialog.FileNames, $false, $false);
$dialog.Dispose()
}
$ScriptHost.RedirectEventJobStreams($job)

View File

@@ -1,8 +0,0 @@
# Display position in window title bar when seeking
$job = Register-ObjectEvent -InputObject ([mpvnet.mp]) -EventName Seek -Action {
[MainForm]::Instance.Text = [mp]::get_property_number("time-pos")
}
$ScriptHost.RedirectEventJobStreams($job)

View File

@@ -3,7 +3,6 @@
function showPlaylist()
{
// set font size
mp.set_property_number("osd-font-size", 40);

View File

@@ -8,18 +8,16 @@
local did_minimize = false
mp.observe_property("window-minimized", "bool", function(name, value)
local pause = mp.get_property_bool("pause")
local pause = mp.get_property_native("pause")
if value == true then
if pause == false then
mp.set_property_bool("pause", true)
mp.set_property_native("pause", true)
did_minimize = true
end
elseif value == false then
if did_minimize and (pause == true) then
mp.set_property_bool("pause", false)
mp.set_property_native("pause", false)
end
did_minimize = false
end
end)

View File

@@ -0,0 +1,20 @@
# Shows the Open File dialog to open a file without loading its folder into the playlist.
# In input.conf add: <key> script-message load-without-folder
$code = {
if ($args[0] -eq 'load-without-folder')
{
$dialog = New-Object Windows.Forms.OpenFileDialog
if ($dialog.ShowDialog() -eq 'OK')
{
$core.LoadFiles($dialog.FileNames, $false, $false);
}
$dialog.Dispose()
}
}
$mp.register_event("client-message", $code)

View File

@@ -0,0 +1,25 @@
$code = {
$isMinimized = $args[0]
$isPaused = $mp.get_property_bool('pause')
if ($isMinimized)
{
if (-not $isPaused)
{
$mp.set_property_bool('pause', $true)
$script:wasPaused = $true
}
}
else
{
if ($script:wasPaused -and $isPaused)
{
$mp.set_property_bool('pause', $false)
}
$script:wasPaused = $false
}
}
$mp.observe_property('window-minimized', 'bool', $code)

View File

@@ -0,0 +1,14 @@
# Shows the current file in File Explorer
# In input.conf add: <key> script-message show-in-file-explorer
$code = {
if ($args[0] -eq 'show-in-file-explorer')
{
# probably works only with shell execute for which powershell has no built-in support
[Diagnostics.Process]::Start('explorer.exe', '/n, /select, "' + $mp.get_property_string('path') + '"')
}
}
$mp.register_event("client-message", $code)