Skip to content

Commit 4c0f1d7

Browse files
committed
CodeQA Pt. 2
1 parent b5da9aa commit 4c0f1d7

22 files changed

Lines changed: 119 additions & 158 deletions

File tree

.editorconfig

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,3 +80,5 @@ dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
8080
dotnet_style_prefer_compound_assignment = true:suggestion
8181
dotnet_style_prefer_simplified_interpolation = true:suggestion
8282
dotnet_style_namespace_match_folder = true:suggestion
83+
84+
resharper_localizable_element_highlighting=hint

CollapseLauncher/Classes/GameManagement/GameSettings/Genshin/RegistryClass/GlobalPerfData.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ internal class GlobalPerfData
120120
// Generate the list of the FPSOption value and order by ascending it.
121121
public static readonly FPSOption[] FPSOptionsList = Enum.GetValues<FPSOption>().OrderBy(GetFPSOptionNumber).ToArray();
122122
// Generate the list of the FPS number to be displayed on FPS Combobox
123+
// Queried in XAML, ReSharper fails to find it
124+
// ReSharper disable once CollectionNeverQueried.Global
123125
public static readonly int[] FPSIndex = FPSOptionsList.Select(GetFPSOptionNumber).ToArray();
124126

125127
private static int GetFPSOptionNumber(FPSOption value)
@@ -131,7 +133,9 @@ private static int GetFPSOptionNumber(FPSOption value)
131133
// Return the number
132134
return number;
133135
}
134-
136+
137+
// Queried in XAML, ReSharper fails to find it
138+
// ReSharper disable once CollectionNeverQueried.Global
135139
public static readonly string[] RenderScaleValuesStr = DictionaryCategory.RenderResolutionOption.Keys.Select(x => x.ToString("0.0")).ToArray();
136140
public static readonly List<double> RenderScaleValues = DictionaryCategory.RenderResolutionOption.Keys.ToList();
137141
public static readonly List<int> RenderScaleIndex = DictionaryCategory.RenderResolutionOption.Values.ToList();

CollapseLauncher/Classes/Helper/Metadata/PresetConfig.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -849,7 +849,7 @@ private bool CheckInnerGameConfig(string gamePath, LauncherType launcherType)
849849
return false;
850850

851851
IniFile ini = IniFile.LoadFrom(configPath);
852-
string? path1 = ini["launcher"]!["game_install_path"].ToString();
852+
string? path1 = ini["launcher"]["game_install_path"].ToString();
853853
if (string.IsNullOrEmpty(path1))
854854
return false;
855855

CollapseLauncher/Classes/Helper/WindowUtility.cs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
using Microsoft.UI.Xaml.Media;
2222
using System;
2323
using System.Collections.Generic;
24+
using System.Diagnostics.CodeAnalysis;
2425
using System.Runtime.InteropServices;
2526
using Windows.Foundation;
2627
using Windows.Graphics;
@@ -285,13 +286,13 @@ internal static IconShowOptions CurrentWindowTitlebarIconShowOption
285286
}
286287
}
287288

288-
private static NotificationService? _currentToastNotificationService;
289-
internal static NotificationService? CurrentToastNotificationService
289+
[field: AllowNull, MaybeNull]
290+
internal static NotificationService CurrentToastNotificationService
290291
{
291292
get
292293
{
293294
// If toast notification service field is null, then initialize
294-
if (_currentToastNotificationService == null)
295+
if (field == null)
295296
{
296297
// Get Icon location paths
297298
(string iconLocationStartMenu, _)
@@ -302,7 +303,7 @@ internal static NotificationService? CurrentToastNotificationService
302303
out _);
303304

304305
// Register notification service
305-
_currentToastNotificationService = new NotificationService(ILoggerHelper.GetILogger("ToastCOM"));
306+
field = new NotificationService(ILoggerHelper.GetILogger("ToastCOM"));
306307

307308
// Get AUMID name from Win32
308309
PInvoke.GetProcessAumid(out string? appAumIdName);
@@ -314,19 +315,19 @@ internal static NotificationService? CurrentToastNotificationService
314315
if (!string.IsNullOrEmpty(appAumIdName))
315316
{
316317
// Initialize Toast Notification service
317-
_currentToastNotificationService.Initialize(
318-
appAumIdName,
319-
executablePath ?? "",
320-
iconLocationStartMenu,
321-
asElevatedUser: true
322-
);
318+
field.Initialize(
319+
appAumIdName,
320+
executablePath ?? "",
321+
iconLocationStartMenu,
322+
asElevatedUser: true
323+
);
323324

324325
// Subscribe ToastCallback
325-
_currentToastNotificationService.ToastCallback += Service_ToastNotificationCallback;
326+
field.ToastCallback += Service_ToastNotificationCallback;
326327
}
327328
}
328329

329-
return _currentToastNotificationService;
330+
return field;
330331
}
331332
}
332333

