Skip to content

Commit eb1ec98

Browse files
committed
fix(patch): Use Updating state; handle zero DstFiles groups
The group-apply loop was reporting InstallProgressState.Install during krpdiff patching. Rename to InstallProgressState.Updating, which is the correct state enum value for an in-place patch operation. When all GroupInfos have empty DstFiles arrays (e.g. the API returned groups without dest file metadata), the previous code initialised TotalStateToComplete and TotalCountToDownload to 0, making the progress bar appear stuck at 0/0. Fall back to the group count as the effective total so the counter always reads 'n/N groups' in that case, and advance it by one per empty group so progress is visible as they are processed.
1 parent a12a616 commit eb1ec98

1 file changed

Lines changed: 21 additions & 4 deletions

File tree

Hi3Helper.Plugin.Wuwa/Management/WuwaGameInstaller.Patch.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1132,9 +1132,11 @@ await _owner.TryDownloadWholeFileWithFallbacksAsync(
11321132

11331133
if (patchIndex.GroupInfos.Length > 0)
11341134
{
1135-
currentProgressState = InstallProgressState.Install;
1135+
currentProgressState = InstallProgressState.Updating;
11361136

1137-
// Count total destination files and bytes across all groups
1137+
// Count total destination files and bytes across all groups.
1138+
// Fall back to group count when DstFiles are empty (e.g. API parsing
1139+
// returned no dest entries) so we never report a total of 0.
11381140
int totalDstFiles = 0;
11391141
long totalPatchBytes = 0;
11401142
foreach (var g in patchIndex.GroupInfos)
@@ -1144,10 +1146,14 @@ await _owner.TryDownloadWholeFileWithFallbacksAsync(
11441146
totalPatchBytes += (long)d.Size;
11451147
}
11461148

1147-
installProgress.TotalStateToComplete = totalDstFiles;
1149+
// If every group has no DstFiles, fall back to the group count
1150+
// so the progress counter shows "0/N groups" rather than "0/0".
1151+
int effectiveTotal = totalDstFiles > 0 ? totalDstFiles : patchIndex.GroupInfos.Length;
1152+
1153+
installProgress.TotalStateToComplete = effectiveTotal;
11481154
installProgress.StateCount = 0;
11491155
installProgress.TotalBytesToDownload = totalPatchBytes;
1150-
installProgress.TotalCountToDownload = totalDstFiles;
1156+
installProgress.TotalCountToDownload = effectiveTotal;
11511157
installProgress.DownloadedBytes = 0;
11521158
installProgress.DownloadedCount = 0;
11531159
ReportProgress();
@@ -1161,7 +1167,18 @@ await _owner.TryDownloadWholeFileWithFallbacksAsync(
11611167

11621168
var group = patchIndex.GroupInfos[groupIdx];
11631169
if (group.DstFiles.Length == 0)
1170+
{
1171+
// When the fallback total is group-based (totalDstFiles == 0),
1172+
// advance the counter by 1 per group so progress is visible.
1173+
if (totalDstFiles == 0)
1174+
{
1175+
Interlocked.Increment(ref installProgress.StateCount);
1176+
Interlocked.Increment(ref installProgress.DownloadedCount);
1177+
ReportProgress();
1178+
}
1179+
completedGroups++;
11641180
continue;
1181+
}
11651182

11661183
// Pre-compute expected byte total for this group
11671184
long groupExpectedBytes = 0;

0 commit comments

Comments
 (0)