Skip to content

Commit 9a15c7f

Browse files
authored
bugfix/v3.17.x.x/repairing-progress-bar-for-unarchive-package (#187)
* Added progress bytes for files. Chnaged mapHashExtractedFiles - always can get hash * Added progress bytes for modified files * Changed lib for pack1 unpackage * Added checking the size of downloaded files when checking size of disk * Changed copy to move files for added files in diff * Refactoring size of files for modified files and unarchive package in diff * Refactoring * Added skipping downloading a package if it is all downloaded * Refactoring checking the size of downloaded files when checking size of disk * Refactoring * Update changelog and version * Refactoring, remove HashExtractedFile * Refactoring Co-authored-by: Jakub Szczyrk <Jakub Szczyrk>
1 parent 644b1f6 commit 9a15c7f

17 files changed

+308
-221
lines changed

Assets/Editor/Tests/Pack1UnarchiverTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,8 @@ public void Unpack()
3030
string metaPath = TestFixtures.GetFilePath("pack1/test.pack1.meta");
3131
string metaString = File.ReadAllText(metaPath);
3232
Pack1Meta meta = Pack1Meta.Parse(metaString);
33-
34-
MapHashExtractedFiles mapHashExtractedFiles = new MapHashExtractedFiles();
35-
var pack1Unarchiver = new Pack1Unarchiver(archivePath, meta, _tempDir, mapHashExtractedFiles, Key);
33+
34+
var pack1Unarchiver = new Pack1Unarchiver(archivePath, meta, _tempDir, Key);
3635
pack1Unarchiver.Unarchive(new CancellationToken());
3736

3837
Assert.True(Directory.Exists(Path.Combine(_tempDir, "dir")));

Assets/Editor/Tests/UnarchiverTest.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,7 @@ private void CheckConsistency(string sourceDirPath, string dirPath)
5353
[Test]
5454
public void Unarchive()
5555
{
56-
MapHashExtractedFiles mapHashExtractedFiles = new MapHashExtractedFiles();
57-
var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath, mapHashExtractedFiles);
56+
var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath);
5857

5958
unarchiver.Unarchive(CancellationToken.Empty);
6059

@@ -64,8 +63,7 @@ public void Unarchive()
6463
[Test]
6564
public void CancelUnarchive()
6665
{
67-
MapHashExtractedFiles mapHashExtractedFiles = new MapHashExtractedFiles();
68-
var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath, mapHashExtractedFiles);
66+
var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath);
6967

7068
CancellationTokenSource source = new CancellationTokenSource();
7169
source.Cancel();
@@ -76,8 +74,7 @@ public void CancelUnarchive()
7674
[Test]
7775
public void UnarchiveCorruptedArchive()
7876
{
79-
MapHashExtractedFiles mapHashExtractedFiles = new MapHashExtractedFiles();
80-
var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/corrupted-zip.zip"), _dirPath, mapHashExtractedFiles);
77+
var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/corrupted-zip.zip"), _dirPath);
8178

8279
Assert.That(() => unarchiver.Unarchive(CancellationToken.Empty), Throws.Exception);
8380
}
@@ -86,9 +83,8 @@ public void UnarchiveCorruptedArchive()
8683
public void UnarchiveWithPassword()
8784
{
8885
string password = "\x08\x07\x18\x24" + "123==";
89-
90-
MapHashExtractedFiles mapHashExtractedFiles = new MapHashExtractedFiles();
91-
var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/password-zip.zip"), _dirPath, mapHashExtractedFiles, password);
86+
87+
var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/password-zip.zip"), _dirPath, password);
9288

9389
unarchiver.Unarchive(CancellationToken.Empty);
9490

@@ -98,8 +94,7 @@ public void UnarchiveWithPassword()
9894
[Test]
9995
public void ProgressReporting()
10096
{
101-
MapHashExtractedFiles mapHashExtractedFiles = new MapHashExtractedFiles();
102-
var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath, mapHashExtractedFiles);
97+
var unarchiver = new ZipUnarchiver(TestFixtures.GetFilePath("unarchiver-test/zip.zip"), _dirPath);
10398

10499
int? lastAmount = null;
105100
int? lastEntry = null;

Assets/PatchKit Patcher/Scripts/AppData/FileSystem/FileOperations.cs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,5 +159,16 @@ private static void MoveInternal(string sourceFilePath, string destinationFilePa
159159
throw;
160160
}
161161
}
162+
163+
public static long GetSizeFile(string filePath)
164+
{
165+
if (string.IsNullOrEmpty(filePath))
166+
{
167+
return 0;
168+
}
169+
170+
FileInfo fInfo = new FileInfo(filePath);
171+
return fInfo.Exists ? fInfo.Length : 0;
172+
}
162173
}
163174
}

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

