Skip to content

Commit

Permalink
CodeQA (pls, this is the last one)
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Jan 27, 2025
1 parent fdfe725 commit 1a94d95
Show file tree
Hide file tree
Showing 16 changed files with 79 additions and 197 deletions.
61 changes: 1 addition & 60 deletions .github/workflows/qodana-scan-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,67 +3,8 @@ on:
pull_request:
branches:
- main
- preview
- stable
paths-ignore:
- '**.md'
- 'Hi3Helper.Core/Lang/**.json'
- 'Docs/**'
- '**/packages.lock.json'

jobs:
qodana:
runs-on: windows-latest

permissions:
actions: read
contents: write
pull-requests: write
checks: write
security-events: write

strategy:
matrix:
configuration: [Release] # No need to distribute Debug builds
platform: [x64]
framework: [net9.0-windows10.0.22621.0]

env:
Configuration: ${{ matrix.configuration }}
Platform: ${{ matrix.platform }}
DOTNET_INSTALL_DIR: '.\.dotnet'
DOTNET_VERSION: '9.x'
DOTNET_QUALITY: 'ga'
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages

steps:
# skip all the steps if the head repo is not the same as the main repo
# https://github.com/orgs/community/discussions/26829#discussioncomment-3253575
- uses: actions/checkout@v4
if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
with:
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
fetch-depth: 0 # a full history is required for pull request analysis
submodules: recursive # many many submodules

- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
dotnet-quality: ${{ env.DOTNET_QUALITY }}
cache: true
cache-dependency-path: CollapseLauncher/packages.lock.json

- name: 'Qodana Scan'
if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
uses: JetBrains/qodana-action@latest
with:
args: --ide,QDNET
pr-mode: true
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }} # read the steps about it below

- uses: github/codeql-action/upload-sarif@v3
if: ${{ github.event.pull_request.head.repo.full_name == github.event.pull_request.base.repo.full_name }}
with:
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
- '**/packages.lock.json'
80 changes: 4 additions & 76 deletions .github/workflows/qodana-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,79 +3,7 @@ on:
workflow_dispatch:
schedule:
- cron: '0 0 * * 0,3,5' # At 00:00 on Sunday, Wednesday, and Friday.
# pull_request:
# branches:
# - main

jobs:
qodana:
runs-on: windows-latest
strategy:
matrix:
configuration: [Release] # No need to distribute Debug builds
platform: [x64]
framework: [net9.0-windows10.0.22621.0]

env:
Configuration: ${{ matrix.configuration }}
Platform: ${{ matrix.platform }}
DOTNET_INSTALL_DIR: '.\.dotnet'
DOTNET_VERSION: '9.x'
DOTNET_QUALITY: 'ga'
NUGET_PACKAGES: ${{ github.workspace }}/.nuget/packages

permissions:
actions: read
contents: write
pull-requests: write
checks: write
security-events: write

steps:
- uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }} # to check out the actual pull request commit, not the merge commit
submodules: recursive # many many submodules

# - name: Install winget
# uses: Cyberboss/install-winget@v1

# - name: Install Qodana CLI
# uses: crazy-max/ghaction-chocolatey@v3
# with:
# args: install qodana --pre --confirm

# - name: Verify Qodana
# run: |
# Import-Module "$env:ChocolateyInstall/helpers/chocolateyInstaller.psm1"
# refreshenv
# qodana --version

- name: Install .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: ${{ env.DOTNET_VERSION }}
dotnet-quality: ${{ env.DOTNET_QUALITY }}
cache: true
cache-dependency-path: CollapseLauncher/packages.lock.json

# - name: Qodana Scan
# run: |
# Import-Module "$env:ChocolateyInstall/helpers/chocolateyInstaller.psm1"
# refreshenv
# qodana scan --ide QDNET-EAP -o ${{ runner.temp }}\qodana\results --cache-dir ${{ runner.temp }}\qodana\cache

- name: Qodana Scan
uses: JetBrains/qodana-action@v2024.3.3
continue-on-error: true
with:
args: --ide,QDNET
pr-mode: false
env:
QODANA_TOKEN: ${{ secrets.QODANA_TOKEN }}

