Skip to content

Commit d5d7407

Browse files
authored
Merge pull request #53 from patchkit-net/feature/zlib-exception-in-unpacking
Cherrypicking the zlib exception handling into 3.10
2 parents ad1e9fb + ebff586 commit d5d7407

File tree

4 files changed

+54
-13
lines changed

4 files changed

+54
-13
lines changed

Assets/PatchKit Patcher/Scripts/AppData/Local/Pack1Unarchiver.cs

Lines changed: 28 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
using PatchKit.Unity.Patcher.Data;
99
using PatchKit.Unity.Patcher.Debug;
1010
using PatchKit.Unity.Utilities;
11+
using SharpRaven;
12+
using SharpRaven.Data;
1113

1214
namespace PatchKit.Unity.Patcher.AppData.Local
1315
{
@@ -225,16 +227,33 @@ private void ExtractFileFromStream(
225227
{
226228
using (var gzipStream = new GZipStream(cryptoStream, Ionic.Zlib.CompressionMode.Decompress))
227229
{
228-
long bytesProcessed = 0;
229-
const int bufferSize = 128 * 1024;
230-
var buffer = new byte[bufferSize];
231-
int count;
232-
while ((count = gzipStream.Read(buffer, 0, bufferSize)) != 0)
230+
try
233231
{
234-
cancellationToken.ThrowIfCancellationRequested();
235-
targetStream.Write(buffer, 0, count);
236-
bytesProcessed += count;
237-
onProgress((double) gzipStream.Position / file.Size.Value);
232+
long bytesProcessed = 0;
233+
const int bufferSize = 128 * 1024;
234+
var buffer = new byte[bufferSize];
235+
int count;
236+
while ((count = gzipStream.Read(buffer, 0, bufferSize)) != 0)
237+
{
238+
targetStream.Write(buffer, 0, count);
239+
bytesProcessed += count;
240+
onProgress(bytesProcessed / (double) file.Size.Value);
241+
}
242+
}
243+
catch (Exception e)
244+
{
245+
DebugLogger.LogException(e);
246+
247+
var logManager = PatcherLogManager.Instance;
248+
PatcherLogSentryRegistry sentryRegistry = logManager.SentryRegistry;
249+
RavenClient ravenClient = sentryRegistry.RavenClient;
250+
251+
var sentryEvent = new SentryEvent(e);
252+
PatcherLogSentryRegistry.AddDataToSentryEvent(sentryEvent, logManager.Storage.Guid.ToString());
253+
254+
ravenClient.Capture(sentryEvent);
255+
256+
throw;
238257
}
239258
}
240259
}

Assets/PatchKit Patcher/Scripts/Debug/PatcherLogManager.cs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,14 @@ public static PatcherLogManager Instance
3636
}
3737
}
3838

39+
public PatcherLogSentryRegistry SentryRegistry
40+
{
41+
get
42+
{
43+
return _sentryRegistry;
44+
}
45+
}
46+
3947
private static readonly DebugLogger DebugLogger = new DebugLogger(typeof(PatcherLogManager));
4048

4149
private PatcherLogStream _stream;
@@ -45,6 +53,8 @@ public static PatcherLogManager Instance
4553
private PatcherLogRegisterTriggers _registerTriggers;
4654

4755
private PatcherLogStorage _storage;
56+
57+
public PatcherLogStorage Storage { get { return _storage; } }
4858

4959
private PatcherLogSentryRegistry _sentryRegistry;
5060

Assets/PatchKit Patcher/Scripts/Debug/PatcherLogSentryRegistry.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,23 @@ namespace PatchKit.Unity.Patcher.Debug
88
{
99
public class PatcherLogSentryRegistry
1010
{
11+
public RavenClient RavenClient
12+
{
13+
get
14+
{
15+
return _ravenClient;
16+
}
17+
}
18+
1119
private readonly RavenClient _ravenClient;
1220

21+
public static readonly string RavenClientId = "https://cb13d9a4a32f456c8411c79c6ad7be9d:[email protected]/175617";
22+
1323
public PatcherLogSentryRegistry()
1424
{
1525
ServicePointManager.ServerCertificateValidationCallback += (sender, certificate, chain, errors) => true;
1626

17-
_ravenClient
18-
= new RavenClient(
19-
"https://cb13d9a4a32f456c8411c79c6ad7be9d:[email protected]/175617");
27+
_ravenClient = new RavenClient(RavenClientId);
2028
}
2129

2230
public void RegisterWithException(Issue issue, string logFileGuid)
@@ -41,7 +49,7 @@ public void RegisterWithException(Exception exception, string logFileGuid)
4149
}, logFileGuid);
4250
}
4351

44-
private static void AddDataToSentryEvent(SentryEvent sentryEvent, string logFileGuid)
52+
public static void AddDataToSentryEvent(SentryEvent sentryEvent, string logFileGuid)
4553
{
4654
sentryEvent.Exception.Data.Add("log-guid", logFileGuid);
4755
sentryEvent.Exception.Data.Add("log-link", string.Format(

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
3030
- Rename PK_PATCHER_MAIN_URL environmental variable to PK_PATCHER_API_URL
3131
- The patcher will now delete the lockfile when quitting
3232

33+
## [3.9.2]
34+
### Added
35+
- Logging the probable cause of the Zlib exception when unpacking
36+
3337
## [3.9.1]
3438
### Fixed
3539
- Use 'any' instead of 'all' for publish method

0 commit comments

Comments
 (0)