Skip to content

Commit f6d807e

Browse files
committed
CodeQA
1 parent df6455b commit f6d807e

File tree

20 files changed

+240
-272
lines changed

20 files changed

+240
-272
lines changed

CollapseLauncher/Classes/Helper/HttpClientBuilder.Dns.cs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -507,17 +507,16 @@ bool IsLoopbackOrIPAddr(string hostLocal, out (ResourceRecordCollection, Resourc
507507
}
508508

509509
ResourceRecordCollection CreateFromSingle(string hostInner, byte[] addressByte)
510-
=> new ResourceRecordCollection(
511-
[new ResourceRecord(hostInner,
512-
addressByte.Length > 4 ? DnsType.AAAA : DnsType.A,
513-
DnsClass.IN,
514-
uint.MaxValue,
515-
(ushort)addressByte.Length,
516-
addressByte)]
517-
);
518-
519-
ResourceRecordCollection CreateEmpty()
520-
=> new ResourceRecordCollection();
510+
=> new(
511+
[new ResourceRecord(hostInner,
512+
addressByte.Length > 4 ? DnsType.AAAA : DnsType.A,
513+
DnsClass.IN,
514+
uint.MaxValue,
515+
(ushort)addressByte.Length,
516+
addressByte)]
517+
);
518+
519+
ResourceRecordCollection CreateEmpty() => new();
521520
}
522521

523522
private static bool TryGetCachedIp(ReadOnlySpan<char> host, out IPAddress[]? cachedIpAddress)

CollapseLauncher/Classes/Helper/Metadata/LauncherMetadataHelper.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,7 @@ internal static class LauncherMetadataHelper
3232
internal static string LauncherMetadataFolder => Path.Combine(LauncherConfig.AppGameFolder, "_metadatav3");
3333

3434
internal static string LauncherStampRemoteURLPath =>
35-
ConverterTool.CombineURLFromString($"/metadata/{MetadataVersion}/{CurrentLauncherChannel}/",
36-
LauncherMetadataStampPrefix);
35+
$"/metadata/{MetadataVersion}/{CurrentLauncherChannel}/".CombineURLFromString(LauncherMetadataStampPrefix);
3736

3837
#endregion
3938

