Skip to content

Commit

Permalink
CodeQA Pt. 2
Browse files Browse the repository at this point in the history
  • Loading branch information
bagusnl committed Dec 21, 2024
1 parent b5da9aa commit 4c0f1d7
Show file tree
Hide file tree
Showing 22 changed files with 119 additions and 158 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -80,3 +80,5 @@ dotnet_style_prefer_inferred_anonymous_type_member_names = true:suggestion
dotnet_style_prefer_compound_assignment = true:suggestion
dotnet_style_prefer_simplified_interpolation = true:suggestion
dotnet_style_namespace_match_folder = true:suggestion

resharper_localizable_element_highlighting=hint
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,8 @@ internal class GlobalPerfData
// Generate the list of the FPSOption value and order by ascending it.
public static readonly FPSOption[] FPSOptionsList = Enum.GetValues<FPSOption>().OrderBy(GetFPSOptionNumber).ToArray();
// Generate the list of the FPS number to be displayed on FPS Combobox
// Queried in XAML, ReSharper fails to find it
// ReSharper disable once CollectionNeverQueried.Global
public static readonly int[] FPSIndex = FPSOptionsList.Select(GetFPSOptionNumber).ToArray();

private static int GetFPSOptionNumber(FPSOption value)
Expand All @@ -131,7 +133,9 @@ private static int GetFPSOptionNumber(FPSOption value)
// Return the number
return number;
}


// Queried in XAML, ReSharper fails to find it
// ReSharper disable once CollectionNeverQueried.Global
public static readonly string[] RenderScaleValuesStr = DictionaryCategory.RenderResolutionOption.Keys.Select(x => x.ToString("0.0")).ToArray();
public static readonly List<double> RenderScaleValues = DictionaryCategory.RenderResolutionOption.Keys.ToList();
public static readonly List<int> RenderScaleIndex = DictionaryCategory.RenderResolutionOption.Values.ToList();
Expand Down
2 changes: 1 addition & 1 deletion CollapseLauncher/Classes/Helper/Metadata/PresetConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -849,7 +849,7 @@ private bool CheckInnerGameConfig(string gamePath, LauncherType launcherType)
return false;

IniFile ini = IniFile.LoadFrom(configPath);
string? path1 = ini["launcher"]!["game_install_path"].ToString();
string? path1 = ini["launcher"]["game_install_path"].ToString();
if (string.IsNullOrEmpty(path1))
return false;

Expand Down
25 changes: 13 additions & 12 deletions CollapseLauncher/Classes/Helper/WindowUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
using Microsoft.UI.Xaml.Media;
using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using Windows.Foundation;
using Windows.Graphics;
Expand Down Expand Up @@ -285,13 +286,13 @@ internal static IconShowOptions CurrentWindowTitlebarIconShowOption
}
}

