From bbfa9769490f958d05d1546c7b5469dd63a4505e Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Tue, 15 May 2018 12:36:15 +0200 Subject: [PATCH 1/4] Additional try catch and immediate reporting --- .../Scripts/AppData/Local/Pack1Unarchiver.cs | 45 +++++++++++++++++++ .../Scripts/Debug/PatcherLogManager.cs | 2 + .../Scripts/Debug/PatcherLogSentryRegistry.cs | 2 +- 3 files changed, 48 insertions(+), 1 deletion(-) diff --git a/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs b/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs index eac14b30..1a2aeac7 100644 --- a/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs +++ b/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs @@ -7,6 +7,8 @@ using PatchKit.Unity.Patcher.Data; using PatchKit.Unity.Patcher.Debug; using PatchKit.Unity.Utilities; +using SharpRaven; +using SharpRaven.Data; namespace PatchKit.Unity.Patcher.AppData.Local { @@ -174,6 +176,49 @@ private void UnpackRegularFile(Pack1Meta.FileEntry file, Action onProgre DebugLogger.Log("File " + file.Name + " unpacked successfully!"); } + private void ExtractFileFromStream( + Stream sourceStream, + Stream targetStream, + Pack1Meta.FileEntry file, + ICryptoTransform decryptor, + Action onProgress, + CancellationToken cancellationToken) + { + using (var cryptoStream = new CryptoStream(sourceStream, decryptor, CryptoStreamMode.Read)) + { + using (var gzipStream = new GZipStream(cryptoStream, Ionic.Zlib.CompressionMode.Decompress)) + { + try + { + long bytesProcessed = 0; + const int bufferSize = 128 * 1024; + var buffer = new byte[bufferSize]; + int count; + while ((count = gzipStream.Read(buffer, 0, bufferSize)) != 0) + { + cancellationToken.ThrowIfCancellationRequested(); + targetStream.Write(buffer, 0, count); + bytesProcessed += count; + onProgress((double) gzipStream.Position / file.Size.Value); + } + } + catch (Exception e) + { + DebugLogger.LogException(e); + + var ravenClient + = new RavenClient("https://cb13d9a4a32f456c8411c79c6ad7be9d:90ba86762829401e925a9e5c4233100c@sentry.io/175617"); + + var sentryEvent = new SentryEvent(e); + var logManager = PatcherLogManager.Instance; + PatcherLogSentryRegistry.AddDataToSentryEvent(sentryEvent, logManager.Storage.Guid.ToString()); + + ravenClient.Capture(sentryEvent); + } + } + } + } + protected virtual void OnUnarchiveProgressChanged(string name, bool isFile, int entry, int amount, double entryProgress) { var handler = UnarchiveProgressChanged; diff --git a/Assets/PatchKit Patcher/Scripts/Debug/PatcherLogManager.cs b/Assets/PatchKit Patcher/Scripts/Debug/PatcherLogManager.cs index 6a816808..e0313d6f 100644 --- a/Assets/PatchKit Patcher/Scripts/Debug/PatcherLogManager.cs +++ b/Assets/PatchKit Patcher/Scripts/Debug/PatcherLogManager.cs @@ -45,6 +45,8 @@ public static PatcherLogManager Instance private PatcherLogRegisterTriggers _registerTriggers; private PatcherLogStorage _storage; + + public PatcherLogStorage Storage { get { return _storage; } } private PatcherLogSentryRegistry _sentryRegistry; diff --git a/Assets/PatchKit Patcher/Scripts/Debug/PatcherLogSentryRegistry.cs b/Assets/PatchKit Patcher/Scripts/Debug/PatcherLogSentryRegistry.cs index fbb237a5..289dec07 100644 --- a/Assets/PatchKit Patcher/Scripts/Debug/PatcherLogSentryRegistry.cs +++ b/Assets/PatchKit Patcher/Scripts/Debug/PatcherLogSentryRegistry.cs @@ -41,7 +41,7 @@ public void RegisterWithException(Exception exception, string logFileGuid) }, logFileGuid); } - private static void AddDataToSentryEvent(SentryEvent sentryEvent, string logFileGuid) + public static void AddDataToSentryEvent(SentryEvent sentryEvent, string logFileGuid) { sentryEvent.Exception.Data.Add("log-guid", logFileGuid); sentryEvent.Exception.Data.Add("log-link", string.Format( From 0aef6414014e70eade6d7003033be8be637a917e Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Tue, 15 May 2018 12:36:39 +0200 Subject: [PATCH 2/4] Rethrow --- .../PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs b/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs index 1a2aeac7..bc87df23 100644 --- a/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs +++ b/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs @@ -214,6 +214,8 @@ var ravenClient PatcherLogSentryRegistry.AddDataToSentryEvent(sentryEvent, logManager.Storage.Guid.ToString()); ravenClient.Capture(sentryEvent); + + throw; } } } From dd3a8ced5f21c3ec26b10084723ee50eb8f96a1c Mon Sep 17 00:00:00 2001 From: Dzejkop Date: Tue, 15 May 2018 12:48:57 +0200 Subject: [PATCH 3/4] Actually logging --- .../Scripts/AppData/Local/Pack1Unarchiver.cs | 87 +++++++------------ 1 file changed, 30 insertions(+), 57 deletions(-) diff --git a/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs b/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs index bc87df23..7a40cf7b 100644 --- a/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs +++ b/Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs @@ -151,74 +151,47 @@ private void UnpackRegularFile(Pack1Meta.FileEntry file, Action onProgre { using (var gzipStream = new GZipStream(cryptoStream, Ionic.Zlib.CompressionMode.Decompress)) { - using (var fileWritter = new FileStream(destPath, FileMode.Create)) + try { - long bytesProcessed = 0; - const int bufferSize = 131072; - var buffer = new byte[bufferSize]; - int count; - while ((count = gzipStream.Read(buffer, 0, bufferSize)) != 0) + using (var fileWritter = new FileStream(destPath, FileMode.Create)) { - fileWritter.Write(buffer, 0, count); - bytesProcessed += count; - onProgress(bytesProcessed / (double) file.Size.Value); - } - if (Platform.IsPosix()) - { - Chmod.SetMode(file.Mode.Substring(3), destPath); + long bytesProcessed = 0; + const int bufferSize = 131072; + var buffer = new byte[bufferSize]; + int count; + while ((count = gzipStream.Read(buffer, 0, bufferSize)) != 0) + { + fileWritter.Write(buffer, 0, count); + bytesProcessed += count; + onProgress(bytesProcessed / (double) file.Size.Value); + } + if (Platform.IsPosix()) + { + Chmod.SetMode(file.Mode.Substring(3), destPath); + } } } - } - } - } - } - - DebugLogger.Log("File " + file.Name + " unpacked successfully!"); - } - - private void ExtractFileFromStream( - Stream sourceStream, - Stream targetStream, - Pack1Meta.FileEntry file, - ICryptoTransform decryptor, - Action onProgress, - CancellationToken cancellationToken) - { - using (var cryptoStream = new CryptoStream(sourceStream, decryptor, CryptoStreamMode.Read)) - { - using (var gzipStream = new GZipStream(cryptoStream, Ionic.Zlib.CompressionMode.Decompress)) - { - try - { - long bytesProcessed = 0; - const int bufferSize = 128 * 1024; - var buffer = new byte[bufferSize]; - int count; - while ((count = gzipStream.Read(buffer, 0, bufferSize)) != 0) - { - cancellationToken.ThrowIfCancellationRequested(); - targetStream.Write(buffer, 0, count); - bytesProcessed += count; - onProgress((double) gzipStream.Position / file.Size.Value); - } - } - catch (Exception e) - { - DebugLogger.LogException(e); + catch (Exception e) + { + DebugLogger.LogException(e); - var ravenClient - = new RavenClient("https://cb13d9a4a32f456c8411c79c6ad7be9d:90ba86762829401e925a9e5c4233100c@sentry.io/175617"); + var ravenClient + = new RavenClient("https://cb13d9a4a32f456c8411c79c6ad7be9d:90ba86762829401e925a9e5c4233100c@sentry.io/175617"); - var sentryEvent = new SentryEvent(e); - var logManager = PatcherLogManager.Instance; - PatcherLogSentryRegistry.AddDataToSentryEvent(sentryEvent, logManager.Storage.Guid.ToString()); + var sentryEvent = new SentryEvent(e); + var logManager = PatcherLogManager.Instance; + PatcherLogSentryRegistry.AddDataToSentryEvent(sentryEvent, logManager.Storage.Guid.ToString()); - ravenClient.Capture(sentryEvent); + ravenClient.Capture(sentryEvent); - throw; + throw; + } + } } } } + + DebugLogger.Log("File " + file.Name + " unpacked successfully!"); } protected virtual void OnUnarchiveProgressChanged(string name, bool isFile, int entry, int amount, double entryProgress) From 0d8dde086edde13b530dd463cafd45866c3ba0f1 Mon Sep 17 00:00:00 2001 From: Tomasz Jaworski Date: Tue, 15 May 2018 13:14:36 +0200 Subject: [PATCH 4/4] Update CHANGELOG.md --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8d236207..7e669d6f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](http://keepachangelog.com/) and this project adheres to [Semantic Versioning](http://semver.org/). +## [3.9.2] +### Added +- Logging the probable cause of the Zlib exception when unpacking + ## [3.9.1] ### Fixed - Use 'any' instead of 'all' for publish method