- uses: github/codeql-action/upload-sarif@v3
if: always()
continue-on-error: true
with:
sarif_file: ${{ runner.temp }}/qodana/results/qodana.sarif.json
pull_request:
branches:
- preview
- stable
5 changes: 4 additions & 1 deletion CollapseLauncher/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,10 @@ namespace CollapseLauncher
{
public partial class App
{
public static bool IsAppKilled { get; set; } = false;
// TODO: #671 This App.IsAppKilled will be replaced with cancellable-awaitable event
// to ensure no hot-exit being called before all background tasks
// hasn't being cancelled.
// public static bool IsAppKilled { get; set; } = false;

public App()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using CollapseLauncher.Interfaces;
using Microsoft.UI.Xaml;
// ReSharper disable IdentifierTypo
// ReSharper disable InconsistentNaming
// ReSharper disable StringLiteralTypo
Expand All @@ -10,13 +9,8 @@ namespace CollapseLauncher.GameManagement.Versioning
{
internal partial class GameVersionBase : IGameVersion
{
#region Properties
protected UIElement ParentUIElement { get; set; }
#endregion

protected GameVersionBase(UIElement parentUIElement, RegionResourceProp gameRegionProp, string gameName, string gameRegion)
protected GameVersionBase(RegionResourceProp gameRegionProp, string gameName, string gameRegion)
{
ParentUIElement = parentUIElement;
GameApiProp = gameRegionProp;
GameName = gameName;
GameRegion = gameRegion;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
using CollapseLauncher.GameManagement.Versioning;
using Microsoft.UI.Xaml;
using System.Collections.Generic;
using System.IO;
// ReSharper disable IdentifierTypo

namespace CollapseLauncher.GameVersioning
{
internal sealed class GameTypeGenshinVersion(
UIElement parentUIElement,
RegionResourceProp gameRegionProp,
string gameName,
string gamePreset)
: GameVersionBase(parentUIElement, gameRegionProp, gameName, gamePreset)
: GameVersionBase(gameRegionProp, gameName, gamePreset)
{
#region Const
private const string GlobalExecName = "GenshinImpact.exe";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
using CollapseLauncher.GameManagement.Versioning;
using Microsoft.UI.Xaml;
using System;
// ReSharper disable IdentifierTypo

namespace CollapseLauncher.GameVersioning
{
internal sealed class GameTypeHonkaiVersion(
UIElement parentUIElement,
RegionResourceProp gameRegionProp,
string gameName,
string gameRegion)
: GameVersionBase(parentUIElement, gameRegionProp, gameName, gameRegion)
: GameVersionBase(gameRegionProp, gameName, gameRegion)
{
#region Statics
private static readonly Version senadinaVersion = new(7, 3, 0);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Hi3Helper;
using Hi3Helper.EncTool.Parser.AssetMetadata;
using Hi3Helper.EncTool.Proto.StarRail;
using Microsoft.UI.Xaml;
using System;
using System.Text;

Expand All @@ -15,8 +14,8 @@ internal sealed class GameTypeStarRailVersion : GameVersionBase
public SRMetadata StarRailMetadataTool { get; set; }
#endregion

public GameTypeStarRailVersion(UIElement parentUIElement, RegionResourceProp gameRegionProp, string gameName, string gameRegion)
: base(parentUIElement, gameRegionProp, gameName, gameRegion)
public GameTypeStarRailVersion(RegionResourceProp gameRegionProp, string gameName, string gameRegion)
: base(gameRegionProp, gameName, gameRegion)
{
// Initialize Star Rail metadata tool
if (GamePreset.ProtoDispatchKey != null)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using CollapseLauncher.GameManagement.Versioning;
using CollapseLauncher.Helper.Metadata;
using Hi3Helper;
using Microsoft.UI.Xaml;
using System;
using System.Buffers;
using System.Buffers.Binary;
Expand Down Expand Up @@ -115,8 +114,8 @@ void DisableRepairAndCacheInstance(PresetConfig config)
}
#endregion

public GameTypeZenlessVersion(UIElement parentUIElement, RegionResourceProp gameRegionProp, PresetConfig gamePreset, string gameName, string gameRegion)
: base(parentUIElement, gameRegionProp, gameName, gameRegion)
public GameTypeZenlessVersion(RegionResourceProp gameRegionProp, PresetConfig gamePreset, string gameName, string gameRegion)
: base(gameRegionProp, gameName, gameRegion)
{
// Try check for reinitializing game version.
InitializeSleepy(gamePreset);
Expand Down
8 changes: 4 additions & 4 deletions CollapseLauncher/Classes/GamePresetProperty.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,28 +48,28 @@ internal GamePresetProperty(UIElement uiElementParent, RegionResourceProp apiRes
switch (gamePreset.GameType)
{
case GameNameType.Honkai:
GameVersion = new GameTypeHonkaiVersion(uiElementParent, ApiResourceProp, gameName, gameRegion);
GameVersion = new GameTypeHonkaiVersion(ApiResourceProp, gameName, gameRegion);
GameSettings = new HonkaiSettings(GameVersion);
GameCache = new HonkaiCache(uiElementParent, GameVersion);
GameRepair = new HonkaiRepair(uiElementParent, GameVersion, GameCache, GameSettings);
GameInstall = new HonkaiInstall(uiElementParent, GameVersion, GameCache);
break;
case GameNameType.StarRail:
GameVersion = new GameTypeStarRailVersion(uiElementParent, ApiResourceProp, gameName, gameRegion);
GameVersion = new GameTypeStarRailVersion(ApiResourceProp, gameName, gameRegion);
GameSettings = new StarRailSettings(GameVersion);
GameCache = new StarRailCache(uiElementParent, GameVersion);
GameRepair = new StarRailRepair(uiElementParent, GameVersion);
GameInstall = new StarRailInstall(uiElementParent, GameVersion);
break;
case GameNameType.Genshin:
GameVersion = new GameTypeGenshinVersion(uiElementParent, ApiResourceProp, gameName, gameRegion);
GameVersion = new GameTypeGenshinVersion(ApiResourceProp, gameName, gameRegion);
GameSettings = new GenshinSettings(GameVersion);
GameCache = null;
GameRepair = new GenshinRepair(uiElementParent, GameVersion, GameVersion.GameApiProp.data!.game!.latest!.decompressed_path);
GameInstall = new GenshinInstall(uiElementParent, GameVersion);
break;
case GameNameType.Zenless:
GameVersion = new GameTypeZenlessVersion(uiElementParent, ApiResourceProp, gamePreset, gameName, gameRegion);
GameVersion = new GameTypeZenlessVersion(ApiResourceProp, gamePreset, gameName, gameRegion);
GameSettings = new ZenlessSettings(GameVersion);
GameCache = new ZenlessCache(uiElementParent, GameVersion, (GameSettings as ZenlessSettings)!);
GameRepair = new ZenlessRepair(uiElementParent, GameVersion, (GameSettings as ZenlessSettings)!);
Expand Down
6 changes: 3 additions & 3 deletions CollapseLauncher/Classes/GamePropertyVault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -79,11 +79,11 @@ private static async void CleanupUnusedGameProperty()
public static async Task AttachNotificationForCurrentGame(int hashID = int.MinValue)
{
if (hashID < 0) hashID = CurrentGameHashID;
if (Vault.TryGetValue(hashID, out var gameProperty))
if (Vault.TryGetValue(hashID, out GamePresetProperty? gameProperty))
{
if (gameProperty is { GameInstall.IsRunning: true })
{
var bgNotification = Locale.Lang._BackgroundNotification;
Locale.LocalizationParams.LangBackgroundNotification? bgNotification = Locale.Lang._BackgroundNotification;
string actTitle = string.Format(await gameProperty.GameVersion.GetGameState() switch
{
GameInstallStateEnum.InstalledHavePreload => bgNotification.CategoryTitle_DownloadingPreload,
Expand All @@ -108,7 +108,7 @@ public static void DetachNotificationForCurrentGame(int hashID = int.MinValue)
[SuppressMessage("ReSharper", "PartialTypeWithSinglePart")]
internal partial class PageStatics
{
internal static CommunityToolsProperty CommunityToolsProperty { get; set; } = new()
internal static CommunityToolsProperty? CommunityToolsProperty { get; set; } = new()
{
OfficialToolsDictionary = new Dictionary<GameNameType, List<CommunityToolsEntry>>(),
CommunityToolsDictionary = new Dictionary<GameNameType, List<CommunityToolsEntry>>()
Expand Down
6 changes: 1 addition & 5 deletions CollapseLauncher/Classes/Helper/HttpClientBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -207,14 +207,10 @@ public HttpClientBuilder<THandler> AddHeader(string key, string? value)
// If the key already exist, then override the previous one.
// Otherwise, add the new key-value pair
// ReSharper disable once RedundantDictionaryContainsKeyBeforeAdding
if (HttpHeaders.ContainsKey(key))
if (!HttpHeaders.TryAdd(key, value))
{
HttpHeaders[key] = value;
}
else
{
HttpHeaders?.Add(key, value);
}

// Return the instance of the builder
return this;
Expand Down
Loading

0 comments on commit 1a94d95

Please sign in to comment.