From bff2a8a63dd2cf92868c193d03fc2b16a88896c0 Mon Sep 17 00:00:00 2001 From: Ivan Martell Date: Sat, 20 Jul 2024 19:09:20 +0900 Subject: [PATCH] Missed some .ini initializations and async saving to file --- LittleWarGameClient/Form1.Designer.cs | 1 + LittleWarGameClient/Form1.cs | 9 +++++++-- LittleWarGameClient/Fullscreen.cs | 2 +- LittleWarGameClient/Settings.cs | 29 ++++++++++++++++++--------- LittleWarGameClient/VersionHandler.cs | 2 +- 5 files changed, 29 insertions(+), 14 deletions(-) diff --git a/LittleWarGameClient/Form1.Designer.cs b/LittleWarGameClient/Form1.Designer.cs index 633fab0..90de348 100644 --- a/LittleWarGameClient/Form1.Designer.cs +++ b/LittleWarGameClient/Form1.Designer.cs @@ -61,6 +61,7 @@ private void InitializeComponent() Name = "Form1"; Text = "Littlewargame"; Activated += Form1_Activated; + FormClosing += Form1_FormClosing; ResizeEnd += Form1_ResizeEnd; Resize += Form1_Resize; ((System.ComponentModel.ISupportInitialize)webView).EndInit(); diff --git a/LittleWarGameClient/Form1.cs b/LittleWarGameClient/Form1.cs index 3910130..c42d457 100644 --- a/LittleWarGameClient/Form1.cs +++ b/LittleWarGameClient/Form1.cs @@ -74,7 +74,7 @@ private void webView_WebMessageReceived(object sender, Microsoft.Web.WebView2.Co else mouseLocked = false; settings.SetMouseLock(mouseLocked); - settings.Save(); + settings.SaveAsync(); CaptureCursor(); break; default: @@ -109,7 +109,7 @@ private void Form1_ResizeEnd(object sender, EventArgs e) { CaptureCursor(); settings.SetWindowSize(this.Size); - settings.Save(); + settings.SaveAsync(); } private void Form1_Resize(object sender, EventArgs e) @@ -134,5 +134,10 @@ private void ResizeGameWindows() } } } + + private void Form1_FormClosing(object sender, FormClosingEventArgs e) + { + settings.Save(); + } } } diff --git a/LittleWarGameClient/Fullscreen.cs b/LittleWarGameClient/Fullscreen.cs index 68b2cde..971d545 100644 --- a/LittleWarGameClient/Fullscreen.cs +++ b/LittleWarGameClient/Fullscreen.cs @@ -33,7 +33,7 @@ internal void Toggle() Enter(); } settings.SetFullScreen(state); - settings.Save(); + settings.SaveAsync(); } private void Enter() diff --git a/LittleWarGameClient/Settings.cs b/LittleWarGameClient/Settings.cs index 92ba46e..eb9ca08 100644 --- a/LittleWarGameClient/Settings.cs +++ b/LittleWarGameClient/Settings.cs @@ -43,6 +43,8 @@ private void Init() SetUpdateInterval(GetUpdateInterval()); SetOptionsMenuHotkey(GetOptionsMenuHotkey()); SetFriendsMenuHotkey(GetFriendsMenuHotkey()); + SetChatHistoryMenuHotkey(GetChatHistoryMenuHotkey()); + SetFullscreenHotkey(GetFullscreenHotkey()); Save(); } @@ -78,18 +80,25 @@ private void CreateDefaultIniFile() internal void Save() { - for (int numTries = 0; numTries < 5; numTries++) - { - try - { - settings.SaveTo(fileName); - break; - } - catch + settings.SaveTo(fileName); + } + + internal async void SaveAsync() + { + await Task.Run(() => { + for (int numTries = 0; numTries < 5; numTries++) { - Thread.Sleep(50); + try + { + settings.SaveTo(fileName); + break; + } + catch + { + Thread.Sleep(50); + } } - } + }); } internal void SetMouseLock(bool value) diff --git a/LittleWarGameClient/VersionHandler.cs b/LittleWarGameClient/VersionHandler.cs index c2f3daf..4a83409 100644 --- a/LittleWarGameClient/VersionHandler.cs +++ b/LittleWarGameClient/VersionHandler.cs @@ -54,7 +54,7 @@ internal virtual void CheckForUpdate(object? sender, EventArgs e) System.Windows.Forms.Application.Exit(); } settings.SetLastUpdateChecked(DateTime.Now.Date); - settings.Save(); + settings.SaveAsync(); } private bool RequiresUpdate()