@@ -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