Lines changed: 0 additions & 31 deletions
This file was deleted.

Assets/PatchKit Patcher/Scripts/AppData/Local/MapHashExtractedFiles.cs.meta

Lines changed: 0 additions & 11 deletions
This file was deleted.

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

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
using System.IO;
33
using System.Security.Cryptography;
44
using System.Text;
5-
using Ionic.Zlib;
5+
using System.IO.Compression;
66
using PatchKit.Network;
77
using PatchKit.Unity.Patcher.AppData.FileSystem;
88
using PatchKit.Unity.Patcher.Cancellation;
@@ -40,9 +40,7 @@ public class Pack1Unarchiver : IUnarchiver
4040
/// The range (in bytes) of the partial pack1 source file
4141
/// </summary>
4242
private readonly BytesRange _range;
43-
44-
private MapHashExtractedFiles _mapHashExtractedFiles;
45-
43+
4644
public event UnarchiveProgressChangedHandler UnarchiveProgressChanged;
4745

4846
// set to true to continue unpacking on error. Check HasErrors later to see if there are any
@@ -51,24 +49,23 @@ public class Pack1Unarchiver : IUnarchiver
5149
// After Unarchive() finishes if this set to true, there were unpacking errors.
5250
public bool HasErrors { get; private set; }
5351

54-
public Pack1Unarchiver(string packagePath, Pack1Meta metaData, string destinationDirPath, MapHashExtractedFiles mapHashExtractedFiles, string key, string suffix = "")
55-
: this(packagePath, metaData, destinationDirPath, mapHashExtractedFiles, Encoding.ASCII.GetBytes(key), suffix, new BytesRange(0, -1))
52+
public Pack1Unarchiver(string packagePath, Pack1Meta metaData, string destinationDirPath, string key, string suffix = "")
53+
: this(packagePath, metaData, destinationDirPath, Encoding.ASCII.GetBytes(key), suffix, new BytesRange(0, -1))
5654
{
5755
// do nothing
5856
}
5957

60-
public Pack1Unarchiver(string packagePath, Pack1Meta metaData, string destinationDirPath, MapHashExtractedFiles mapHashExtractedFiles, string key, string suffix, BytesRange range)
61-
: this(packagePath, metaData, destinationDirPath, mapHashExtractedFiles, Encoding.ASCII.GetBytes(key), suffix, range)
58+
public Pack1Unarchiver(string packagePath, Pack1Meta metaData, string destinationDirPath, string key, string suffix, BytesRange range)
59+
: this(packagePath, metaData, destinationDirPath, Encoding.ASCII.GetBytes(key), suffix, range)
6260
{
6361
// do nothing
6462
}
6563

