@@ -108,7 +108,7 @@ await SophonPatch.CreateSophonChunkManifestInfoPair(httpClient,
108
108
SophonDownloadSpeedLimiter . CreateInstance ( LauncherConfig . DownloadSpeedLimitCached ) ;
109
109
110
110
// Get the patch assets to download
111
- ( List < SophonPatchAsset > , List < SophonChunkManifestInfoPair > ) patchAssets =
111
+ ( List < SophonPatchAsset > AssetList , List < SophonChunkManifestInfoPair > InfoPairs , bool IsAllowRemoveOldFile ) patchAssets =
112
112
await GetAlterSophonPatchAssets ( httpClient ,
113
113
branchResources . PatchUrl ,
114
114
( isPreloadMode ? branchResources . PreloadUrl : branchResources . MainUrl ) ?? "" ,
@@ -120,8 +120,9 @@ await GetAlterSophonPatchAssets(httpClient,
120
120
// Start the patch pipeline
121
121
await StartAlterSophonPatch ( httpClient ,
122
122
isPreloadMode ,
123
- patchAssets . Item1 ,
124
- patchAssets . Item2 ,
123
+ patchAssets . AssetList ,
124
+ patchAssets . InfoPairs ,
125
+ patchAssets . IsAllowRemoveOldFile ,
125
126
downloadSpeedLimiter ,
126
127
maxThread ,
127
128
Token . Token ) ;
@@ -135,7 +136,7 @@ protected virtual async Task ConfirmAdditionalPatchDataPackageFiles(SophonChunkM
135
136
{
136
137
string currentVersion = GameVersion . ToString ( ) ;
137
138
138
- List < SophonManifestPatchIdentity > otherManifestIdentity = patchManifest . OtherSophonPatchData . ManifestIdentityList
139
+ List < SophonManifestPatchIdentity > otherManifestIdentity = patchManifest . OtherSophonPatchData ! . ManifestIdentityList
139
140
. Where ( x => ! CommonSophonPackageMatchingFields . Contains ( x . MatchingField , StringComparer . OrdinalIgnoreCase ) )
140
141
. ToList ( ) ;
141
142
@@ -303,7 +304,7 @@ protected async Task<bool> SpawnAdditionalPackageDownloadDialog(long baseDownloa
303
304
return confirmAdditionalTag == ContentDialogResult . Primary ;
304
305
}
305
306
306
- protected virtual async Task < ( List < SophonPatchAsset > , List < SophonChunkManifestInfoPair > ) >
307
+ protected virtual async Task < ( List < SophonPatchAsset > AssetList , List < SophonChunkManifestInfoPair > InfoPairs , bool IsAllowRemoveOldFile ) >
307
308
GetAlterSophonPatchAssets ( HttpClient httpClient ,
308
309
string manifestUrl ,
309
310
string downloadOverUrl ,
@@ -315,6 +316,7 @@ protected async Task<bool> SpawnAdditionalPackageDownloadDialog(long baseDownloa
315
316
SophonChunkManifestInfoPair ? rootPatchManifest = null ;
316
317
SophonChunkManifestInfoPair ? rootMainManifest = null ;
317
318
List < ( SophonChunkManifestInfoPair Patch , SophonChunkManifestInfoPair Main , bool IsCommon ) > patchManifestList = [ ] ;
319
+ bool isAlowRemoveOldFile = true ;
318
320
319
321
// Iterate matching fields and get the patch metadata
320
322
foreach ( string matchingField in matchingFields )
@@ -338,8 +340,15 @@ protected async Task<bool> SpawnAdditionalPackageDownloadDialog(long baseDownloa
338
340
Logger . LogWriteLine ( $ "Getting diff for matching field: { matchingField } ", LogType . Debug , true ) ;
339
341
340
342
// Get the manifest pair based on the matching field
341
- SophonChunkManifestInfoPair patchManifest = rootPatchManifest
342
- . GetOtherPatchInfoPair ( matchingField , updateVersionfrom ) ;
343
+ if ( ! rootPatchManifest
344
+ . TryGetOtherPatchInfoPair ( matchingField , updateVersionfrom , out var patchManifest ) )
345
+ {
346
+ Logger . LogWriteLine ( $ "[InstallManagerBase::GetAlterSophonPatchAssets] Cannot find past-version patch manifest for matching field: { matchingField } , Skipping!",
347
+ LogType . Warning ,
348
+ true ) ;
349
+ isAlowRemoveOldFile = false ;
350
+ continue ;
351
+ }
343
352
344
353
// Get the main manifest pair based on the matching field
345
354
SophonChunkManifestInfoPair mainManifest = rootMainManifest
@@ -364,18 +373,38 @@ protected async Task<bool> SpawnAdditionalPackageDownloadDialog(long baseDownloa
364
373
{
365
374
// Get the asset and add it to the list
366
375
await foreach ( SophonPatchAsset patchAsset in SophonPatch
367
- . EnumerateUpdateAsync ( httpClient ,
368
- manifestPair . Patch ,
369
- manifestPair . Main ,
370
- updateVersionfrom ,
371
- downloadLimiter ,
372
- token ) )
376
+ . EnumerateUpdateAsync ( httpClient ,
377
+ manifestPair . Patch ,
378
+ manifestPair . Main ,
379
+ updateVersionfrom ,
380
+ downloadLimiter ,
381
+ token ) )
373
382
{
374
383
patchAssets . Add ( patchAsset ) ;
375
384
}
376
385
}
377
386
378
- 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 ) ;
379
408
}
380
409
381
410
protected virtual async Task < List < string > > GetAlterSophonPatchVOMatchingFields ( CancellationToken token )
@@ -403,13 +432,14 @@ protected virtual async Task<List<string>> GetAlterSophonPatchVOMatchingFields(C
403
432
return voAudioMatchingFields ;
404
433
}
405
434
406
- protected virtual async Task StartAlterSophonPatch ( HttpClient httpClient ,
407
- bool isPreloadMode ,
408
- List < SophonPatchAsset > patchAssets ,
435
+ protected virtual async Task StartAlterSophonPatch ( HttpClient httpClient ,
436
+ bool isPreloadMode ,
437
+ List < SophonPatchAsset > patchAssets ,
409
438
List < SophonChunkManifestInfoPair > patchManifestInfoPairs ,
410
- SophonDownloadSpeedLimiter downloadLimiter ,
411
- int threadNum ,
412
- CancellationToken token )
439
+ bool isAllowRemoveOldFile ,
440
+ SophonDownloadSpeedLimiter downloadLimiter ,
441
+ int threadNum ,
442
+ CancellationToken token )
413
443
{
414
444
Dictionary < string , int > downloadedPatchHashSet = new ( ) ;
415
445
Lock dictionaryLock = new ( ) ;
@@ -435,7 +465,7 @@ protected virtual async Task StartAlterSophonPatch(HttpClient httpClient,
435
465
parallelOptions . MaxDegreeOfParallelism = Environment . ProcessorCount ;
436
466
}
437
467
438
- string patchOutputDir = _gameSophonChunkDir ;
468
+ string patchOutputDir = Path . Combine ( GamePath , "ldiff" ) ;
439
469
440
470
// Get download sizes
441
471
long downloadSizeTotalAssetRemote = patchAssets . Where ( x => x . PatchMethod != SophonPatchMethod . Remove ) . Sum ( x => x . TargetFileSize ) ;
@@ -555,7 +585,7 @@ async ValueTask ImplPatchUpdate(Tuple<SophonPatchAsset, Dictionary<string, int>>
555
585
await patchAsset . ApplyPatchUpdateAsync ( httpClient ,
556
586
GamePath ,
557
587
patchOutputDir ,
558
- true ,
588
+ isAllowRemoveOldFile ,
559
589
read =>
560
590
{
561
591
UpdateSophonFileDownloadProgress ( 0 , read ) ;
0 commit comments