2727using System . Linq ;
2828using System . Net . Http ;
2929using System . Numerics ;
30+ using System . Text . RegularExpressions ;
3031using System . Threading ;
3132using System . Threading . Tasks ;
3233using SophonLogger = Hi3Helper . Sophon . Helper . Logger ;
@@ -184,7 +185,7 @@ public virtual async Task StartPackageInstallSophon(GameInstallStateEnum gameSta
184185
185186 // Get the requested URL and version based on current state.
186187 if ( GameVersionManager . GamePreset
187- . LauncherResourceChunksURL != null )
188+ . LauncherResourceChunksURL != null )
188189 {
189190 // Reassociate the URL if branch url exist
190191 string ? branchUrl = GameVersionManager . GamePreset
@@ -242,8 +243,7 @@ await GameVersionManager.GamePreset
242243
243244 // Get the info pair based on info provided above (for main game file)
244245 var sophonMainInfoPair = await
245- SophonManifest . CreateSophonChunkManifestInfoPair (
246- httpClient ,
246+ SophonManifest . CreateSophonChunkManifestInfoPair ( httpClient ,
247247 requestedUrl ,
248248 GameVersionManager . GamePreset . LauncherResourceChunksURL . MainBranchMatchingField ,
249249 Token . Token ) ;
@@ -360,6 +360,7 @@ await SimpleDialogs.Dialog_ChooseAudioLanguageChoice(
360360 httpClient ,
361361 sophonInfoPairList ,
362362 downloadSpeedLimiter ,
363+ GameVersionManager . GamePreset . LauncherResourceChunksURL ? . ExcludeMatchingFieldMain ?? [ ] ,
363364 Token . Token ) ;
364365
365366 // Get the remote total size and current total size
@@ -498,6 +499,7 @@ private async Task<List<SophonAsset>> GetSophonAssetListFromPair(
498499 HttpClient client ,
499500 List < SophonChunkManifestInfoPair > sophonInfoPairs ,
500501 SophonDownloadSpeedLimiter downloadSpeedLimiter ,
502+ string [ ] excludeMatchingFieldPatterns ,
501503 CancellationToken token )
502504 {
503505 List < SophonAsset > sophonAssetList = [ ] ;
@@ -506,7 +508,10 @@ private async Task<List<SophonAsset>> GetSophonAssetListFromPair(
506508
507509 // Avoid duplicates by using HashSet of the url
508510 HashSet < string > currentlyProcessedPair = [ ] ;
509- foreach ( SophonChunkManifestInfoPair sophonDownloadInfoPair in sophonInfoPairs )
511+ foreach ( SophonChunkManifestInfoPair sophonDownloadInfoPair in sophonInfoPairs
512+ . WhereMatchPattern ( x => x . MatchingField ,
513+ true ,
514+ excludeMatchingFieldPatterns ) )
510515 {
511516 // Try add and if the hashset already contains the same Manifest ID registered, then skip
512517 if ( ! currentlyProcessedPair . Add ( sophonDownloadInfoPair . ManifestInfo ! . ManifestId ) )
@@ -780,6 +785,11 @@ await GameVersionManager.GamePreset
780785 return ;
781786 }
782787
788+ string [ ] excludeMatchingFieldPatterns =
789+ isPreloadMode
790+ ? GameVersionManager . GamePreset . LauncherResourceChunksURL . ExcludeMatchingFieldPreload
791+ : GameVersionManager . GamePreset . LauncherResourceChunksURL . ExcludeMatchingFieldUpdate ;
792+
783793 // If the game has lang list path, then add it
784794 if ( _gameAudioLangListPath != null )
785795 {
@@ -788,13 +798,15 @@ await AddSophonAdditionalVODiffAssetsToList(httpClient,
788798 requestedBaseUrlFrom ,
789799 requestedBaseUrlTo ,
790800 sophonUpdateAssetList ,
801+ excludeMatchingFieldPatterns ,
791802 downloadSpeedLimiter ) ;
792803 }
793804
794805 await TryGetAdditionalPackageForSophonDiff ( httpClient ,
795806 requestedBaseUrlFrom ,
796807 requestedBaseUrlTo ,
797808 GameVersionManager . GamePreset . LauncherResourceChunksURL . MainBranchMatchingField ,
809+ excludeMatchingFieldPatterns ,
798810 sophonUpdateAssetList ,
799811 downloadSpeedLimiter ) ;
800812 }
@@ -1074,6 +1086,7 @@ private async Task TryGetAdditionalPackageForSophonDiff(HttpClient
10741086 string requestedUrlFrom ,
10751087 string requestedUrlTo ,
10761088 string mainMatchingField ,
1089+ string [ ] excludeMatchingFieldsPattern ,
10771090 List < SophonAsset > sophonPreloadAssetList ,
10781091 SophonDownloadSpeedLimiter downloadSpeedLimiter )
10791092 {
@@ -1085,10 +1098,12 @@ private async Task TryGetAdditionalPackageForSophonDiff(HttpClient
10851098 return ;
10861099 }
10871100
1088- List < string > additionalPackageMatchingFields = manifestPair . OtherSophonBuildData ! . ManifestIdentityList
1089- . Where ( x => ! CommonSophonPackageMatchingFields . Contains ( x . MatchingField , StringComparer . OrdinalIgnoreCase ) )
1090- . Select ( x => x . MatchingField )
1091- . ToList ( ) ;
1101+ List < string > additionalPackageMatchingFields =
1102+ manifestPair . OtherSophonBuildData ! . ManifestIdentityList
1103+ . Where ( x => ! CommonSophonPackageMatchingFields . Contains ( x . MatchingField , StringComparer . OrdinalIgnoreCase ) )
1104+ . Select ( x => x . MatchingField )
1105+ . WhereMatchPattern ( x => x , true , excludeMatchingFieldsPattern )
1106+ . ToList ( ) ;
10921107
10931108 if ( additionalPackageMatchingFields . Count == 0 )
10941109 {
@@ -1176,22 +1191,28 @@ private async Task<bool> AddSophonDiffAssetsToList(HttpClient ht
11761191 return true ;
11771192 }
11781193
1179- private async Task AddSophonAdditionalVODiffAssetsToList ( HttpClient httpClient ,
1180- string requestedUrlFrom ,
1181- string requestedUrlTo ,
1182- List < SophonAsset > sophonPreloadAssetList ,
1183- SophonDownloadSpeedLimiter downloadSpeedLimiter )
1194+ private async Task AddSophonAdditionalVODiffAssetsToList (
1195+ HttpClient httpClient ,
1196+ string requestedUrlFrom ,
1197+ string requestedUrlTo ,
1198+ List < SophonAsset > sophonPreloadAssetList ,
1199+ string [ ] excludeMatchingFieldsPattern ,
1200+ SophonDownloadSpeedLimiter downloadSpeedLimiter )
11841201 {
11851202 // Get the main VO language name from Id
11861203 string mainLangId = GetLanguageLocaleCodeByID ( _gameVoiceLanguageID ) ;
1187- // Get the manifest pair for both previous (from) and next (to) version for the main VO
1188- await AddSophonDiffAssetsToList ( httpClient ,
1189- requestedUrlFrom ,
1190- requestedUrlTo ,
1191- sophonPreloadAssetList ,
1192- mainLangId ,
1193- false ,
1194- downloadSpeedLimiter ) ;
1204+
1205+ if ( ! excludeMatchingFieldsPattern . Any ( x => Regex . IsMatch ( mainLangId , x ) ) )
1206+ {
1207+ // Get the manifest pair for both previous (from) and next (to) version for the main VO
1208+ await AddSophonDiffAssetsToList ( httpClient ,
1209+ requestedUrlFrom ,
1210+ requestedUrlTo ,
1211+ sophonPreloadAssetList ,
1212+ mainLangId ,
1213+ false ,
1214+ downloadSpeedLimiter ) ;
1215+ }
11951216
11961217 // Check if the audio lang list file is exist, then try add others
11971218 FileInfo fileInfo = new FileInfo ( _gameAudioLangListPath ) . StripAlternateDataStream ( ) . EnsureNoReadOnly ( ) ;
@@ -1211,7 +1232,8 @@ await AddSophonDiffAssetsToList(httpClient,
12111232
12121233 // Check if the voice pack is actually the same as default.
12131234 if ( string . IsNullOrEmpty ( otherLangId ) ||
1214- otherLangId . Equals ( mainLangId , StringComparison . OrdinalIgnoreCase ) )
1235+ otherLangId . Equals ( mainLangId , StringComparison . OrdinalIgnoreCase ) ||
1236+ excludeMatchingFieldsPattern . Any ( x => Regex . IsMatch ( otherLangId , x ) ) )
12151237 {
12161238 continue ;
12171239 }
0 commit comments