From e7d41ff6265a012ccfbef2324a5cf4146f856425 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sat, 23 Mar 2019 15:42:57 +0100 Subject: [PATCH] - --- README.md | 34 ++++++------------------------ mpv.net/Command.cs | 8 +++---- mpv.net/MainForm.cs | 32 ++++++++++++++++++++++++---- mpv.net/Native.cs | 5 +++++ mpv.net/NativeHelp.cs | 22 +++++++++++++++++++ mpv.net/Properties/AssemblyInfo.cs | 4 ++-- 6 files changed, 68 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 2c2a373..a5bf812 100644 --- a/README.md +++ b/README.md @@ -121,6 +121,12 @@ Please note that PowerShell don't allow assigning to events and mpv.net uses as ### Changes +### 1.7 + +- showing the conf files mpv.net uses now the app that is registered for txt files, before it just shell executed the conf file which only worked if conf files were associated with an application +- leaving fullscreen mode the previous window size and position wasn't restored +- when the source video aspect ratio changes the height is kept and the width is adjusted and a check is performed to assure the window is within screen bounds + ### 1.6 - a crash caused by WM_APPCOMMAND (multimedia keyboards) commands was fixed @@ -156,30 +162,4 @@ Please note that PowerShell don't allow assigning to events and mpv.net uses as ### 1.0 -- much more feature packed context menu - -### 0.2.5 - -- mpv lib updated to 2019-02-24 -- UI glitch fixed the appeared when started in fullscreen mode -- fixed default video output mode which caused video playback to fail - -### 0.2.4 - -- changed minimum runtime to .NET 4.7.2 -- fixed mpv.net not working with new mpv lib -- the track name in the title bar was sometimes wrong -- mpv lib updated to 2018-12-16 -- quit-watch-later added to context menu (Shift+Q) to exit and resume at the last position -- ab loop added to menu -- added the possibility to modify mpv.conf settings using the context menu -- added link to the manual and default keys to the menu - -### 0.2.2 - -- history feature added -- mpv lib updated - -### 0.2.1 - -- right-click in fullscreen in the right-left corner closes the app +- much more feature packed context menu \ No newline at end of file diff --git a/mpv.net/Command.cs b/mpv.net/Command.cs index e98604b..7255d6e 100644 --- a/mpv.net/Command.cs +++ b/mpv.net/Command.cs @@ -62,12 +62,12 @@ namespace mpvnet public static void show_keys(string[] args) { - Process.Start(mp.InputConfPath); + Process.Start(NativeHelp.GetAssociatedApplication(".txt"), mp.InputConfPath); } public static void show_prefs(string[] args) { - Process.Start(mp.mpvConfPath); + Process.Start(NativeHelp.GetAssociatedApplication(".txt"), mp.mpvConfPath); } public static void history(string[] args) @@ -148,7 +148,7 @@ namespace mpvnet bitrate = "0"; var bitrate2 = Convert.ToDouble(bitrate) / 1000.0 / 1000.0; - var format = mp.get_property_string("video-format").ToUpper(); + var videoCodec = mp.get_property_string("video-format").ToUpper(); var filename = fileInfo.Name; var text = @@ -157,7 +157,7 @@ namespace mpvnet FormatTime(duration.TotalMinutes) + ":" + FormatTime(duration.Seconds) + "\n" + Convert.ToInt32(fileInfo.Length / 1024 / 1024).ToString() + - $" MB - {width} x {height}\n{format} - {bitrate2.ToString("f1")} Mb/s" + "\n" + filename; + $" MB - {width} x {height}\n{videoCodec} - {bitrate2.ToString("f1")} Mb/s" + "\n" + filename; mp.commandv("show-text", text, "5000"); } diff --git a/mpv.net/MainForm.cs b/mpv.net/MainForm.cs index 2c908b5..1a9c13f 100644 --- a/mpv.net/MainForm.cs +++ b/mpv.net/MainForm.cs @@ -61,10 +61,10 @@ namespace mpvnet Rectangle target = screen.Bounds; Left = target.X + Convert.ToInt32((target.Width - Width) / 2.0); Top = target.Y + Convert.ToInt32((target.Height - Height) / 2.0); - SetFormPositionAndSize(); + SetStartFormPositionAndSize(); } - void SetFormPositionAndSize() + void SetStartFormPositionAndSize() { if (IsFullscreen || mp.VideoSize.Width == 0) return; Screen screen = Screen.FromControl(this); @@ -78,6 +78,30 @@ namespace mpvnet Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */); } + void SetFormPositionAndSizeKeepHeight() + { + if (IsFullscreen || mp.VideoSize.Width == 0) return; + Screen screen = Screen.FromControl(this); + int height = ClientSize.Height; + int width = Convert.ToInt32(height * mp.VideoSize.Width / (double)mp.VideoSize.Height); + Point middlePos = new Point(Left + Width / 2, Top + Height / 2); + var rect = new Native.RECT(new Rectangle(screen.Bounds.X, screen.Bounds.Y, width, height)); + NativeHelp.AddWindowBorders(Handle, ref rect); + int left = middlePos.X - rect.Width / 2; + int top = middlePos.Y - rect.Height / 2; + Screen[] screens = Screen.AllScreens; + + if (left < screens[0].Bounds.Left) + left = screens[0].Bounds.Left; + + int maxLeft = screens[0].Bounds.Left + screens.Select((sc) => sc.Bounds.Width).Sum() - rect.Width - SystemInformation.CaptionHeight; + + if (left > maxLeft) + left = maxLeft; + + Native.SetWindowPos(Handle, IntPtr.Zero /* HWND_TOP */, left, top, rect.Width, rect.Height, 4 /* SWP_NOZORDER */); + } + protected void ProcessCommandLineEarly() { var args = Environment.GetCommandLineArgs().Skip(1); @@ -186,7 +210,7 @@ namespace mpvnet private void mp_VideoSizeChanged() { - BeginInvoke(new Action(() => SetFormPositionAndSize())); + BeginInvoke(new Action(() => SetFormPositionAndSizeKeepHeight())); } private void mp_Shutdown() @@ -218,7 +242,7 @@ namespace mpvnet { WindowState = FormWindowState.Normal; FormBorderStyle = FormBorderStyle.Sizable; - SetFormPositionAndSize(); + SetFormPositionAndSizeKeepHeight(); } } diff --git a/mpv.net/Native.cs b/mpv.net/Native.cs index 5d3fa0d..2d4a636 100644 --- a/mpv.net/Native.cs +++ b/mpv.net/Native.cs @@ -1,6 +1,8 @@ using System; using System.Drawing; +using System.IO; using System.Runtime.InteropServices; +using System.Text; namespace mpvnet { @@ -30,6 +32,9 @@ namespace mpvnet [DllImport("user32.dll", SetLastError = true)] public static extern bool SetWindowPos(IntPtr hWnd, IntPtr hWndInsertAfter, int X, int Y, int cx, int cy, int uFlags); + [DllImport("Shlwapi.dll", SetLastError = true, CharSet = CharSet.Unicode)] + public static extern uint AssocQueryString(uint flags, uint str, string pszAssoc, string pszExtra, StringBuilder pszOut, ref uint pcchOut); + [StructLayout(LayoutKind.Sequential)] public struct RECT { diff --git a/mpv.net/NativeHelp.cs b/mpv.net/NativeHelp.cs index caea177..8e8b54a 100644 --- a/mpv.net/NativeHelp.cs +++ b/mpv.net/NativeHelp.cs @@ -1,4 +1,6 @@ using System; +using System.IO; +using System.Text; namespace mpvnet { @@ -34,5 +36,25 @@ namespace mpvnet { Native.AdjustWindowRect(ref rc, (uint)Native.GetWindowLongPtrW(hwnd, -16 /* GWL_STYLE */), false); } + + public static string GetAssociatedApplication(string ext) + { + uint returnValue = 0U; + // ASSOCF_VERIFY, ASSOCSTR_EXECUTABLE + if (1 == Native.AssocQueryString(0x40, 2, ext, null, null, ref returnValue)) + { + if (returnValue > 0) + { + StringBuilder sb = new StringBuilder(Convert.ToInt32(returnValue)); + // ASSOCF_VERIFY, ASSOCSTR_EXECUTABLE + if (0 == Native.AssocQueryString(0x40, 2, ext, null, sb, ref returnValue)) + { + var ret = sb.ToString(); + if (File.Exists(ret)) return ret; + } + } + } + return ""; + } } } \ No newline at end of file diff --git a/mpv.net/Properties/AssemblyInfo.cs b/mpv.net/Properties/AssemblyInfo.cs index 9582c2a..39b3466 100644 --- a/mpv.net/Properties/AssemblyInfo.cs +++ b/mpv.net/Properties/AssemblyInfo.cs @@ -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("1.6.0.0")] -[assembly: AssemblyFileVersion("1.6.0.0")] +[assembly: AssemblyVersion("1.7.0.0")] +[assembly: AssemblyFileVersion("1.7.0.0")]