From 8d08b0e1a134e79c9cd1376ca9d0e8a99c35a688 Mon Sep 17 00:00:00 2001 From: Captain ALM Date: Sun, 18 Sep 2022 15:16:32 +0100 Subject: [PATCH] Update to 0.4.0.1. Fix issue with allowing concurrent update. --- YTDLNetFrontEnd/YTDLNetFrontEnd/Main.cs | 24 ++++++++++--------- .../Properties/AssemblyInfo.cs | 4 ++-- .../util/MonitorableProcess.cs | 11 +++++---- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/YTDLNetFrontEnd/YTDLNetFrontEnd/Main.cs b/YTDLNetFrontEnd/YTDLNetFrontEnd/Main.cs index 700e81d..d934342 100644 --- a/YTDLNetFrontEnd/YTDLNetFrontEnd/Main.cs +++ b/YTDLNetFrontEnd/YTDLNetFrontEnd/Main.cs @@ -81,11 +81,22 @@ namespace com.captainalm.YTDLNetFrontEnd private void backgroundWorkerMain_DoWork(object sender, DoWorkEventArgs e) { + setEnableButtons(false); + + if (theProcess != null) + { + if (((Control.ModifierKeys & Keys.Shift) == Keys.Shift)) theProcess.kill(); + theProcess.waitForExit(); + theProcess.close(); + } + switch ((BWArg)e.Argument) { case BWArg.Install: - setEnableButtons(false); - + this.Invoke(new Action(() => + { + textBoxOutput.AppendText("Updating YT-DL BackEnd..." + Environment.NewLine); + })); using (var locpro = YTDL.executeInstall((YTDL.getInstalled() != ApplicationType.Unavailable) ? YTDL.getInstalled() : (((Control.ModifierKeys & Keys.Shift) == Keys.Shift) ? ApplicationType.YoutubeDL : ApplicationType.YT_DLP), @@ -120,15 +131,6 @@ namespace com.captainalm.YTDLNetFrontEnd setEnableButtons(true); break; case BWArg.Go: - setEnableButtons(false); - - if (theProcess != null) - { - if (((Control.ModifierKeys & Keys.Shift) == Keys.Shift)) theProcess.kill(); - theProcess.waitForExit(); - theProcess.close(); - } - var theTarget = ""; var extraArgs = ""; diff --git a/YTDLNetFrontEnd/YTDLNetFrontEnd/Properties/AssemblyInfo.cs b/YTDLNetFrontEnd/YTDLNetFrontEnd/Properties/AssemblyInfo.cs index 2d11c17..4cae549 100644 --- a/YTDLNetFrontEnd/YTDLNetFrontEnd/Properties/AssemblyInfo.cs +++ b/YTDLNetFrontEnd/YTDLNetFrontEnd/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("0.4.0.0")] -[assembly: AssemblyFileVersion("0.4.0.0")] +[assembly: AssemblyVersion("0.4.0.1")] +[assembly: AssemblyFileVersion("0.4.0.1")] diff --git a/YTDLNetFrontEnd/YTDLNetFrontEnd/util/MonitorableProcess.cs b/YTDLNetFrontEnd/YTDLNetFrontEnd/util/MonitorableProcess.cs index 9a3dd6f..dc342f2 100644 --- a/YTDLNetFrontEnd/YTDLNetFrontEnd/util/MonitorableProcess.cs +++ b/YTDLNetFrontEnd/YTDLNetFrontEnd/util/MonitorableProcess.cs @@ -12,6 +12,7 @@ namespace com.captainalm.YTDLNetFrontEnd.util protected Process representation; protected List outputReceivers = new List(); protected List errorReceivers = new List(); + protected bool closed = false; private object inputSLock = new object(); private object outputSLock = new object(); @@ -68,7 +69,7 @@ namespace com.captainalm.YTDLNetFrontEnd.util { lock (processSLock) { - if (!startInfo.RedirectStandardInput || representation == null || representation.HasExited) return; + if (!startInfo.RedirectStandardInput || representation == null || closed || representation.HasExited) return; lock (inputSLock) { representation.StandardInput.Write(inputData); @@ -78,6 +79,7 @@ namespace com.captainalm.YTDLNetFrontEnd.util public Process start() { + if (closed) return null; lock (processSLock) { representation = Process.Start(startInfo); @@ -128,7 +130,7 @@ namespace com.captainalm.YTDLNetFrontEnd.util public void waitForExit() { - if (representation == null) return; + if (representation == null || closed) return; if (!representation.HasExited) representation.WaitForExit(); } @@ -139,7 +141,8 @@ namespace com.captainalm.YTDLNetFrontEnd.util public void close() { - if (representation == null) return; + if (representation == null || closed) return; + closed = true; waitForExit(); if (representation != null && startInfo.RedirectStandardInput) representation.StandardInput.Close(); representation.Close(); @@ -147,7 +150,7 @@ namespace com.captainalm.YTDLNetFrontEnd.util public void kill() { - if (representation != null && !representation.HasExited) representation.Kill(); + if (representation != null && !closed && !representation.HasExited) representation.Kill(); } } }