From be13c08959cb4a2dc3196f00a2421f7cc6d23fe0 Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Fri, 19 Nov 2021 04:42:19 +1000 Subject: [PATCH] Warn when freezing >200 addresses at once (resolves #1155) --- src/BizHawk.Client.Common/tools/CheatList.cs | 12 +++++++++--- src/BizHawk.Client.EmuHawk/MainForm.cs | 2 +- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/src/BizHawk.Client.Common/tools/CheatList.cs b/src/BizHawk.Client.Common/tools/CheatList.cs index 7d2059a648..d38ae84211 100644 --- a/src/BizHawk.Client.Common/tools/CheatList.cs +++ b/src/BizHawk.Client.Common/tools/CheatList.cs @@ -24,13 +24,16 @@ namespace BizHawk.Client.Common private const string TypeColumn = "DisplayTypeColumn"; private const string ComparisonType = "ComparisonTypeColumn"; + private readonly IDialogParent _dialogParent; + private readonly ICheatConfig _config; private List _cheatList = new List(); private string _defaultFileName = ""; private bool _changes; - public CheatCollection(ICheatConfig config) + public CheatCollection(IDialogParent dialogParent, ICheatConfig config) { + _dialogParent = dialogParent; _config = config; } @@ -131,8 +134,11 @@ namespace BizHawk.Client.Common public void AddRange(IEnumerable cheats) { - _cheatList.AddRange( - cheats.Where(c => !_cheatList.Contains(c))); + var toAdd = cheats.Where(c => !_cheatList.Contains(c)).ToList(); + if (toAdd.Count is 0) return; + const int WARN_WHEN_ADDING_MORE_THAN = 200; + if (toAdd.Count > WARN_WHEN_ADDING_MORE_THAN && !_dialogParent.ModalMessageBox2($"Adding {toAdd.Count} freezes/cheats at once is probably a bad idea. Do it anyway?")) return; + _cheatList.AddRange(toAdd); Changes = true; } diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 976e800874..ad3f496223 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -479,7 +479,7 @@ namespace BizHawk.Client.EmuHawk Sound.StartSound(); InputManager.SyncControls(Emulator, MovieSession, Config); - CheatList = new CheatCollection(Config.Cheats); + CheatList = new CheatCollection(this, Config.Cheats); CheatList.Changed += Tools.UpdateCheatRelatedTools; RewireSound();