From ad0ac2760bda4517dd7ce61fa1c1fe5c77e88759 Mon Sep 17 00:00:00 2001 From: Bagus Nur Listiyono Date: Wed, 3 Apr 2024 11:42:07 +0700 Subject: [PATCH] (CodeQA) Genshin repair Fetch.cs - Removed unused using - Suppress some NRE - Add debug log when fetching URLs - Line wrap fixes --- .../Classes/RepairManagement/Genshin/Fetch.cs | 122 +++++++++++++----- 1 file changed, 90 insertions(+), 32 deletions(-) diff --git a/CollapseLauncher/Classes/RepairManagement/Genshin/Fetch.cs b/CollapseLauncher/Classes/RepairManagement/Genshin/Fetch.cs index 6b1aa026e..28215d7fa 100644 --- a/CollapseLauncher/Classes/RepairManagement/Genshin/Fetch.cs +++ b/CollapseLauncher/Classes/RepairManagement/Genshin/Fetch.cs @@ -7,7 +7,6 @@ using Hi3Helper.Shared.ClassStruct; using System; using System.Collections.Generic; -using System.Data; using System.IO; using System.Linq; using System.Security.Cryptography; @@ -63,7 +62,7 @@ private async ValueTask> Fetch(List assetIndex) private List EliminateUnnecessaryAssetIndex(IEnumerable assetIndex) { // Section: Eliminate unused audio files - List audioLangList = (_gameVersionManager as GameTypeGenshinVersion)._audioVoiceLanguageList; + List audioLangList = (_gameVersionManager as GameTypeGenshinVersion)!._audioVoiceLanguageList; string audioLangListPath = Path.Combine(_gamePath, $"{_execPrefix}_Data", "Persistent", "audio_lang_14"); // Get the list of audio lang list @@ -106,28 +105,69 @@ private async Task BuildPrimaryManifest(Http _httpClient, List BuildPersistentManifest(Http _httpClient, List assetIndex, Dictionary hashtableManifest, CancellationToken token) + private async Task BuildPersistentManifest(Http _httpClient, List assetIndex, + Dictionary hashtableManifest, CancellationToken token) { try { @@ -168,24 +209,37 @@ private async Task BuildPersistentManifest(Http _httpClient, List (byte)x).ToArray()); if (PrefTemplateBytes != null) File.WriteAllBytes(PersistentPath + "\\DownloadPref", PrefTemplateBytes); #nullable disable @@ -366,6 +420,7 @@ private void SavePersistentRevision(QueryProperty dispatchQuery) #endregion #region DispatcherParser + // ReSharper disable once UnusedParameter.Local private async Task GetDispatcherQuery(Http _httpClient, CancellationToken token) { // Initialize dispatch helper @@ -386,7 +441,7 @@ private async Task GetDispatcherQuery(Http _httpClient, Cancellat LogWriteLine(dFormat); #endif // Write the decrypted query response in the log (for diagnostic) - WriteLog(dFormat, LogType.Default); + WriteLog(dFormat); // Try decrypt the dispatcher, parse it and return it return await TryDecryptAndParseDispatcher(dispatchInfo, dispatchDecryptor, dispatchHelper); @@ -429,7 +484,7 @@ private async Task TryDecryptAndParseDispatcher(YSDispatchInfo di #if DEBUG LogWriteLine(dFormat); #endif - WriteLog(dFormat, LogType.Default); + WriteLog(dFormat); // Parse the dispatcher data in protobuf format and return it as QueryProperty await dispatchHelper.LoadDispatch(decryptedData); @@ -462,11 +517,14 @@ private void EnumerateManifestToAssetIndex(string path, string filter, List /// /// + /// private void ParseManifestToAssetIndex(string manifestPath, List assetIndex, Dictionary hashtable, string parentPath, string acceptedExtension, string parentURL, bool forceStoreInStreaming = false) { // Initialize local entry. + // ReSharper disable TooWideLocalVariableScope PkgVersionProperties entry; - bool isHashHasValue = false; + bool isHashHasValue; + // ReSharper restore TooWideLocalVariableScope // Iterate JSON that only contains defined extensions. foreach (string data in File.ReadAllLines(manifestPath).Where(x => x.EndsWith(acceptedExtension, StringComparison.OrdinalIgnoreCase))) @@ -477,12 +535,12 @@ private void ParseManifestToAssetIndex(string manifestPath, List