Skip to content

Commit d603da6

Browse files
authored
Bugfix/v3.17.x.x/repairing progress bar for unarchive package rc2 (#188)
* size of files for progress unarchive package in install content * Size of files for progress in repair files Co-authored-by: Jakub Szczyrk <Jakub Szczyrk>
1 parent 9a15c7f commit d603da6

File tree

4 files changed

+39
-19
lines changed

4 files changed

+39
-19
lines changed

Assets/PatchKit Patcher/Scripts/AppUpdater/AppUpdaterRepairStrategy.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,8 @@ ICheckVersionIntegrityCommand checkVersionIntegrityCommand
132132
_context,
133133
resource,
134134
brokenFiles,
135-
meta);
135+
meta,
136+
cancellationToken);
136137

137138
repairCommand.Prepare(_status, cancellationToken);
138139
repairCommand.Execute(cancellationToken);

Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/AppUpdaterCommandFactory.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,14 @@ public IDownloadPackageCommand CreateDownloadDiffPackageCommand(int versionId, s
4040
return new DownloadPackageCommand(resource, destinationFilePath, destinationMetaPath);
4141
}
4242

43-
public IRepairFilesCommand CreateRepairFilesCommand(int versionId, AppUpdaterContext context, RemoteResource resource, Pack1Meta.FileEntry[] brokenFiles, Pack1Meta meta)
43+
public IRepairFilesCommand CreateRepairFilesCommand(int versionId, AppUpdaterContext context, RemoteResource resource,
44+
Pack1Meta.FileEntry[] brokenFiles, Pack1Meta meta, CancellationToken cancellationToken)
4445
{
4546
string packagePath = context.App.DownloadDirectory.GetContentPackagePath(versionId);
4647
string packagePassword = context.App.RemoteData.GetContentPackageResourcePassword(versionId);
48+
AppContentSummary versionContentSummary = context.App.RemoteMetaData.GetContentSummary(versionId, cancellationToken);
4749

48-
return new RepairFilesCommand(resource, meta, brokenFiles, packagePath, packagePassword, context.App.LocalDirectory);
50+
return new RepairFilesCommand(resource, meta, brokenFiles, packagePath, packagePassword, context.App.LocalDirectory, versionContentSummary);
4951
}
5052

5153
public IInstallContentCommand CreateInstallContentCommand(int versionId, AppUpdaterContext context, CancellationToken cancellationToken)

Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/InstallContentCommand.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class InstallContentCommand : BaseAppUpdaterCommand, IInstallContentComma
2929
private readonly ILocalMetaData _localMetaData;
3030

3131
private OperationStatus _copyFilesStatus;
32-
private OperationStatus _unarchivePackageStatus;
32+
private ProgressBytesFilesStatus _unarchivePackageStatus;
3333
private Pack1Meta _pack1Meta;
3434

