Skip to content

Commit 0037f76

Browse files
committed
[Sophon] Add API on SophonPatch, Reverts and Refactors
+ Adding SophonPatch.EnumerateRemovableAsync() + Refactor SophonPatch.EnumerateUpdateAsync() on how to enumerating assets. > Assets with SophonPatchMethod.Remove will no longer be enumerated. Instead, use SophonPatch.EnumerateRemovableAsync() to enumerate them. > Remove unused re-enumeration on async SophonPatch.SophonPatch.EnumerateUpdateAsync() overloads. > Accepts assets with no patch available > This due to changes on how Sophon for ZZZ behaves. The files won't always be indexed if the next version has no changes to that files. But this comes with a risk of that files being ignored (or no longer being downloaded). So instead of indexing from its patch info manifest counterparts, we changed the source to its main info manifest instead. + Fix the update mechanism mistakenly removed old, but still in use files.
1 parent 4b2c2ae commit 0037f76

File tree

3 files changed

+53
-29
lines changed

3 files changed

+53
-29
lines changed

CollapseLauncher/Classes/InstallManagement/Base/InstallManagerBase.Sophon.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ await GameVersionManager.GamePreset
249249
Token.Token);
250250

251251
// Ensure that the manifest is ordered based on _gameVoiceLanguageLocaleIdOrdered
252-
RearrangeDataListLocaleOrder(sophonMainInfoPair.OtherSophonBuildData.ManifestIdentityList,
252+
RearrangeDataListLocaleOrder(sophonMainInfoPair.OtherSophonBuildData!.ManifestIdentityList,
253253
x => x.MatchingField);
254254

255255
// Add the manifest to the pair list
@@ -356,8 +356,8 @@ await SimpleDialogs.Dialog_ChooseAudioLanguageChoice(
356356
Token.Token);
357357

358358
// Get the remote total size and current total size
359-
ProgressAllCountTotal = sophonInfoPairList.Sum(x => x.ChunksInfo.FilesCount);
360-
ProgressAllSizeTotal = sophonInfoPairList.Sum(x => x.ChunksInfo.TotalSize);
359+
ProgressAllCountTotal = sophonInfoPairList.Sum(x => x.ChunksInfo!.FilesCount);
360+
ProgressAllSizeTotal = sophonInfoPairList.Sum(x => x.ChunksInfo!.TotalSize);
361361
ProgressAllSizeCurrent = 0;
362362

363363
// Check for the disk space requirement first and ensure that the space is sufficient
@@ -501,7 +501,7 @@ private async Task<List<SophonAsset>> GetSophonAssetListFromPair(
501501
foreach (SophonChunkManifestInfoPair sophonDownloadInfoPair in sophonInfoPairs)
502502
{
503503
// Try add and if the hashset already contains the same Manifest ID registered, then skip
504-
if (!currentlyProcessedPair.Add(sophonDownloadInfoPair.ManifestInfo.ManifestId))
504+
if (!currentlyProcessedPair.Add(sophonDownloadInfoPair.ManifestInfo!.ManifestId))
505505
{
506506
Logger.LogWriteLine($"Found duplicate operation for {sophonDownloadInfoPair.ManifestInfo.ManifestId}! Skipping...",
507507
LogType.Warning, true);
@@ -542,9 +542,9 @@ protected async Task ConfirmAdditionalInstallDataPackageFiles(
542542
return;
543543
}
544544

545-
List<string> matchingFieldsList = installManifest.Select(x => x.MatchingField).ToList();
545+
List<string> matchingFieldsList = installManifest.Select(x => x.MatchingField).ToList()!;
546546

547-
List<SophonManifestBuildIdentity> otherManifestIdentity = installManifestFirst.OtherSophonBuildData.ManifestIdentityList
547+
List<SophonManifestBuildIdentity> otherManifestIdentity = installManifestFirst.OtherSophonBuildData!.ManifestIdentityList
548548
.Where(x => !commonPackageMatchingFields.Contains(x.MatchingField, StringComparer.OrdinalIgnoreCase))
549549
.ToList();
550550

@@ -1027,7 +1027,7 @@ private async Task TryGetAdditionalPackageForSophonDiff(HttpClient
10271027
return;
10281028
}
10291029

1030-
List<string> additionalPackageMatchingFields = manifestPair.OtherSophonBuildData.ManifestIdentityList
1030+
List<string> additionalPackageMatchingFields = manifestPair.OtherSophonBuildData!.ManifestIdentityList
10311031
.Where(x => !CommonSophonPackageMatchingFields.Contains(x.MatchingField, StringComparer.OrdinalIgnoreCase))
10321032
.Select(x => x.MatchingField)
10331033
.ToList();
@@ -1081,13 +1081,13 @@ private async Task<bool> AddSophonDiffAssetsToList(HttpClient ht
10811081
return false;
10821082
}
10831083

1084-
RearrangeDataListLocaleOrder(requestPairTo.OtherSophonBuildData.ManifestIdentityList,
1084+
RearrangeDataListLocaleOrder(requestPairTo.OtherSophonBuildData!.ManifestIdentityList,
10851085
x => x.MatchingField);
10861086

10871087
if (requestPairFrom.IsFound)
10881088
{
10891089
// Ensure that the manifest is ordered based on _gameVoiceLanguageLocaleIdOrdered
1090-
RearrangeDataListLocaleOrder(requestPairFrom.OtherSophonBuildData.ManifestIdentityList,
1090+
RearrangeDataListLocaleOrder(requestPairFrom.OtherSophonBuildData!.ManifestIdentityList,
10911091
x => x.MatchingField);
10921092

10931093
// Add asset to the list

CollapseLauncher/Classes/InstallManagement/Base/InstallManagerBase.SophonPatch.cs

Lines changed: 43 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ await SophonPatch.CreateSophonChunkManifestInfoPair(httpClient,
108108
SophonDownloadSpeedLimiter.CreateInstance(LauncherConfig.DownloadSpeedLimitCached);
109109

110110
// Get the patch assets to download
111-
(List<SophonPatchAsset>, List<SophonChunkManifestInfoPair>) patchAssets =
111+
(List<SophonPatchAsset> AssetList, List<SophonChunkManifestInfoPair> InfoPairs, bool IsAllowRemoveOldFile) patchAssets =
112112
await GetAlterSophonPatchAssets(httpClient,
113113
branchResources.PatchUrl,
114114
(isPreloadMode ? branchResources.PreloadUrl : branchResources.MainUrl) ?? "",
@@ -120,8 +120,9 @@ await GetAlterSophonPatchAssets(httpClient,
120120
// Start the patch pipeline
121121
await StartAlterSophonPatch(httpClient,
122122
isPreloadMode,
123-
patchAssets.Item1,
124-
patchAssets.Item2,
123+
patchAssets.AssetList,
124+
patchAssets.InfoPairs,
125+
patchAssets.IsAllowRemoveOldFile,
125126
downloadSpeedLimiter,
126127
maxThread,
127128
Token.Token);
@@ -135,7 +136,7 @@ protected virtual async Task ConfirmAdditionalPatchDataPackageFiles(SophonChunkM
135136
{
136137
string currentVersion = GameVersion.ToString();
137138

138-
List<SophonManifestPatchIdentity> otherManifestIdentity = patchManifest.OtherSophonPatchData.ManifestIdentityList
139+
List<SophonManifestPatchIdentity> otherManifestIdentity = patchManifest.OtherSophonPatchData!.ManifestIdentityList
139140
.Where(x => !CommonSophonPackageMatchingFields.Contains(x.MatchingField, StringComparer.OrdinalIgnoreCase))
140141
.ToList();
141142

@@ -303,7 +304,7 @@ protected async Task<bool> SpawnAdditionalPackageDownloadDialog(long baseDownloa
303304
return confirmAdditionalTag == ContentDialogResult.Primary;
304305
}
305306

306-
protected virtual async Task<(List<SophonPatchAsset>, List<SophonChunkManifestInfoPair>)>
307+
protected virtual async Task<(List<SophonPatchAsset> AssetList, List<SophonChunkManifestInfoPair> InfoPairs, bool IsAllowRemoveOldFile)>
307308
GetAlterSophonPatchAssets(HttpClient httpClient,
308309
string manifestUrl,
309310
string downloadOverUrl,
@@ -315,6 +316,7 @@ protected async Task<bool> SpawnAdditionalPackageDownloadDialog(long baseDownloa
315316
SophonChunkManifestInfoPair? rootPatchManifest = null;
316317
SophonChunkManifestInfoPair? rootMainManifest = null;
317318
List<(SophonChunkManifestInfoPair Patch, SophonChunkManifestInfoPair Main, bool IsCommon)> patchManifestList = [];
319+
bool isAlowRemoveOldFile = true;
318320

319321
// Iterate matching fields and get the patch metadata
320322
foreach (string matchingField in matchingFields)
@@ -344,6 +346,7 @@ protected async Task<bool> SpawnAdditionalPackageDownloadDialog(long baseDownloa
344346
Logger.LogWriteLine($"[InstallManagerBase::GetAlterSophonPatchAssets] Cannot find past-version patch manifest for matching field: {matchingField}, Skipping!",
345347
LogType.Warning,
346348
true);
349+
isAlowRemoveOldFile = false;
347350
continue;
348351
}
349352

@@ -370,18 +373,38 @@ protected async Task<bool> SpawnAdditionalPackageDownloadDialog(long baseDownloa
370373
{
371374
// Get the asset and add it to the list
372375
await foreach (SophonPatchAsset patchAsset in SophonPatch
373-
.EnumerateUpdateAsync(httpClient,
374-
manifestPair.Patch,
375-
manifestPair.Main,
376-
updateVersionfrom,
377-
downloadLimiter,
378-
token))
376+
.EnumerateUpdateAsync(httpClient,
377+
manifestPair.Patch,
378+
manifestPair.Main,
379+
updateVersionfrom,
380+
downloadLimiter,
381+
token))
379382
{
380383
patchAssets.Add(patchAsset);
381384
}
382385
}
383386

384-
return (patchAssets, patchManifestList.Select(x => x.Patch).ToList());
387+
// Find the removable assets and compare with the added list.
388+
List<SophonPatchAsset> removableAssets = [];
389+
foreach (var manifestPair in patchManifestList)
390+
{
391+
// Get the asset and add it to the list
392+
await foreach (SophonPatchAsset patchAsset in SophonPatch
393+
.EnumerateRemovableAsync(httpClient,
394+
manifestPair.Patch,
395+
manifestPair.Main,
396+
updateVersionfrom,
397+
patchAssets,
398+
token))
399+
{
400+
removableAssets.Add(patchAsset);
401+
}
402+
}
403+
404+
// Add the removable list to patch assets.
405+
patchAssets.AddRange(removableAssets);
406+
407+
return (patchAssets, patchManifestList.Select(x => x.Patch).ToList(), isAlowRemoveOldFile);
385408
}
386409

387410
protected virtual async Task<List<string>> GetAlterSophonPatchVOMatchingFields(CancellationToken token)
@@ -409,13 +432,14 @@ protected virtual async Task<List<string>> GetAlterSophonPatchVOMatchingFields(C
409432
return voAudioMatchingFields;
410433
}
411434

412-
protected virtual async Task StartAlterSophonPatch(HttpClient httpClient,
413-
bool isPreloadMode,
414-
List<SophonPatchAsset> patchAssets,
435+
protected virtual async Task StartAlterSophonPatch(HttpClient httpClient,
436+
bool isPreloadMode,
437+
List<SophonPatchAsset> patchAssets,
415438
List<SophonChunkManifestInfoPair> patchManifestInfoPairs,
416-
SophonDownloadSpeedLimiter downloadLimiter,
417-
int threadNum,
418-
CancellationToken token)
439+
bool isAllowRemoveOldFile,
440+
SophonDownloadSpeedLimiter downloadLimiter,
441+
int threadNum,
442+
CancellationToken token)
419443
{
420444
Dictionary<string, int> downloadedPatchHashSet = new();
421445
Lock dictionaryLock = new();
@@ -556,7 +580,7 @@ async ValueTask ImplPatchUpdate(Tuple<SophonPatchAsset, Dictionary<string, int>>
556580
await patchAsset.ApplyPatchUpdateAsync(httpClient,
557581
GamePath,
558582
patchOutputDir,
559-
true,
583+
isAllowRemoveOldFile,
560584
read =>
561585
{
562586
UpdateSophonFileDownloadProgress(0, read);

0 commit comments

Comments
 (0)