@@ -501,8 +500,7 @@ async ValueTask LoadRegionMetadataConfig((int, (Stamp?, ConcurrentDictionary<str
501500

502501
string configLocalFilePath = Path.Combine(LauncherMetadataFolder, stamp.MetadataPath);
503502
string configRemoteFilePath =
504-
ConverterTool.CombineURLFromString($"/metadata/{MetadataVersion}/{currentChannel}/",
505-
stamp.MetadataPath);
503+
$"/metadata/{MetadataVersion}/{currentChannel}/".CombineURLFromString(stamp.MetadataPath);
506504

507505
FileStream? configLocalStream = null;
508506
try

CollapseLauncher/Classes/Helper/Metadata/PresetConfig.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ public Task EnsureReassociated(HttpClient client, string? branchUrl, string bizN
164164
// Re-associate url if patch URL property exists
165165
if (!string.IsNullOrEmpty(PatchUrl))
166166
{
167-
HoYoPlayGameInfoBranchField? branchField = (isPreloadForPatch ? branch.GamePreloadField : branch.GameMainField) ?? throw new InvalidOperationException($"Cannot find branch field for respective patch URL (isPreloadForPatch: {isPreloadForPatch}).");
167+
HoYoPlayGameInfoBranchField branchField = (isPreloadForPatch ? branch.GamePreloadField : branch.GameMainField) ?? throw new InvalidOperationException($"Cannot find branch field for respective patch URL (isPreloadForPatch: {isPreloadForPatch}).");
168168
ArgumentException.ThrowIfNullOrEmpty(branchField.PackageId);
169169
ArgumentException.ThrowIfNullOrEmpty(branchField.Password);
170170

@@ -668,7 +668,7 @@ private void SetVoiceLanguageID_Genshin(int langID)
668668
RegistryKey keys = Registry.CurrentUser.CreateSubKey(ConfigRegistryLocation, true);
669669

670670
byte[] result = (byte[])keys.GetValue("GENERAL_DATA_h2389025596", Array.Empty<byte>());
671-
GeneralDataProp initValue = JsonSerializerHelper.Deserialize(result, GeneralDataPropJsonContext.Default.GeneralDataProp) ?? new GeneralDataProp();
671+
GeneralDataProp initValue = result.Deserialize(GeneralDataPropJsonContext.Default.GeneralDataProp) ?? new GeneralDataProp();
672672
initValue.deviceVoiceLanguageType = langID;
673673

674674
string jsonString = initValue.Serialize(GeneralDataPropJsonContext.Default.GeneralDataProp);
@@ -764,7 +764,7 @@ public int GetRegServerNameID()
764764

765765
try
766766
{
767-
return (int)(JsonSerializerHelper.Deserialize(value, GeneralDataPropJsonContext.Default.GeneralDataProp)?.selectedServerName ?? ServerRegionID.os_usa);
767+
return (int)(value.Deserialize(GeneralDataPropJsonContext.Default.GeneralDataProp)?.selectedServerName ?? ServerRegionID.os_usa);
768768
}
769769
catch (Exception ex)
770770
{

CollapseLauncher/Classes/Helper/Update/LauncherUpdateHelper.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ internal static async Task<bool> IsUpdateAvailable(bool isForceCheckUpdate = fal
5252
string updateChannel = LauncherConfig.IsPreview ? "preview" : "stable";
5353

5454
CDNURLProperty launcherUpdatePreferredCdn = FallbackCDNUtil.GetPreferredCDN();
55-
string launcherUpdateManagerBaseUrl = ConverterTool.CombineURLFromString(launcherUpdatePreferredCdn.URLPrefix,
56-
#if USEVELOPACK
55+
string launcherUpdateManagerBaseUrl = launcherUpdatePreferredCdn.URLPrefix.CombineURLFromString(
56+
#if USEVELOPACK
5757
"velopack",
5858
updateChannel
5959
#else
@@ -130,8 +130,8 @@ internal static async Task<bool> IsUpdateAvailable(bool isForceCheckUpdate = fal
130130

131131
private static async ValueTask<AppUpdateVersionProp?> GetUpdateMetadata(string updateChannel)
132132
{
133-
string relativePath = ConverterTool.CombineURLFromString(updateChannel, "fileindex.json");
134-
await using BridgedNetworkStream ms = await FallbackCDNUtil.TryGetCDNFallbackStream(relativePath);
133+
string relativePath = updateChannel.CombineURLFromString("fileindex.json");
134+
await using BridgedNetworkStream ms = await FallbackCDNUtil.TryGetCDNFallbackStream(relativePath);
135135
return await ms.DeserializeAsync(AppUpdateVersionPropJsonContext.Default.AppUpdateVersionProp);
136136
}
137137
}

CollapseLauncher/Classes/InstallManagement/Base/InstallManagerBase.PkgVersion.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -202,8 +202,7 @@ static void ExitFromOverlay(object? sender, RoutedEventArgs args)
202202
if (!string.IsNullOrEmpty(packageExtractBasePath))
203203
{
204204
// Check Fail-safe: Download main pkg_version file
205-
string mainPkgVersionUrl = ConverterTool.CombineURLFromString(packageExtractBasePath,
206-
"pkg_version");
205+
string mainPkgVersionUrl = packageExtractBasePath.CombineURLFromString("pkg_version");
207206
await downloadClient.DownloadAsync(mainPkgVersionUrl, pkgVersionPath, true);
208207

209208
// Check Fail-safe: Download audio pkg_version files
@@ -339,7 +338,7 @@ protected virtual async ValueTask DownloadOtherAudioPkgVersion(string audioListF
339338
// Get the pkg_version filename, url and then download it
340339
string pkgFileName = $"Audio_{line.Trim()}_pkg_version";
341340
string pkgPath = Path.Combine(GamePath, pkgFileName);
342-
string pkgUrl = ConverterTool.CombineURLFromString(baseExtractUrl, pkgFileName);
341+
string pkgUrl = baseExtractUrl.CombineURLFromString(pkgFileName);
343342

344343
// Skip if URL is not found
345344
if ((await FallbackCDNUtil.GetURLStatusCode(pkgUrl, default)).StatusCode == HttpStatusCode.NotFound)

CollapseLauncher/Classes/Interfaces/Class/CacheAsset.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@ internal sealed partial class CacheAssetJsonContext : JsonSerializerContext;
1717
internal sealed class CacheAsset : IAssetIndexSummary
1818
{
1919
// Concatenate N and CRC to get the filepath.
20-
public string ConcatN => IsUseLocalPath ? $"{N}" : $"{N}_{CRC}.unity3d";
20+
public string ConcatN => IsUseLocalPath ? $"{N}" : $"{N}_{CRC}.unity3d";
2121
public string ConcatNRemote => $"{N}_{CRC}";
22-
public string BaseURL { get; set; }
23-
public string BasePath { get; set; }
24-
public string ConcatURL => ConverterTool.CombineURLFromString(BaseURL, ConcatNRemote);
25-
public string ConcatPath => Path.Combine(BasePath, ConverterTool.NormalizePath(ConcatN));
22+
public string BaseURL { get; set; }
23+
public string BasePath { get; set; }
24+
public string ConcatURL => BaseURL.CombineURLFromString(ConcatNRemote);
25+
public string ConcatPath => Path.Combine(BasePath, ConverterTool.NormalizePath(ConcatN));
2626

2727
// Filepath for input.
2828
// You have to concatenate the N with CRC to get the filepath using ConcatN()

CollapseLauncher/Classes/Interfaces/Class/ProgressBase.cs

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1197,25 +1197,32 @@ protected virtual async ValueTask RunPatchTask(DownloadClient downloadClient, Do
11971197
// Always do loop if patch doesn't get downloaded properly
11981198
while (true)
11991199
{
1200-
await using FileStream patchFileStream = await patchOutputFile.NaivelyOpenFileStreamAsync(FileMode.Open, FileAccess.Read, FileShare.None);
1201-
// Verify the patch file and if it doesn't match, then re-download it
1202-
byte[] patchCrc = await GetCryptoHashAsync<MD5>(patchFileStream, null, true, false, token);
1203-
Array.Reverse(patchCrc);
1204-
if (!IsArrayMatch(patchCrc, patchHash.Span))
1200+
FileStream patchFileStream = await patchOutputFile.NaivelyOpenFileStreamAsync(FileMode.Open, FileAccess.Read, FileShare.None);
1201+
try
12051202
{
1206-
// Revert back the total size
1207-
Interlocked.Add(ref ProgressAllSizeCurrent, -patchSize);
1203+
// Verify the patch file and if it doesn't match, then re-download it
1204+
byte[] patchCrc = await GetCryptoHashAsync<MD5>(patchFileStream, null, true, false, token);
1205+
Array.Reverse(patchCrc);
1206+
if (!IsArrayMatch(patchCrc, patchHash.Span))
1207+
{
1208+
// Revert back the total size
1209+
Interlocked.Add(ref ProgressAllSizeCurrent, -patchSize);
12081210

1209-
// Dispose patch stream before redownloading
1210-
await patchFileStream.DisposeAsync();
1211+
// Dispose patch stream before re-downloading
1212+
await patchFileStream.DisposeAsync();
12111213

1212-
// Re-download the patch file
1213-
await RunDownloadTask(patchSize, patchOutputFile, patchURL, downloadClient, downloadProgress, token);
1214-
continue;
1215-
}
1214+
// Re-download the patch file
1215+
await RunDownloadTask(patchSize, patchOutputFile, patchURL, downloadClient, downloadProgress, token);
1216+
continue;
1217+
}
12161218

1217-
// else, break and quit from loop
1218-
break;
1219+
// else, break and quit from loop
1220+
break;
1221+
}
1222+
finally
1223+
{
1224+
await patchFileStream.DisposeAsync();
1225+
}
12191226
}
12201227

12211228
// Start patching process

CollapseLauncher/Classes/RegionManagement/FallbackCDNUtil.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -430,7 +430,7 @@ void HttpInstanceDownloadProgressAdapter(int read, DownloadProgress downloadProg
430430
private static async ValueTask<(bool, string)> TryGetURLStatus(CDNURLProperty cdnProp, DownloadClient downloadClient, string relativeURL, CancellationToken token)
431431
{
432432
// Concat the URL Prefix and Relative URL
433-
string absoluteURL = ConverterTool.CombineURLFromString(cdnProp.URLPrefix, relativeURL);
433+
string absoluteURL = cdnProp.URLPrefix.CombineURLFromString(relativeURL);
434434

435435
LogWriteLine($"Getting CDN Content from: {cdnProp.Name} at URL: {absoluteURL}", LogType.Default, true);
436436

@@ -454,7 +454,7 @@ private static async ValueTask<CDNUtilHTTPStatus> TryGetURLStatus(CDNURLProperty
454454
try
455455
{
456456
// Concat the URL Prefix and Relative URL
457-
string absoluteURL = ConverterTool.CombineURLFromString(cdnProp.URLPrefix, relativeURL);
457+
string absoluteURL = cdnProp.URLPrefix.CombineURLFromString(relativeURL);
458458

459459
LogWriteLine($"Getting CDN Content from: {cdnProp.Name} at URL: {absoluteURL}", LogType.Default, true);
460460

@@ -643,7 +643,7 @@ public static string TryGetAbsoluteToRelativeCDNURL(string URL, string searchInd
643643

644644
CDNURLProperty preferredCDN = GetPreferredCDN();
645645
string cdnParentURL = preferredCDN.URLPrefix;
646-
URL = ConverterTool.CombineURLFromString(cdnParentURL, relativeURL);
646+
URL = cdnParentURL.CombineURLFromString(relativeURL);
647647
return URL;
648648
}
649649
}

CollapseLauncher/Classes/RepairManagement/Genshin/Check.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ private async Task CheckRedundantFiles(List<PkgVersionProperties> targetAssetInd
409409
{
410410
localName = strippedName,
411411
fileSize = fInfo.Length,
412-
type = RepairAssetType.Unused.ToString()
412+
type = nameof(RepairAssetType.Unused)
413413
};
414414
Dispatch(() => AssetEntry.Add(
415415
new AssetProperty<RepairAssetType>(
@@ -446,7 +446,7 @@ private async Task CheckRedundantFiles(List<PkgVersionProperties> targetAssetInd
446446
{
447447
localName = strippedName,
448448
fileSize = fileInfo.Length,
449-
type = RepairAssetType.Unused.ToString()
449+
type = nameof(RepairAssetType.Unused)
450450
};
451451
Dispatch(() => AssetEntry.Add(
452452
new AssetProperty<RepairAssetType>(

0 commit comments

Comments
 (0)