@@ -82,12 +82,27 @@ protected bool _isSophonPreloadCompleted
8282 #endregion
8383
8484 #region Public Virtual Properties
85- public virtual bool IsUseSophon =>
86- GameVersionManager . IsForceRedirectToSophon ( ) ||
87- ( GameVersionManager . GamePreset . LauncherResourceChunksURL != null
88- && ! File . Exists ( Path . Combine ( GamePath , "@DisableSophon" ) )
89- && ! _canDeltaPatch && ! _forceIgnoreDeltaPatch
90- && LauncherConfig . GetAppConfigValue ( "IsEnableSophon" ) . ToBool ( ) ) ;
85+ public virtual bool IsUseSophon
86+ {
87+ get
88+ {
89+ bool isForceRedirect = GameVersionManager . IsForceRedirectToSophon ( ) ;
90+ bool isEnabled = GameVersionManager . GamePreset . LauncherResourceChunksURL != null
91+ && ! File . Exists ( Path . Combine ( GamePath , "@DisableSophon" ) )
92+ && ! _canDeltaPatch
93+ && ! _forceIgnoreDeltaPatch
94+ && LauncherConfig . GetAppConfigValue ( "IsEnableSophon" ) . ToBool ( ) ;
95+
96+ return isForceRedirect || isEnabled ;
97+ }
98+ }
99+
100+ public virtual bool AskAdditionalSophonPkg
101+ {
102+ get => File . Exists ( Path . Combine ( GamePath , "@AskAdditionalSophonPackage" ) ) ;
103+ }
104+
105+ public string [ ] CommonSophonPackageMatchingFields = [ "game" , "en-us" , "zh-tw" , "zh-cn" , "ko-kr" , "ja-jp" ] ;
91106 #endregion
92107
93108 #region Sophon Verification Methods
@@ -540,14 +555,17 @@ protected async Task ConfirmAdditionalInstallDataPackageFiles(
540555 long sizeAdditionalToDownload = otherManifestIdentity
541556 . Sum ( x => x . ChunkInfo . CompressedSize ) ;
542557
543- bool isDownloadAdditionalData = await SpawnAdditionalPackageDownloadDialog ( sizeCurrentToDownload ,
544- sizeAdditionalToDownload ,
545- false ,
546- GetFileDetails ) ;
547-
548- if ( ! isDownloadAdditionalData )
558+ if ( AskAdditionalSophonPkg )
549559 {
550- return ;
560+ bool isDownloadAdditionalData = await SpawnAdditionalPackageDownloadDialog ( sizeCurrentToDownload ,
561+ sizeAdditionalToDownload ,
562+ false ,
563+ GetFileDetails ) ;
564+
565+ if ( ! isDownloadAdditionalData )
566+ {
567+ return ;
568+ }
551569 }
552570
553571 List < string > additionalMatchingFields = otherManifestIdentity . Select ( x => x . MatchingField ) . ToList ( ) ;
@@ -702,6 +720,7 @@ await GameVersionManager.GamePreset
702720 requestedBaseUrlTo ,
703721 sophonUpdateAssetList ,
704722 GameVersionManager . GamePreset . LauncherResourceChunksURL . MainBranchMatchingField ,
723+ false ,
705724 downloadSpeedLimiter ) ;
706725
707726 // If it doesn't success to get the base diff, then fallback to actually download the whole game
@@ -748,10 +767,19 @@ await GameVersionManager.GamePreset
748767 if ( _gameAudioLangListPath != null )
749768 {
750769 // Add existing voice-over diff data
751- await AddSophonAdditionalVODiffAssetsToList ( httpClient , requestedBaseUrlFrom ,
752- requestedBaseUrlTo , sophonUpdateAssetList ,
770+ await AddSophonAdditionalVODiffAssetsToList ( httpClient ,
771+ requestedBaseUrlFrom ,
772+ requestedBaseUrlTo ,
773+ sophonUpdateAssetList ,
753774 downloadSpeedLimiter ) ;
754775 }
776+
777+ await TryGetAdditionalPackageForSophonDiff ( httpClient ,
778+ requestedBaseUrlFrom ,
779+ requestedBaseUrlTo ,
780+ GameVersionManager . GamePreset . LauncherResourceChunksURL . MainBranchMatchingField ,
781+ sophonUpdateAssetList ,
782+ downloadSpeedLimiter ) ;
755783 }
756784
757785 // Get the remote chunk size
@@ -972,27 +1000,69 @@ await SimpleDialogs.Dialog_InsufficientDriveSpace(driveInfo.TotalFreeSpace,
9721000 }
9731001 }
9741002
975- #endregion
1003+ #endregion
9761004
9771005 #region Sophon Asset Package Methods
1006+ private async Task TryGetAdditionalPackageForSophonDiff ( HttpClient httpClient ,
1007+ string requestedUrlFrom ,
1008+ string requestedUrlTo ,
1009+ string mainMatchingField ,
1010+ List < SophonAsset > sophonPreloadAssetList ,
1011+ SophonDownloadSpeedLimiter downloadSpeedLimiter )
1012+ {
1013+ SophonChunkManifestInfoPair manifestPair = await SophonManifest
1014+ . CreateSophonChunkManifestInfoPair ( httpClient , requestedUrlTo , mainMatchingField , false , Token . Token ) ;
1015+
1016+ if ( ! manifestPair . IsFound )
1017+ {
1018+ return ;
1019+ }
1020+
1021+ List < string > additionalPackageMatchingFields = manifestPair . OtherSophonBuildData . ManifestIdentityList
1022+ . Where ( x => ! CommonSophonPackageMatchingFields . Contains ( x . MatchingField , StringComparer . OrdinalIgnoreCase ) )
1023+ . Select ( x => x . MatchingField )
1024+ . ToList ( ) ;
1025+
1026+ if ( additionalPackageMatchingFields . Count == 0 )
1027+ {
1028+ return ;
1029+ }
1030+
1031+ foreach ( string matchingField in additionalPackageMatchingFields )
1032+ {
1033+ await AddSophonDiffAssetsToList ( httpClient ,
1034+ requestedUrlFrom ,
1035+ requestedUrlTo ,
1036+ sophonPreloadAssetList ,
1037+ matchingField ,
1038+ true ,
1039+ downloadSpeedLimiter ) ;
1040+ }
1041+ }
1042+
9781043 private async Task < bool > AddSophonDiffAssetsToList ( HttpClient httpClient ,
9791044 string requestedUrlFrom ,
9801045 string requestedUrlTo ,
9811046 List < SophonAsset > sophonPreloadAssetList ,
9821047 string matchingField ,
1048+ bool discardIfOldNotExist ,
9831049 SophonDownloadSpeedLimiter downloadSpeedLimiter )
9841050 {
9851051 // Get the manifest pair for both previous (from) and next (to) version
9861052 SophonChunkManifestInfoPair requestPairFrom = await SophonManifest
987- . CreateSophonChunkManifestInfoPair ( httpClient , requestedUrlFrom , matchingField , Token . Token ) ;
1053+ . CreateSophonChunkManifestInfoPair ( httpClient , requestedUrlFrom , matchingField , false , Token . Token ) ;
9881054 SophonChunkManifestInfoPair requestPairTo = await SophonManifest
989- . CreateSophonChunkManifestInfoPair ( httpClient , requestedUrlTo , matchingField , Token . Token ) ;
1055+ . CreateSophonChunkManifestInfoPair ( httpClient , requestedUrlTo , matchingField , false , Token . Token ) ;
9901056
9911057 // If the request pair source is not found, then return false
992- if ( ! requestPairFrom . IsFound )
1058+ if ( ! requestPairFrom . IsFound && ! requestPairTo . IsFound )
9931059 {
9941060 Logger . LogWriteLine ( $ "Sophon manifest for source via URL: { requestedUrlFrom } is not found! Return message: { requestPairFrom . ReturnMessage } ({ requestPairFrom . ReturnCode } )", LogType . Warning , true ) ;
995- return false ;
1061+ if ( ! requestPairTo . IsFound )
1062+ {
1063+ return false ;
1064+ }
1065+ Logger . LogWriteLine ( $ "The target Sophon manifest still exist. The assets from target's matching field: { matchingField } will be used instead!", LogType . Warning , true ) ;
9961066 }
9971067
9981068 // If the request pair target is not found, then return false
@@ -1002,19 +1072,37 @@ private async Task<bool> AddSophonDiffAssetsToList(HttpClient ht
10021072 return false ;
10031073 }
10041074
1005- // Ensure that the manifest is ordered based on _gameVoiceLanguageLocaleIdOrdered
1006- RearrangeDataListLocaleOrder ( requestPairFrom . OtherSophonBuildData . ManifestIdentityList ,
1007- x => x . MatchingField ) ;
10081075 RearrangeDataListLocaleOrder ( requestPairTo . OtherSophonBuildData . ManifestIdentityList ,
10091076 x => x . MatchingField ) ;
10101077
1011- // Add asset to the list
1012- await foreach ( SophonAsset sophonAsset in SophonUpdate
1013- . EnumerateUpdateAsync ( httpClient , requestPairFrom , requestPairTo ,
1014- false , downloadSpeedLimiter )
1015- . WithCancellation ( Token . Token ) )
1078+ if ( requestPairFrom . IsFound )
1079+ {
1080+ // Ensure that the manifest is ordered based on _gameVoiceLanguageLocaleIdOrdered
1081+ RearrangeDataListLocaleOrder ( requestPairFrom . OtherSophonBuildData . ManifestIdentityList ,
1082+ x => x . MatchingField ) ;
1083+
1084+ // Add asset to the list
1085+ await foreach ( SophonAsset sophonAsset in SophonUpdate
1086+ . EnumerateUpdateAsync ( httpClient , requestPairFrom , requestPairTo ,
1087+ false , downloadSpeedLimiter )
1088+ . WithCancellation ( Token . Token ) )
1089+ {
1090+ sophonPreloadAssetList . Add ( sophonAsset ) ;
1091+ }
1092+ }
1093+ else
10161094 {
1017- sophonPreloadAssetList . Add ( sophonAsset ) ;
1095+ await foreach ( SophonAsset sophonAsset in SophonManifest . EnumerateAsync ( httpClient , requestPairTo , downloadSpeedLimiter , Token . Token ) )
1096+ {
1097+ string filePath = Path . Combine ( GamePath , sophonAsset . AssetName ) ;
1098+ if ( ! File . Exists ( filePath ) && discardIfOldNotExist )
1099+ {
1100+ Logger . LogWriteLine ( $ "Asset from matching field: { matchingField } is discarded: { sophonAsset . AssetName } ", LogType . Warning , true ) ;
1101+ continue ;
1102+ }
1103+
1104+ sophonPreloadAssetList . Add ( sophonAsset ) ;
1105+ }
10181106 }
10191107
10201108 // Return as success
@@ -1030,8 +1118,13 @@ private async Task AddSophonAdditionalVODiffAssetsToList(HttpClient
10301118 // Get the main VO language name from Id
10311119 string mainLangId = GetLanguageLocaleCodeByID ( _gameVoiceLanguageID ) ;
10321120 // Get the manifest pair for both previous (from) and next (to) version for the main VO
1033- await AddSophonDiffAssetsToList ( httpClient , requestedUrlFrom , requestedUrlTo ,
1034- sophonPreloadAssetList , mainLangId , downloadSpeedLimiter ) ;
1121+ await AddSophonDiffAssetsToList ( httpClient ,
1122+ requestedUrlFrom ,
1123+ requestedUrlTo ,
1124+ sophonPreloadAssetList ,
1125+ mainLangId ,
1126+ false ,
1127+ downloadSpeedLimiter ) ;
10351128
10361129 // Check if the audio lang list file is exist, then try add others
10371130 FileInfo fileInfo = new FileInfo ( _gameAudioLangListPath ) . StripAlternateDataStream ( ) . EnsureNoReadOnly ( ) ;
@@ -1047,7 +1140,7 @@ await AddSophonDiffAssetsToList(httpClient, requestedUrlFrom, reques
10471140#if ! DEBUG
10481141 , false
10491142#endif
1050- ) ;
1143+ ) ;
10511144
10521145 // Check if the voice pack is actually the same as default.
10531146 if ( string . IsNullOrEmpty ( otherLangId ) ||
@@ -1057,8 +1150,13 @@ await AddSophonDiffAssetsToList(httpClient, requestedUrlFrom, reques
10571150 }
10581151
10591152 // Get the manifest pair for both previous (from) and next (to) version for other VOs
1060- await AddSophonDiffAssetsToList ( httpClient , requestedUrlFrom , requestedUrlTo ,
1061- sophonPreloadAssetList , otherLangId , downloadSpeedLimiter ) ;
1153+ await AddSophonDiffAssetsToList ( httpClient ,
1154+ requestedUrlFrom ,
1155+ requestedUrlTo ,
1156+ sophonPreloadAssetList ,
1157+ otherLangId ,
1158+ false ,
1159+ downloadSpeedLimiter ) ;
10621160 }
10631161 }
10641162 }
0 commit comments