3535
public InstallContentCommand(string packagePath, string packageMetaPath, string packagePassword, int versionId,
@@ -69,7 +69,7 @@ public override void Prepare(UpdaterStatus status, CancellationToken cancellatio
6969
};
7070
status.RegisterOperation(_copyFilesStatus);
7171

72-
_unarchivePackageStatus = new OperationStatus
72+
_unarchivePackageStatus = new ProgressBytesFilesStatus("Unarchiving package")
7373
{
7474
Weight = {Value = StatusWeightHelper.GetUnarchivePackageWeight(_versionContentSummary.Size)}
7575
};
@@ -108,15 +108,29 @@ public override void Execute(CancellationToken cancellationToken)
108108
_unarchivePackageStatus.IsActive.Value = true;
109109
_unarchivePackageStatus.Description.Value = "Unarchiving package...";
110110
_unarchivePackageStatus.Progress.Value = 0.0;
111+
_unarchivePackageStatus.TotalBytes.Value = _versionContentSummary.UncompressedSize;
111112

113+
int lastEntry = 0, nextEntry = -1;
114+
112115
unarchiver.UnarchiveProgressChanged += (name, isFile, entry, amount, entryProgress) =>
113116
{
114-
var entryMinProgress = (entry - 1) / (double) amount;
115-
var entryMaxProgress = entry / (double) amount;
117+
if (lastEntry != entry)
118+
{
119+
lastEntry = entry;
116120

117-
_unarchivePackageStatus.Progress.Value = entryMinProgress + (entryMaxProgress - entryMinProgress) * entryProgress;
121+
DebugLogger.Log(string.Format("Unarchiving entry ({0}/{1})...", entry, amount));
122+
DebugLogger.Log("entry = " + entry);
123+
}
118124

119-
_unarchivePackageStatus.Description.Value = string.Format("Unarchiving package ({0}/{1})...", entry, amount);
125+
if (nextEntry == entry)
126+
{
127+
return;
128+
}
129+
130+
nextEntry = entry;
131+
string entryName = HashCalculator.ComputeMD5Hash(name);
132+
133+
_unarchivePackageStatus.ObserveFile(Path.Combine(packageDir.Path, entryName) + Suffix);
120134
};
121135

122136
// Allow to unpack with errors. This allows to install content even on corrupted hard drives, and attempt to fix these later

Assets/PatchKit Patcher/Scripts/AppUpdater/Commands/RepairFilesCommand.cs

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4+
using System.Linq;
5+
using PatchKit.Api.Models.Main;
46
using PatchKit.Logging;
57
using PatchKit.Network;
68
using PatchKit.Unity.Patcher.AppData;
@@ -22,11 +24,12 @@ public class RepairFilesCommand : BaseAppUpdaterCommand, IRepairFilesCommand
2224
{
2325
private struct EntryStatus
2426
{
25-
public OperationStatus RepairStatus;
27+
public ProgressBytesFilesStatus RepairStatus;
2628
public DownloadStatus DownloadStatus;
2729
}
2830

2931
private RemoteResource _resource;
32+
private AppContentSummary _contentSummary;
3033
private Pack1Meta _meta;
3134
private Pack1Meta.FileEntry[] _entries;
3235

@@ -48,14 +51,16 @@ public RepairFilesCommand(
4851
Pack1Meta.FileEntry[] fileEntries,
4952
string destinationPackagePath,
5053
string packagePassword,
51-
ILocalDirectory localData)
54+
ILocalDirectory localData,
55+
AppContentSummary contentSummary)
5256
{
5357
_resource = resource;
5458
_meta = meta;
5559
_entries = fileEntries;
5660

5761
_packagePath = destinationPackagePath;
5862
_packagePassword = packagePassword;
63+
_contentSummary = contentSummary;
5964

6065
_localData = localData;
6166

@@ -113,20 +118,18 @@ public override void Execute(CancellationToken cancellationToken)
113118
repairStatus.IsActive.Value = true;
114119
repairStatus.Description.Value = "Applying fixes...";
115120
repairStatus.Progress.Value = 0.0;
121+
repairStatus.TotalBytes.Value = _contentSummary.Files.First(f => f.Path == entry.Name).Size;
116122

117123
_logger.LogDebug("Unarchiving the package.");
118124
var unarchiver = new Pack1Unarchiver(packagePath, _meta, unarchivePath, _packagePassword, _unpackingSuffix, effectiveRange);
119125
// allow repair to continue on errors, because after the repair process, all the files must be validated again
120126
unarchiver.ContinueOnError = true;
121-
122-
unarchiver.UnarchiveProgressChanged += (name, isFile, unarchiveEntry, amount, entryProgress) =>
123-
{
124-
repairStatus.Progress.Value = entryProgress;
125-
};
126-
127-
unarchiver.UnarchiveSingleFile(entry, cancellationToken);
127+
128128
string nameHash = HashCalculator.ComputeMD5Hash(entry.Name);
129+
repairStatus.ObserveFile(Path.Combine(unarchivePath, nameHash) + _unpackingSuffix);
129130

131+
unarchiver.UnarchiveSingleFile(entry, cancellationToken);
132+
130133
EmplaceFile(Path.Combine(unarchivePath, nameHash + _unpackingSuffix),
131134
Path.Combine(_localData.Path, entry.Name), cancellationToken);
132135

@@ -141,7 +144,7 @@ public override void Prepare(UpdaterStatus status, CancellationToken cancellatio
141144

142145
foreach(var entry in _entries)
143146
{
144-
var repairStatus = new OperationStatus
147+
var repairStatus = new ProgressBytesFilesStatus("Applying fixes")
145148
{
146149
Weight = { Value = StatusWeightHelper.GetUnarchivePackageWeight(entry.Size.Value) }
147150
};

0 commit comments

Comments
 (0)