From b33178f18117fec03dcc7d6c115ad9e8b64db951 Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Thu, 13 Dec 2018 04:26:33 +0100 Subject: [PATCH 1/4] Fix logic of sending PatcherCanceled event --- Assets/PatchKit Patcher/Scripts/Patcher.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/Patcher.cs b/Assets/PatchKit Patcher/Scripts/Patcher.cs index 3d1f20e8..5339f3ce 100644 --- a/Assets/PatchKit Patcher/Scripts/Patcher.cs +++ b/Assets/PatchKit Patcher/Scripts/Patcher.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections; using System.Diagnostics; using System.Linq; @@ -375,8 +375,6 @@ private void CancelThread() { DebugLogger.Log("Cancelling patcher thread..."); - PatcherStatistics.DispatchSendEvent(PatcherStatistics.Event.PatcherCanceled); - _threadCancellationTokenSource.Cancel(); } @@ -853,6 +851,12 @@ private void ThreadUpdateApp(bool automatically, CancellationToken cancellationT _wasUpdateSuccessfulOrNotNecessary = true; } } + catch (OperationCanceledException) + { + PatcherStatistics.DispatchSendEvent(PatcherStatistics.Event.PatcherCanceled); + + throw; + } finally { _state.Value = PatcherState.None; From e259401c813e44be46e996aef026821554371963 Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Thu, 13 Dec 2018 04:26:59 +0100 Subject: [PATCH 2/4] Fix lock file removing --- Assets/PatchKit Patcher/Scripts/Patcher.cs | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/Patcher.cs b/Assets/PatchKit Patcher/Scripts/Patcher.cs index 5339f3ce..f2f73d3c 100644 --- a/Assets/PatchKit Patcher/Scripts/Patcher.cs +++ b/Assets/PatchKit Patcher/Scripts/Patcher.cs @@ -229,12 +229,15 @@ private void CloseLockFile() _lockFileStream.Close(); DebugLogger.Log("Deleting the lock file."); - FileOperations.Delete(_data.Value.LockFilePath, CancellationToken.Empty); + if (File.Exists(_data.Value.LockFilePath)) + { + FileOperations.Delete(_data.Value.LockFilePath, CancellationToken.Empty); + } } } - catch + catch(Exception e) { - DebugLogger.LogWarning("Lock file closing error"); + DebugLogger.LogWarning("Lock file closing error - " + e); } } From 280363457577cbb73eb2840fcc825ae576194436 Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Thu, 13 Dec 2018 05:45:42 +0100 Subject: [PATCH 3/4] New method of closing the patcher --- Assets/PatchKit Patcher/Scripts/Patcher.cs | 52 ++++++++++++---------- 1 file changed, 28 insertions(+), 24 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/Patcher.cs b/Assets/PatchKit Patcher/Scripts/Patcher.cs index f2f73d3c..89450240 100644 --- a/Assets/PatchKit Patcher/Scripts/Patcher.cs +++ b/Assets/PatchKit Patcher/Scripts/Patcher.cs @@ -62,7 +62,7 @@ public static Patcher Instance private Thread _thread; - private bool _isThreadBeingKilled; + private bool _isForceQuitting; private App _app; @@ -200,12 +200,6 @@ public void CancelUpdateApp() public void Quit() { DebugLogger.Log("Quitting application."); - _canStartThread = false; - - if (_wasUpdateSuccessfulOrNotNecessary && !_hasGameBeenStarted) - { - PatcherStatistics.DispatchSendEvent(PatcherStatistics.Event.PatcherSucceededClosed); - } #if UNITY_EDITOR if (Application.isEditor) @@ -215,7 +209,6 @@ public void Quit() else #endif { - CloseLockFile(); Application.Quit(); } } @@ -293,35 +286,44 @@ private void Update() private void OnApplicationQuit() { - if (_thread != null && _thread.IsAlive) - { - DebugLogger.Log("Cancelling application quit because patcher thread is alive."); - - Application.CancelQuit(); - - StartCoroutine(KillThread()); - } + Application.CancelQuit(); + StartCoroutine(ForceQuit()); } - private IEnumerator KillThread() + private IEnumerator ForceQuit() { - if (_isThreadBeingKilled) + if (_isForceQuitting) { yield break; } - _isThreadBeingKilled = true; + _isForceQuitting = true; - DebugLogger.Log("Killing patcher thread..."); + try + { + _canStartThread = false; - yield return StartCoroutine(KillThreadInner()); + CloseLockFile(); - DebugLogger.Log("Patcher thread has been killed."); + yield return StartCoroutine(KillThread()); - _isThreadBeingKilled = false; + if (_wasUpdateSuccessfulOrNotNecessary && !_hasGameBeenStarted) + { + yield return StartCoroutine(PatcherStatistics.SendEvent(PatcherStatistics.Event.PatcherSucceededClosed)); + } + + if (!Application.isEditor) + { + Process.GetCurrentProcess().Kill(); + } + } + finally + { + _isForceQuitting = false; + } } - private IEnumerator KillThreadInner() + private IEnumerator KillThread() { if (_thread == null) { @@ -364,6 +366,8 @@ private IEnumerator KillThreadInner() yield return null; } } + + _thread = null; } private void StartThread() From cb49a57135f317c9375b6c6ad7b5ce70eb636f5e Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Thu, 13 Dec 2018 05:46:42 +0100 Subject: [PATCH 4/4] Update changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index abd2a371..eeb4c460 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -27,6 +27,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/). - Invalid display of progress value when unarchiving - Wrapping the GZipStream input to avoid errors - Fixed all warnings that appear when launching on 5.3.4f1 +- Freeze or crash after closing the patcher ### Removed - Torrent downloading