From 778c2a4662c993ff9a8ba64c6eccf85301ae5389 Mon Sep 17 00:00:00 2001 From: Foglio Date: Thu, 27 May 2021 12:37:58 +0200 Subject: [PATCH] small refactoring in App --- TCC.Core/App.xaml.cs | 64 ++++++++--- TCC.Core/R.cs | 150 ++++++++++++------------- TCC.Core/Settings/SettingsContainer.cs | 85 +++++--------- TCC.Core/UI/WindowManager.cs | 12 +- TCC.Interop/Proxy/StubInterface.cs | 2 +- 5 files changed, 155 insertions(+), 158 deletions(-) diff --git a/TCC.Core/App.xaml.cs b/TCC.Core/App.xaml.cs index e4cb2227..bf549938 100644 --- a/TCC.Core/App.xaml.cs +++ b/TCC.Core/App.xaml.cs @@ -11,9 +11,7 @@ using System.Windows.Interop; using System.Windows.Media; using System.Windows.Threading; -using TCC.Analysis; using TCC.Data; -using TCC.Exceptions; using TCC.Interop; using TCC.Interop.Proxy; using TCC.Loader; @@ -24,6 +22,8 @@ using TCC.Update; using TCC.Utilities; using TCC.Utils; +using TCC.Utils.Exceptions; +using TeraPacketParser.Analysis; using MessageBoxImage = TCC.Data.MessageBoxImage; namespace TCC @@ -61,33 +61,42 @@ public partial class App public static bool Loading { get; private set; } public static bool ToolboxMode { get; private set; } public static bool FirstStart { get; set; } + public static Random Random { get; } = new(DateTime.Now.DayOfYear + DateTime.Now.Year + DateTime.Now.Minute + DateTime.Now.Second + DateTime.Now.Millisecond); + public static TccSplashScreen SplashScreen { get; set; } = null!; public static SettingsContainer Settings { get; set; } = null!; - private async void OnStartup(object sender, StartupEventArgs e) { _running = true; AppVersion = TccUtils.GetTccVersion(); Log.Config(Path.Combine(BasePath, "logs"), AppVersion); // NLog when? ParseStartupArgs(e.Args.ToList()); - if (!File.Exists(Path.Combine(BasePath, SettingsGlobals.SettingsFileName))) - FirstStart = true; + + FirstStart = !File.Exists(Path.Combine(BasePath, SettingsGlobals.SettingsFileName)); + BaseDispatcher = Dispatcher.CurrentDispatcher; BaseDispatcher.Thread.Name = "Main"; - + Utils.Utilities.CloseRequested += () => Close(); TccMessageBox.CreateAsync(); if (IsAlreadyRunning() && !Debugger.IsAttached) { - if (!ToolboxMode) TccMessageBox.Show(SR.AnotherInstanceRunning, MessageBoxType.Information); + if (!ToolboxMode) + { + TccMessageBox.Show(SR.AnotherInstanceRunning, MessageBoxType.Information); + } Current.Shutdown(); return; } - if (!Debugger.IsAttached) AppDomain.CurrentDomain.UnhandledException += GlobalExceptionHandler.HandleGlobalException; + + if (!Debugger.IsAttached) + { + AppDomain.CurrentDomain.UnhandledException += GlobalExceptionHandler.OnGlobalException; + } Loading = true; await Setup(); @@ -98,9 +107,9 @@ private async void OnStartup(object sender, StartupEventArgs e) new WelcomeWindow().Show(); } + //Tester.Enable(); //Tester.ShowDebugWindow(); - } private static async Task Setup() @@ -124,12 +133,14 @@ private static async Task Setup() SplashScreen.VM.BottomText = "Loading settings..."; Settings = SettingsContainer.Load(); WindowManager.InitSettingsWindow(); // need it in case language is not correct - SplashScreen.VM.Progress = 20; Process.GetCurrentProcess().PriorityClass = Settings.HighPriority ? ProcessPriorityClass.High : ProcessPriorityClass.Normal; - if (Settings.ForceSoftwareRendering) RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; + if (Settings.ForceSoftwareRendering) + { + RenderOptions.ProcessRenderMode = RenderMode.SoftwareOnly; + } // ---------------------------- SplashScreen.VM.Progress = 30; @@ -151,10 +162,18 @@ private static async Task Setup() _ = Task.Run(() => new IconsUpdater().CheckForUpdates()); // ---------------------------- - SplashScreen.VM.BottomText = "Initializing packet processor..."; SplashScreen.VM.Progress = 80; + SplashScreen.VM.BottomText = "Initializing packet processor..."; PacketAnalyzer.ProcessorReady += LoadModules; - await PacketAnalyzer.InitAsync(); + await PacketAnalyzer.InitAsync(Settings.CaptureMode, ToolboxMode); + PacketAnalyzer.InitServerDatabase(DataPath, Path.Combine(ResourcesPath, "config/server-overrides.txt"), string.IsNullOrEmpty(Settings.LastLanguage) + ? "EU-EN" + : Settings.LastLanguage); + _ = StubInterface.Instance.InitAsync(Settings.LfgWindowSettings.Enabled, + Settings.EnablePlayerMenu, + Settings.EnableProxy, + Settings.ShowIngameChat, + Settings.ChatEnabled); // ---------------------------- SplashScreen.VM.Progress = 90; @@ -165,14 +184,16 @@ private static async Task Setup() SplashScreen.VM.Progress = 100; SplashScreen.CloseWindowSafe(); - // ---------------------------- Log.Chat($"{AppVersion} ready."); ReadyEvent?.Invoke(); if (!Beta && Settings.BetaNotification && UpdateManager.IsBetaNewer()) + { Log.N("TCC beta available", SR.BetaAvailable, NotificationType.Success, 10000); + } } + private static void ParseStartupArgs(IList args) { // --toolbox @@ -194,12 +215,14 @@ private static void ParseStartupArgs(IList args) ResourcesPath = Path.Combine(BasePath, "resources"); DataPath = Path.Combine(ResourcesPath, "data"); } + public static void Restart() { Settings.Save(); Process.Start("TCC.exe", $"--restart{(ToolboxMode ? " --toolbox" : "")}"); Close(); } + public static void Close(bool releaseMutex = true, int code = 0) { _running = false; @@ -215,6 +238,7 @@ public static void Close(bool releaseMutex = true, int code = 0) } Environment.Exit(code); } + private static bool IsAlreadyRunning() { _mutex = new Mutex(true, nameof(TCC), out var createdNew); @@ -222,6 +246,7 @@ private static bool IsAlreadyRunning() _mutex.WaitOne(); return false; } + public static void ReleaseMutex() { _running = false; @@ -237,6 +262,7 @@ public static void ReleaseMutex() } }); } + private static void LoadModules() { BaseDispatcher.Invoke(() => @@ -259,6 +285,7 @@ private static void LoadModules() } #region Dispatchers + public static Dispatcher BaseDispatcher { get; private set; } = null!; public static ConcurrentDictionary RunningDispatchers { get; } = new(); @@ -310,8 +337,9 @@ private static void StartDispatcherWatcher() }); Thread.Sleep(1000); } - catch + catch (Exception e) { + Log.CW($"Error while checking for threads activity: {e}"); } if (deadlockedDispatchers.Count <= 1) continue; @@ -322,7 +350,8 @@ private static void StartDispatcherWatcher() }) { Name = "Watcher" }.Start(); } - #endregion + + #endregion Dispatchers #region Misc @@ -340,7 +369,6 @@ public static void FUBH() }); } - #endregion - + #endregion Misc } } \ No newline at end of file diff --git a/TCC.Core/R.cs b/TCC.Core/R.cs index 74a75964..3a27dedd 100644 --- a/TCC.Core/R.cs +++ b/TCC.Core/R.cs @@ -549,124 +549,124 @@ public static class TemplateSelectors // pack://application:,,,/Nostrum;component/Resources/Converters.xaml public static class Nostrum_Converters { - public static BoolToVisibility BoolToVisibility => ((BoolToVisibility)App.Current.FindResource("BoolToVisibility")); - public static RoundedClipConverter RoundedClipConverter => ((RoundedClipConverter)App.Current.FindResource("RoundedClipConverter")); - public static NullToVisibilityConverter NullToVisibility => ((NullToVisibilityConverter)App.Current.FindResource("NullToVisibility")); + public static MathMultiplicationConverter MathMultiplication => ((MathMultiplicationConverter)App.Current.FindResource("MathMultiplication")); public static BooleanInverter BoolInverter => ((BooleanInverter)App.Current.FindResource("BoolInverter")); - public static ColorToTransparent ColorToTransparent => ((ColorToTransparent)App.Current.FindResource("ColorToTransparent")); + public static ListBoxItemIndexConverter ListBoxItemIndex => ((ListBoxItemIndexConverter)App.Current.FindResource("ListBoxItemIndex")); + public static EnumDescriptionConverter EnumDescriptionConverter => ((EnumDescriptionConverter)App.Current.FindResource("EnumDescriptionConverter")); + public static BoolToVisibility BoolToVisibility => ((BoolToVisibility)App.Current.FindResource("BoolToVisibility")); public static DurationToStringConverter DurationToString => ((DurationToStringConverter)App.Current.FindResource("DurationToString")); + public static RoundedClipConverter RoundedClipConverter => ((RoundedClipConverter)App.Current.FindResource("RoundedClipConverter")); public static EpochConverter EpochConverter => ((EpochConverter)App.Current.FindResource("EpochConverter")); - public static EnumDescriptionConverter EnumDescriptionConverter => ((EnumDescriptionConverter)App.Current.FindResource("EnumDescriptionConverter")); - public static MathMultiplicationConverter MathMultiplication => ((MathMultiplicationConverter)App.Current.FindResource("MathMultiplication")); - public static ValueToFactorConverter ValueToFactor => ((ValueToFactorConverter)App.Current.FindResource("ValueToFactor")); + public static ColorToTransparent ColorToTransparent => ((ColorToTransparent)App.Current.FindResource("ColorToTransparent")); public static FactorToAngleConverter FactorToAngle => ((FactorToAngleConverter)App.Current.FindResource("FactorToAngle")); - public static ListBoxItemIndexConverter ListBoxItemIndex => ((ListBoxItemIndexConverter)App.Current.FindResource("ListBoxItemIndex")); + public static ValueToFactorConverter ValueToFactor => ((ValueToFactorConverter)App.Current.FindResource("ValueToFactor")); + public static NullToVisibilityConverter NullToVisibility => ((NullToVisibilityConverter)App.Current.FindResource("NullToVisibility")); } // pack://application:,,,/Nostrum;component/Resources/MiscResources.xaml public static class Nostrum_MiscResources { - public static ScaleTransform DefaultScaleTransform => ((ScaleTransform)App.Current.FindResource("DefaultScaleTransform")); - public static RotateTransform Rotate45 => ((RotateTransform)App.Current.FindResource("Rotate45")); - public static SkewTransform Skew45Inv => ((SkewTransform)App.Current.FindResource("Skew45Inv")); + public static RotateTransform Rotate45Inv => ((RotateTransform)App.Current.FindResource("Rotate45Inv")); public static QuadraticEase QuadraticEase => ((QuadraticEase)App.Current.FindResource("QuadraticEase")); + public static RotateTransform Rotate45 => ((RotateTransform)App.Current.FindResource("Rotate45")); public static TranslateTransform DefaultTranslateTransform => ((TranslateTransform)App.Current.FindResource("DefaultTranslateTransform")); public static RotateTransform DefaultRotateTransform => ((RotateTransform)App.Current.FindResource("DefaultRotateTransform")); + public static ScaleTransform DefaultScaleTransform => ((ScaleTransform)App.Current.FindResource("DefaultScaleTransform")); + public static SkewTransform Skew45Inv => ((SkewTransform)App.Current.FindResource("Skew45Inv")); public static SkewTransform Skew45 => ((SkewTransform)App.Current.FindResource("Skew45")); - public static RotateTransform Rotate45Inv => ((RotateTransform)App.Current.FindResource("Rotate45Inv")); } // pack://application:,,,/Nostrum;component/Resources/SVG.xaml public static class Nostrum_SVG { + public static StreamGeometry SvgGift => ((StreamGeometry)App.Current.FindResource("SvgGift")); + public static StreamGeometry SvgStar => ((StreamGeometry)App.Current.FindResource("SvgStar")); + public static StreamGeometry SvgRemoveCircle => ((StreamGeometry)App.Current.FindResource("SvgRemoveCircle")); + public static StreamGeometry SvgClose => ((StreamGeometry)App.Current.FindResource("SvgClose")); + public static StreamGeometry SvgExpandAll => ((StreamGeometry)App.Current.FindResource("SvgExpandAll")); + public static StreamGeometry SvgMapMarker => ((StreamGeometry)App.Current.FindResource("SvgMapMarker")); + public static StreamGeometry SvgTwitch => ((StreamGeometry)App.Current.FindResource("SvgTwitch")); public static StreamGeometry SvgPaypal => ((StreamGeometry)App.Current.FindResource("SvgPaypal")); - public static StreamGeometry SvgSocial => ((StreamGeometry)App.Current.FindResource("SvgSocial")); + public static StreamGeometry SvgMatching => ((StreamGeometry)App.Current.FindResource("SvgMatching")); public static StreamGeometry SvgBlurOn => ((StreamGeometry)App.Current.FindResource("SvgBlurOn")); - public static StreamGeometry SvgOpenLink => ((StreamGeometry)App.Current.FindResource("SvgOpenLink")); + public static StreamGeometry SvgBlock => ((StreamGeometry)App.Current.FindResource("SvgBlock")); + public static StreamGeometry SvgGitHub => ((StreamGeometry)App.Current.FindResource("SvgGitHub")); + public static StreamGeometry SvgPen => ((StreamGeometry)App.Current.FindResource("SvgPen")); + public static StreamGeometry SvgCheckCircle => ((StreamGeometry)App.Current.FindResource("SvgCheckCircle")); public static StreamGeometry SvgUserAdd => ((StreamGeometry)App.Current.FindResource("SvgUserAdd")); - public static StreamGeometry SvgGuild => ((StreamGeometry)App.Current.FindResource("SvgGuild")); - public static StreamGeometry SvgEye => ((StreamGeometry)App.Current.FindResource("SvgEye")); - public static StreamGeometry SvgAchievements => ((StreamGeometry)App.Current.FindResource("SvgAchievements")); - public static StreamGeometry SvgUpArrow => ((StreamGeometry)App.Current.FindResource("SvgUpArrow")); - public static StreamGeometry SvgCopy => ((StreamGeometry)App.Current.FindResource("SvgCopy")); - public static StreamGeometry SvgCollapseAll => ((StreamGeometry)App.Current.FindResource("SvgCollapseAll")); - public static StreamGeometry SvgDownArrow => ((StreamGeometry)App.Current.FindResource("SvgDownArrow")); - public static StreamGeometry SvgTwitch => ((StreamGeometry)App.Current.FindResource("SvgTwitch")); - public static StreamGeometry SvgTrophy => ((StreamGeometry)App.Current.FindResource("SvgTrophy")); - public static StreamGeometry SvgAdd => ((StreamGeometry)App.Current.FindResource("SvgAdd")); - public static StreamGeometry SvgExpandAll => ((StreamGeometry)App.Current.FindResource("SvgExpandAll")); public static StreamGeometry SvgDiscord => ((StreamGeometry)App.Current.FindResource("SvgDiscord")); - public static StreamGeometry SvgRemoveUser => ((StreamGeometry)App.Current.FindResource("SvgRemoveUser")); - public static StreamGeometry SvgQuestLog => ((StreamGeometry)App.Current.FindResource("SvgQuestLog")); - public static StreamGeometry SvgDisband => ((StreamGeometry)App.Current.FindResource("SvgDisband")); - public static StreamGeometry SvgMail => ((StreamGeometry)App.Current.FindResource("SvgMail")); - public static StreamGeometry SvgShop => ((StreamGeometry)App.Current.FindResource("SvgShop")); - public static StreamGeometry SvgSettings => ((StreamGeometry)App.Current.FindResource("SvgSettings")); - public static StreamGeometry SvgDotsVertical => ((StreamGeometry)App.Current.FindResource("SvgDotsVertical")); - public static StreamGeometry SvgAddCircle => ((StreamGeometry)App.Current.FindResource("SvgAddCircle")); - public static StreamGeometry SvgAuto => ((StreamGeometry)App.Current.FindResource("SvgAuto")); - public static StreamGeometry SvgBlock => ((StreamGeometry)App.Current.FindResource("SvgBlock")); - public static StreamGeometry SvgClose => ((StreamGeometry)App.Current.FindResource("SvgClose")); - public static StreamGeometry SvgDrag => ((StreamGeometry)App.Current.FindResource("SvgDrag")); - public static StreamGeometry SvgShirt => ((StreamGeometry)App.Current.FindResource("SvgShirt")); - public static StreamGeometry SvgInfo => ((StreamGeometry)App.Current.FindResource("SvgInfo")); + public static StreamGeometry SvgCheckAll => ((StreamGeometry)App.Current.FindResource("SvgCheckAll")); + public static StreamGeometry SvgTrophy => ((StreamGeometry)App.Current.FindResource("SvgTrophy")); public static StreamGeometry SvgBasket => ((StreamGeometry)App.Current.FindResource("SvgBasket")); - public static StreamGeometry SvgQuestionMark => ((StreamGeometry)App.Current.FindResource("SvgQuestionMark")); - public static StreamGeometry SvgWarning => ((StreamGeometry)App.Current.FindResource("SvgWarning")); - public static StreamGeometry SvgUnpin => ((StreamGeometry)App.Current.FindResource("SvgUnpin")); - public static StreamGeometry SvgConfirm => ((StreamGeometry)App.Current.FindResource("SvgConfirm")); - public static StreamGeometry SvgBlurOff => ((StreamGeometry)App.Current.FindResource("SvgBlurOff")); - public static StreamGeometry SvgGitHub => ((StreamGeometry)App.Current.FindResource("SvgGitHub")); - public static StreamGeometry SvgChatMessage => ((StreamGeometry)App.Current.FindResource("SvgChatMessage")); public static StreamGeometry SvgUsers => ((StreamGeometry)App.Current.FindResource("SvgUsers")); - public static StreamGeometry SvgAwaken => ((StreamGeometry)App.Current.FindResource("SvgAwaken")); - public static StreamGeometry SvgMapMarker => ((StreamGeometry)App.Current.FindResource("SvgMapMarker")); - public static StreamGeometry SvgMinimize => ((StreamGeometry)App.Current.FindResource("SvgMinimize")); public static StreamGeometry SvgUser => ((StreamGeometry)App.Current.FindResource("SvgUser")); - public static StreamGeometry SvgShare => ((StreamGeometry)App.Current.FindResource("SvgShare")); - public static StreamGeometry SvgStar => ((StreamGeometry)App.Current.FindResource("SvgStar")); - public static StreamGeometry SvgMenuRight => ((StreamGeometry)App.Current.FindResource("SvgMenuRight")); - public static StreamGeometry SvgMove => ((StreamGeometry)App.Current.FindResource("SvgMove")); + public static StreamGeometry SvgSettings => ((StreamGeometry)App.Current.FindResource("SvgSettings")); public static StreamGeometry SvgDelegateLeader => ((StreamGeometry)App.Current.FindResource("SvgDelegateLeader")); + public static StreamGeometry SvgRemoveUser => ((StreamGeometry)App.Current.FindResource("SvgRemoveUser")); + public static StreamGeometry SvgWarning => ((StreamGeometry)App.Current.FindResource("SvgWarning")); public static StreamGeometry SvgMoney => ((StreamGeometry)App.Current.FindResource("SvgMoney")); - public static StreamGeometry SvgCheckAll => ((StreamGeometry)App.Current.FindResource("SvgCheckAll")); + public static StreamGeometry SvgDisband => ((StreamGeometry)App.Current.FindResource("SvgDisband")); public static StreamGeometry SvgAddUser => ((StreamGeometry)App.Current.FindResource("SvgAddUser")); - public static StreamGeometry SvgFolder => ((StreamGeometry)App.Current.FindResource("SvgFolder")); + public static StreamGeometry SvgInfo => ((StreamGeometry)App.Current.FindResource("SvgInfo")); + public static StreamGeometry SvgShirt => ((StreamGeometry)App.Current.FindResource("SvgShirt")); + public static StreamGeometry SvgAddCircle => ((StreamGeometry)App.Current.FindResource("SvgAddCircle")); + public static StreamGeometry SvgMove => ((StreamGeometry)App.Current.FindResource("SvgMove")); + public static StreamGeometry SvgMenuRight => ((StreamGeometry)App.Current.FindResource("SvgMenuRight")); + public static StreamGeometry SvgCollapseAll => ((StreamGeometry)App.Current.FindResource("SvgCollapseAll")); + public static StreamGeometry SvgMail => ((StreamGeometry)App.Current.FindResource("SvgMail")); public static StreamGeometry SvgReload => ((StreamGeometry)App.Current.FindResource("SvgReload")); - public static StreamGeometry SvgHeart => ((StreamGeometry)App.Current.FindResource("SvgHeart")); - public static StreamGeometry SvgGift => ((StreamGeometry)App.Current.FindResource("SvgGift")); - public static StreamGeometry SvgRemoveCircle => ((StreamGeometry)App.Current.FindResource("SvgRemoveCircle")); - public static StreamGeometry SvgCrossedSwords => ((StreamGeometry)App.Current.FindResource("SvgCrossedSwords")); - public static StreamGeometry SvgSearch => ((StreamGeometry)App.Current.FindResource("SvgSearch")); + public static StreamGeometry SvgAchievements => ((StreamGeometry)App.Current.FindResource("SvgAchievements")); + public static StreamGeometry SvgSocial => ((StreamGeometry)App.Current.FindResource("SvgSocial")); + public static StreamGeometry SvgCopy => ((StreamGeometry)App.Current.FindResource("SvgCopy")); + public static StreamGeometry SvgDrag => ((StreamGeometry)App.Current.FindResource("SvgDrag")); + public static StreamGeometry SvgGuild => ((StreamGeometry)App.Current.FindResource("SvgGuild")); + public static StreamGeometry SvgFolder => ((StreamGeometry)App.Current.FindResource("SvgFolder")); public static StreamGeometry SvgPin => ((StreamGeometry)App.Current.FindResource("SvgPin")); - public static StreamGeometry SvgMatching => ((StreamGeometry)App.Current.FindResource("SvgMatching")); - public static StreamGeometry SvgAddUsers => ((StreamGeometry)App.Current.FindResource("SvgAddUsers")); - public static StreamGeometry SvgPen => ((StreamGeometry)App.Current.FindResource("SvgPen")); - public static StreamGeometry SvgCheckCircle => ((StreamGeometry)App.Current.FindResource("SvgCheckCircle")); + public static StreamGeometry SvgUnpin => ((StreamGeometry)App.Current.FindResource("SvgUnpin")); + public static StreamGeometry SvgShare => ((StreamGeometry)App.Current.FindResource("SvgShare")); + public static StreamGeometry SvgSearch => ((StreamGeometry)App.Current.FindResource("SvgSearch")); + public static StreamGeometry SvgMinimize => ((StreamGeometry)App.Current.FindResource("SvgMinimize")); public static StreamGeometry SvgHide => ((StreamGeometry)App.Current.FindResource("SvgHide")); + public static StreamGeometry SvgQuestLog => ((StreamGeometry)App.Current.FindResource("SvgQuestLog")); + public static StreamGeometry SvgHeart => ((StreamGeometry)App.Current.FindResource("SvgHeart")); + public static StreamGeometry SvgAdd => ((StreamGeometry)App.Current.FindResource("SvgAdd")); + public static StreamGeometry SvgAuto => ((StreamGeometry)App.Current.FindResource("SvgAuto")); + public static StreamGeometry SvgQuestionMark => ((StreamGeometry)App.Current.FindResource("SvgQuestionMark")); + public static StreamGeometry SvgShop => ((StreamGeometry)App.Current.FindResource("SvgShop")); + public static StreamGeometry SvgUpArrow => ((StreamGeometry)App.Current.FindResource("SvgUpArrow")); + public static StreamGeometry SvgAwaken => ((StreamGeometry)App.Current.FindResource("SvgAwaken")); + public static StreamGeometry SvgBlurOff => ((StreamGeometry)App.Current.FindResource("SvgBlurOff")); + public static StreamGeometry SvgConfirm => ((StreamGeometry)App.Current.FindResource("SvgConfirm")); + public static StreamGeometry SvgAddUsers => ((StreamGeometry)App.Current.FindResource("SvgAddUsers")); + public static StreamGeometry SvgOpenLink => ((StreamGeometry)App.Current.FindResource("SvgOpenLink")); + public static StreamGeometry SvgDownArrow => ((StreamGeometry)App.Current.FindResource("SvgDownArrow")); + public static StreamGeometry SvgChatMessage => ((StreamGeometry)App.Current.FindResource("SvgChatMessage")); + public static StreamGeometry SvgDotsVertical => ((StreamGeometry)App.Current.FindResource("SvgDotsVertical")); + public static StreamGeometry SvgEye => ((StreamGeometry)App.Current.FindResource("SvgEye")); + public static StreamGeometry SvgCrossedSwords => ((StreamGeometry)App.Current.FindResource("SvgCrossedSwords")); } // pack://application:,,,/Nostrum;component/Resources/Styles.xaml public static class Nostrum_Styles { - public static Style ComboBoxMainStyle => ((Style)App.Current.FindResource("ComboBoxMainStyle")); - public static DropShadowEffect BigDropShadow => ((DropShadowEffect)App.Current.FindResource("BigDropShadow")); - public static Style ComboBoxToggleButton => ((Style)App.Current.FindResource("ComboBoxToggleButton")); public static DropShadowEffect DropShadow => ((DropShadowEffect)App.Current.FindResource("DropShadow")); - public static ControlTemplate MenuItemControlTemplate1 => ((ControlTemplate)App.Current.FindResource("MenuItemControlTemplate1")); + public static Style ButtonContentOpacityStyle => ((Style)App.Current.FindResource("ButtonContentOpacityStyle")); + public static Style ComboBoxToggleButton => ((Style)App.Current.FindResource("ComboBoxToggleButton")); + public static DropShadowEffect FadedDropShadow => ((DropShadowEffect)App.Current.FindResource("FadedDropShadow")); + public static Style ComboBoxEditableTextBox => ((Style)App.Current.FindResource("ComboBoxEditableTextBox")); public static SolidColorBrush SelectionBorderBrush => ((SolidColorBrush)App.Current.FindResource("SelectionBorderBrush")); - public static Style DefaultListItemStyle => ((Style)App.Current.FindResource("DefaultListItemStyle")); public static Style EmptyFocusVisual => ((Style)App.Current.FindResource("EmptyFocusVisual")); public static SolidColorBrush SelectionBackgroundBrush => ((SolidColorBrush)App.Current.FindResource("SelectionBackgroundBrush")); - public static Style ComboBoxEditableTextBox => ((Style)App.Current.FindResource("ComboBoxEditableTextBox")); - public static ControlTemplate ComboBoxEditableTemplate => ((ControlTemplate)App.Current.FindResource("ComboBoxEditableTemplate")); public static Style NoHilightListItemStyleWithLines => ((Style)App.Current.FindResource("NoHilightListItemStyleWithLines")); - public static Style ButtonContentOpacityStyle => ((Style)App.Current.FindResource("ButtonContentOpacityStyle")); - public static SolidColorBrush SelectionBackgroundLightBrush => ((SolidColorBrush)App.Current.FindResource("SelectionBackgroundLightBrush")); + public static Style ComboBoxMainStyle => ((Style)App.Current.FindResource("ComboBoxMainStyle")); + public static ControlTemplate ComboBoxEditableTemplate => ((ControlTemplate)App.Current.FindResource("ComboBoxEditableTemplate")); public static Style ButtonMainStyle => ((Style)App.Current.FindResource("ButtonMainStyle")); - public static DropShadowEffect FadedDropShadow => ((DropShadowEffect)App.Current.FindResource("FadedDropShadow")); - public static ControlTemplate ComboBoxTemplate => ((ControlTemplate)App.Current.FindResource("ComboBoxTemplate")); + public static Style DefaultListItemStyle => ((Style)App.Current.FindResource("DefaultListItemStyle")); + public static SolidColorBrush SelectionBackgroundLightBrush => ((SolidColorBrush)App.Current.FindResource("SelectionBackgroundLightBrush")); public static Style NoHilightListItemStyle => ((Style)App.Current.FindResource("NoHilightListItemStyle")); + public static ControlTemplate MenuItemControlTemplate1 => ((ControlTemplate)App.Current.FindResource("MenuItemControlTemplate1")); + public static ControlTemplate ComboBoxTemplate => ((ControlTemplate)App.Current.FindResource("ComboBoxTemplate")); + public static DropShadowEffect BigDropShadow => ((DropShadowEffect)App.Current.FindResource("BigDropShadow")); } } diff --git a/TCC.Core/Settings/SettingsContainer.cs b/TCC.Core/Settings/SettingsContainer.cs index 94611bcd..b527e2c1 100644 --- a/TCC.Core/Settings/SettingsContainer.cs +++ b/TCC.Core/Settings/SettingsContainer.cs @@ -22,7 +22,7 @@ public class SettingsContainer private bool _enableProxy; #region Misc - // Misc + public DateTime LastRun { get; set; } public string LastLanguage { @@ -50,16 +50,16 @@ public bool EnableProxy get => _enableProxy || App.ToolboxMode; set => _enableProxy = value; } - public bool DontShowFUBH { get; set; } public ControlShape AbnormalityShape { get; set; } public ControlShape SkillShape { get; set; } public CaptureMode CaptureMode { get; set; } public MentionMode MentionMode { get; set; } - #endregion + #endregion Misc #region Hotkeys + public HotKey LfgHotkey { get; set; } public HotKey DashboardHotkey { get; set; } public HotKey SettingsHotkey { get; set; } @@ -70,9 +70,10 @@ public bool EnableProxy public HotKey ToggleHideAllHotkey { get; set; } public HotKey AbnormalSettingsHotkey { get; set; } - #endregion + #endregion Hotkeys #region Webhooks + public bool WebhookEnabledFieldBoss { get; set; } public string WebhookUrlFieldBoss { get; set; } public string WebhookMessageFieldBossSpawn { get; set; } @@ -82,7 +83,8 @@ public bool EnableProxy public string WebhookMessageGuildBam { get; set; } public bool WebhookEnabledMentions { get; set; } public string WebhookUrlMentions { get; set; } - #endregion + + #endregion Webhooks public CooldownWindowSettings CooldownWindowSettings { get; set; } public CharacterWindowSettings CharacterWindowSettings { get; set; } @@ -98,6 +100,7 @@ public bool EnableProxy public PerfMonitorSettings PerfMonitorSettings { get; set; } #region Chat + public TSObservableCollection ChatWindowsSettings { get; } public WindowSettingsBase ChatSettings { get; private set; } // added to have the EnabledChanged event public bool ChatEnabled @@ -127,42 +130,43 @@ public bool ChatEnabled public int FontSize { get; set; } public int ChatScrollAmount { get; set; } public List UserExcludedSysMsg { get; set; } - #endregion + + #endregion Chat #region Twitch + [JsonIgnore] public string TwitchName { get; set; } //TODO: re-add this + [JsonIgnore] public string TwitchToken { get; set; } //TODO: re-add this + [JsonIgnore] - public string TwitchChannelName { get; set; } //TODO: re-add this - #endregion + public string TwitchChannelName { get; set; } //TODO: re-add this + + #endregion Twitch public static string SettingsOverride { get; set; } = ""; public string LastAccountNameHash { get; set; } = ""; public bool BackgroundNotifications { get; set; } public bool EnablePlayerMenu { get; set; } - public bool ShowDecimalsInCooldowns { get; set; } - //public bool ShowConsole { get; set; } - + public bool ShowDecimalsInCooldowns { get; set; } //TODO: move to CooldownWindowSettings public SettingsContainer() { - MessageFactory.ReleaseVersionChanged += OnReleaseVersionChanged; - StatSentVersion = App.AppVersion; _lastLanguage = ""; StatSentTime = DateTime.MinValue; LastScreenSize = FocusManager.TeraScreen.Bounds.Size; - CooldownWindowSettings = new CooldownWindowSettings(/*.4, .7, 0, 0, true, ClickThruMode.Never, 1, true, .5, false, true, false, null, nameof(CooldownWindowSettings)*/); - CharacterWindowSettings = new CharacterWindowSettings(/*.4, 1, 0, 0, true, ClickThruMode.Never, 1, true, .5, false, true, false, null, nameof(CharacterWindowSettings)*/); - NpcWindowSettings = new NpcWindowSettings(/*.4, 0, 0, 0, true, ClickThruMode.Never, 1, true, .5, false, true, false, null, nameof(NpcWindowSettings)*/); - BuffWindowSettings = new BuffWindowSettings(/*1, .7, 0, 0, true, ClickThruMode.Never, 1, true, .5, false, true, false, null, nameof(BuffWindowSettings)*/); - ClassWindowSettings = new ClassWindowSettings(/*.25, .6, 0, 0, true, ClickThruMode.Never, 1, true, .5, false, true, false, null, nameof(ClassWindowSettings)*/); - GroupWindowSettings = new GroupWindowSettings(/*0, 0, 0, 0, true, ClickThruMode.Never, 1, true, .5, false, true, false, null, nameof(GroupWindowSettings)*/); - FlightGaugeWindowSettings = new FlightWindowSettings(/*0, 0, 0, 0, true, ClickThruMode.Always, 1, false, 1, false, true, false*/); - FloatingButtonSettings = new FloatingButtonWindowSettings(/*0, 0, 0, 0, true, ClickThruMode.Never, 1, false, 1, false, true, true*/); - CivilUnrestWindowSettings = new CivilUnrestWindowSettings(/*1, .45, 0, 0, true, ClickThruMode.Never, 1, true, .5, false, true, false, null, nameof(CivilUnrestWindowSettings)*/); + CooldownWindowSettings = new CooldownWindowSettings(); + CharacterWindowSettings = new CharacterWindowSettings(); + NpcWindowSettings = new NpcWindowSettings(); + BuffWindowSettings = new BuffWindowSettings(); + ClassWindowSettings = new ClassWindowSettings(); + GroupWindowSettings = new GroupWindowSettings(); + FlightGaugeWindowSettings = new FlightWindowSettings(); + FloatingButtonSettings = new FloatingButtonWindowSettings(); + CivilUnrestWindowSettings = new CivilUnrestWindowSettings(); ChatWindowsSettings = new TSObservableCollection(App.BaseDispatcher); PerfMonitorSettings = new PerfMonitorSettings(); ChatSettings = new WindowSettingsBase(); @@ -218,39 +222,6 @@ public SettingsContainer() ShowDecimalsInCooldowns = true; } - private void OnReleaseVersionChanged(int v) - { -#if TERA_X64 - var major = v / 100; - if (major >= 97) - { - var settings = new List - { - CooldownWindowSettings, - CharacterWindowSettings, - NpcWindowSettings, - BuffWindowSettings, - ClassWindowSettings, - GroupWindowSettings, - FlightGaugeWindowSettings, - FloatingButtonSettings, - CivilUnrestWindowSettings, - NotificationAreaSettings - }.Concat(ChatWindowsSettings).Where(s => s.ClickThruMode == ClickThruMode.GameDriven); - - if (settings.Any()) - { - foreach (var ws in settings) - { - ws.ClickThruMode = ClickThruMode.Always; - } - - TccMessageBox.Show("TCC", SR.ForcingGameDrivenClickThruOff, MessageBoxButton.OK); - } - } -#endif - } - public static SettingsContainer Load() { var settingsPath = SettingsOverride == "" @@ -258,12 +229,12 @@ public static SettingsContainer Load() : SettingsOverride; return new JsonSettingsReader().LoadSettings(settingsPath); } + public void Save() { var toRemove = ChatWindowsSettings.Where(s => s.Tabs.Count == 0).ToList(); toRemove.ForEach(s => ChatWindowsSettings.Remove(s)); new JsonSettingsWriter().Save(); } - } -} +} \ No newline at end of file diff --git a/TCC.Core/UI/WindowManager.cs b/TCC.Core/UI/WindowManager.cs index c7111b7c..9b53bfd0 100644 --- a/TCC.Core/UI/WindowManager.cs +++ b/TCC.Core/UI/WindowManager.cs @@ -18,15 +18,17 @@ namespace TCC.UI public static class WindowManager { public static event Action? RepositionRequestedEvent; + public static event Action? ResetToCenterEvent; + public static event Action? MakeGlobalEvent; + public static event Action? DisposeEvent; public static TccTrayIcon TrayIcon { get; } = new(); public static VisibilityManager VisibilityManager { get; } = new(); public static Size ScreenSize => FocusManager.TeraScreen.Bounds.Size; - public static CooldownWindow CooldownWindow { get; private set; } = null!; public static CharacterWindow CharacterWindow { get; private set; } = null!; public static BossWindow BossWindow { get; private set; } = null!; @@ -38,6 +40,7 @@ public static class WindowManager public static FloatingButtonWindow FloatingButton { get; private set; } = null!; public static NotificationAreaWindow NotificationArea { get; private set; } = null!; public static FlightDurationWindow FlightDurationWindow { get; private set; } = null!; + //public static SkillConfigWindow? SkillConfigWindow { get; set; } public static PerfMonitorWindow PerfMonitor { get; private set; } = null!; @@ -45,14 +48,12 @@ public static class WindowManager public static LfgListWindow LfgListWindow { get; private set; } = null!; - public static async Task Init() { FocusManager.Init(); await LoadWindows(); - if (App.Settings.UseHotkeys) KeyboardHook.Instance.Enable(); KeyboardHook.Instance.RegisterCallback(App.Settings.ToggleBoundariesHotkey, TccWidget.OnShowAllHandlesToggled); @@ -61,6 +62,7 @@ public static async Task Init() SystemEvents.DisplaySettingsChanged += SystemEventsOnDisplaySettingsChanged; ToolTipService.ShowDurationProperty.OverrideMetadata(typeof(DependencyObject), new FrameworkPropertyMetadata(int.MaxValue)); + } private static void SystemEventsOnDisplaySettingsChanged(object? sender, EventArgs e) @@ -80,7 +82,6 @@ public static void Dispose() TrayIcon.Dispose(); CloseOtherWindows(); }); - } private static void CloseOtherWindows() @@ -92,7 +93,6 @@ private static void CloseOtherWindows() private static async Task LoadWindows() { - // TODO: TccModules should define and create their own windows var b1 = new TccWidgetBuilder(App.Settings.CharacterWindowSettings); CharacterWindow = await b1.GetWindow(); @@ -147,7 +147,6 @@ private static async Task LoadWindows() ChatManager.Start(); } - public static void ReloadPositions() { RepositionRequestedEvent?.Invoke(); @@ -192,6 +191,5 @@ public static class ViewModels public static LfgListViewModel LfgVM => _lfgVm ??= new LfgListViewModel(App.Settings.LfgWindowSettings); public static FlightGaugeViewModel FlightGaugeVM => _flightGaugeVm ??= new FlightGaugeViewModel(App.Settings.FlightGaugeWindowSettings); } - } } \ No newline at end of file diff --git a/TCC.Interop/Proxy/StubInterface.cs b/TCC.Interop/Proxy/StubInterface.cs index 415708f6..1a27d271 100644 --- a/TCC.Interop/Proxy/StubInterface.cs +++ b/TCC.Interop/Proxy/StubInterface.cs @@ -25,7 +25,7 @@ private StubInterface() } - public async Task Init(bool useLfg, bool enablePlayerMenu, bool enableProxy, bool showIngameChat, bool tccChatEnabled) + public async Task InitAsync(bool useLfg, bool enablePlayerMenu, bool enableProxy, bool showIngameChat, bool tccChatEnabled) { StubServer.RequestReceived += _messageParser.HandleRequest; StubServer.ResponseReceived += _messageParser.HandleResponse;