@@ -38,19 +38,16 @@ private async Task<List<CacheAsset>> Fetch(CancellationToken token)
3838 . SetAllowedDecompression ( DecompressionMethods . None )
3939 . Create ( ) ;
4040
41- // Use a new DownloadClient for fetching
42- DownloadClient downloadClient = DownloadClient . CreateInstance ( httpClientNew ) ;
43-
4441 // Build _gameRepoURL from loading Dispatcher and Gateway
45- await BuildGameRepoURL ( downloadClient . GetHttpClient ( ) , token ) ;
42+ await BuildGameRepoURL ( httpClientNew , token ) ;
4643
4744 // Iterate type and do fetch
4845 await Parallel . ForEachAsync (
4946 Enum . GetValues < CacheAssetType > ( ) ,
5047 new ParallelOptions
5148 {
5249 MaxDegreeOfParallelism = ThreadCount ,
53- CancellationToken = token
50+ CancellationToken = token
5451 } ,
5552 async ( type , ctx ) =>
5653 {
@@ -62,16 +59,16 @@ await Parallel.ForEachAsync(
6259 {
6360 // uint = Count of the assets available
6461 // long = Total size of the assets available
65- ( int , long ) count = await FetchByType ( type , downloadClient , returnAsset , ctx ) ;
62+ ( int , long ) count = await FetchByType ( type , httpClientNew , returnAsset , ctx ) ;
6663
6764 // Write a log about the metadata
68- LogWriteLine ( $ "Cache Metadata [T: { type } ]:", LogType . Default , true ) ;
69- LogWriteLine ( $ " Cache Count = { count . Item1 } ", LogType . NoTag , true ) ;
70- LogWriteLine ( $ " Cache Size = { SummarizeSizeSimple ( count . Item2 ) } ", LogType . NoTag , true ) ;
65+ LogWriteLine ( $ "Cache Metadata [T: { type } ]:", LogType . Default , true ) ;
66+ LogWriteLine ( $ " Cache Count = { count . Item1 } ", LogType . NoTag , true ) ;
67+ LogWriteLine ( $ " Cache Size = { SummarizeSizeSimple ( count . Item2 ) } ", LogType . NoTag , true ) ;
7168
7269 // Increment the Total Size and Count
7370 Interlocked . Add ( ref ProgressAllCountTotal , count . Item1 ) ;
74- Interlocked . Add ( ref ProgressAllSizeTotal , count . Item2 ) ;
71+ Interlocked . Add ( ref ProgressAllSizeTotal , count . Item2 ) ;
7572 }
7673 break ;
7774 default :
@@ -83,7 +80,7 @@ await Parallel.ForEachAsync(
8380 return returnAsset ;
8481 }
8582
86- private async Task BuildGameRepoURL ( HttpClient downloadClient , CancellationToken token )
83+ private async Task BuildGameRepoURL ( HttpClient client , CancellationToken token )
8784 {
8885 KianaDispatch dispatch = null ;
8986 Exception lastException = null ;
@@ -101,10 +98,13 @@ private async Task BuildGameRepoURL(HttpClient downloadClient, CancellationToken
10198 string key = GameVersionManager . GamePreset . DispatcherKey ;
10299
103100 // Try assign dispatcher
104- dispatch = await KianaDispatch . GetDispatch ( downloadClient , baseURL ,
101+ dispatch = await KianaDispatch . GetDispatch ( client ,
102+ baseURL ,
105103 GameVersionManager . GamePreset . GameDispatchURLTemplate ,
106104 GameVersionManager . GamePreset . GameDispatchChannelName ,
107- key , GameVersion . VersionArray , token ) ;
105+ key ,
106+ GameVersion . VersionArray ,
107+ token ) ;
108108 lastException = null ;
109109 break ;
110110 }
@@ -119,13 +119,13 @@ private async Task BuildGameRepoURL(HttpClient downloadClient, CancellationToken
119119
120120 // Get gatewayURl and fetch the gateway
121121 GameGateway =
122- await KianaDispatch . GetGameserver ( downloadClient , dispatch ! , GameVersionManager . GamePreset . GameGatewayDefault ! , token ) ;
122+ await KianaDispatch . GetGameserver ( client , dispatch ! , GameVersionManager . GamePreset . GameGatewayDefault ! , token ) ;
123123 GameRepoURL = BuildAssetBundleURL ( GameGateway ) ;
124124 }
125125
126126 private static string BuildAssetBundleURL ( KianaDispatch gateway ) => CombineURLFromString ( gateway ! . AssetBundleUrls ! [ 0 ] , "/{0}/editor_compressed/" ) ;
127127
128- private async Task < ( int , long ) > FetchByType ( CacheAssetType type , DownloadClient downloadClient , List < CacheAsset > assetIndex , CancellationToken token )
128+ private async Task < ( int , long ) > FetchByType ( CacheAssetType type , HttpClient client , List < CacheAsset > assetIndex , CancellationToken token )
129129 {
130130 // Set total activity string as "Fetching Caches Type: <type>"
131131 Status . ActivityStatus = string . Format ( Lang ! . _CachesPage ! . CachesStatusFetchingType ! , type ) ;
@@ -143,9 +143,7 @@ private async Task BuildGameRepoURL(HttpClient downloadClient, CancellationToken
143143#endif
144144
145145 // Get a direct HTTP Stream
146- await using HttpResponseInputStream remoteStream = await HttpResponseInputStream . CreateStreamAsync (
147- downloadClient . GetHttpClient ( ) , assetIndexURL , null , null , null , null , null , token ) ;
148-
146+ await using Stream remoteStream = ( await client . TryGetCachedStreamFrom ( assetIndexURL , token : token ) ) . Stream ;
149147 await using XORStream stream = new XORStream ( remoteStream ) ;
150148
151149 // Build the asset index and return the count and size of each type
@@ -233,7 +231,7 @@ private IEnumerable<CacheAsset> EnumerateCacheTextAsset(CacheAssetType type, IEn
233231 }
234232
235233 // Set base URL and Path and add it to asset index
236- content . BaseURL = baseUrl ;
234+ content . BaseURL = baseUrl ;
237235 content . DataType = type ;
238236 content . BasePath = GetAssetBasePathByType ( type ) ;
239237
@@ -249,7 +247,7 @@ private async ValueTask<ValueTuple<int, long>> BuildAssetIndex(CacheAssetType ty
249247
250248 // Set isFirst flag as true if type is Data and
251249 // also convert type as lowered string.
252-
250+
253251 // Unused as of Aug 4th 2024, bonk @bagusnl if not true
254252 // bool isFirst = type == CacheAssetType.Data;
255253 // bool isNeedReadLuckyNumber = type == CacheAssetType.Data;
@@ -347,17 +345,16 @@ private static bool IsValidRegionFile(string input, string lang)
347345
348346 public KianaDispatch GetCurrentGateway ( ) => GameGateway ;
349347
350- public async Task < ( List < CacheAsset > , string , string , int ) > GetCacheAssetList (
351- DownloadClient downloadClient , CacheAssetType type , CancellationToken token )
348+ public async Task < ( List < CacheAsset > , string , string , int ) > GetCacheAssetList ( HttpClient client , CacheAssetType type , CancellationToken token )
352349 {
353350 // Initialize asset index for the return
354351 List < CacheAsset > returnAsset = [ ] ;
355352
356353 // Build _gameRepoURL from loading Dispatcher and Gateway
357- await BuildGameRepoURL ( downloadClient . GetHttpClient ( ) , token ) ;
354+ await BuildGameRepoURL ( client , token ) ;
358355
359356 // Fetch the progress
360- _ = await FetchByType ( type , downloadClient , returnAsset , token ) ;
357+ _ = await FetchByType ( type , client , returnAsset , token ) ;
361358
362359 // Return the list and base asset bundle repo URL
363360 return ( returnAsset , GameGateway ! . ExternalAssetUrls ! . FirstOrDefault ( ) , BuildAssetBundleURL ( GameGateway ) ,
0 commit comments