Skip to content

Commit 0ea710d

Browse files
committed
Update EncTool + Fix Taskbar progress in invalid state on ZZZ repair
1 parent edbbf45 commit 0ea710d

File tree

2 files changed

+54
-44
lines changed

2 files changed

+54
-44
lines changed

CollapseLauncher/Classes/RepairManagement/Zenless/ZenlessRepair.Repair.cs

Lines changed: 53 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
using Hi3Helper.Data;
55
using Hi3Helper.Http;
66
using Hi3Helper.Shared.ClassStruct;
7-
using System;
87
using System.Collections.Concurrent;
98
using System.Collections.Generic;
109
using System.Collections.ObjectModel;
@@ -21,65 +20,76 @@ internal partial class ZenlessRepair
2120
private async Task<bool> Repair(List<FilePropertiesRemote> repairAssetIndex, CancellationToken token)
2221
{
2322
// Set total activity string as "Waiting for repair process to start..."
24-
Status.ActivityStatus = Locale.Lang._GameRepairPage.Status11;
25-
Status.IsProgressAllIndetermined = true;
23+
Status.ActivityStatus = Locale.Lang._GameRepairPage.Status11;
24+
Status.IsProgressAllIndetermined = true;
2625
Status.IsProgressPerFileIndetermined = true;
26+
Status.IsCompleted = false;
2727

28-
// Update status
29-
UpdateStatus();
28+
try
29+
{
30+
// Update status
31+
UpdateStatus();
3032

31-
// Initialize new proxy-aware HttpClient
32-
using HttpClient client = new HttpClientBuilder<SocketsHttpHandler>()
33-
.UseLauncherConfig(DownloadThreadWithReservedCount)
34-
.SetUserAgent(UserAgent)
35-
.SetAllowedDecompression(DecompressionMethods.None)
36-
.Create();
33+
// Initialize new proxy-aware HttpClient
34+
using HttpClient client = new HttpClientBuilder<SocketsHttpHandler>()
35+
.UseLauncherConfig(DownloadThreadWithReservedCount)
36+
.SetUserAgent(UserAgent)
37+
.SetAllowedDecompression(DecompressionMethods.None)
38+
.Create();
3739

38-
// Use the new DownloadClient instance
39-
DownloadClient downloadClient = DownloadClient.CreateInstance(client);
40+
// Use the new DownloadClient instance
41+
DownloadClient downloadClient = DownloadClient.CreateInstance(client);
4042

41-
// Iterate repair asset and check it using different method for each type
42-
ObservableCollection<IAssetProperty> assetProperty = [.. AssetEntry];
43-
if (IsBurstDownloadEnabled)
44-
{
45-
await Parallel.ForEachAsync(
46-
PairEnumeratePropertyAndAssetIndexPackage(
43+
// Iterate repair asset and check it using different method for each type
44+
ObservableCollection<IAssetProperty> assetProperty = [.. AssetEntry];
45+
if (IsBurstDownloadEnabled)
46+
{
47+
await Parallel.ForEachAsync(
48+
PairEnumeratePropertyAndAssetIndexPackage(
4749
#if ENABLEHTTPREPAIR
48-
EnforceHttpSchemeToAssetIndex(repairAssetIndex)
50+
EnforceHttpSchemeToAssetIndex(repairAssetIndex)
4951
#else
5052
repairAssetIndex
5153
#endif
52-
, assetProperty),
53-
new ParallelOptions { CancellationToken = token, MaxDegreeOfParallelism = DownloadThreadCount },
54-
async (asset, innerToken) =>
55-
{
56-
// Assign a task depends on the asset type
57-
Task assetTask = RepairAssetTypeGeneric(asset, downloadClient, IsCacheUpdateMode ? _httpClient_UpdateAssetProgress : _httpClient_RepairAssetProgress, innerToken);
54+
, assetProperty),
55+
new ParallelOptions { CancellationToken = token, MaxDegreeOfParallelism = DownloadThreadCount },
56+
async (asset, innerToken) =>
57+
{
58+
// Assign a task depends on the asset type
59+
Task assetTask = RepairAssetTypeGeneric(asset, downloadClient, IsCacheUpdateMode ? _httpClient_UpdateAssetProgress : _httpClient_RepairAssetProgress, innerToken);
5860

59-
// Await the task
60-
await assetTask;
61-
});
62-
}
63-
else
64-
{
65-
foreach ((FilePropertiesRemote AssetIndex, IAssetProperty AssetProperty) asset in
66-
PairEnumeratePropertyAndAssetIndexPackage(
61+
// Await the task
62+
await assetTask;
63+
});
64+
}
65+
else
66+
{
67+
foreach ((FilePropertiesRemote AssetIndex, IAssetProperty AssetProperty) asset in
68+
PairEnumeratePropertyAndAssetIndexPackage(
6769
#if ENABLEHTTPREPAIR
68-
EnforceHttpSchemeToAssetIndex(repairAssetIndex)
70+
EnforceHttpSchemeToAssetIndex(repairAssetIndex)
6971
#else
7072
repairAssetIndex
7173
#endif
72-
, assetProperty))
73-
{
74-
// Assign a task depends on the asset type
75-
Task assetTask = RepairAssetTypeGeneric(asset, downloadClient, IsCacheUpdateMode ? _httpClient_UpdateAssetProgress : _httpClient_RepairAssetProgress, token);
74+
, assetProperty))
75+
{
76+
// Assign a task depends on the asset type
77+
Task assetTask = RepairAssetTypeGeneric(asset, downloadClient, IsCacheUpdateMode ? _httpClient_UpdateAssetProgress : _httpClient_RepairAssetProgress, token);
7678

77-
// Await the task
78-
await assetTask;
79+
// Await the task
80+
await assetTask;
81+
}
7982
}
80-
}
8183

82-
return true;
84+
return true;
85+
}
86+
finally
87+
{
88+
Status.IsCompleted = true;
89+
Status.IsCanceled = token.IsCancellationRequested;
90+
// Update status
91+
UpdateStatus();
92+
}
8393
}
8494

8595
#region GenericRepair

Hi3Helper.EncTool

0 commit comments

Comments
 (0)