Skip to content

Commit c62515d

Browse files
authored
Add more information about invalid chunk data exception (#185)
Co-authored-by: Jakub Szczyrk <Jakub Szczyrk>
1 parent 405142a commit c62515d

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

Assets/PatchKit Patcher/Scripts/AppData/Remote/Downloaders/ChunkedFileStream.cs

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -188,14 +188,18 @@ public void Write([NotNull] byte[] buffer, int offset, int count)
188188

189189
if (ChunkFullyInBuffer())
190190
{
191-
if (BufferedChunkValid())
191+
byte[] bufferHash = _hashFunction(_buffer, 0, (int) Math.Min(_chunksData.ChunkSize, RemainingLength));
192+
byte[] chunkHash = _chunksData.Chunks[_chunkIndex + _startChunk].Hash;
193+
194+
if (BufferedChunkValid(bufferHash, chunkHash))
192195
{
193196
FlushBuffer();
194197
}
195198
else
196199
{
197200
DiscardBuffer();
198-
throw new InvalidChunkDataException("Invalid chunk data.");
201+
throw new InvalidChunkDataException("Invalid chunk data. Expected " +
202+
BitConverter.ToString(chunkHash) + ", got " + BitConverter.ToString(bufferHash));
199203
}
200204
}
201205
} while (count > 0);
@@ -206,11 +210,8 @@ private bool ChunkFullyInBuffer()
206210
return _bufferPos == Math.Min(_chunksData.ChunkSize, RemainingLength);
207211
}
208212

209-
private bool BufferedChunkValid()
213+
private bool BufferedChunkValid(byte[] bufferHash, byte[] chunkHash)
210214
{
211-
byte[] bufferHash = _hashFunction(_buffer, 0, (int) Math.Min(_chunksData.ChunkSize, RemainingLength));
212-
byte[] chunkHash = _chunksData.Chunks[_chunkIndex + _startChunk].Hash;
213-
214215
return bufferHash.SequenceEqual(chunkHash);
215216
}
216217

Assets/PatchKit Patcher/Scripts/Version.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ public static class Version
55
public const int Major = 3;
66
public const int Minor = 17;
77
public const int Patch = 9;
8-
public const int Hotfix = 2;
8+
public const int Hotfix = 3;
99

1010
public static string Value
1111
{

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/)
55
and this project adheres to [Semantic Versioning](http://semver.org/).
66

7+
## [3.17.9.3]
8+
### Added
9+
- More information about invalid chunk data exception
10+
711
## [3.17.9.2]
812
### Changed
913
- HDPI scale thresholds

0 commit comments

Comments
 (0)