private static NotificationService? _currentToastNotificationService;
internal static NotificationService? CurrentToastNotificationService
[field: AllowNull, MaybeNull]
internal static NotificationService CurrentToastNotificationService
{
get
{
// If toast notification service field is null, then initialize
if (_currentToastNotificationService == null)
if (field == null)
{
// Get Icon location paths
(string iconLocationStartMenu, _)
Expand All @@ -302,7 +303,7 @@ internal static NotificationService? CurrentToastNotificationService
out _);

// Register notification service
_currentToastNotificationService = new NotificationService(ILoggerHelper.GetILogger("ToastCOM"));
field = new NotificationService(ILoggerHelper.GetILogger("ToastCOM"));

// Get AUMID name from Win32
PInvoke.GetProcessAumid(out string? appAumIdName);
Expand All @@ -314,19 +315,19 @@ internal static NotificationService? CurrentToastNotificationService
if (!string.IsNullOrEmpty(appAumIdName))
{
// Initialize Toast Notification service
_currentToastNotificationService.Initialize(
appAumIdName,
executablePath ?? "",
iconLocationStartMenu,
asElevatedUser: true
);
field.Initialize(
appAumIdName,
executablePath ?? "",
iconLocationStartMenu,
asElevatedUser: true
);

// Subscribe ToastCallback
_currentToastNotificationService.ToastCallback += Service_ToastNotificationCallback;
field.ToastCallback += Service_ToastNotificationCallback;
}
}

return _currentToastNotificationService;
return field;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1752,18 +1752,18 @@ private async Task ExtractUsingNativeZipWorker(IEnumerable<int> entriesIndex, L
await runningTask.ConfigureAwait(false);
}

void StartWriteInner(byte[] buffer, FileStream outputStream, Stream entryStream, CancellationToken cancellationToken)
void StartWriteInner(byte[] bufferInner, FileStream outputStream, Stream entryStream, CancellationToken cancellationTokenInner)
{
int read;

// Perform async read
while ((read = entryStream.Read(buffer, 0, buffer.Length)) > 0)
while ((read = entryStream.Read(bufferInner, 0, bufferInner.Length)) > 0)
{
// Throw if cancellation requested
cancellationToken.ThrowIfCancellationRequested();
cancellationTokenInner.ThrowIfCancellationRequested();

// Perform sync write
outputStream.Write(buffer, 0, read);
outputStream.Write(bufferInner, 0, read);

// Increment total size
_progressAllSizeCurrent += read;
Expand Down
14 changes: 7 additions & 7 deletions CollapseLauncher/Classes/Interfaces/Class/DeltaPatchProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ internal class DeltaPatchProperty
internal DeltaPatchProperty(string PatchFile)
{
ReadOnlySpan<string> strings = Path.GetFileNameWithoutExtension(PatchFile).Split('_');
this.MD5hash = strings[5];
this.ZipHash = strings[4];
this.ProfileName = strings[0];
this.SourceVer = strings[1];
this.TargetVer = strings[2];
this.PatchCompr = strings[3];
this.PatchPath = PatchFile;
MD5hash = strings[5];
ZipHash = strings[4];
ProfileName = strings[0];
SourceVer = strings[1];
TargetVer = strings[2];
PatchCompr = strings[3];
PatchPath = PatchFile;
}

public string ZipHash { get; set; }

Check warning on line 20 in CollapseLauncher/Classes/Interfaces/Class/DeltaPatchProperty.cs

View workflow job for this annotation

GitHub Actions / Qodana for .NET

Auto-property accessor is never used (non-private accessibility)

Auto-property accessor 'ZipHash.get' is never used
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics;
using static Hi3Helper.Shared.Region.LauncherConfig;

namespace CollapseLauncher.Interfaces
Expand Down
48 changes: 19 additions & 29 deletions CollapseLauncher/Classes/Interfaces/Class/ProgressBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -201,22 +201,19 @@ protected virtual void _httpClient_UpdateAssetProgress(int size, DownloadProgres
double percentage = ConverterTool.GetPercentageNumber(_progressAllSizeCurrent, _progressAllSizeTotal);

// Update current progress percentages and speed
if (_progress != null)
lock (_progress)
{
_progress.ProgressAllPercentage = percentage;
}

// Update current activity status
if (_status != null)
{
_status.IsProgressAllIndetermined = false;
string timeLeftString = string.Format(Lang._Misc.TimeRemainHMSFormat, timeLeftSpan);
_status.ActivityAll = string.Format(Lang._Misc.Downloading + ": {0}/{1} ", _progressAllCountCurrent,
_progressAllCountTotal)
+ string.Format($"({Lang._Misc.SpeedPerSec})",
ConverterTool.SummarizeSizeSimple(speedClamped))
+ $" | {timeLeftString}";
}
_status.IsProgressAllIndetermined = false;
string timeLeftString = string.Format(Lang._Misc.TimeRemainHMSFormat, timeLeftSpan);
_status.ActivityAll = string.Format(Lang._Misc.Downloading + ": {0}/{1} ", _progressAllCountCurrent,
_progressAllCountTotal)
+ string.Format($"({Lang._Misc.SpeedPerSec})",
ConverterTool.SummarizeSizeSimple(speedClamped))
+ $" | {timeLeftString}";

// Trigger update
UpdateAll();
Expand Down Expand Up @@ -462,15 +459,12 @@ protected void UpdateSophonFileDownloadProgress(long downloadedWrite, long curre
protected void UpdateSophonDownloadStatus(SophonAsset asset)
{
Interlocked.Add(ref _progressAllCountCurrent, 1);
if (_status != null)
{
_status.ActivityStatus = string.Format("{0}: {1}",
_isSophonInUpdateMode
? Lang._Misc.Updating
: Lang._Misc.Downloading,
string.Format(Lang._Misc.PerFromTo, _progressAllCountCurrent,
_progressAllCountTotal));
}
_status.ActivityStatus = string.Format("{0}: {1}",
_isSophonInUpdateMode
? Lang._Misc.Updating
: Lang._Misc.Downloading,
string.Format(Lang._Misc.PerFromTo, _progressAllCountCurrent,
_progressAllCountTotal));

UpdateStatus();
}
Expand Down Expand Up @@ -884,17 +878,13 @@ protected async Task<bool> TryRunExamineThrow(Task<bool> action)
}
finally
{
// Define that the status is not running
if (_status != null)
// Clear the _assetIndex after that
if (_status is { IsCompleted: false })
{
// Clear the _assetIndex after that
if (_status is { IsCompleted: false })
{
_assetIndex.Clear();
}

_status.IsRunning = false;
_assetIndex.Clear();
}

_status.IsRunning = false;
}
}

Expand Down
19 changes: 7 additions & 12 deletions CollapseLauncher/Classes/RepairManagement/Genshin/Fetch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,8 @@ internal partial class GenshinRepair
private async ValueTask<List<PkgVersionProperties>> Fetch(List<PkgVersionProperties> assetIndex, CancellationToken token)
{
// Set total activity string as "Loading Indexes..."
if (_status != null)
{
_status.ActivityStatus = Lang._GameRepairPage.Status2;
_status.IsProgressAllIndetermined = true;
}
_status.ActivityStatus = Lang._GameRepairPage.Status2;
_status.IsProgressAllIndetermined = true;

UpdateStatus();

Expand Down Expand Up @@ -582,15 +579,13 @@ private void _httpClient_FetchManifestAssetProgress(int read, DownloadProgress d
{
// Update fetch status
double speed = CalculateSpeed(read);
if (_status != null)
{
_status.IsProgressPerFileIndetermined = false;
_status.ActivityPerFile =
string.Format(Lang._GameRepairPage.PerProgressSubtitle3, SummarizeSizeSimple(speed));
}

_status.IsProgressPerFileIndetermined = false;
_status.ActivityPerFile =
string.Format(Lang._GameRepairPage.PerProgressSubtitle3, SummarizeSizeSimple(speed));

// Update fetch progress
if (_progress != null)
lock (_progress)
{
_progress.ProgressPerFilePercentage =
GetPercentageNumber(downloadProgress.BytesDownloaded, downloadProgress.BytesTotal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

namespace CollapseLauncher
{
public enum GenshinAudioLanguage : int
public enum GenshinAudioLanguage
{
English = 0,
Chinese = 1,
Expand Down
Loading

0 comments on commit 4c0f1d7

Please sign in to comment.