Skip to content

Commit

Permalink
Fix QA
Browse files Browse the repository at this point in the history
  • Loading branch information
neon-nyan committed Jul 13, 2024
1 parent e2010db commit f5cf481
Show file tree
Hide file tree
Showing 8 changed files with 264 additions and 204 deletions.
8 changes: 5 additions & 3 deletions CollapseLauncher/Classes/EventsManagement/EventsHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
using static CollapseLauncher.InnerLauncherConfig;
using static Hi3Helper.Locale;
using static Hi3Helper.Shared.Region.LauncherConfig;
// ReSharper disable CheckNamespace
// ReSharper disable AssignNullToNotNullAttribute

namespace CollapseLauncher
{
Expand Down Expand Up @@ -301,11 +303,11 @@ internal class BackgroundImgChangerInvoker
{
public static event EventHandler<BackgroundImgProperty> ImgEvent;
public static event EventHandler<bool> IsImageHide;
BackgroundImgProperty property;

public void ChangeBackground(string ImgPath, Action ActionAfterLoaded,
bool IsCustom, bool IsForceRecreateCache = false, bool IsRequestInit = false)
bool IsCustom, bool IsForceRecreateCache = false, bool IsRequestInit = false)
{
ImgEvent?.Invoke(this, property = new BackgroundImgProperty(ImgPath, IsCustom, IsForceRecreateCache, IsRequestInit, ActionAfterLoaded));
ImgEvent?.Invoke(this, new BackgroundImgProperty(ImgPath, IsCustom, IsForceRecreateCache, IsRequestInit, ActionAfterLoaded));
}

public void ToggleBackground(bool Hide) => IsImageHide?.Invoke(this, Hide);
Expand Down
1 change: 0 additions & 1 deletion CollapseLauncher/Classes/FileDialogCOM/Interfaces.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ internal partial interface IFileSaveDialog
[GeneratedComInterface]
internal partial interface IFileDialogEvents; // This dialog is no longer being used

[ComImport]
[Guid(IIDGuid.IShellItem)]
[InterfaceType(ComInterfaceType.InterfaceIsIUnknown)]
[GeneratedComInterface]
Expand Down
128 changes: 70 additions & 58 deletions CollapseLauncher/Classes/GamePropertyVault.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,48 +19,52 @@
using System.IO;
using System.Linq;
using System.Threading.Tasks;
// ReSharper disable CheckNamespace

namespace CollapseLauncher.Statics
{
internal class GamePresetProperty : IDisposable
{
internal GamePresetProperty(UIElement UIElementParent, RegionResourceProp APIResouceProp, string GameName, string GameRegion)
{
PresetConfig GamePreset = LauncherMetadataHelper.LauncherMetadataConfig[GameName][GameRegion];

_APIResouceProp = APIResouceProp!.Copy();
switch (GamePreset!.GameType)
if (LauncherMetadataHelper.LauncherMetadataConfig != null)
{
case GameNameType.Honkai:
_GameVersion = new GameTypeHonkaiVersion(UIElementParent, _APIResouceProp, GameName, GameRegion);
_GameSettings = new HonkaiSettings(_GameVersion);
_GameCache = new HonkaiCache(UIElementParent, _GameVersion);
_GameRepair = new HonkaiRepair(UIElementParent, _GameVersion, _GameCache, _GameSettings);
_GameInstall = new HonkaiInstall(UIElementParent, _GameVersion, _GameCache, _GameSettings);
break;
case GameNameType.StarRail:
_GameVersion = new GameTypeStarRailVersion(UIElementParent, _APIResouceProp, 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, _APIResouceProp, 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, _APIResouceProp, GameName, GameRegion);
_GameSettings = new ZenlessSettings(_GameVersion);
_GameCache = null;
_GameRepair = null;
_GameInstall = new ZenlessInstall(UIElementParent, _GameVersion);
break;
default:
throw new NotSupportedException($"[GamePresetProperty.Ctor] Game type: {GamePreset.GameType} ({GamePreset.ProfileName} - {GamePreset.ZoneName}) is not supported!");
PresetConfig GamePreset = LauncherMetadataHelper.LauncherMetadataConfig[GameName][GameRegion];

_APIResouceProp = APIResouceProp!.Copy();
switch (GamePreset!.GameType)
{
case GameNameType.Honkai:
_GameVersion = new GameTypeHonkaiVersion(UIElementParent, _APIResouceProp, GameName, GameRegion);
_GameSettings = new HonkaiSettings(_GameVersion);
_GameCache = new HonkaiCache(UIElementParent, _GameVersion);
_GameRepair = new HonkaiRepair(UIElementParent, _GameVersion, _GameCache, _GameSettings);
_GameInstall = new HonkaiInstall(UIElementParent, _GameVersion, _GameCache, _GameSettings);
break;
case GameNameType.StarRail:
_GameVersion = new GameTypeStarRailVersion(UIElementParent, _APIResouceProp, 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, _APIResouceProp, 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, _APIResouceProp, GameName, GameRegion);
_GameSettings = new ZenlessSettings(_GameVersion);
_GameCache = null;
_GameRepair = null;
_GameInstall = new ZenlessInstall(UIElementParent, _GameVersion);
break;
default:
throw new NotSupportedException($"[GamePresetProperty.Ctor] Game type: {GamePreset.GameType} ({GamePreset.ProfileName} - {GamePreset.ZoneName}) is not supported!");
}
}
}

Expand Down Expand Up @@ -103,9 +107,9 @@ internal bool IsGameRunning
// returns a null if something goes wrong. If not, then pass it to .Where(x) method which will select the given value with the certain logic.
// (in this case, we need to ensure that the MainWindowHandle is not a non-zero pointer) and then piped into null-break operator.
internal Process? GetGameProcessWithActiveWindow() =>
Process.GetProcessesByName(Path.GetFileNameWithoutExtension(_GamePreset!.GameExecutableName))?
.Where(x => x.MainWindowHandle != IntPtr.Zero)?
.FirstOrDefault();
Process
.GetProcessesByName(Path.GetFileNameWithoutExtension(_GamePreset!.GameExecutableName))
.FirstOrDefault(x => x.MainWindowHandle != IntPtr.Zero);
#nullable disable

/*
Expand Down Expand Up @@ -146,33 +150,41 @@ internal static class GamePropertyVault

public static void LoadGameProperty(UIElement UIElementParent, RegionResourceProp APIResouceProp, string GameName, string GameRegion)
{
PresetConfig GamePreset = LauncherMetadataHelper.LauncherMetadataConfig[GameName][GameRegion];
if (LauncherMetadataHelper.LauncherMetadataConfig != null)
{
PresetConfig GamePreset = LauncherMetadataHelper.LauncherMetadataConfig[GameName][GameRegion];

LastGameHashID = LastGameHashID == 0 ? GamePreset!.HashID : LastGameHashID;
CurrentGameHashID = GamePreset!.HashID;
}

LastGameHashID = LastGameHashID == 0 ? GamePreset!.HashID : LastGameHashID;
CurrentGameHashID = GamePreset!.HashID;
RegisterGameProperty(UIElementParent, APIResouceProp, GameName, GameRegion);
}

private static void RegisterGameProperty(UIElement UIElementParent, RegionResourceProp APIResouceProp, string GameName, string GameRegion)
{
PresetConfig GamePreset = LauncherMetadataHelper.LauncherMetadataConfig[GameName][GameRegion];

CleanupUnusedGameProperty();
if (Vault!.ContainsKey(GamePreset!.HashID))
if (LauncherMetadataHelper.LauncherMetadataConfig != null)
{
#if DEBUG
Logger.LogWriteLine($"[GamePropertyVault] Game property has been cached by Hash ID: {GamePreset.HashID}", LogType.Debug, true);
#endif
// Try reinitialize the config file on reloading cached game property
Vault[GamePreset!.HashID]?._GameVersion?.Reinitialize();
return;
PresetConfig GamePreset = LauncherMetadataHelper.LauncherMetadataConfig[GameName][GameRegion];

CleanupUnusedGameProperty();
if (Vault!.ContainsKey(GamePreset!.HashID))
{
#if DEBUG
Logger.LogWriteLine($"[GamePropertyVault] Game property has been cached by Hash ID: {GamePreset.HashID}", LogType.Debug, true);
#endif
// Try reinitialize the config file on reloading cached game property
Vault[GamePreset!.HashID]?._GameVersion?.Reinitialize();
return;
}

GamePresetProperty Property = new GamePresetProperty(UIElementParent, APIResouceProp, GameName, GameRegion);
Vault.Add(GamePreset.HashID, Property);
#if DEBUG
Logger.LogWriteLine($"[GamePropertyVault] Creating & caching game property by Hash ID: {GamePreset.HashID}", LogType.Debug, true);
}

GamePresetProperty Property = new GamePresetProperty(UIElementParent, APIResouceProp, GameName, GameRegion);
Vault.Add(GamePreset.HashID, Property);
#if DEBUG
Logger.LogWriteLine($"[GamePropertyVault] Creating & caching game property by Hash ID: {GamePreset.HashID}", LogType.Debug, true);
#endif
#endif
}

#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously
Expand All @@ -182,9 +194,9 @@ private static async void CleanupUnusedGameProperty()
if (Vault == null || Vault.Count == 0) return;

int[] unusedGamePropertyHashID = Vault.Values
.Where(x => !x!._GameInstall!.IsRunning && !x.IsGameRunning && x._GamePreset!.HashID != CurrentGameHashID)?
.Select(x => x._GamePreset.HashID)?
.ToArray();
.Where(x => !x!._GameInstall!.IsRunning && !x.IsGameRunning && x._GamePreset!.HashID != CurrentGameHashID)
.Select(x => x._GamePreset.HashID)
.ToArray();

foreach (int key in unusedGamePropertyHashID)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using Squirrel.Sources;
using System;
using System.Threading.Tasks;
// ReSharper disable CheckNamespace

namespace CollapseLauncher.Helper.Update
{
Expand All @@ -24,11 +25,11 @@ static LauncherUpdateHelper()
internal static AppUpdateVersionProp? AppUpdateVersionProp;
internal static bool IsLauncherUpdateAvailable;

private static GameVersion _launcherCurrentVersion;
private static readonly GameVersion _launcherCurrentVersion;
internal static GameVersion? LauncherCurrentVersion
=> _launcherCurrentVersion;

private static string _launcherCurrentVersionString;
private static readonly string _launcherCurrentVersionString;
internal static string LauncherCurrentVersionString
=> _launcherCurrentVersionString;

Expand Down Expand Up @@ -66,7 +67,7 @@ internal static async Task<bool> IsUpdateAvailable(bool isForceCheckUpdate = fal
IsLauncherUpdateAvailable = LauncherCurrentVersion.Compare(remoteVersion);

bool isUserIgnoreUpdate = (LauncherConfig.GetAppConfigValue("DontAskUpdate").ToBoolNullable() ?? false) && !isForceCheckUpdate;
bool isUpdateRoutineSkipped = isUserIgnoreUpdate && !(AppUpdateVersionProp?.IsForceUpdate ?? false);
bool isUpdateRoutineSkipped = isUserIgnoreUpdate && !AppUpdateVersionProp.IsForceUpdate;

return IsLauncherUpdateAvailable && !isUpdateRoutineSkipped;
}
Expand All @@ -75,7 +76,7 @@ internal static async Task<bool> IsUpdateAvailable(bool isForceCheckUpdate = fal
private static async ValueTask<AppUpdateVersionProp?> GetUpdateMetadata(string updateChannel)
{
string relativePath = ConverterTool.CombineURLFromString(updateChannel, "fileindex.json");
await using BridgedNetworkStream ms = await FallbackCDNUtil.TryGetCDNFallbackStream(relativePath, default);
await using BridgedNetworkStream ms = await FallbackCDNUtil.TryGetCDNFallbackStream(relativePath);
return await ms.DeserializeAsync<AppUpdateVersionProp>(InternalAppJSONContext.Default);
}
}
Expand Down
Loading

0 comments on commit f5cf481

Please sign in to comment.