diff --git a/Changelog.md b/Changelog.md index b11038c..f8d7f60 100644 --- a/Changelog.md +++ b/Changelog.md @@ -5,6 +5,10 @@ - Improved window scaling. - Title property implementation. - Command palette shows commands without assigned menu item. +- The code from the included JavaScript file was ported into the core player + because JavaScript is currently broken in the builds of shinshiro. +- MediaInfo 21.3 +- libmpv 2021-02-28 5.4.8.7 Beta (2021-03-09) diff --git a/LICENSE.txt b/LICENSE.txt index 1cb98ce..2bb3bec 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,7 +1,7 @@ MIT License -Copyright (C) 2017-2020 Frank Skare (stax76) +Copyright (C) 2017-2021 mpv.net/mpv/mplayer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and ssociated documentation diff --git a/Manual.md b/Manual.md index db52b3c..f4b660e 100644 --- a/Manual.md +++ b/Manual.md @@ -59,19 +59,8 @@ mpv.net requires the .NET Framework 4.8 and Windows 7 or 10 and a modern graphic There is a setup exe and a portable zip file download. -x64 editions have the advantage of being typically better optimized and tested. - For internet streaming youtube-dl must be downloaded and installed manually, meaning it must be located in the PATH environment variable or in the startup directory. -### Scoop - -If you use Scoop - -``` -scoop bucket add extras -scoop install mpv.net -``` - #### File Associations diff --git a/README.md b/README.md index 9546cd3..6ec6bae 100644 --- a/README.md +++ b/README.md @@ -79,7 +79,7 @@ Features - Fast startup performance - Usable as video player, audio player and image viewer with a wide range of supported formats - Built-in decoders, no external codecs have to be installed -- Setup as x64, x86, installer, portable, Chocolatey and Scoop +- Setup as x64 installer, portable and Chocolatey - Build-in media streaming (requires youtube-dl being installed) - File associations can be created by the setup and from the player - External audio and subtitle files can be loaded manually or automatically diff --git a/Release.ps1 b/Release.ps1 index 173f3fe..2e20da3 100644 --- a/Release.ps1 +++ b/Release.ps1 @@ -1,9 +1,7 @@ $tmpDir = 'D:\Work' -$exePath = $PSScriptRoot + '\mpv.net\bin\x64\mpvnet.exe' +$exePath = $PSScriptRoot + '\mpv.net\bin\mpvnet.exe' $versionInfo = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath) -$vsDir = 'C:\Program Files (x86)\Microsoft Visual Studio\2019' -$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' @@ -34,25 +32,11 @@ function UploadBeta($sourceFile) if ($versionInfo.FilePrivatePart -eq 0) { - & $msBuild mpv.net.sln -t:Rebuild -p:Configuration=Debug -p:Platform=x64 + & $inno setup.iss if ($LastExitCode) { throw $LastExitCode } - & $msBuild mpv.net.sln -t:Rebuild -p:Configuration=Debug -p:Platform=x86 - if ($LastExitCode) { throw $LastExitCode } - - & $inno /Darch=x64 setup.iss - if ($LastExitCode) { throw $LastExitCode } - - & $inno /Darch=x86 setup.iss - if ($LastExitCode) { throw $LastExitCode } - - $targetDir = $tmpDir + "\mpv.net-portable-x64-$($versionInfo.FileVersion)" - Copy-Item .\mpv.net\bin\x64 $targetDir -Recurse -Exclude System.Management.Automation.xml - & $7z a -tzip -mx9 "$targetDir.zip" -r "$targetDir\*" - if ($LastExitCode) { throw $LastExitCode } - - $targetDir = $tmpDir + "\mpv.net-portable-x86-$($versionInfo.FileVersion)" - Copy-Item .\mpv.net\bin\x86 $targetDir -Recurse -Exclude System.Management.Automation.xml + $targetDir = $tmpDir + "\mpv.net-$($versionInfo.FileVersion)-portable" + Copy-Item .\mpv.net\bin $targetDir -Recurse -Exclude System.Management.Automation.xml & $7z a -tzip -mx9 "$targetDir.zip" -r "$targetDir\*" if ($LastExitCode) { throw $LastExitCode } @@ -62,20 +46,8 @@ if ($versionInfo.FilePrivatePart -eq 0) } 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 = "$tmpDir\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" - - $targetDir = $tmpDir + "\mpv.net-portable-x86-$($versionInfo.FileVersion)-beta" - Copy-Item .\mpv.net\bin\x86 $targetDir -Recurse -Exclude System.Management.Automation.xml + $targetDir = "$tmpDir\mpv.net-$($versionInfo.FileVersion)-portable-beta" + Copy-Item .\mpv.net\bin $targetDir -Recurse -Exclude System.Management.Automation.xml & $7z a -t7z -mx9 "$targetDir.7z" -r "$targetDir\*" if ($LastExitCode) { throw $LastExitCode } UploadBeta "$targetDir.7z" diff --git a/extensions/RatingExtension/RatingExtension.cs b/extensions/RatingExtension/RatingExtension.cs index 808a8b6..4d189a8 100644 --- a/extensions/RatingExtension/RatingExtension.cs +++ b/extensions/RatingExtension/RatingExtension.cs @@ -95,10 +95,21 @@ namespace RatingExtension // the assembly name must end with 'Extension' else { TimeSpan ts = DateTime.Now - DeleteTime; - - if (FileToDelete == core.get_property_string("path") && ts.TotalSeconds < 5 && File.Exists(FileToDelete)) + string path = core.get_property_string("path"); + + if (FileToDelete == path && ts.TotalSeconds < 5 && File.Exists(FileToDelete)) { core.command("playlist-remove current"); + int pos = core.get_property_int("playlist-pos"); + + if (pos == -1) + { + int count = core.get_property_int("playlist-count"); + + if (count > 0) + core.set_property_int("playlist-pos", count - 1); + } + Thread.Sleep(2000); FileSystem.DeleteFile(FileToDelete, UIOption.OnlyErrorDialogs, RecycleOption.SendToRecycleBin); } diff --git a/extensions/RatingExtension/RatingExtension.csproj b/extensions/RatingExtension/RatingExtension.csproj index 8f4e02a..e610099 100644 --- a/extensions/RatingExtension/RatingExtension.csproj +++ b/extensions/RatingExtension/RatingExtension.csproj @@ -13,39 +13,23 @@ 512 - + true - ..\..\mpv.net\bin\x86\Extensions\RatingExtension\ + ..\..\mpv.net\bin\Extensions\RatingExtension\ DEBUG;TRACE full - x86 + AnyCPU + 7.3 prompt MinimumRecommendedRules.ruleset - - ..\..\mpv.net\bin\x86\Extensions\RatingExtension\ + + ..\..\mpv.net\bin\Extensions\RatingExtension\ TRACE true pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset - - - true - ..\..\mpv.net\bin\x64\Extensions\RatingExtension\ - DEBUG;TRACE - full - x64 - prompt - MinimumRecommendedRules.ruleset - - - ..\..\mpv.net\bin\x64\Extensions\RatingExtension\ - TRACE - true - pdbonly - x64 + AnyCPU + 7.3 prompt MinimumRecommendedRules.ruleset diff --git a/extensions/ScriptingExtension/ScriptingExtension.csproj b/extensions/ScriptingExtension/ScriptingExtension.csproj index 3703692..2a8c199 100644 --- a/extensions/ScriptingExtension/ScriptingExtension.csproj +++ b/extensions/ScriptingExtension/ScriptingExtension.csproj @@ -13,39 +13,23 @@ 512 - + true - ..\..\mpv.net\bin\x86\Extensions\ScriptingExtension\ + ..\..\mpv.net\bin\Extensions\ScriptingExtension\ DEBUG;TRACE full - x86 + AnyCPU + 7.3 prompt MinimumRecommendedRules.ruleset - - ..\..\mpv.net\bin\x86\Extensions\ScriptingExtension\ + + ..\..\mpv.net\bin\Extensions\ScriptingExtension\ TRACE true pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset - - - true - ..\..\mpv.net\bin\x64\Extensions\ScriptingExtension\ - DEBUG;TRACE - full - x64 - prompt - MinimumRecommendedRules.ruleset - - - ..\..\mpv.net\bin\x64\Extensions\ScriptingExtension\ - TRACE - true - pdbonly - x64 + AnyCPU + 7.3 prompt MinimumRecommendedRules.ruleset diff --git a/mpv.net.sln b/mpv.net.sln index 739cfb8..f6a313d 100644 --- a/mpv.net.sln +++ b/mpv.net.sln @@ -11,36 +11,22 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScriptingExtension", "exten EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution - Debug|x64 = Debug|x64 - Debug|x86 = Debug|x86 - Release|x64 = Release|x64 - Release|x86 = Release|x86 + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|x64.ActiveCfg = Debug|x64 - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|x64.Build.0 = Debug|x64 - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|x86.ActiveCfg = Debug|x86 - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|x86.Build.0 = Debug|x86 - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|x64.ActiveCfg = Release|x64 - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|x64.Build.0 = Release|x64 - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|x86.ActiveCfg = Release|x86 - {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|x86.Build.0 = Release|x86 - {55C88710-539D-4402-84C8-31694841C731}.Debug|x64.ActiveCfg = Debug|x64 - {55C88710-539D-4402-84C8-31694841C731}.Debug|x64.Build.0 = Debug|x64 - {55C88710-539D-4402-84C8-31694841C731}.Debug|x86.ActiveCfg = Debug|x86 - {55C88710-539D-4402-84C8-31694841C731}.Debug|x86.Build.0 = Debug|x86 - {55C88710-539D-4402-84C8-31694841C731}.Release|x64.ActiveCfg = Release|x64 - {55C88710-539D-4402-84C8-31694841C731}.Release|x64.Build.0 = Release|x64 - {55C88710-539D-4402-84C8-31694841C731}.Release|x86.ActiveCfg = Release|x86 - {55C88710-539D-4402-84C8-31694841C731}.Release|x86.Build.0 = Release|x86 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x64.ActiveCfg = Debug|x64 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x64.Build.0 = Debug|x64 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x86.ActiveCfg = Debug|x86 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|x86.Build.0 = Debug|x86 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|x64.ActiveCfg = Release|x64 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|x64.Build.0 = Release|x64 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|x86.ActiveCfg = Release|x86 - {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|x86.Build.0 = Release|x86 + {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1751F378-8EDF-4B62-BE6D-304C7C287089}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1751F378-8EDF-4B62-BE6D-304C7C287089}.Release|Any CPU.Build.0 = Release|Any CPU + {55C88710-539D-4402-84C8-31694841C731}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {55C88710-539D-4402-84C8-31694841C731}.Debug|Any CPU.Build.0 = Debug|Any CPU + {55C88710-539D-4402-84C8-31694841C731}.Release|Any CPU.ActiveCfg = Release|Any CPU + {55C88710-539D-4402-84C8-31694841C731}.Release|Any CPU.Build.0 = Release|Any CPU + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Debug|Any CPU.Build.0 = Debug|Any CPU + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|Any CPU.ActiveCfg = Release|Any CPU + {94255EF2-C823-4D82-9017-0E993CC0F5A1}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/mpv.net/Misc/App.cs b/mpv.net/Misc/App.cs index 453b346..083170b 100644 --- a/mpv.net/Misc/App.cs +++ b/mpv.net/Misc/App.cs @@ -83,7 +83,7 @@ namespace mpvnet core.Initialized += Initialized; } - public static void RunAction(Action action) + public static void RunTask(Action action) { Task.Run(() => { try { @@ -96,7 +96,7 @@ namespace mpvnet public static string Version { get { - return "Copyright (C) 2000-2021 mpv.net/mpv/mplayer\n" + + return "Copyright (C) 2017-2021 mpv.net/mpv/mplayer\n" + $"mpv.net {Application.ProductVersion} ({File.GetLastWriteTime(Application.ExecutablePath).ToShortDateString()})\n" + $"{core.get_property_string("mpv-version")} ({File.GetLastWriteTime(Folder.Startup + "mpv-1.dll").ToShortDateString()})\nffmpeg {core.get_property_string("ffmpeg-version")}\nMIT License"; } diff --git a/mpv.net/Misc/Commands.cs b/mpv.net/Misc/Commands.cs index e86b84c..2bcdac1 100644 --- a/mpv.net/Misc/Commands.cs +++ b/mpv.net/Misc/Commands.cs @@ -12,6 +12,7 @@ using VB = Microsoft.VisualBasic; using static mpvnet.NewLine; using static mpvnet.Core; +using System.Threading.Tasks; namespace mpvnet { @@ -48,10 +49,13 @@ namespace mpvnet case "show-keys": ShowTextWithEditor("input-key-list", core.get_property_string("input-key-list").Replace(",", BR)); break; case "show-media-search": ShowDialog(typeof(EverythingWindow)); break; case "show-profiles": ShowTextWithEditor("profile-list", mpvHelp.GetProfiles()); break; + case "show-playlist": ShowPlaylist(); break; case "show-properties": ShowProperties(); break; case "show-protocols": ShowTextWithEditor("protocol-list", mpvHelp.GetProtocols()); break; case "show-setup-dialog": ShowDialog(typeof(SetupWindow)); break; + case "show-text": ShowText(args[0], Convert.ToInt32(args[1]), Convert.ToInt32(args[2])); break; case "update-check": UpdateCheck.CheckOnline(true); break; + default: Msg.ShowError($"No command '{id}' found."); break; } } @@ -161,7 +165,7 @@ namespace mpvnet { fileSize = new FileInfo(path).Length; - if (Core.AudioTypes.Contains(path.Ext())) + if (AudioTypes.Contains(path.Ext())) { using (MediaInfo mediaInfo = new MediaInfo(path)) { @@ -185,7 +189,7 @@ namespace mpvnet return; } } - else if (Core.ImageTypes.Contains(path.Ext())) + else if (ImageTypes.Contains(path.Ext())) { using (MediaInfo mediaInfo = new MediaInfo(path)) { @@ -308,7 +312,7 @@ namespace mpvnet core.commandv("show-text", aid + ": " + tracks[aid - 1].Text.Substring(3), "5000"); } - static void ShowCommands() + public static void ShowCommands() { string code = @" foreach ($item in ($json | ConvertFrom-Json | foreach { $_ } | sort name)) @@ -333,22 +337,54 @@ namespace mpvnet ShowTextWithEditor("command-list", PowerShell.InvokeAndReturnString(code, "json", json)); } - static void ShowProperties() + public static void ShowProperties() { var props = core.get_property_string("property-list").Split(',').OrderBy(prop => prop); ShowTextWithEditor("property-list", string.Join(BR, props)); } - static void ShowTextWithEditor(string name, string text) + public static void ShowTextWithEditor(string name, string text) { string file = Path.GetTempPath() + $"\\{name}.txt"; File.WriteAllText(file, BR + text.Trim() + BR); ProcessHelp.ShellExecute(file); } - static void ScaleWindow(float factor) + public static void ScaleWindow(float factor) { core.RaiseScaleWindow(factor); } + + public static void ShowText(string text, int duration = 0, int fontSize = 0) + { + if (string.IsNullOrEmpty(text)) + return; + + if (duration == 0) + duration = core.get_property_int("osd-duration"); + + if (fontSize == 0) + fontSize = core.get_property_int("osd-font-size"); + + core.command("show-text \"${osd-ass-cc/0}{\\\\fs" + fontSize + + "}${osd-ass-cc/1}" + text + "\" " + duration); + } + + public static void ShowPlaylist(string[] args = null) + { + int duration = 5000; + + if (args?.Length == 1) + duration = Convert.ToInt32(args[0]); + + var size = core.get_property_number("osd-font-size"); + core.set_property_number("osd-font-size", 40); + core.command("show-text ${playlist} " + duration); + + App.RunTask(() => { + Thread.Sleep(6000); + core.set_property_number("osd-font-size", size); + }); + } } } diff --git a/mpv.net/Misc/Misc.cs b/mpv.net/Misc/Misc.cs index a5f9246..610d915 100644 --- a/mpv.net/Misc/Misc.cs +++ b/mpv.net/Misc/Misc.cs @@ -74,13 +74,13 @@ namespace mpvnet RegistryHelp.SetValue($@"HKCR\" + "." + ext, null, ExeFilenameNoExt + "." + ext); RegistryHelp.SetValue($@"HKCR\" + "." + ext + @"\OpenWithProgIDs", ExeFilenameNoExt + "." + ext, ""); - if (Core.VideoTypes.Contains(ext)) + if (VideoTypes.Contains(ext)) RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "video"); - if (Core.AudioTypes.Contains(ext)) + if (AudioTypes.Contains(ext)) RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "audio"); - if (Core.ImageTypes.Contains(ext)) + if (ImageTypes.Contains(ext)) RegistryHelp.SetValue(@"HKCR\" + "." + ext, "PerceivedType", "image"); RegistryHelp.SetValue($@"HKCR\" + ExeFilenameNoExt + "." + ext + @"\shell\open\command", null, $"\"{ExePath}\" \"%1\""); diff --git a/mpv.net/Misc/PowerShell.cs b/mpv.net/Misc/PowerShell.cs index 4515a47..2b86832 100644 --- a/mpv.net/Misc/PowerShell.cs +++ b/mpv.net/Misc/PowerShell.cs @@ -19,7 +19,7 @@ namespace mpvnet public bool Print { get; set; } public List Scripts { get; } = new List(); public List> Variables = new List>(); - public string[] Parameters { get; } + public string[] Arguments { get; } public event Action Event; public event Action PropertyChanged; public List> EventHandlers = new List>(); @@ -41,8 +41,8 @@ namespace mpvnet foreach (string script in Scripts) Pipeline.Commands.AddScript(script); - if (Parameters != null) - foreach (string param in Parameters) + if (Arguments != null) + foreach (string param in Arguments) foreach (Command command in Pipeline.Commands) command.Parameters.Add(null, param); @@ -137,19 +137,19 @@ namespace mpvnet switch (type) { case "bool": case "boolean": - core.observe_property_bool(name, (value) => App.RunAction(() => PropertyChanged.Invoke(name, value))); + core.observe_property_bool(name, (value) => App.RunTask(() => PropertyChanged.Invoke(name, value))); break; case "string": - core.observe_property_string(name, (value) => App.RunAction(() => PropertyChanged.Invoke(name, value))); + core.observe_property_string(name, (value) => App.RunTask(() => PropertyChanged.Invoke(name, value))); break; case "int": case "integer": - core.observe_property_int(name, (value) => App.RunAction(() => PropertyChanged.Invoke(name, value))); + core.observe_property_int(name, (value) => App.RunTask(() => PropertyChanged.Invoke(name, value))); break; case "float": case "double": - core.observe_property_double(name, (value) => App.RunAction(() => PropertyChanged.Invoke(name, value))); + core.observe_property_double(name, (value) => App.RunTask(() => PropertyChanged.Invoke(name, value))); break; case "nil": case "none": case "native": - core.observe_property(name, () => App.RunAction(() => PropertyChanged.Invoke(name, null))); + core.observe_property(name, () => App.RunTask(() => 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"); diff --git a/mpv.net/Misc/UpdateCheck.cs b/mpv.net/Misc/UpdateCheck.cs index 6db31c1..dafcb72 100644 --- a/mpv.net/Misc/UpdateCheck.cs +++ b/mpv.net/Misc/UpdateCheck.cs @@ -32,7 +32,7 @@ namespace mpvnet var response = await client.GetAsync("https://api.github.com/repos/stax76/mpv.net/releases/latest"); response.EnsureSuccessStatusCode(); string content = await response.Content.ReadAsStringAsync(); - Match match = Regex.Match(content, @"""mpv\.net-([\d\.]+)-portable-x64\.zip"""); + Match match = Regex.Match(content, @"""mpv\.net-([\d\.]+)-portable\.zip"""); Version onlineVersion = Version.Parse(match.Groups[1].Value); Version currentVersion = Assembly.GetEntryAssembly().GetName().Version; @@ -48,15 +48,14 @@ namespace mpvnet != onlineVersion.ToString() || showUpToDateMessage) && Msg.ShowQuestion( $"New version {onlineVersion} is available, update now?") == MsgResult.OK) { - string arch = IntPtr.Size == 8 ? "64" : "86"; - string url = $"https://github.com/stax76/mpv.net/releases/download/{onlineVersion}/mpv.net-{onlineVersion}-portable-x{arch}.zip"; + string url = $"https://github.com/stax76/mpv.net/releases/download/{onlineVersion}/mpv.net-{onlineVersion}-portable.zip"; using (Process proc = new Process()) { proc.StartInfo.UseShellExecute = true; proc.StartInfo.WorkingDirectory = Environment.GetFolderPath(Environment.SpecialFolder.Desktop); proc.StartInfo.FileName = "powershell.exe"; - proc.StartInfo.Arguments = $"-NoLogo -NoExit -File \"{Folder.Startup + "Setup\\update.ps1"}\" \"{url}\" \"{Folder.Startup.TrimEnd(Path.DirectorySeparatorChar)}\""; + proc.StartInfo.Arguments = $"-NoExit -ExecutionPolicy Bypass -File \"{Folder.Startup + "Setup\\update.ps1"}\" \"{url}\" \"{Folder.Startup.TrimEnd(Path.DirectorySeparatorChar)}\""; if (Folder.Startup.Contains("Program Files")) proc.StartInfo.Verb = "runas"; diff --git a/mpv.net/Native/TaskDialog.cs b/mpv.net/Native/TaskDialog.cs index fd377ce..8541819 100644 --- a/mpv.net/Native/TaskDialog.cs +++ b/mpv.net/Native/TaskDialog.cs @@ -462,18 +462,20 @@ public class TaskDialog : TaskDialogNative, IDisposable { if (Buttons != null && Buttons.Count > 0) { - ButtonArray = TaskDialog.AllocateAndMarshalButtons(Buttons); + ButtonArray = AllocateAndMarshalButtons(Buttons); Config.pButtons = ButtonArray; Config.cButtons = (uint)Buttons.Count; } - if (RadioButtons == null || RadioButtons.Count <= 0) return; - RadioButtonArray = TaskDialog.AllocateAndMarshalButtons(RadioButtons); + if (RadioButtons == null || RadioButtons.Count <= 0) + return; + + RadioButtonArray = AllocateAndMarshalButtons(RadioButtons); Config.pRadioButtons = RadioButtonArray; Config.cRadioButtons = (uint)RadioButtons.Count; } - public static IntPtr AllocateAndMarshalButtons(List structs) + public static IntPtr AllocateAndMarshalButtons(List structs) { var initialPtr = Marshal.AllocHGlobal(Marshal.SizeOf(typeof(TASKDIALOG_BUTTON)) * structs.Count); var currentPtr = initialPtr; diff --git a/mpv.net/Native/Taskbar.cs b/mpv.net/Native/Taskbar.cs index 7f97099..d5fe8d1 100644 --- a/mpv.net/Native/Taskbar.cs +++ b/mpv.net/Native/Taskbar.cs @@ -23,7 +23,7 @@ public class Taskbar // ITaskbarList2 [PreserveSig] void MarkFullscreenWindow(IntPtr hwnd, [MarshalAs(UnmanagedType.Bool)] bool fFullscreen); // ITaskbarList3 - [PreserveSig] void SetProgressValue(IntPtr hwnd, UInt64 ullCompleted, UInt64 ullTotal); + [PreserveSig] void SetProgressValue(IntPtr hwnd, ulong ullCompleted, ulong ullTotal); [PreserveSig] void SetProgressState(IntPtr hwnd, TaskbarStates state); } @@ -41,7 +41,7 @@ public class Taskbar public void SetValue(double progressValue, double progressMax) { - Instance.SetProgressValue(Handle, (UInt64)progressValue, (UInt64)progressMax); + Instance.SetProgressValue(Handle, (ulong)progressValue, (ulong)progressMax); } } diff --git a/mpv.net/Resources/input.conf.txt b/mpv.net/Resources/input.conf.txt index 55c09e2..d25649f 100644 --- a/mpv.net/Resources/input.conf.txt +++ b/mpv.net/Resources/input.conf.txt @@ -56,11 +56,11 @@ . frame-step #menu: Navigate > Jump Next Frame , frame-back-step #menu: Navigate > Jump Previous Frame _ ignore #menu: Navigate > - - Right seek 7 #menu: Navigate > Jump 7 sec forward - Left seek -7 #menu: Navigate > Jump 7 sec backward + Right seek 5 #menu: Navigate > Jump 5 sec forward + Left seek -5 #menu: Navigate > Jump 5 sec backward _ ignore #menu: Navigate > - - Up seek 40 #menu: Navigate > Jump 40 sec forward - Down seek -40 #menu: Navigate > Jump 40 sec backward + Up seek 30 #menu: Navigate > Jump 30 sec forward + Down seek -30 #menu: Navigate > Jump 30 sec backward _ ignore #menu: Navigate > - Ctrl+Right seek 300 #menu: Navigate > Jump 5 min forward Ctrl+Left seek -300 #menu: Navigate > Jump 5 min backward @@ -158,7 +158,7 @@ _ script-message mpv.net show-decoders #menu: View > Show Decoders _ script-message mpv.net show-demuxers #menu: View > Show Demuxers _ script-message mpv.net show-keys #menu: View > Show Keys - F8 script-binding show-playlist #menu: View > Show Playlist + F8 script-message mpv.net show-playlist #menu: View > Show Playlist Ctrl+p script-message mpv.net show-profiles #menu: View > Show Profiles p show-progress #menu: View > Show Progress Shift+p script-message mpv.net show-properties #menu: View > Show Properties diff --git a/mpv.net/WPF/CommandPaletteWindow.xaml b/mpv.net/WPF/CommandPaletteWindow.xaml index 797e7f6..159b3f4 100644 --- a/mpv.net/WPF/CommandPaletteWindow.xaml +++ b/mpv.net/WPF/CommandPaletteWindow.xaml @@ -11,6 +11,7 @@ Width="400" FontSize="13" ResizeMode="NoResize" + ShowInTaskbar="False" WindowStartupLocation="CenterOwner" Loaded="Window_Loaded"> diff --git a/mpv.net/WPF/EverythingWindow.xaml.cs b/mpv.net/WPF/EverythingWindow.xaml.cs index 4bea558..d3a12c1 100644 --- a/mpv.net/WPF/EverythingWindow.xaml.cs +++ b/mpv.net/WPF/EverythingWindow.xaml.cs @@ -119,7 +119,7 @@ namespace mpvnet void FilterTextBox_TextChanged(object sender, TextChangedEventArgs e) { string searchtext = FilterTextBox.Text; - App.RunAction(() => Search(searchtext)); + App.RunTask(() => Search(searchtext)); } object LockObject = new object(); diff --git a/mpv.net/WinForms/MainForm.cs b/mpv.net/WinForms/MainForm.cs index eb3e02e..df8d069 100644 --- a/mpv.net/WinForms/MainForm.cs +++ b/mpv.net/WinForms/MainForm.cs @@ -953,8 +953,8 @@ namespace mpvnet protected override void OnKeyDown(KeyEventArgs e) { - // prevent beep using alt key - if (Control.ModifierKeys == Keys.Alt) + // prevent annoying beep using alt key + if (ModifierKeys == Keys.Alt) e.SuppressKeyPress = true; base.OnKeyDown(e); diff --git a/mpv.net/mpv.net.csproj b/mpv.net/mpv.net.csproj index ec78c84..35b44f9 100644 --- a/mpv.net/mpv.net.csproj +++ b/mpv.net/mpv.net.csproj @@ -33,47 +33,28 @@ app.manifest - + true - bin\x86\ + bin\ DEBUG;TRACE full - x86 - Auto + AnyCPU 7.3 prompt MinimumRecommendedRules.ruleset + false + false - - bin\x86\ + + bin\ TRACE true pdbonly - x86 - prompt - MinimumRecommendedRules.ruleset - Auto - - - true - bin\x64\ - DEBUG;TRACE - full - x64 - Auto + AnyCPU 7.3 prompt MinimumRecommendedRules.ruleset - - - bin\x64\ - TRACE - true - pdbonly - x64 - prompt - MinimumRecommendedRules.ruleset - Auto + false diff --git a/mpv.net/mpv/Core.cs b/mpv.net/mpv/Core.cs index 565612f..1a1c643 100644 --- a/mpv.net/mpv/Core.cs +++ b/mpv.net/mpv/Core.cs @@ -103,12 +103,12 @@ namespace mpvnet public string Title { get; set; } = ""; public string Vid { get; set; } = ""; - public bool WasInitialSizeSet; public bool Border { get; set; } = true; public bool Fullscreen { get; set; } public bool IsLogoVisible { set; get; } public bool IsQuitNeeded { set; get; } = true; public bool TaskbarProgress { get; set; } = true; + public bool WasInitialSizeSet; public bool WindowMaximized { get; set; } public bool WindowMinimized { get; set; } @@ -129,7 +129,7 @@ namespace mpvnet mpv_request_log_messages(Handle, "terminal-default"); - App.RunAction(() => EventLoop()); + App.RunTask(() => EventLoop()); if (App.IsStartedFromTerminal) { @@ -152,8 +152,6 @@ namespace mpvnet Initialized?.Invoke(); InvokeAsync(InitializedAsync); - - LoadMpvScripts(); } public void ProcessProperty(string name, string value) @@ -287,37 +285,11 @@ namespace mpvnet } } - public void LoadMpvScripts() - { - if (Directory.Exists(Folder.Startup + "Scripts")) - foreach (string path in Directory.GetFiles(Folder.Startup + "Scripts")) - if ((path.EndsWith(".lua") || path.EndsWith(".js")) && KnownScripts.Contains(Path.GetFileName(path))) - commandv("load-script", $"{path}"); - } - - public string[] KnownScripts { get; } = { "show-playlist.js"}; - public void LoadScripts() { - if (Directory.Exists(Folder.Startup + "Scripts")) - { - foreach (string file in Directory.GetFiles(Folder.Startup + "Scripts")) - { - if (KnownScripts.Contains(Path.GetFileName(file))) - { - if (file.EndsWith(".ps1")) - App.RunAction(() => InvokePowerShellScript(file)); - } - else - ConsoleHelp.WriteError("Failed to load script:\n" + file + - "\nOnly scripts that ship with mpv.net are allowed in \\scripts." + - "\nNever copy or install a new mpv.net version on top of a old mpv.net version."); - } - } - if (Directory.Exists(ConfigFolder + "scripts-ps")) foreach (string file in Directory.GetFiles(ConfigFolder + "scripts-ps", "*.ps1")) - App.RunAction(() => InvokePowerShellScript(file)); + App.RunTask(() => InvokePowerShellScript(file)); } public void InvokePowerShellScript(string file) @@ -425,7 +397,7 @@ namespace mpvnet string[] args = ConvertFromUtf8Strings(data.args, data.num_args); if (args.Length > 1 && args[0] == "mpv.net") - App.RunAction(() => Commands.Execute(args[1], args.Skip(2).ToArray())); + App.RunTask(() => Commands.Execute(args[1], args.Skip(2).ToArray())); InvokeAsync(ClientMessageAsync, args); ClientMessage?.Invoke(args); @@ -473,9 +445,9 @@ namespace mpvnet VideoSizeAutoResetEvent.Set(); - App.RunAction(new Action(() => ReadMetaData())); + App.RunTask(new Action(() => ReadMetaData())); - App.RunAction(new Action(() => { + App.RunTask(new Action(() => { string path = core.get_property_string("path"); if (path.Contains("://")) @@ -641,7 +613,7 @@ namespace mpvnet foreach (Action a in action.GetInvocationList()) { var a2 = a; - App.RunAction(a2); + App.RunTask(a2); } } } @@ -653,7 +625,7 @@ namespace mpvnet foreach (Action a in action.GetInvocationList()) { var a2 = a; - App.RunAction(() => a2.Invoke(t)); + App.RunTask(() => a2.Invoke(t)); } } } @@ -665,7 +637,7 @@ namespace mpvnet foreach (Action a in action.GetInvocationList()) { var a2 = a; - App.RunAction(() => a2.Invoke(t1, t2)); + App.RunTask(() => a2.Invoke(t1, t2)); } } } @@ -675,20 +647,6 @@ namespace mpvnet command("overlay-remove 0"); IsLogoVisible = false; } - - public void commandv(params string[] args) - { - IntPtr mainPtr = AllocateUtf8ArrayWithSentinel(args, out IntPtr[] byteArrayPointers); - mpv_error err = mpv_command(Handle, mainPtr); - - foreach (IntPtr ptr in byteArrayPointers) - Marshal.FreeHGlobal(ptr); - - Marshal.FreeHGlobal(mainPtr); - - if (err < 0) - HandleError(err, true, "error executing command:", string.Join("\n", args)); - } public void command(string command, bool throwException = false) { @@ -698,6 +656,70 @@ namespace mpvnet HandleError(err, throwException, "error executing command:", command); } + public void commandv(params string[] args) + { + int count = args.Length + 1; + IntPtr[] pointers = new IntPtr[count]; + IntPtr rootPtr = Marshal.AllocHGlobal(IntPtr.Size * count); + + for (int index = 0; index < args.Length; index++) + { + var bytes = GetUtf8Bytes(args[index]); + IntPtr ptr = Marshal.AllocHGlobal(bytes.Length); + Marshal.Copy(bytes, 0, ptr, bytes.Length); + pointers[index] = ptr; + } + + Marshal.Copy(pointers, 0, rootPtr, count); + mpv_error err = mpv_command(Handle, rootPtr); + + foreach (IntPtr ptr in pointers) + Marshal.FreeHGlobal(ptr); + + Marshal.FreeHGlobal(rootPtr); + + if (err < 0) + HandleError(err, true, "error executing command:", string.Join("\n", args)); + } + + public string expand(string value) + { + string[] args = { "expand-text", value }; + int count = args.Length + 1; + IntPtr[] pointers = new IntPtr[count]; + IntPtr rootPtr = Marshal.AllocHGlobal(IntPtr.Size * count); + + for (int index = 0; index < args.Length; index++) + { + var bytes = GetUtf8Bytes(args[index]); + IntPtr ptr = Marshal.AllocHGlobal(bytes.Length); + Marshal.Copy(bytes, 0, ptr, bytes.Length); + pointers[index] = ptr; + } + + Marshal.Copy(pointers, 0, rootPtr, count); + IntPtr resultNodePtr = Marshal.AllocHGlobal(16); + mpv_error err = mpv_command_ret(Handle, rootPtr, resultNodePtr); + + foreach (IntPtr ptr in pointers) + Marshal.FreeHGlobal(ptr); + + Marshal.FreeHGlobal(rootPtr); + + if (err < 0) + { + HandleError(err, true, "error executing command:", string.Join("\n", args)); + Marshal.FreeHGlobal(resultNodePtr); + return "property expansion error"; + } + + mpv_node resultNode = Marshal.PtrToStructure(resultNodePtr); + string ret = ConvertFromUtf8(resultNode.str); + mpv_free_node_contents(resultNodePtr); + Marshal.FreeHGlobal(resultNodePtr); + return ret; + } + public bool get_property_bool(string name, bool throwException = false) { mpv_error err = mpv_get_property(Handle, GetUtf8Bytes(name), @@ -711,7 +733,7 @@ namespace mpvnet public void set_property_bool(string name, bool value, bool throwException = false) { - Int64 val = (value) ? 1 : 0; + long val = (value) ? 1 : 0; mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_FLAG, ref val); if (err < 0) @@ -731,7 +753,7 @@ namespace mpvnet public void set_property_int(string name, int value, bool throwException = false) { - Int64 val = value; + long val = value; mpv_error err = mpv_set_property(Handle, GetUtf8Bytes(name), mpv_format.MPV_FORMAT_INT64, ref val); if (err < 0) @@ -917,18 +939,6 @@ namespace mpvnet } } - public void show_text(string text, int duration = 0, int fontSize = 0) - { - if (duration == 0) - duration = get_property_int("osd-duration"); - - if (fontSize == 0) - fontSize = get_property_int("osd-font-size"); - - core.command("show-text \"${osd-ass-cc/0}{\\\\fs" + fontSize + - "}${osd-ass-cc/1}" + text + "\" " + duration); - } - public void HandleError(mpv_error err, bool throwException, params string[] messages) { if (throwException) @@ -1106,7 +1116,7 @@ namespace mpvnet set_property_int("playlist-pos", 0); if (loadFolder && !append) - App.RunAction(() => LoadFolder()); + App.RunTask(() => LoadFolder()); } public void LoadISO(string path) diff --git a/mpv.net/mpv/libmpv.cs b/mpv.net/mpv/libmpv.cs index 53b41c7..8e5a56f 100644 --- a/mpv.net/mpv/libmpv.cs +++ b/mpv.net/mpv/libmpv.cs @@ -17,6 +17,12 @@ public class libmpv [DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)] public static extern mpv_error mpv_command_string(IntPtr mpvHandle, [MarshalAs(UnmanagedType.LPUTF8Str)] string command); + [DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)] + public static extern mpv_error mpv_command_ret(IntPtr mpvHandle, IntPtr strings, IntPtr node); + + [DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)] + public static extern void mpv_free_node_contents(IntPtr node); + [DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)] public static extern IntPtr mpv_error_string(mpv_error error); @@ -42,16 +48,16 @@ public class libmpv public static extern mpv_error mpv_set_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref byte[] data); [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); + public static extern mpv_error mpv_set_property(IntPtr mpvHandle, byte[] name, mpv_format format, ref long 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); + public static extern mpv_error mpv_observe_property(IntPtr mpvHandle, ulong reply_userdata, [MarshalAs(UnmanagedType.LPUTF8Str)] string name, mpv_format format); [DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)] - public static extern int mpv_unobserve_property(IntPtr mpvHandle, UInt64 registered_reply_userdata); + public static extern int mpv_unobserve_property(IntPtr mpvHandle, ulong registered_reply_userdata); [DllImport("mpv-1.dll", CallingConvention = CallingConvention.Cdecl)] public static extern void mpv_free(IntPtr data); @@ -163,7 +169,7 @@ public class libmpv { public mpv_event_id event_id; public int error; - public UInt64 reply_userdata; + public ulong reply_userdata; public IntPtr data; } @@ -189,22 +195,16 @@ public class libmpv public int error; } - public static IntPtr AllocateUtf8ArrayWithSentinel(string[] arr, out IntPtr[] byteArrayPointers) + [StructLayout(LayoutKind.Explicit, Size = 16)] + public struct mpv_node { - int numberOfStrings = arr.Length + 1; // add extra element for extra null pointer last (sentinel) - byteArrayPointers = new IntPtr[numberOfStrings]; - IntPtr rootPointer = Marshal.AllocCoTaskMem(IntPtr.Size * numberOfStrings); - - for (int index = 0; index < arr.Length; index++) - { - var bytes = GetUtf8Bytes(arr[index]); - IntPtr unmanagedPointer = Marshal.AllocHGlobal(bytes.Length); - Marshal.Copy(bytes, 0, unmanagedPointer, bytes.Length); - byteArrayPointers[index] = unmanagedPointer; - } - - Marshal.Copy(byteArrayPointers, 0, rootPointer, numberOfStrings); - return rootPointer; + [FieldOffset(0)] public IntPtr str; + [FieldOffset(0)] public int flag; + [FieldOffset(0)] public long int64; + [FieldOffset(0)] public double dbl; + [FieldOffset(0)] public IntPtr list; + [FieldOffset(0)] public IntPtr ba; + [FieldOffset(8)] public mpv_format format; } public static string[] ConvertFromUtf8Strings(IntPtr utf8StringArray, int stringCount) diff --git a/setup.iss b/setup.iss index 1e1ca6c..005c971 100644 --- a/setup.iss +++ b/setup.iss @@ -1,32 +1,18 @@ #define MyAppName "mpv.net" #define MyAppExeName "mpvnet.exe" - -#ifndef arch - #define arch "x64" -#endif - -#if arch == "x64" - #define MyAppSourceDir "mpv.net\bin\x64" - #define MyAppVersion GetFileVersion("mpv.net\bin\x64\mpvnet.exe") -#else - #define MyAppSourceDir "mpv.net\bin\x86" - #define MyAppVersion GetFileVersion("mpv.net\bin\x86\mpvnet.exe") -#endif +#define MyAppSourceDir "mpv.net\bin" +#define MyAppVersion GetFileVersion("mpv.net\bin\mpvnet.exe") [Setup] AppId={{9AA2B100-BEF3-44D0-B819-D8FC3C4D557D}} AppName={#MyAppName} AppVersion={#MyAppVersion} AppPublisher=Frank Skare (stax76) - -#if arch == "x64" - ArchitecturesInstallIn64BitMode=x64 -#endif - +ArchitecturesInstallIn64BitMode=x64 Compression=lzma2 DefaultDirName={commonpf}\{#MyAppName} -OutputBaseFilename=mpv.net-{#MyAppVersion}-setup-{#arch} +OutputBaseFilename=mpv.net-{#MyAppVersion}-setup OutputDir={#GetEnv('USERPROFILE')}\Desktop DefaultGroupName={#MyAppName} SetupIconFile=mpv.net\mpvnet.ico @@ -40,6 +26,6 @@ Source: "{#MyAppSourceDir}\{#MyAppExeName}"; DestDir: "{app}"; Flags: ignorevers Source: "{#MyAppSourceDir}\*"; DestDir: "{app}"; Flags: ignoreversion recursesubdirs createallsubdirs; [UninstallRun] -Filename: "powershell.exe"; Flags: runhidden; Parameters: "-ExecutionPolicy Bypass -File ""{app}\Setup\remove file associations.ps1""" -Filename: "powershell.exe"; Flags: runhidden; Parameters: "-ExecutionPolicy Bypass -File ""{app}\Setup\remove start menu shortcut.ps1""" -Filename: "powershell.exe"; Flags: runhidden; Parameters: "-ExecutionPolicy Bypass -File ""{app}\Setup\remove environment variable.ps1""" +Filename: "powershell.exe"; Flags: runhidden; Parameters: "-NoProfile -ExecutionPolicy Bypass -File ""{app}\Setup\remove file associations.ps1""" +Filename: "powershell.exe"; Flags: runhidden; Parameters: "-NoProfile -ExecutionPolicy Bypass -File ""{app}\Setup\remove start menu shortcut.ps1""" +Filename: "powershell.exe"; Flags: runhidden; Parameters: "-NoProfile -ExecutionPolicy Bypass -File ""{app}\Setup\remove environment variable.ps1"""