From 63d57ccd12b76baab7d6f091a6fa4ad3e33352cc Mon Sep 17 00:00:00 2001 From: NorbiPeti Date: Sat, 9 Apr 2022 01:36:55 +0200 Subject: [PATCH] Fix game exit handling popup, color Play button when a mod is broken/outdated --- TBMM/MainForm.cs | 18 ++++++++++++++++-- TBMM/MainModInstaller.cs | 2 ++ TBMM/MainModList.cs | 10 +++++++--- TBMM/MainPatcher.cs | 6 ++++-- TBMM/MainUtils.cs | 18 +++++++++++++----- TBMM/ModInfo.cs | 4 +++- 6 files changed, 45 insertions(+), 13 deletions(-) diff --git a/TBMM/MainForm.cs b/TBMM/MainForm.cs index 3ac21d8..cb4fe07 100644 --- a/TBMM/MainForm.cs +++ b/TBMM/MainForm.cs @@ -80,10 +80,24 @@ If you encounter an issue while any mods are installed, report it to us. If you private async void playbtn_Click(object sender, EventArgs e) { if (playbtn.ForeColor == Color.Green) return; //Disabled + if (mods.Any(mod => mod.Value.Installed && mod.Value.Broken is true)) + if (MessageBox.Show("Some installed mods are known to be broken on the current version of the game. The game might crash.", + "Warning", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) == DialogResult.Cancel) + return; await UpdateAPI(); await PatchStartGame(); //It will call EndWork(); } + private void UpdatePlayButtonColor() + { + if (mods.Any(mod => mod.Value.Installed && mod.Value.Broken is true)) + playbtn.ForeColor = Color.Red; + else if (mods.Any(mod => mod.Value.Installed && mod.Value.Outdated(lastGameUpdateTime))) + playbtn.ForeColor = Color.DarkOrange; + else + playbtn.ForeColor = Color.Lime; + } + private void settingsbtn_Click(object sender, EventArgs e) { if (settingsbtn.ForeColor == Color.Green) return; //Disabled @@ -124,9 +138,9 @@ If you encounter an issue while any mods are installed, report it to us. If you { if (mod.Updatable) addText("New version available! " + mod.UpdateDetails, Color.Aqua); - if (mod.Broken) + if (mod.Broken is true) addText("Outdated mod! It has been confirmed that the mod is broken on the current version of the game.", Color.Red); - else if (mod.LastUpdated != default && mod.LastUpdated < lastGameUpdateTime) + else if (mod.Outdated(lastGameUpdateTime)) addText("Outdated mod! It may not work properly on the current version of the game.", Color.DarkOrange); if (mod.Description != null) modinfobox.AppendText(mod.Description.Replace("\n", Environment.NewLine)); diff --git a/TBMM/MainModInstaller.cs b/TBMM/MainModInstaller.cs index 75489c2..32ac9b5 100644 --- a/TBMM/MainModInstaller.cs +++ b/TBMM/MainModInstaller.cs @@ -66,6 +66,7 @@ namespace TBMM } GetInstalledMods(); //Update list } + UpdatePlayButtonColor(); } public void ExtractMod(ZipArchive archive, string destinationDirectoryName, ModInfo mod) @@ -170,6 +171,7 @@ namespace TBMM { MessageBox.Show("Could not remove mod files! Make sure the game isn't running.\n" + e.Message); } + UpdatePlayButtonColor(); } public async Task UpdateAPI() diff --git a/TBMM/MainModList.cs b/TBMM/MainModList.cs index de8a88f..561192d 100644 --- a/TBMM/MainModList.cs +++ b/TBMM/MainModList.cs @@ -59,6 +59,7 @@ namespace TBMM public async Task GetAvailableMods() { bool preview = GetExe()?.Contains("Preview") ?? false; + //byte anyModOutdated = 0; using (var client = GetClient()) { string str = await client.DownloadStringTaskAsync("https://exmods.org/mods/modlist.tsv"); @@ -96,6 +97,7 @@ namespace TBMM == DialogResult.Yes) Process.Start(tbmm.DownloadURL); } + UpdatePlayButtonColor(); } public async Task FetchModInfo(ModInfo mod, bool preview, bool desc) @@ -186,6 +188,7 @@ namespace TBMM omod.Description = mod.Description ?? omod.Description; omod.DownloadURL = mod.DownloadURL ?? omod.DownloadURL; omod.UpdateDetails = mod.UpdateDetails ?? omod.UpdateDetails; + omod.Broken = mod.Broken ?? omod.Broken; items[1].Text = omod.Author ?? ""; items[2].Text = (omod.Version ?? omod.LatestVersion)?.ToString(); items[3].Text = omod.LatestVersion != null ? omod.LastUpdated.ToString() : ""; @@ -202,10 +205,10 @@ namespace TBMM } if (mod.LatestVersion != null && mod.Version != null && mod.Version < mod.LatestVersion) item.ForeColor = Color.Blue; - else if(mod.Broken) + else if(mod.Broken is true) item.ForeColor = Color.Red; - else if (mod.LastUpdated != default && mod.LastUpdated < lastGameUpdateTime) - item.ForeColor = Color.OrangeRed; + else if (mod.Outdated(lastGameUpdateTime)) + item.ForeColor = Color.DarkOrange; else item.ForeColor = modlist.ForeColor; } @@ -223,6 +226,7 @@ namespace TBMM delete.Add(name); } delete.ForEach(name => { mods.Remove(name); modlist.Items[name].Remove(); }); + UpdatePlayButtonColor(); } } } diff --git a/TBMM/MainPatcher.cs b/TBMM/MainPatcher.cs index 7ff9af3..54b6f64 100644 --- a/TBMM/MainPatcher.cs +++ b/TBMM/MainPatcher.cs @@ -13,7 +13,7 @@ namespace TBMM partial class MainForm { public GameState CheckIfPatched() => CheckIfPatched(out _); - + public GameState CheckIfPatched(out bool patched) { Dictionary statusTexts = new() @@ -23,8 +23,9 @@ namespace TBMM { GameState.NoPatcher, ("Patcher missing", "Clicking Play will install it", "") }, { GameState.OldPatcher, ("Patcher outdated", "nClicking play will update it", "") }, { GameState.Unpatched, ("Unpatched", "", "") }, - { GameState.Patched, ("Patched", "", "")} + { GameState.Patched, ("Patched", "", "") } }; + void SetStatusText(GameState state, bool patched) { var (statusText, extra, play) = statusTexts[state]; @@ -35,6 +36,7 @@ namespace TBMM status.Text += "\nUnpatch on exit disabled"; playbtn.Text = play; } + if (GetExe() == null) { patched = false; diff --git a/TBMM/MainUtils.cs b/TBMM/MainUtils.cs index 66cfc85..a932548 100644 --- a/TBMM/MainUtils.cs +++ b/TBMM/MainUtils.cs @@ -16,13 +16,23 @@ namespace TBMM { if (enabled) { - button.ForeColor = Color.Lime; + if (button.ForeColor == Color.Green) + button.ForeColor = Color.Lime; + else if(button.ForeColor == Color.DarkRed) + button.ForeColor = Color.Red; + else if (button.ForeColor == Color.FromArgb(127, 65, 0)) + button.ForeColor = Color.DarkOrange; button.FlatAppearance.MouseOverBackColor = Color.FromArgb(0, 40, 0); button.FlatAppearance.MouseDownBackColor = Color.Green; } else { - button.ForeColor = Color.Green; + if (button.ForeColor == Color.Lime) + button.ForeColor = Color.Green; + else if (button.ForeColor == Color.Red) + button.ForeColor = Color.DarkRed; + else if (button.ForeColor == Color.DarkOrange) + button.ForeColor = Color.FromArgb(127, 65, 0); button.FlatAppearance.MouseOverBackColor = Color.Black; button.FlatAppearance.MouseDownBackColor = Color.Black; } @@ -136,9 +146,7 @@ namespace TBMM Debug.WriteLine("Game has not exited"); return true; case { HasExited: true }: - Debug.WriteLine("Game has exited, dialog shown"); - MessageBox.Show("Game has exited without handling... Please report."); - HandleGameExit(null, EventArgs.Empty); + Debug.WriteLine("Game has seemingly exited without handling, probably as part of the exit handler"); return false; default: Debug.WriteLine($"Process seems to be null: {_gameProcess}"); diff --git a/TBMM/ModInfo.cs b/TBMM/ModInfo.cs index 273b03c..555e851 100644 --- a/TBMM/ModInfo.cs +++ b/TBMM/ModInfo.cs @@ -31,6 +31,8 @@ namespace TBMM public HashSet ModFiles { get; set; } public string UpdateDetails { get; set; } public bool Updatable => Version != null && LatestVersion != null && Version < LatestVersion; - public bool Broken { get; set; } + public bool? Broken { get; set; } + + public bool Outdated(DateTime lastGameUpdateTime) => LastUpdated != default && LastUpdated < lastGameUpdateTime; } }