Skip to content

Commit

Permalink
Missed some .ini initializations and async saving to file
Browse files Browse the repository at this point in the history
  • Loading branch information
ivanpmartell committed Jul 20, 2024
1 parent 41bf155 commit bff2a8a
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 14 deletions.
1 change: 1 addition & 0 deletions LittleWarGameClient/Form1.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 7 additions & 2 deletions LittleWarGameClient/Form1.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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)
Expand All @@ -134,5 +134,10 @@ private void ResizeGameWindows()
}
}
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
settings.Save();
}
}
}
2 changes: 1 addition & 1 deletion LittleWarGameClient/Fullscreen.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ internal void Toggle()
Enter();
}
settings.SetFullScreen(state);
settings.Save();
settings.SaveAsync();
}

private void Enter()
Expand Down
29 changes: 19 additions & 10 deletions LittleWarGameClient/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ private void Init()
SetUpdateInterval(GetUpdateInterval());
SetOptionsMenuHotkey(GetOptionsMenuHotkey());
SetFriendsMenuHotkey(GetFriendsMenuHotkey());
SetChatHistoryMenuHotkey(GetChatHistoryMenuHotkey());
SetFullscreenHotkey(GetFullscreenHotkey());
Save();
}

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion LittleWarGameClient/VersionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit bff2a8a

Please sign in to comment.