From 3fd1285ad8a37be2aed09a36dccd39c0950fe702 Mon Sep 17 00:00:00 2001 From: Frank Skare Date: Sun, 17 Mar 2019 20:56:10 +0100 Subject: [PATCH] - --- mpv.net/MainForm.Designer.cs | 1 - mpv.net/MainForm.cs | 45 +++++++++++++++++++++--------------- mpv.net/mp.cs | 5 ++-- release.ps1 | 2 -- 4 files changed, 29 insertions(+), 24 deletions(-) diff --git a/mpv.net/MainForm.Designer.cs b/mpv.net/MainForm.Designer.cs index fc0ff2e..0c1a2ab 100644 --- a/mpv.net/MainForm.Designer.cs +++ b/mpv.net/MainForm.Designer.cs @@ -52,7 +52,6 @@ this.Name = "MainForm"; this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; this.Text = "mpv.net"; - this.Load += new System.EventHandler(this.MainForm_Load); this.ResumeLayout(false); } diff --git a/mpv.net/MainForm.cs b/mpv.net/MainForm.cs index 11b4533..ba8f45d 100644 --- a/mpv.net/MainForm.cs +++ b/mpv.net/MainForm.cs @@ -4,7 +4,7 @@ using System.IO; using System.Runtime.InteropServices; using System.Threading; using System.Windows.Forms; - +using System.Diagnostics; using static mpvnet.StaticUsing; namespace mpvnet @@ -16,7 +16,7 @@ namespace mpvnet private Point LastCursorPosChanged; private int LastCursorChangedTickCount; - private bool IsCloseRequired = true; + private bool IsClosed; public ContextMenuStripEx CMS; @@ -93,7 +93,7 @@ namespace mpvnet private string LastHistory; - private void mpv_PlaybackRestart() + private void mp_PlaybackRestart() { var fn = mp.GetStringProp("filename"); BeginInvoke(new Action(() => { Text = fn + " - mpv.net " + Application.ProductVersion; })); @@ -121,14 +121,14 @@ namespace mpvnet MsgError(e.ToString()); } - private void Mpv_VideoSizeChanged() + private void mp_VideoSizeChanged() { BeginInvoke(new Action(() => SetFormPosSize())); } - private void Mpv_AfterShutdown() + private void mp_Shutdown() { - if (IsCloseRequired) + if (!IsClosed) Invoke(new Action(() => Close())); } @@ -137,7 +137,7 @@ namespace mpvnet get => WindowState == FormWindowState.Maximized; } - void MpvChangeFullscreen(bool value) + void mp_ChangeFullscreen(bool value) { BeginInvoke(new Action(() => ChangeFullscreen(value))); } @@ -263,13 +263,6 @@ namespace mpvnet CursorHelp.Show(); } - protected override void OnFormClosed(FormClosedEventArgs e) - { - base.OnFormClosed(e); - IsCloseRequired = false; - mp.Command("quit"); - } - bool IsMouseInOSC() { return PointToClient(Control.MousePosition).Y > ClientSize.Height * 0.9; @@ -290,13 +283,27 @@ namespace mpvnet } } - private void MainForm_Load(object sender, EventArgs ea) + protected override void OnLoad(EventArgs e) { + base.OnLoad(e); mp.Init(); - mp.ObserveBoolProp("fullscreen", MpvChangeFullscreen); - mp.Shutdown += Mpv_AfterShutdown; - mp.VideoSizeChanged += Mpv_VideoSizeChanged; - mp.PlaybackRestart += mpv_PlaybackRestart; + mp.ObserveBoolProp("fullscreen", mp_ChangeFullscreen); + mp.Shutdown += mp_Shutdown; + mp.VideoSizeChanged += mp_VideoSizeChanged; + mp.PlaybackRestart += mp_PlaybackRestart; + } + + protected override void OnFormClosed(FormClosedEventArgs e) + { + base.OnFormClosed(e); + IsClosed = true; + mp.Command("quit"); + + for (int i = 0; i < 99; i++) + { + if (mp.IsShutdownComplete) break; + Thread.Sleep(50); + } } } } \ No newline at end of file diff --git a/mpv.net/mp.cs b/mpv.net/mp.cs index fafa086..6643157 100644 --- a/mpv.net/mp.cs +++ b/mpv.net/mp.cs @@ -1,12 +1,12 @@ using System; using System.Collections.Generic; -using System.Diagnostics; using System.Drawing; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.InteropServices; using System.Text; +using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; @@ -61,6 +61,7 @@ namespace mpvnet public static string InputConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\input.conf"; public static string mpvConfPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\mpv\\mpv.conf"; public static List PyScripts { get; } = new List(); + public static bool IsShutdownComplete { get; set; } private static Dictionary _mpvConv; @@ -133,7 +134,6 @@ namespace mpvnet { IntPtr ptr = mpv_wait_event(MpvHandle, -1); mpv_event evt = (mpv_event)Marshal.PtrToStructure(ptr, typeof(mpv_event)); - //Debug.WriteLine(evt.event_id); if (MpvWindowHandle == IntPtr.Zero) MpvWindowHandle = FindWindowEx(MainForm.Hwnd, IntPtr.Zero, "mpv", null); @@ -142,6 +142,7 @@ namespace mpvnet { case mpv_event_id.MPV_EVENT_SHUTDOWN: Shutdown?.Invoke(); + IsShutdownComplete = true; return; case mpv_event_id.MPV_EVENT_LOG_MESSAGE: LogMessage?.Invoke(); diff --git a/release.ps1 b/release.ps1 index 372e247..7550191 100644 --- a/release.ps1 +++ b/release.ps1 @@ -3,10 +3,8 @@ $exePath = $scriptDir + "\mpv.net\bin\Debug\mpvnet.exe" $version = [Diagnostics.FileVersionInfo]::GetVersionInfo($exePath).FileVersion $desktopDir = [Environment]::GetFolderPath("Desktop") $targetDir = $desktopDir + "\mpv.net-" + $version -if (Test-Path $targetDir) { rd $targetDir -recurse } Copy-Item $scriptDir\mpv.net\bin\Debug $targetDir -recurse $addonDir = $targetDir + "\Addons" -Remove-Item $addonDir -Recurse -Include *mpvnet.exe, *mpvnet.exe.config, *mpvnet.pdb $7zPath = "C:\Program Files\7-Zip\7z.exe" $args = "a -t7z -mx9 $targetDir.7z -r $targetDir\*" Start-Process -FilePath $7zPath -ArgumentList $args \ No newline at end of file