66-
private Pack1Unarchiver(string packagePath, Pack1Meta metaData, string destinationDirPath, MapHashExtractedFiles mapHashExtractedFiles, byte[] key, string suffix, BytesRange range)
64+
private Pack1Unarchiver(string packagePath, Pack1Meta metaData, string destinationDirPath, byte[] key, string suffix, BytesRange range)
6765
{
6866
Checks.ArgumentFileExists(packagePath, "packagePath");
6967
Checks.ArgumentDirectoryExists(destinationDirPath, "destinationDirPath");
7068
Checks.ArgumentNotNull(suffix, "suffix");
71-
Checks.ArgumentNotNull(mapHashExtractedFiles, "mapHashExtractedFiles");
7269

7370
if (range.Start == 0)
7471
{
@@ -85,7 +82,6 @@ private Pack1Unarchiver(string packagePath, Pack1Meta metaData, string destinati
8582
_destinationDirPath = destinationDirPath;
8683
_suffix = suffix;
8784
_range = range;
88-
_mapHashExtractedFiles = mapHashExtractedFiles;
8985

9086
using (var sha256 = SHA256.Create())
9187
{
@@ -203,7 +199,7 @@ private void Unpack(Pack1Meta.FileEntry file, Action<double> progress, Cancellat
203199

204200
private void UnpackDirectory(Pack1Meta.FileEntry file, CancellationToken cancellationToken)
205201
{
206-
string destPath = Path.Combine(_destinationDirPath, _mapHashExtractedFiles.Add(file.Name));
202+
string destPath = Path.Combine(_destinationDirPath, HashCalculator.ComputeMD5Hash(file.Name));
207203

208204
DebugLogger.Log("Creating directory " + destPath);
209205
DirectoryOperations.CreateDirectory(destPath, cancellationToken);
@@ -212,7 +208,7 @@ private void UnpackDirectory(Pack1Meta.FileEntry file, CancellationToken cancell
212208

213209
private void UnpackSymlink(Pack1Meta.FileEntry file)
214210
{
215-
string destPath = Path.Combine(_destinationDirPath, _mapHashExtractedFiles.Add(file.Name));
211+
string destPath = Path.Combine(_destinationDirPath, HashCalculator.ComputeMD5Hash(file.Name));
216212
DebugLogger.Log("Creating symlink: " + destPath);
217213
// TODO: how to create a symlink?
218214
}
@@ -234,7 +230,7 @@ private DecompressorCreator ResolveDecompressor(Pack1Meta meta)
234230

235231
private void UnpackRegularFile(Pack1Meta.FileEntry file, Action<double> onProgress, CancellationToken cancellationToken, string destinationDirPath = null)
236232
{
237-
string destPath = Path.Combine(destinationDirPath == null ? _destinationDirPath : destinationDirPath, _mapHashExtractedFiles.Add(file.Name) + _suffix);
233+
string destPath = Path.Combine(destinationDirPath == null ? _destinationDirPath : destinationDirPath, HashCalculator.ComputeMD5Hash(file.Name) + _suffix);
238234

239235
DebugLogger.LogFormat("Unpacking regular file {0} to {1}", file, destPath);
240236

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ public class ZipUnarchiver : IUnarchiver
1717
private readonly string _password;
1818

1919
private bool _unarchiveHasBeenCalled;
20-
private MapHashExtractedFiles _mapHashExtractedFiles;
2120

2221
public event UnarchiveProgressChangedHandler UnarchiveProgressChanged;
2322

@@ -27,11 +26,10 @@ public class ZipUnarchiver : IUnarchiver
2726
// not used
2827
public bool HasErrors { get; private set; }
2928

30-
public ZipUnarchiver(string packagePath, string destinationDirPath, MapHashExtractedFiles mapHashExtractedFiles, string password = null)
29+
public ZipUnarchiver(string packagePath, string destinationDirPath, string password = null)
3130
{
3231
Checks.ArgumentFileExists(packagePath, "packagePath");
3332
Checks.ArgumentDirectoryExists(destinationDirPath, "destinationDirPath");
34-
Checks.ArgumentNotNull(mapHashExtractedFiles, "mapHashExtractedFiles");
3533

3634
DebugLogger.LogConstructor();
3735
DebugLogger.LogVariable(packagePath, "packagePath");
@@ -40,7 +38,6 @@ public ZipUnarchiver(string packagePath, string destinationDirPath, MapHashExtra
4038
_packagePath = packagePath;
4139
_destinationDirPath = destinationDirPath;
4240
_password = password;
43-
_mapHashExtractedFiles = mapHashExtractedFiles;
4441
}
4542

4643
public void Unarchive(CancellationToken cancellationToken)
@@ -73,7 +70,7 @@ public void Unarchive(CancellationToken cancellationToken)
7370
private void UnarchiveEntry(ZipEntry zipEntry)
7471
{
7572
DebugLogger.Log(string.Format("Unarchiving entry {0}", zipEntry.FileName));
76-
string destPath = Path.Combine(_destinationDirPath, _mapHashExtractedFiles.Add(zipEntry.FileName));
73+
string destPath = Path.Combine(_destinationDirPath, HashCalculator.ComputeMD5Hash(zipEntry.FileName));
7774
using (var target = new FileStream(destPath, FileMode.Create))
7875
{
7976
zipEntry.Extract(target);

0 commit comments

Comments
 (0)