CollapseLauncher/Classes/InstallManagement/BaseClass/InstallManagerBase.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,18 +1752,18 @@ private async Task ExtractUsingNativeZipWorker(IEnumerable<int> entriesIndex, L
17521752
await runningTask.ConfigureAwait(false);
17531753
}
17541754

1755-
void StartWriteInner(byte[] buffer, FileStream outputStream, Stream entryStream, CancellationToken cancellationToken)
1755+
void StartWriteInner(byte[] bufferInner, FileStream outputStream, Stream entryStream, CancellationToken cancellationTokenInner)
17561756
{
17571757
int read;
17581758

17591759
// Perform async read
1760-
while ((read = entryStream.Read(buffer, 0, buffer.Length)) > 0)
1760+
while ((read = entryStream.Read(bufferInner, 0, bufferInner.Length)) > 0)
17611761
{
17621762
// Throw if cancellation requested
1763-
cancellationToken.ThrowIfCancellationRequested();
1763+
cancellationTokenInner.ThrowIfCancellationRequested();
17641764

17651765
// Perform sync write
1766-
outputStream.Write(buffer, 0, read);
1766+
outputStream.Write(bufferInner, 0, read);
17671767

17681768
// Increment total size
17691769
_progressAllSizeCurrent += read;

CollapseLauncher/Classes/Interfaces/Class/DeltaPatchProperty.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@ internal class DeltaPatchProperty
88
internal DeltaPatchProperty(string PatchFile)
99
{
1010
ReadOnlySpan<string> strings = Path.GetFileNameWithoutExtension(PatchFile).Split('_');
11-
this.MD5hash = strings[5];
12-
this.ZipHash = strings[4];
13-
this.ProfileName = strings[0];
14-
this.SourceVer = strings[1];
15-
this.TargetVer = strings[2];
16-
this.PatchCompr = strings[3];
17-
this.PatchPath = PatchFile;
11+
MD5hash = strings[5];
12+
ZipHash = strings[4];
13+
ProfileName = strings[0];
14+
SourceVer = strings[1];
15+
TargetVer = strings[2];
16+
PatchCompr = strings[3];
17+
PatchPath = PatchFile;
1818
}
1919

2020
public string ZipHash { get; set; }

CollapseLauncher/Classes/Interfaces/Class/GamePropertyBase.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
using System;
44
using System.Collections.Generic;
55
using System.Collections.ObjectModel;
6-
using System.Diagnostics;
76
using static Hi3Helper.Shared.Region.LauncherConfig;
87

98
namespace CollapseLauncher.Interfaces

CollapseLauncher/Classes/Interfaces/Class/ProgressBase.cs

Lines changed: 19 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -201,22 +201,19 @@ protected virtual void _httpClient_UpdateAssetProgress(int size, DownloadProgres
201201
double percentage = ConverterTool.GetPercentageNumber(_progressAllSizeCurrent, _progressAllSizeTotal);
202202

203203
// Update current progress percentages and speed
204-
if (_progress != null)
204+
lock (_progress)
205205
{
206206
_progress.ProgressAllPercentage = percentage;
207207
}
208208

209209
// Update current activity status
210-
if (_status != null)
211-
{
212-
_status.IsProgressAllIndetermined = false;
213-
string timeLeftString = string.Format(Lang._Misc.TimeRemainHMSFormat, timeLeftSpan);
214-
_status.ActivityAll = string.Format(Lang._Misc.Downloading + ": {0}/{1} ", _progressAllCountCurrent,
215-
_progressAllCountTotal)
216-
+ string.Format($"({Lang._Misc.SpeedPerSec})",
217-
ConverterTool.SummarizeSizeSimple(speedClamped))
218-
+ $" | {timeLeftString}";
219-
}
210+
_status.IsProgressAllIndetermined = false;
211+
string timeLeftString = string.Format(Lang._Misc.TimeRemainHMSFormat, timeLeftSpan);
212+
_status.ActivityAll = string.Format(Lang._Misc.Downloading + ": {0}/{1} ", _progressAllCountCurrent,
213+
_progressAllCountTotal)
214+
+ string.Format($"({Lang._Misc.SpeedPerSec})",
215+
ConverterTool.SummarizeSizeSimple(speedClamped))
216+
+ $" | {timeLeftString}";
220217

221218
// Trigger update
222219
UpdateAll();
@@ -462,15 +459,12 @@ protected void UpdateSophonFileDownloadProgress(long downloadedWrite, long curre
462459
protected void UpdateSophonDownloadStatus(SophonAsset asset)
463460
{
464461
Interlocked.Add(ref _progressAllCountCurrent, 1);
465-
if (_status != null)
466-
{
467-
_status.ActivityStatus = string.Format("{0}: {1}",
468-
_isSophonInUpdateMode
469-
? Lang._Misc.Updating
470-
: Lang._Misc.Downloading,
471-
string.Format(Lang._Misc.PerFromTo, _progressAllCountCurrent,
472-
_progressAllCountTotal));
473-
}
462+
_status.ActivityStatus = string.Format("{0}: {1}",
463+
_isSophonInUpdateMode
464+
? Lang._Misc.Updating
465+
: Lang._Misc.Downloading,
466+
string.Format(Lang._Misc.PerFromTo, _progressAllCountCurrent,
467+
_progressAllCountTotal));
474468

475469
UpdateStatus();
476470
}
@@ -884,17 +878,13 @@ protected async Task<bool> TryRunExamineThrow(Task<bool> action)
884878
}
885879
finally
886880
{
887-
// Define that the status is not running
888-
if (_status != null)
881+
// Clear the _assetIndex after that
882+
if (_status is { IsCompleted: false })
889883
{
890-
// Clear the _assetIndex after that
891-
if (_status is { IsCompleted: false })
892-
{
893-
_assetIndex.Clear();
894-
}
895-
896-
_status.IsRunning = false;
884+
_assetIndex.Clear();
897885
}
886+
887+
_status.IsRunning = false;
898888
}
899889
}
900890

CollapseLauncher/Classes/RepairManagement/Genshin/Fetch.cs

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -28,11 +28,8 @@ internal partial class GenshinRepair
2828
private async ValueTask<List<PkgVersionProperties>> Fetch(List<PkgVersionProperties> assetIndex, CancellationToken token)
2929
{
3030
// Set total activity string as "Loading Indexes..."
31-
if (_status != null)
32-
{
33-
_status.ActivityStatus = Lang._GameRepairPage.Status2;
34-
_status.IsProgressAllIndetermined = true;
35-
}
31+
_status.ActivityStatus = Lang._GameRepairPage.Status2;
32+
_status.IsProgressAllIndetermined = true;
3633

3734
UpdateStatus();
3835

@@ -582,15 +579,13 @@ private void _httpClient_FetchManifestAssetProgress(int read, DownloadProgress d
582579
{
583580
// Update fetch status
584581
double speed = CalculateSpeed(read);
585-
if (_status != null)
586-
{
587-
_status.IsProgressPerFileIndetermined = false;
588-
_status.ActivityPerFile =
589-
string.Format(Lang._GameRepairPage.PerProgressSubtitle3, SummarizeSizeSimple(speed));
590-
}
582+
583+
_status.IsProgressPerFileIndetermined = false;
584+
_status.ActivityPerFile =
585+
string.Format(Lang._GameRepairPage.PerProgressSubtitle3, SummarizeSizeSimple(speed));
591586

592587
// Update fetch progress
593-
if (_progress != null)
588+
lock (_progress)
594589
{
595590
_progress.ProgressPerFilePercentage =
596591
GetPercentageNumber(downloadProgress.BytesDownloaded, downloadProgress.BytesTotal);

CollapseLauncher/Classes/RepairManagement/Genshin/GenshinRepair.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99

1010
namespace CollapseLauncher
1111
{
12-
public enum GenshinAudioLanguage : int
12+
public enum GenshinAudioLanguage
1313
{
1414
English = 0,
1515
Chinese = 1,

0 commit comments

Comments
 (0)