From f5cf481fd18453ca706acc907a8ae4b11bf5a7ab Mon Sep 17 00:00:00 2001 From: Kemal Setya Adhi Date: Sat, 13 Jul 2024 21:51:36 +0700 Subject: [PATCH] Fix QA --- .../Classes/EventsManagement/EventsHandler.cs | 8 +- .../Classes/FileDialogCOM/Interfaces.cs | 1 - CollapseLauncher/Classes/GamePropertyVault.cs | 128 ++++---- .../Helper/Update/LauncherUpdateHelper.cs | 9 +- .../XAMLs/MainApp/MainPage.xaml.cs | 286 ++++++++++-------- .../XAMLs/MainApp/Pages/HomePage.xaml.cs | 6 +- .../XAMLs/MainApp/Pages/SettingsPage.xaml.cs | 27 +- Hi3Helper.Core/Classes/Logger/LoggerBase.cs | 3 +- 8 files changed, 264 insertions(+), 204 deletions(-) diff --git a/CollapseLauncher/Classes/EventsManagement/EventsHandler.cs b/CollapseLauncher/Classes/EventsManagement/EventsHandler.cs index 624d2f770..989320cdd 100644 --- a/CollapseLauncher/Classes/EventsManagement/EventsHandler.cs +++ b/CollapseLauncher/Classes/EventsManagement/EventsHandler.cs @@ -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 { @@ -301,11 +303,11 @@ internal class BackgroundImgChangerInvoker { public static event EventHandler ImgEvent; public static event EventHandler 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); diff --git a/CollapseLauncher/Classes/FileDialogCOM/Interfaces.cs b/CollapseLauncher/Classes/FileDialogCOM/Interfaces.cs index facf3e5ea..c0e43be6e 100644 --- a/CollapseLauncher/Classes/FileDialogCOM/Interfaces.cs +++ b/CollapseLauncher/Classes/FileDialogCOM/Interfaces.cs @@ -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] diff --git a/CollapseLauncher/Classes/GamePropertyVault.cs b/CollapseLauncher/Classes/GamePropertyVault.cs index 66b98c793..b0e75a966 100644 --- a/CollapseLauncher/Classes/GamePropertyVault.cs +++ b/CollapseLauncher/Classes/GamePropertyVault.cs @@ -19,6 +19,7 @@ using System.IO; using System.Linq; using System.Threading.Tasks; +// ReSharper disable CheckNamespace namespace CollapseLauncher.Statics { @@ -26,41 +27,44 @@ 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!"); + } } } @@ -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 /* @@ -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 @@ -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) { diff --git a/CollapseLauncher/Classes/Helper/Update/LauncherUpdateHelper.cs b/CollapseLauncher/Classes/Helper/Update/LauncherUpdateHelper.cs index 31785563d..c1c4c28e1 100644 --- a/CollapseLauncher/Classes/Helper/Update/LauncherUpdateHelper.cs +++ b/CollapseLauncher/Classes/Helper/Update/LauncherUpdateHelper.cs @@ -6,6 +6,7 @@ using Squirrel.Sources; using System; using System.Threading.Tasks; +// ReSharper disable CheckNamespace namespace CollapseLauncher.Helper.Update { @@ -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; @@ -66,7 +67,7 @@ internal static async Task 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; } @@ -75,7 +76,7 @@ internal static async Task IsUpdateAvailable(bool isForceCheckUpdate = fal private static async ValueTask 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(InternalAppJSONContext.Default); } } diff --git a/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs b/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs index 8e3178666..dad402ff1 100644 --- a/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/MainPage.xaml.cs @@ -44,6 +44,10 @@ using static Hi3Helper.Logger; using static Hi3Helper.Shared.Region.LauncherConfig; using UIElementExtensions = CollapseLauncher.Extension.UIElementExtensions; +// ReSharper disable CheckNamespace +// ReSharper disable RedundantExtendsListEntry +// ReSharper disable InconsistentNaming +// ReSharper disable UnusedMember.Local namespace CollapseLauncher { @@ -65,8 +69,8 @@ public partial class MainPage : Page internal static List PreviousTagString = new(); #nullable enable - internal static BackgroundMediaUtility? CurrentBackgroundHandler = null; - private BackgroundMediaUtility? LocalBackgroundHandler = null; + internal static BackgroundMediaUtility? CurrentBackgroundHandler; + private BackgroundMediaUtility? _localBackgroundHandler; #nullable restore #endregion @@ -75,8 +79,8 @@ public MainPage() { try { - LogWriteLine($"Welcome to Collapse Launcher v{LauncherUpdateHelper.LauncherCurrentVersionString} - {MainEntryPoint.GetVersionString()}", LogType.Default, false); - LogWriteLine($"Application Data Location:\r\n\t{AppDataFolder}", LogType.Default); + LogWriteLine($"Welcome to Collapse Launcher v{LauncherUpdateHelper.LauncherCurrentVersionString} - {MainEntryPoint.GetVersionString()}"); + LogWriteLine($"Application Data Location:\r\n\t{AppDataFolder}"); InitializeComponent(); m_mainPage = this; ToggleNotificationPanelBtn.Translation += Shadow16; @@ -97,10 +101,10 @@ private void Page_Unloaded(object sender, RoutedEventArgs e) { UnsubscribeEvents(); #if !DISABLEDISCORD - AppDiscordPresence.Dispose(); + AppDiscordPresence?.Dispose(); #endif ImageLoaderHelper.DestroyWaifu2X(); - LocalBackgroundHandler?.Dispose(); + _localBackgroundHandler?.Dispose(); } private async void StartRoutine(object sender, RoutedEventArgs e) @@ -123,7 +127,7 @@ private async void StartRoutine(object sender, RoutedEventArgs e) if (!await CheckForAdminAccess(this)) { if (WindowUtility.CurrentWindow is MainWindow mainWindow) - mainWindow?.CloseApp(); + mainWindow.CloseApp(); return; } @@ -157,7 +161,7 @@ private async Task InitializeStartup() // Initialize the background image utility CurrentBackgroundHandler = await BackgroundMediaUtility.CreateInstanceAsync(this, BackgroundAcrylicMask, BackgroundOverlayTitleBar, BackgroundNewBackGrid, BackgroundNewMediaPlayerGrid); - LocalBackgroundHandler = CurrentBackgroundHandler; + _localBackgroundHandler = CurrentBackgroundHandler; Type Page = typeof(HomePage); @@ -334,7 +338,7 @@ private void ChangeTitleDragAreaInvoker_TitleBarEvent(object sender, ChangeTitle { UpdateLayout(); - InputNonClientPointerSource nonClientInputSrc = InputNonClientPointerSource.GetForWindowId(WindowUtility.CurrentWindowId.Value); + InputNonClientPointerSource nonClientInputSrc = InputNonClientPointerSource.GetForWindowId(WindowUtility.CurrentWindowId ?? throw new NullReferenceException()); WindowUtility.EnableWindowNonClientArea(); WindowUtility.SetWindowTitlebarDragArea(DragAreaMode_Full); @@ -447,34 +451,50 @@ private void BackgroundImg_IsImageHideEvent(object sender, bool e) private void CustomBackgroundChanger_Event(object sender, BackgroundImgProperty e) { - LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal = e.ImgPath; - IsCustomBG = e.IsCustom; + if (LauncherMetadataHelper.CurrentMetadataConfig?.GameLauncherApi != null) + { + LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal = e.ImgPath; + IsCustomBG = e.IsCustom; - if (e.IsCustom) - SetAndSaveConfigValue("CustomBGPath", LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal); + if (e.IsCustom) + SetAndSaveConfigValue("CustomBGPath", + LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi + .GameBackgroundImgLocal); - if (!File.Exists(LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal)) - { - LogWriteLine($"Custom background file {e.ImgPath} is missing!", LogType.Warning, true); - LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal = AppDefaultBG; - } + if (!File.Exists(LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal)) + { + LogWriteLine($"Custom background file {e.ImgPath} is missing!", LogType.Warning, true); + LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal = AppDefaultBG; + } - CurrentBackgroundHandler?.LoadBackground(LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal, e.IsRequestInit, e.IsForceRecreateCache, (Exception ex) => - { - LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal = AppDefaultBG; - LogWriteLine($"An error occured while loading background {e.ImgPath}\r\n{ex}", LogType.Error, true); - ErrorSender.SendException(ex); - }, e.ActionAfterLoaded); + CurrentBackgroundHandler + ?.LoadBackground(LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal, + e.IsRequestInit, e.IsForceRecreateCache, ex => + { + LauncherMetadataHelper + .CurrentMetadataConfig + .GameLauncherApi + .GameBackgroundImgLocal = + AppDefaultBG; + LogWriteLine($"An error occured while loading background {e.ImgPath}\r\n{ex}", + LogType.Error, true); + ErrorSender.SendException(ex); + }, e.ActionAfterLoaded); + } } internal async void ChangeBackgroundImageAsRegionAsync(bool ShowLoadingMsg = false) { IsCustomBG = GetAppConfigValue("UseCustomBG").ToBool(); - bool isAPIBackgroundAvailable = !string.IsNullOrEmpty(LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImg); + bool isAPIBackgroundAvailable = !string.IsNullOrEmpty(LauncherMetadataHelper.CurrentMetadataConfig?.GameLauncherApi?.GameBackgroundImg); if (IsCustomBG) { string BGPath = GetAppConfigValue("CustomBGPath").ToString(); - LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal = string.IsNullOrEmpty(BGPath) ? AppDefaultBG : BGPath; + if (LauncherMetadataHelper.CurrentMetadataConfig?.GameLauncherApi != null) + { + LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal = + string.IsNullOrEmpty(BGPath) ? AppDefaultBG : BGPath; + } } else if (isAPIBackgroundAvailable) { @@ -491,10 +511,10 @@ internal async void ChangeBackgroundImageAsRegionAsync(bool ShowLoadingMsg = fal } // Use default background if the API background is empty (in-case HoYo did something catchy) - if (!isAPIBackgroundAvailable && !IsCustomBG) + if (!isAPIBackgroundAvailable && !IsCustomBG && LauncherMetadataHelper.CurrentMetadataConfig?.GameLauncherApi != null) LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal = AppDefaultBG; - if (!IsCustomBG || IsFirstStartup) + if ((!IsCustomBG || IsFirstStartup) && LauncherMetadataHelper.CurrentMetadataConfig?.GameLauncherApi != null) { BackgroundImgChanger.ChangeBackground(LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal, () => @@ -573,7 +593,7 @@ private async void RunBackgroundCheck() // Run the update check and trigger routine LauncherUpdateHelper.RunUpdateCheckDetached(); #else - LogWriteLine("Running debug build, stopping update checks!", LogType.Error, false); + LogWriteLine("Running debug build, stopping update checks!", LogType.Error); #endif } catch (JsonException ex) @@ -622,7 +642,7 @@ private async Task FetchNotificationFeed() NotificationData = await networkStream.DeserializeAsync(InternalAppJSONContext.Default, TokenSource.Token); IsLoadNotifComplete = true; - NotificationData.EliminatePushList(); + NotificationData?.EliminatePushList(); } catch (Exception ex) { @@ -632,7 +652,7 @@ private async Task FetchNotificationFeed() private void GenerateLocalAppNotification() { - NotificationData.AppPush.Add(new NotificationProp + NotificationData?.AppPush.Add(new NotificationProp { Show = true, MsgId = 0, @@ -648,7 +668,7 @@ private void GenerateLocalAppNotification() if (IsPreview) { - NotificationData.AppPush.Add(new NotificationProp + NotificationData?.AppPush.Add(new NotificationProp { Show = true, MsgId = -1, @@ -671,7 +691,7 @@ private void GenerateLocalAppNotification() private Button GenerateNotificationButtonStartProcess(string IconGlyph, string PathOrURL, string Text, bool IsUseShellExecute = true) { - return NotificationPush.GenerateNotificationButton(IconGlyph, Text, (s, e) => + return NotificationPush.GenerateNotificationButton(IconGlyph, Text, (_, _) => { new Process { @@ -696,8 +716,8 @@ private async void RunTimeoutCancel(CancellationTokenSource Token) private async Task SpawnPushAppNotification() { - TypedEventHandler ClickCloseAction = null; - if (NotificationData.AppPush == null) return; + TypedEventHandler ClickCloseAction; + if (NotificationData?.AppPush == null) return; foreach (NotificationProp Entry in NotificationData.AppPush) { // Check for Close Action for certain MsgIds @@ -705,11 +725,11 @@ private async Task SpawnPushAppNotification() { case 0: { - ClickCloseAction = new TypedEventHandler((sender, args) => - { - NotificationData.AddIgnoredMsgIds(0); - SaveLocalNotificationData(); - }); + ClickCloseAction = (_, _) => + { + NotificationData?.AddIgnoredMsgIds(0); + SaveLocalNotificationData(); + }; } break; default: @@ -743,17 +763,17 @@ private void SpawnAppUpdatedNotification() { string UpdateNotifFile = Path.Combine(AppDataFolder, "_NewVer"); string NeedInnoUpdateFile = Path.Combine(AppDataFolder, "_NeedInnoLogUpdate"); - TypedEventHandler ClickClose = new TypedEventHandler((sender, args) => - { - File.Delete(UpdateNotifFile); - }); + TypedEventHandler ClickClose = (_, _) => + { + File.Delete(UpdateNotifFile); + }; // If the update was handled by squirrel and it needs Inno Setup Log file to get updated, then do the routine if (File.Exists(NeedInnoUpdateFile)) { try { - string InnoLogPath = Path.Combine(Path.GetDirectoryName(AppFolder), "unins000.dat"); + string InnoLogPath = Path.Combine(Path.GetDirectoryName(AppFolder) ?? string.Empty, "unins000.dat"); if (File.Exists(InnoLogPath)) InnoSetupLogUpdate.UpdateInnoSetupLog(InnoLogPath); File.Delete(NeedInnoUpdateFile); } @@ -798,7 +818,10 @@ private void SpawnAppUpdatedNotification() } } } - catch { } + catch + { + // ignored + } } private InfoBarSeverity NotifSeverity2InfoBarSeverity(NotifSeverity inp) @@ -816,16 +839,16 @@ private InfoBarSeverity NotifSeverity2InfoBarSeverity(NotifSeverity inp) } } - private void SpawnNotificationPush(string Title, string Content, NotifSeverity Severity, int MsgId = 0, bool IsClosable = true, + private void SpawnNotificationPush(string Title, string TextContent, NotifSeverity Severity, int MsgId = 0, bool IsClosable = true, bool Disposable = false, TypedEventHandler CloseClickHandler = null, FrameworkElement OtherContent = null, bool IsAppNotif = true, bool? Show = false, bool ForceShowNotificationPanel = false) { if (!(Show ?? false)) return; - if (NotificationData.CurrentShowMsgIds.Contains(MsgId)) return; + if (NotificationData?.CurrentShowMsgIds.Contains(MsgId) ?? false) return; - if (NotificationData.IsMsgIdIgnored(MsgId)) return; + if (NotificationData?.IsMsgIdIgnored(MsgId) ?? false) return; - NotificationData.CurrentShowMsgIds.Add(MsgId); + NotificationData?.CurrentShowMsgIds.Add(MsgId); DispatcherQueue?.TryEnqueue(() => { @@ -833,13 +856,13 @@ private void SpawnNotificationPush(string Title, string Content, NotifSeverity S InfoBar Notification = new InfoBar { - Title = Title, - Message = Content, - Severity = NotifSeverity2InfoBarSeverity(Severity), - IsClosable = IsClosable, + Title = Title, + Message = TextContent, + Severity = NotifSeverity2InfoBarSeverity(Severity), + IsClosable = IsClosable, IsIconVisible = true, - Shadow = SharedShadow, - IsOpen = true + Shadow = SharedShadow, + IsOpen = true } .WithMargin(4d, 4d, 4d, 0d).WithWidth(600) .WithCornerRadius(8).WithHorizontalAlignment(HorizontalAlignment.Right); @@ -879,7 +902,7 @@ private void SpawnNotificationPush(string Title, string Content, NotifSeverity S private void SpawnNotificationoUI(int tagID, InfoBar Notification) { Grid Container = UIElementExtensions.CreateGrid().WithTag(tagID); - Notification.Loaded += (a, b) => + Notification.Loaded += (_, _) => { NoNotificationIndicator.Opacity = NotificationContainer.Children.Count > 0 ? 0f : 1f; NewNotificationCountBadge.Visibility = Visibility.Visible; @@ -888,16 +911,16 @@ private void SpawnNotificationoUI(int tagID, InfoBar Notification) NotificationPanelClearAllGrid.Visibility = NotificationContainer.Children.Count > 0 ? Visibility.Visible : Visibility.Collapsed; }; - Notification.Closed += (s, a) => + Notification.Closed += (s, _) => { s.Translation -= Shadow32; s.SetHeight(0d); s.SetMargin(0d); int msg = (int)s.Tag; - if (NotificationData.CurrentShowMsgIds.Contains(msg)) + if (NotificationData?.CurrentShowMsgIds.Contains(msg) ?? false) { - NotificationData.CurrentShowMsgIds.Remove(msg); + NotificationData?.CurrentShowMsgIds.Remove(msg); } NotificationContainer.Children.Remove(Container); NoNotificationIndicator.Opacity = NotificationContainer.Children.Count > 0 ? 0f : 1f; @@ -917,11 +940,11 @@ private void SpawnNotificationoUI(int tagID, InfoBar Notification) private void RemoveNotificationUI(int tagID) { - Grid notif = NotificationContainer.Children.OfType().Where(x => (int)x.Tag == tagID).FirstOrDefault(); + Grid notif = NotificationContainer.Children.OfType().FirstOrDefault(x => (int)x.Tag == tagID); if (notif != null) { NotificationContainer.Children.Remove(notif); - InfoBar notifBar = notif.Children.OfType()?.FirstOrDefault(); + InfoBar notifBar = notif.Children.OfType().FirstOrDefault(); if (notifBar != null && notifBar.IsClosable) notifBar.IsOpen = false; } @@ -936,8 +959,8 @@ private async void ClearAllNotification(object sender, RoutedEventArgs args) for (; stackIndex < NotificationContainer.Children.Count;) { if (NotificationContainer.Children[stackIndex] is not Grid container - || container.Children == null || container.Children.Count == 0 - || container.Children[0] is not InfoBar notifBar || notifBar == null + || container.Children == null || container.Children.Count == 0 + || container.Children[0] is not InfoBar notifBar || !notifBar.IsClosable) { ++stackIndex; @@ -962,16 +985,22 @@ private async void ClearAllNotification(object sender, RoutedEventArgs args) private void NeverAskNotif_Checked(object sender, RoutedEventArgs e) { - string[] Data = (sender as CheckBox).Tag.ToString().Split(','); - NotificationData.AddIgnoredMsgIds(int.Parse(Data[0]), bool.Parse(Data[1])); - SaveLocalNotificationData(); + string[] Data = (sender as CheckBox)?.Tag.ToString()?.Split(','); + if (Data != null) + { + NotificationData?.AddIgnoredMsgIds(int.Parse(Data[0]), bool.Parse(Data[1])); + SaveLocalNotificationData(); + } } private void NeverAskNotif_Unchecked(object sender, RoutedEventArgs e) { - string[] Data = (sender as CheckBox).Tag.ToString().Split(','); - NotificationData.RemoveIgnoredMsgIds(int.Parse(Data[0]), bool.Parse(Data[1])); - SaveLocalNotificationData(); + string[] Data = (sender as CheckBox)?.Tag.ToString()?.Split(','); + if (Data != null) + { + NotificationData?.RemoveIgnoredMsgIds(int.Parse(Data[0]), bool.Parse(Data[1])); + SaveLocalNotificationData(); + } } private async void ForceShowNotificationPanel() @@ -1087,7 +1116,7 @@ private async Task CheckMetadataUpdateInBackground() ) .WithMargin(0d, 0d, 0d, 16d); - UpdateMetadatabtn.Loaded += async (a, b) => + UpdateMetadatabtn.Loaded += async (a, _) => { TextBlock Text = new TextBlock { @@ -1102,8 +1131,12 @@ private async Task CheckMetadataUpdateInBackground() StackPanel StackPane = UIElementExtensions.CreateStackPanel(Orientation.Horizontal); StackPane.AddElementToStackPanel(LoadBar); StackPane.AddElementToStackPanel(Text); - (a as Button).Content = StackPane; - (a as Button).IsEnabled = false; + Button aButton = a as Button; + if (aButton != null) + { + aButton.Content = StackPane; + aButton.IsEnabled = false; + } // Put 2 seconds delay before updating int i = 2; @@ -1125,7 +1158,7 @@ private async Task CheckMetadataUpdateInBackground() catch (Exception ex) { LogWriteLine($"Error has occured while updating metadata!\r\n{ex}", LogType.Error, true); - ErrorSender.SendException(ex, ErrorType.Unhandled); + ErrorSender.SendException(ex); } }; SpawnNotificationPush( @@ -1345,7 +1378,7 @@ void Navigate(Type sourceType, string tagStr) internal void InvokeMainPageNavigateByTag(string tagStr) { - NavigationViewItem item = NavigationViewControl.MenuItems.OfType()?.Where(x => x.Tag.GetType() == typeof(string) && (string)x.Tag == tagStr)?.FirstOrDefault(); + NavigationViewItem item = NavigationViewControl.MenuItems.OfType().FirstOrDefault(x => x.Tag is string tag && tag == tagStr); if (item != null) { NavigationViewControl.SelectedItem = item; @@ -1375,18 +1408,18 @@ private async void ShowHideNotificationLostFocusBackground(bool show) { if (show) { - NotificationLostFocusBackground.Visibility = Visibility.Visible; - NotificationLostFocusBackground.Opacity = 0.3; - NotificationPanel.Translation += Shadow48; - ToggleNotificationPanelBtn.Translation -= Shadow16; - (ToggleNotificationPanelBtn.Content as FontIcon).FontFamily = FontCollections.FontAwesomeSolid; + NotificationLostFocusBackground.Visibility = Visibility.Visible; + NotificationLostFocusBackground.Opacity = 0.3; + NotificationPanel.Translation += Shadow48; + ToggleNotificationPanelBtn.Translation -= Shadow16; + ((FontIcon)ToggleNotificationPanelBtn.Content).FontFamily = FontCollections.FontAwesomeSolid; } else { - NotificationLostFocusBackground.Opacity = 0; - NotificationPanel.Translation -= Shadow48; - ToggleNotificationPanelBtn.Translation += Shadow16; - (ToggleNotificationPanelBtn.Content as FontIcon).FontFamily = FontCollections.FontAwesomeRegular; + NotificationLostFocusBackground.Opacity = 0; + NotificationPanel.Translation -= Shadow48; + ToggleNotificationPanelBtn.Translation += Shadow16; + ((FontIcon)ToggleNotificationPanelBtn.Content).FontFamily = FontCollections.FontAwesomeRegular; await Task.Delay(200); NotificationLostFocusBackground.Visibility = Visibility.Collapsed; } @@ -1553,7 +1586,7 @@ private void InitKeyboardShortcuts() true, false, null, - NotificationPush.GenerateNotificationButton("", Lang._AppNotification.NotifKbShortcutBtn, (o, e) => ShowKeybinds_Invoked(null, null)), + NotificationPush.GenerateNotificationButton("", Lang._AppNotification.NotifKbShortcutBtn, (_, _) => ShowKeybinds_Invoked(null, null)), true, true, true @@ -1571,36 +1604,39 @@ private void CreateKeyboardShortcutHandlers() LoadKbShortcuts(); int numIndex = 0; - VirtualKeyModifiers keyModifier = KbShortcutList["GameSelection"].Modifier; - for (; numIndex <= LauncherMetadataHelper.CurrentGameNameCount; numIndex++) + if (KbShortcutList != null) { - KeyboardAccelerator keystroke = new KeyboardAccelerator() + VirtualKeyModifiers keyModifier = KbShortcutList["GameSelection"].Modifier; + for (; numIndex <= LauncherMetadataHelper.CurrentGameNameCount; numIndex++) { - Modifiers = keyModifier, - Key = VirtualKey.Number1 + numIndex, - }; - keystroke.Invoked += KeyboardGameShortcut_Invoked; - KeyboardHandler.KeyboardAccelerators.Add(keystroke); + KeyboardAccelerator keystroke = new KeyboardAccelerator() + { + Modifiers = keyModifier, + Key = VirtualKey.Number1 + numIndex, + }; + keystroke.Invoked += KeyboardGameShortcut_Invoked; + KeyboardHandler.KeyboardAccelerators.Add(keystroke); - KeyboardAccelerator keystrokeNP = new KeyboardAccelerator() - { - Key = VirtualKey.NumberPad1 + numIndex, - }; - keystrokeNP.Invoked += KeyboardGameShortcut_Invoked; - KeyboardHandler.KeyboardAccelerators.Add(keystrokeNP); - } + KeyboardAccelerator keystrokeNP = new KeyboardAccelerator() + { + Key = VirtualKey.NumberPad1 + numIndex, + }; + keystrokeNP.Invoked += KeyboardGameShortcut_Invoked; + KeyboardHandler.KeyboardAccelerators.Add(keystrokeNP); + } - numIndex = 0; - keyModifier = KbShortcutList["RegionSelection"].Modifier; - while (numIndex < LauncherMetadataHelper.CurrentGameRegionMaxCount) - { - KeyboardAccelerator keystroke = new KeyboardAccelerator() + numIndex = 0; + keyModifier = KbShortcutList["RegionSelection"].Modifier; + while (numIndex < LauncherMetadataHelper.CurrentGameRegionMaxCount) { - Modifiers = keyModifier, - Key = VirtualKey.Number1 + numIndex++, - }; - keystroke.Invoked += KeyboardGameRegionShortcut_Invoked; - KeyboardHandler.KeyboardAccelerators.Add(keystroke); + KeyboardAccelerator keystroke = new KeyboardAccelerator() + { + Modifiers = keyModifier, + Key = VirtualKey.Number1 + numIndex++, + }; + keystroke.Invoked += KeyboardGameRegionShortcut_Invoked; + KeyboardHandler.KeyboardAccelerators.Add(keystroke); + } } KeyboardAccelerator keystrokeF5 = new KeyboardAccelerator() @@ -1633,13 +1669,16 @@ private void CreateKeyboardShortcutHandlers() foreach (var func in actions) { - KeyboardAccelerator kbfunc = new KeyboardAccelerator() + if (KbShortcutList != null) { - Modifiers = KbShortcutList[func.Key].Modifier, - Key = KbShortcutList[func.Key].Key - }; - kbfunc.Invoked += func.Value; - KeyboardHandler.KeyboardAccelerators.Add(kbfunc); + KeyboardAccelerator kbfunc = new KeyboardAccelerator() + { + Modifiers = KbShortcutList[func.Key].Modifier, + Key = KbShortcutList[func.Key].Key + }; + kbfunc.Invoked += func.Value; + KeyboardHandler.KeyboardAccelerators.Add(kbfunc); + } } } catch (Exception error) @@ -1664,9 +1703,9 @@ private void RefreshPage_Invoked(KeyboardAccelerator sender, KeyboardAccelerator case "settings": return; default: - string Tag = PreviousTag; + string itemTag = PreviousTag; PreviousTag = "Empty"; - NavigateInnerSwitch(Tag); + NavigateInnerSwitch(itemTag); if (LauncherFrame != null && LauncherFrame.BackStack != null && LauncherFrame.BackStack.Count > 0) LauncherFrame.BackStack.RemoveAt(LauncherFrame.BackStack.Count - 1); if (PreviousTagString != null && PreviousTagString.Count > 0) @@ -1696,9 +1735,7 @@ private void RestoreCurrentRegion() var gameName = GetAppConfigValue("GameCategory").ToString(); #nullable enable List? gameNameCollection = LauncherMetadataHelper.GetGameNameCollection()!; - List? gameRegionCollection = LauncherMetadataHelper.GetGameRegionCollection(gameName)!; - - gameName ??= gameRegionCollection.FirstOrDefault(); + _ = LauncherMetadataHelper.GetGameRegionCollection(gameName)!; var indexCategory = gameNameCollection.IndexOf(gameName!); if (indexCategory < 0) indexCategory = 0; @@ -1758,7 +1795,7 @@ private void KeyboardGameRegionShortcut_Invoked(KeyboardAccelerator sender, Keyb DisableInstantRegionChange = false; } - private async void ShowKeybinds_Invoked(KeyboardAccelerator sender, KeyboardAcceleratorInvokedEventArgs args) + private async void ShowKeybinds_Invoked(KeyboardAccelerator? sender, KeyboardAcceleratorInvokedEventArgs? args) { if (CannotUseKbShortcuts) return; @@ -1954,7 +1991,6 @@ private bool SetActivatedRegion() string gameName = args.Game; - #nullable enable List? gameNameCollection = LauncherMetadataHelper.GetGameNameCollection()!; List? gameRegionCollection = LauncherMetadataHelper.GetGameRegionCollection(gameName)!; if (gameRegionCollection == null) @@ -1966,7 +2002,6 @@ private bool SetActivatedRegion() gameRegionCollection = LauncherMetadataHelper.GetGameRegionCollection(gameName)!; } SetAndSaveConfigValue("GameCategory", gameName); - #nullable restore if (args.Region != null) { @@ -1981,7 +2016,6 @@ private bool SetActivatedRegion() int oldGameRegionIndex = LauncherMetadataHelper.GetPreviousGameRegion(gameName); string oldGameRegion = gameRegionCollection.ElementAt(oldGameRegionIndex); - if (oldGameRegion == null) return true; LauncherMetadataHelper.SetPreviousGameRegion(gameName, gameRegion); SetAndSaveConfigValue("GameRegion", gameRegion); @@ -2009,7 +2043,7 @@ private async void ChangeToActivatedRegion() { #if !DISABLEDISCORD if (GetAppConfigValue("EnableDiscordRPC").ToBool() && !sameRegion) - AppDiscordPresence.SetupPresence(); + AppDiscordPresence?.SetupPresence(); #endif InvokeLoadingRegionPopup(false); LauncherFrame.BackStack.Clear(); diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs b/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs index 6ec6b0203..e28edd71e 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/HomePage.xaml.cs @@ -933,7 +933,11 @@ private async void CheckRunningGameInstance(CancellationToken Token) StartGameBtn.IsEnabled = true; StartGameBtnText!.Text = Lang._HomePage.StartBtn; StartGameBtnIcon.Glyph = StartGameBtnIconGlyph; - StartGameBtnAnimatedIconGrid.Opacity = 1; + if (StartGameBtnAnimatedIconGrid != null) + { + StartGameBtnAnimatedIconGrid.Opacity = 1; + } + StartGameBtnIcon.Opacity = 0; GameStartupSetting.IsEnabled = true; diff --git a/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs b/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs index fa7f1d631..a9c5d86d6 100644 --- a/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs +++ b/CollapseLauncher/XAMLs/MainApp/Pages/SettingsPage.xaml.cs @@ -28,7 +28,6 @@ using static CollapseLauncher.Dialogs.SimpleDialogs; using static CollapseLauncher.Helper.Image.Waifu2X; using static CollapseLauncher.InnerLauncherConfig; - using static CollapseLauncher.RegionResourceListHelper; using static CollapseLauncher.WindowSize.WindowSize; using static CollapseLauncher.FileDialogCOM.FileDialogNative; using static Hi3Helper.Locale; @@ -38,6 +37,7 @@ using TaskSched = Microsoft.Win32.TaskScheduler.Task; using Task = System.Threading.Tasks.Task; +// ReSharper disable CheckNamespace // ReSharper disable PossibleNullReferenceException // ReSharper disable AssignNullToNotNullAttribute @@ -66,7 +66,7 @@ public SettingsPage() AboutApp.FindAndSetTextBlockWrapping(TextWrapping.Wrap, HorizontalAlignment.Center, TextAlignment.Center, true); LoadAppConfig(); - this.DataContext = this; + DataContext = this; string Version = $" {LauncherUpdateHelper.LauncherCurrentVersionString}"; #if DEBUG @@ -171,7 +171,7 @@ private async void ClearMetadataFolder(object sender, RoutedEventArgs e) try { var collapsePath = Process.GetCurrentProcess().MainModule?.FileName; - if (collapsePath == null || LauncherMetadataHelper.LauncherMetadataFolder == null) return; + if (collapsePath == null) return; Directory.Delete(LauncherMetadataHelper.LauncherMetadataFolder, true); Process.Start(collapsePath); (WindowUtility.CurrentWindow as MainWindow)?.CloseApp(); @@ -191,9 +191,9 @@ private async void ClearMetadataFolder(object sender, RoutedEventArgs e) private void OpenAppDataFolder(object sender, RoutedEventArgs e) { - new Process() + new Process { - StartInfo = new ProcessStartInfo() + StartInfo = new ProcessStartInfo { UseShellExecute = true, FileName = "explorer.exe", @@ -295,11 +295,18 @@ private async void CheckUpdate(object sender, RoutedEventArgs e) LauncherUpdateInvoker.UpdateEvent += LauncherUpdateInvoker_UpdateEvent; bool isUpdateAvailable = await LauncherUpdateHelper.IsUpdateAvailable(true); - LauncherUpdateWatcher.GetStatus(new LauncherUpdateProperty { IsUpdateAvailable = isUpdateAvailable, NewVersionName = LauncherUpdateHelper.AppUpdateVersionProp.Version.Value }); + if (LauncherUpdateHelper.AppUpdateVersionProp.Version != null) + { + LauncherUpdateWatcher.GetStatus(new LauncherUpdateProperty + { + IsUpdateAvailable = isUpdateAvailable, + NewVersionName = LauncherUpdateHelper.AppUpdateVersionProp.Version.Value + }); + } } catch (Exception ex) { - ErrorSender.SendException(ex, ErrorType.Unhandled); + ErrorSender.SendException(ex); UpdateLoadingStatus.Visibility = Visibility.Collapsed; UpdateAvailableStatus.Visibility = Visibility.Collapsed; UpToDateStatus.Visibility = Visibility.Collapsed; @@ -406,7 +413,7 @@ private TaskSched CreateScheduledTask(string taskName) taskDefinition.Principal.RunLevel = TaskRunLevel.Highest; taskDefinition.Settings.Enabled = false; taskDefinition.Triggers.Add(new LogonTrigger()); - taskDefinition.Actions.Add(new ExecAction(collapseStartupTarget, null, null)); + taskDefinition.Actions.Add(new ExecAction(collapseStartupTarget)); TaskSched task = TaskService.Instance.RootFolder.RegisterTaskDefinition(taskName, taskDefinition); taskDefinition.Dispose(); @@ -490,7 +497,7 @@ private bool IsBGCustom } } BGPathDisplay.Text = LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal; - BackgroundImgChanger.ChangeBackground(LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal, null, true, true, false); + BackgroundImgChanger.ChangeBackground(LauncherMetadataHelper.CurrentMetadataConfig.GameLauncherApi.GameBackgroundImgLocal, null, true, true); AppBGCustomizer.Visibility = Visibility.Visible; AppBGCustomizerNote.Visibility = Visibility.Visible; @@ -979,7 +986,7 @@ private bool IsStartupToTray TaskSched task = ts.GetTask(_collapseStartupTaskName); task.Definition.Actions.Clear(); - task.Definition.Actions.Add(new ExecAction(collapseStartupTarget, value ? "tray" : null, null)); + task.Definition.Actions.Add(new ExecAction(collapseStartupTarget, value ? "tray" : null)); task.RegisterChanges(); task.Dispose(); } diff --git a/Hi3Helper.Core/Classes/Logger/LoggerBase.cs b/Hi3Helper.Core/Classes/Logger/LoggerBase.cs index ce4fbb814..eee3f582d 100644 --- a/Hi3Helper.Core/Classes/Logger/LoggerBase.cs +++ b/Hi3Helper.Core/Classes/Logger/LoggerBase.cs @@ -3,6 +3,7 @@ using System.Text; #if !APPLYUPDATE using Hi3Helper.Shared.Region; +// ReSharper disable CheckNamespace #endif namespace Hi3Helper @@ -39,7 +40,7 @@ public void SetFolderPathAndInitialize(string folderPath, Encoding logEncoding) #if !APPLYUPDATE // Check if the directory exist. If not, then create. - if (!Directory.Exists(_logFolder)) + if (!string.IsNullOrEmpty(_logFolder) && !Directory.Exists(_logFolder)) { Directory.CreateDirectory(_logFolder); }