Add Analyzer to disallow `^= true`

This commit is contained in:
YoshiRulz 2024-07-08 07:09:49 +10:00
parent c99d2212b2
commit 2a5d4b903c
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
38 changed files with 257 additions and 242 deletions

View File

@ -22,6 +22,8 @@ dotnet_diagnostic.BHI1101.severity = error
dotnet_diagnostic.BHI1102.severity = error
# Don't call typeof(T).ToString(), use nameof operator or typeof(T).FullName
dotnet_diagnostic.BHI1103.severity = error
# Don't use ^= (XOR-assign) for inverting the value of booleans
dotnet_diagnostic.BHI1104.severity = error
# Brackets of collection expression should be separated with spaces
dotnet_diagnostic.BHI1110.severity = warning
# Expression-bodied member should be flowed to next line correctly

View File

@ -0,0 +1,79 @@
namespace BizHawk.Analyzers;
using System.Collections.Immutable;
using Microsoft.CodeAnalysis;
using Microsoft.CodeAnalysis.Diagnostics;
using Microsoft.CodeAnalysis.Operations;
/// <remarks>shoutouts to SimpleFlips</remarks>
[DiagnosticAnalyzer(LanguageNames.CSharp)]
public sealed class UseSimplerBoolFlipAnalyzer : DiagnosticAnalyzer
{
private const string ERR_MSG_SIMPLE = "Use e.g. `b = !b;` instead of `b ^= true;`";
private const string ERR_MSG_COMPLEX = $"{ERR_MSG_SIMPLE} (you may want to store part of the expression in a local variable to avoid repeated side-effects or computation)";
private static readonly DiagnosticDescriptor DiagUseSimplerBoolFlip = new(
id: "BHI1104",
title: "Don't use ^= (XOR-assign) for inverting the value of booleans",
messageFormat: "{0}",
category: "Usage",
defaultSeverity: DiagnosticSeverity.Error,
isEnabledByDefault: true);
public override ImmutableArray<DiagnosticDescriptor> SupportedDiagnostics { get; } = ImmutableArray.Create(DiagUseSimplerBoolFlip);
public override void Initialize(AnalysisContext context)
{
context.ConfigureGeneratedCodeAnalysis(GeneratedCodeAnalysisFlags.None);
context.EnableConcurrentExecution();
ISymbol? boolSym = null;
context.RegisterOperationAction(
oac =>
{
static bool IsZeroWorkLocalOrFieldRef(IOperation trunk)
{
while (trunk.Kind is OperationKind.FieldReference)
{
if (trunk.ChildOperations.Count is 0) return true; // in the unit test, the node(s) for the implicit `this.` are missing for some reason
trunk = trunk.ChildOperations.First();
}
return trunk.Kind is OperationKind.InstanceReference or OperationKind.LocalReference;
}
var operation = (ICompoundAssignmentOperation) oac.Operation;
if (operation.OperatorKind is not BinaryOperatorKind.ExclusiveOr) return;
boolSym ??= oac.Compilation.GetTypeByMetadataName("System.Boolean")!;
if (!boolSym.Matches(operation.Type)) return;
if (operation.Value.Kind is not OperationKind.Literal) return;
var lhsOp = operation.Target;
bool lhsIsSimpleExpr;
switch (lhsOp.Kind)
{
case OperationKind.PropertyReference:
lhsIsSimpleExpr = false;
break;
case OperationKind.FieldReference:
lhsIsSimpleExpr = IsZeroWorkLocalOrFieldRef(lhsOp);
break;
case OperationKind.LocalReference:
lhsIsSimpleExpr = true;
break;
case OperationKind.ArrayElementReference:
lhsIsSimpleExpr = false;
break;
default:
oac.ReportDiagnostic(Diagnostic.Create(DiagUseSimplerBoolFlip, operation.Syntax.GetLocation(), $"Left-hand side of XOR-assign was of an unexpected kind: {lhsOp.GetType().FullName}"));
return;
}
oac.ReportDiagnostic(Diagnostic.Create(
DiagUseSimplerBoolFlip,
operation.Syntax.GetLocation(),
lhsIsSimpleExpr ? DiagnosticSeverity.Error : DiagnosticSeverity.Warning,
additionalLocations: null,
properties: null,
lhsIsSimpleExpr ? ERR_MSG_SIMPLE : ERR_MSG_COMPLEX));
},
OperationKind.CompoundAssignment);
}
}

View File

@ -0,0 +1,40 @@
namespace BizHawk.Tests.Analyzers;
using System.Threading.Tasks;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Verify = Microsoft.CodeAnalysis.CSharp.Testing.CSharpAnalyzerVerifier<
BizHawk.Analyzers.UseSimplerBoolFlipAnalyzer,
Microsoft.CodeAnalysis.Testing.DefaultVerifier>;
[TestClass]
public sealed class UseSimplerBoolFlipAnalyzerTests
{
[TestMethod]
public Task CheckMisuseOfXORAssignment()
=> Verify.VerifyAnalyzerAsync("""
public static class Cases {
private static int _z = default;
private static bool _a = default;
private static void CasesMethod() {
_z ^= 0xA5A5;
_a ^= DummyMethod();
{|BHI1104:_a ^= true|};
var b = false;
{|BHI1104:b ^= true|};
bool c = default;
{|BHI1104:c ^= false|}; // this is effectively a no-op so there's no reason it would be used in the first place, but it was easier to flag both
{|BHI1104:AnotherClass.GetInstance().Prop ^= true|}; // care needs to be taken with non-trivial expressions like this; a different message will be given
}
private static bool DummyMethod()
=> default;
}
public sealed class AnotherClass {
public static AnotherClass GetInstance()
=> new();
public bool Prop { get; set; }
private AnotherClass() {}
}
""");
}

Binary file not shown.

View File

@ -147,10 +147,7 @@ namespace BizHawk.Client.Common
_axes[button] = controller.AxisValue(button);
}
foreach (var button in controller.InversedButtons)
{
_buttons[button] ^= true;
}
foreach (var button in controller.InversedButtons) _buttons[button] = !_buttons[button];
}
public void BindMulti(string button, string controlString)

View File

@ -74,8 +74,6 @@ namespace BizHawk.Client.Common
}
public void ToggleAutoLoad()
{
AutoLoad ^= true;
}
=> AutoLoad = !AutoLoad;
}
}

View File

@ -67,7 +67,7 @@ namespace BizHawk.Client.Common
public void ToggleRedo(IMovie movie, int slot)
{
if (slot is >= 1 and <= 10 && movie is not ITasMovie) _redo[slot - 1] ^= true;
if (slot is >= 1 and <= 10 && movie is not ITasMovie) _redo[slot - 1] = !_redo[slot - 1];
}
public bool IsRedo(IMovie movie, int slot)

View File

@ -149,7 +149,7 @@ namespace BizHawk.Client.Common
{
if (!IsSeparator)
{
_enabled ^= true;
_enabled = !_enabled;
if (handleChange)
{
Changes();

View File

@ -988,7 +988,7 @@ namespace BizHawk.Client.EmuHawk
ShortcutKeyDisplayString = RotateHotkeyStr
};
rotate.Click += (o, ev) => { HorizontalOrientation ^= true; };
rotate.Click += (_, _) => HorizontalOrientation = !HorizontalOrientation;
yield return rotate;
}
@ -1372,10 +1372,7 @@ namespace BizHawk.Client.EmuHawk
}
else if (e.IsCtrlShift(Keys.F))
{
if (Rotatable)
{
HorizontalOrientation ^= true;
}
if (Rotatable) HorizontalOrientation = !HorizontalOrientation;
}
// Scroll
else if (e.IsPressed(Keys.PageUp))

View File

@ -189,7 +189,7 @@ namespace BizHawk.Client.EmuHawk.ToolExtensions
Text = recent.Frozen ? "&Unfreeze" : "&Freeze",
Image = recent.Frozen ? Properties.Resources.Unfreeze : Properties.Resources.Freeze
};
freezeItem.Click += (o, ev) => recent.Frozen ^= true;
freezeItem.Click += (_, _) => recent.Frozen = !recent.Frozen;
items.Add(freezeItem);
if (!noAutoload)

View File

@ -359,13 +359,10 @@ namespace BizHawk.Client.EmuHawk
private void LoadNamedStateMenuItem_Click(object sender, EventArgs e) => LoadStateAs();
private void AutoloadLastSlotMenuItem_Click(object sender, EventArgs e)
{
Config.AutoLoadLastSaveSlot ^= true;
}
=> Config.AutoLoadLastSaveSlot = !Config.AutoLoadLastSaveSlot;
private void AutosaveLastSlotMenuItem_Click(object sender, EventArgs e)
{
Config.AutoSaveLastSaveSlot ^= true;
}
=> Config.AutoSaveLastSaveSlot = !Config.AutoSaveLastSaveSlot;
private void SelectSlotMenuItems_Click(object sender, EventArgs e)
{
@ -510,14 +507,10 @@ namespace BizHawk.Client.EmuHawk
}
private void AutomaticMovieBackupMenuItem_Click(object sender, EventArgs e)
{
Config.Movies.EnableBackupMovies ^= true;
}
=> Config.Movies.EnableBackupMovies = !Config.Movies.EnableBackupMovies;
private void FullMovieLoadstatesMenuItem_Click(object sender, EventArgs e)
{
Config.Movies.VBAStyleMovieLoadState ^= true;
}
=> Config.Movies.VBAStyleMovieLoadState = !Config.Movies.VBAStyleMovieLoadState;
private void MovieEndFinishMenuItem_Click(object sender, EventArgs e)
{
@ -601,9 +594,7 @@ namespace BizHawk.Client.EmuHawk
}
private void ScreenshotCaptureOSDMenuItem_Click(object sender, EventArgs e)
{
Config.ScreenshotCaptureOsd ^= true;
}
=> Config.ScreenshotCaptureOsd = !Config.ScreenshotCaptureOsd;
private void ExitMenuItem_Click(object sender, EventArgs e)
{
@ -728,25 +719,19 @@ namespace BizHawk.Client.EmuHawk
}
private void DisplayRerecordsMenuItem_Click(object sender, EventArgs e)
{
Config.DisplayRerecordCount ^= true;
}
=> Config.DisplayRerecordCount = !Config.DisplayRerecordCount;
private void DisplaySubtitlesMenuItem_Click(object sender, EventArgs e)
{
Config.DisplaySubtitles ^= true;
}
=> Config.DisplaySubtitles = !Config.DisplaySubtitles;
private void DisplayStatusBarMenuItem_Click(object sender, EventArgs e)
{
Config.DispChromeStatusBarWindowed ^= true;
Config.DispChromeStatusBarWindowed = !Config.DispChromeStatusBarWindowed;
SetStatusBar();
}
private void DisplayMessagesMenuItem_Click(object sender, EventArgs e)
{
Config.DisplayMessages ^= true;
}
=> Config.DisplayMessages = !Config.DisplayMessages;
private void DisplayLogWindowMenuItem_Click(object sender, EventArgs e)
{
@ -959,7 +944,7 @@ namespace BizHawk.Client.EmuHawk
private void ClockThrottleMenuItem_Click(object sender, EventArgs e)
{
Config.ClockThrottle ^= true;
Config.ClockThrottle = !Config.ClockThrottle;
if (Config.ClockThrottle)
{
var old = Config.SoundThrottle;
@ -982,7 +967,7 @@ namespace BizHawk.Client.EmuHawk
private void AudioThrottleMenuItem_Click(object sender, EventArgs e)
{
Config.SoundThrottle ^= true;
Config.SoundThrottle = !Config.SoundThrottle;
RewireSound();
if (Config.SoundThrottle)
{
@ -1000,7 +985,7 @@ namespace BizHawk.Client.EmuHawk
private void VsyncThrottleMenuItem_Click(object sender, EventArgs e)
{
Config.VSyncThrottle ^= true;
Config.VSyncThrottle = !Config.VSyncThrottle;
_presentationPanel.Resized = true;
if (Config.VSyncThrottle)
{
@ -1024,7 +1009,7 @@ namespace BizHawk.Client.EmuHawk
private void VsyncEnabledMenuItem_Click(object sender, EventArgs e)
{
Config.VSync ^= true;
Config.VSync = !Config.VSync;
if (!Config.VSyncThrottle) // when vsync throttle is on, vsync is forced to on, so no change to make here
{
_presentationPanel.Resized = true;
@ -1038,14 +1023,12 @@ namespace BizHawk.Client.EmuHawk
private void ToggleUnthrottled()
{
Config.Unthrottled ^= true;
Config.Unthrottled = !Config.Unthrottled;
ThrottleMessage();
}
private void MinimizeSkippingMenuItem_Click(object sender, EventArgs e)
{
Config.AutoMinimizeSkipping ^= true;
}
=> Config.AutoMinimizeSkipping = !Config.AutoMinimizeSkipping;
private void NeverSkipMenuItem_Click(object sender, EventArgs e) { Config.FrameSkip = 0; FrameSkipMessage(); }
private void Frameskip1MenuItem_Click(object sender, EventArgs e) { Config.FrameSkip = 1; FrameSkipMessage(); }
@ -1781,9 +1764,7 @@ namespace BizHawk.Client.EmuHawk
}
private void N64CircularAnalogRangeMenuItem_Click(object sender, EventArgs e)
{
Config.N64UseCircularAnalogConstraint ^= true;
}
=> Config.N64UseCircularAnalogConstraint = !Config.N64UseCircularAnalogConstraint;
private static void Mupen64PlusSetMupenStyleLag(bool newValue, ISettingsAdapter settable)
{
@ -2450,7 +2431,7 @@ namespace BizHawk.Client.EmuHawk
private void ShowMenuContextMenuItem_Click(object sender, EventArgs e)
{
MainMenuStrip.Visible ^= true;
MainMenuStrip.Visible = !MainMenuStrip.Visible;
FrameBufferResized();
}
@ -2558,8 +2539,9 @@ namespace BizHawk.Client.EmuHawk
// toggle Link status (only outside of a movie session)
if (!MovieSession.Movie.IsPlaying())
{
Emulator.AsLinkable().LinkConnected ^= true;
Console.WriteLine("Cable connect status to {0}", Emulator.AsLinkable().LinkConnected);
var core = Emulator.AsLinkable();
core.LinkConnected = !core.LinkConnected;
Console.WriteLine($"Cable connect status to {core.LinkConnected}");
}
}

View File

@ -151,7 +151,7 @@ namespace BizHawk.Client.EmuHawk
RebootCore();
break;
case "Toggle Skip Lag Frame":
Config.SkipLagFrame ^= true;
Config.SkipLagFrame = !Config.SkipLagFrame;
AddOnScreenMessage($"Skip Lag Frames toggled {(Config.SkipLagFrame ? "On" : "Off")}");
break;
case "Toggle Key Priority":
@ -382,15 +382,18 @@ namespace BizHawk.Client.EmuHawk
break;
case "Toggle Follow Cursor":
if (!Tools.IsLoaded<TAStudio>()) return false;
Tools.TAStudio.TasPlaybackBox.FollowCursor ^= true;
var playbackBox = Tools.TAStudio.TasPlaybackBox;
playbackBox.FollowCursor = !playbackBox.FollowCursor;
break;
case "Toggle Auto-Restore":
if (!Tools.IsLoaded<TAStudio>()) return false;
Tools.TAStudio.TasPlaybackBox.AutoRestore ^= true;
var playbackBox1 = Tools.TAStudio.TasPlaybackBox;
playbackBox1.AutoRestore = !playbackBox1.AutoRestore;
break;
case "Toggle Turbo Seek":
if (!Tools.IsLoaded<TAStudio>()) return false;
Tools.TAStudio.TasPlaybackBox.TurboSeek ^= true;
var playbackBox2 = Tools.TAStudio.TasPlaybackBox;
playbackBox2.TurboSeek = !playbackBox2.TurboSeek;
break;
case "Undo":
if (!Tools.IsLoaded<TAStudio>()) return false;

View File

@ -129,7 +129,7 @@ namespace BizHawk.Client.EmuHawk
{
if (MovieSession.Movie.IsActive())
{
MovieSession.ReadOnly ^= true;
MovieSession.ReadOnly = !MovieSession.ReadOnly;
AddOnScreenMessage(MovieSession.ReadOnly ? "Movie read-only mode" : "Movie read+write mode");
}
else

View File

@ -120,7 +120,7 @@ namespace BizHawk.Client.EmuHawk
var GBInSGBMenuItem = new ToolStripMenuItem { Text = "GB in SGB" };
GBInSGBMenuItem.Click += (_, _) =>
{
Config.GbAsSgb ^= true;
Config.GbAsSgb = !Config.GbAsSgb;
if (Emulator.SystemId is VSystemID.Raw.GB or VSystemID.Raw.GBC or VSystemID.Raw.SGB) FlagNeedsReboot();
};
CoresSubMenu.DropDownItems.Add(GBInSGBMenuItem);
@ -1298,7 +1298,7 @@ namespace BizHawk.Client.EmuHawk
public void TogglePause()
{
EmulatorPaused ^= true;
EmulatorPaused = !EmulatorPaused;
SetPauseStatusBarIcon();
// TODO: have tastudio set a pause status change callback, or take control over pause
@ -1626,16 +1626,16 @@ namespace BizHawk.Client.EmuHawk
switch (layer)
{
case 1:
result = s.ShowBG1_0 = s.ShowBG1_1 ^= true;
result = s.ShowBG1_0 = s.ShowBG1_1 = !s.ShowBG1_1;
break;
case 2:
result = s.ShowBG2_0 = s.ShowBG2_1 ^= true;
result = s.ShowBG2_0 = s.ShowBG2_1 = !s.ShowBG2_1;
break;
case 3:
result = s.ShowBG3_0 = s.ShowBG3_1 ^= true;
result = s.ShowBG3_0 = s.ShowBG3_1 = !s.ShowBG3_1;
break;
case 4:
result = s.ShowBG4_0 = s.ShowBG4_1 ^= true;
result = s.ShowBG4_0 = s.ShowBG4_1 = !s.ShowBG4_1;
break;
}
@ -1648,16 +1648,16 @@ namespace BizHawk.Client.EmuHawk
switch (layer)
{
case 1:
result = s.ShowBG1_0 = s.ShowBG1_1 ^= true;
result = s.ShowBG1_0 = s.ShowBG1_1 = !s.ShowBG1_1;
break;
case 2:
result = s.ShowBG2_0 = s.ShowBG2_1 ^= true;
result = s.ShowBG2_0 = s.ShowBG2_1 = !s.ShowBG2_1;
break;
case 3:
result = s.ShowBG3_0 = s.ShowBG3_1 ^= true;
result = s.ShowBG3_0 = s.ShowBG3_1 = !s.ShowBG3_1;
break;
case 4:
result = s.ShowBG4_0 = s.ShowBG4_1 ^= true;
result = s.ShowBG4_0 = s.ShowBG4_1 = !s.ShowBG4_1;
break;
}
@ -1670,16 +1670,16 @@ namespace BizHawk.Client.EmuHawk
switch (layer)
{
case 1:
result = s.ShowBg0 ^= true;
result = s.ShowBg0 = !s.ShowBg0;
break;
case 2:
result = s.ShowBg1 ^= true;
result = s.ShowBg1 = !s.ShowBg1;
break;
case 3:
result = s.ShowBg2 ^= true;
result = s.ShowBg2 = !s.ShowBg2;
break;
case 4:
result = s.ShowBg3 ^= true;
result = s.ShowBg3 = !s.ShowBg3;
break;
}
@ -1704,10 +1704,10 @@ namespace BizHawk.Client.EmuHawk
var s = bsnes.GetSettings();
result = layer switch
{
1 => (s.ShowOBJ_0 ^= true),
2 => (s.ShowOBJ_1 ^= true),
3 => (s.ShowOBJ_2 ^= true),
4 => (s.ShowOBJ_3 ^= true),
1 => s.ShowOBJ_0 = !s.ShowOBJ_0,
2 => s.ShowOBJ_1 = !s.ShowOBJ_1,
3 => s.ShowOBJ_2 = !s.ShowOBJ_2,
4 => s.ShowOBJ_3 = !s.ShowOBJ_3,
_ => result
};
@ -1719,10 +1719,10 @@ namespace BizHawk.Client.EmuHawk
var s = snes9X.GetSettings();
result = layer switch
{
1 => (s.ShowSprites0 ^= true),
2 => (s.ShowSprites1 ^= true),
3 => (s.ShowSprites2 ^= true),
4 => (s.ShowSprites3 ^= true),
1 => s.ShowSprites0 = !s.ShowSprites0,
2 => s.ShowSprites1 = !s.ShowSprites1,
3 => s.ShowSprites2 = !s.ShowSprites2,
4 => s.ShowSprites3 = !s.ShowSprites3,
_ => result
};
@ -2646,28 +2646,20 @@ namespace BizHawk.Client.EmuHawk
}
private void ToggleFps()
{
Config.DisplayFps ^= true;
}
=> Config.DisplayFps = !Config.DisplayFps;
private void ToggleFrameCounter()
{
Config.DisplayFrameCounter ^= true;
}
=> Config.DisplayFrameCounter = !Config.DisplayFrameCounter;
private void ToggleLagCounter()
{
Config.DisplayLagCounter ^= true;
}
=> Config.DisplayLagCounter = !Config.DisplayLagCounter;
private void ToggleInputDisplay()
{
Config.DisplayInput ^= true;
}
=> Config.DisplayInput = !Config.DisplayInput;
public void ToggleSound()
{
Config.SoundEnabled ^= true;
Config.SoundEnabled = !Config.SoundEnabled;
Sound.StopSound();
Sound.StartSound();
}
@ -2945,7 +2937,7 @@ namespace BizHawk.Client.EmuHawk
private void ToggleBackgroundInput()
{
Config.AcceptBackgroundInput ^= true;
Config.AcceptBackgroundInput = !Config.AcceptBackgroundInput;
AddOnScreenMessage($"Background Input {(Config.AcceptBackgroundInput ? "enabled" : "disabled")}");
}

View File

@ -73,8 +73,6 @@ namespace BizHawk.Client.EmuHawk
}
private void label4_Click(object sender, EventArgs e)
{
AlwaysCheckbox.Checked ^= true;
}
=> AlwaysCheckbox.Checked = !AlwaysCheckbox.Checked;
}
}

View File

@ -67,7 +67,11 @@ namespace BizHawk.Client.EmuHawk
Checked = _getConfig().RAAutostart,
CheckOnClick = true,
};
tsi.CheckedChanged += (_, _) => _getConfig().RAAutostart ^= true;
tsi.CheckedChanged += (_, _) =>
{
var config = _getConfig();
config.RAAutostart = !config.RAAutostart;
};
_raDropDownItems.Add(tsi);
var tss = new ToolStripSeparator();

View File

@ -147,14 +147,14 @@ namespace BizHawk.Client.EmuHawk
{
if (_gameData.GameID == 0)
{
AllowUnofficialCheevos ^= true;
AllowUnofficialCheevos = !AllowUnofficialCheevos;
return;
}
_activeModeUnlocksRequest.Wait();
DeactivateCheevos(HardcoreMode);
AllowUnofficialCheevos ^= true;
AllowUnofficialCheevos = !AllowUnofficialCheevos;
ActivateCheevos(HardcoreMode);
}

View File

@ -72,7 +72,11 @@ namespace BizHawk.Client.EmuHawk
Checked = _getConfig().RAAutostart,
CheckOnClick = true,
};
autoStartRAItem.CheckedChanged += (_, _) => _getConfig().RAAutostart ^= true;
autoStartRAItem.CheckedChanged += (_, _) =>
{
var config = _getConfig();
config.RAAutostart = !config.RAAutostart;
};
raDropDownItems.Add(autoStartRAItem);
var loginItem = new ToolStripMenuItem("Login")
@ -110,7 +114,7 @@ namespace BizHawk.Client.EmuHawk
Checked = CheevosActive,
CheckOnClick = true
};
enableCheevosItem.CheckedChanged += (_, _) => CheevosActive ^= true;
enableCheevosItem.CheckedChanged += (_, _) => CheevosActive = !CheevosActive;
raDropDownItems.Add(enableCheevosItem);
var enableLboardsItem = new ToolStripMenuItem("Enable Leaderboards")
@ -119,7 +123,7 @@ namespace BizHawk.Client.EmuHawk
CheckOnClick = true,
Enabled = HardcoreMode
};
enableLboardsItem.CheckedChanged += (_, _) => LBoardsActive ^= true;
enableLboardsItem.CheckedChanged += (_, _) => LBoardsActive = !LBoardsActive;
raDropDownItems.Add(enableLboardsItem);
var enableRichPresenceItem = new ToolStripMenuItem("Enable Rich Presence")
@ -127,7 +131,7 @@ namespace BizHawk.Client.EmuHawk
Checked = RichPresenceActive,
CheckOnClick = true
};
enableRichPresenceItem.CheckedChanged += (_, _) => RichPresenceActive ^= true;
enableRichPresenceItem.CheckedChanged += (_, _) => RichPresenceActive = !RichPresenceActive;
raDropDownItems.Add(enableRichPresenceItem);
var enableHardcoreItem = new ToolStripMenuItem("Enable Hardcore Mode")
@ -137,8 +141,7 @@ namespace BizHawk.Client.EmuHawk
};
enableHardcoreItem.CheckedChanged += (_, _) =>
{
_hardcoreMode ^= true;
_hardcoreMode = !_hardcoreMode;
if (HardcoreMode)
{
_hardcoreMode = _mainForm.RebootCore(); // unset hardcore mode if we fail to reboot core somehow
@ -159,7 +162,7 @@ namespace BizHawk.Client.EmuHawk
Checked = EnableSoundEffects,
CheckOnClick = true
};
enableSoundEffectsItem.CheckedChanged += (_, _) => EnableSoundEffects ^= true;
enableSoundEffectsItem.CheckedChanged += (_, _) => EnableSoundEffects = !EnableSoundEffects;
raDropDownItems.Add(enableSoundEffectsItem);
var enableUnofficialCheevosItem = new ToolStripMenuItem("Test Unofficial Achievements")

View File

@ -121,7 +121,7 @@ namespace BizHawk.Client.EmuHawk
}
else if (e.Button == MouseButtons.Right)
{
Radial ^= true;
Radial = !Radial;
}
base.OnMouseDown(e);

View File

@ -366,9 +366,7 @@ namespace BizHawk.Client.EmuHawk
}
private void Label13_Click(object sender, EventArgs e)
{
cbAllowTearing.Checked ^= true;
}
=> cbAllowTearing.Checked = !cbAllowTearing.Checked;
private void BtnDefaults_Click(object sender, EventArgs e)
{

View File

@ -387,9 +387,7 @@ namespace BizHawk.Client.EmuHawk
=> MemoryDomainsMenuItem.ReplaceDropDownItems(MemoryDomains.MenuItems(SetMemoryDomain, _currentDomain.Name).ToArray());
private void BigEndianMenuItem_Click(object sender, EventArgs e)
{
_bigEndian ^= true;
}
=> _bigEndian = !_bigEndian;
private void DataSizeMenuItem_DropDownOpened(object sender, EventArgs e)
{
@ -414,9 +412,7 @@ namespace BizHawk.Client.EmuHawk
}
private void TurboWhileBottingMenuItem_Click(object sender, EventArgs e)
{
Settings.TurboWhenBotting ^= true;
}
=> Settings.TurboWhenBotting = !Settings.TurboWhenBotting;
private void RunBtn_Click(object sender, EventArgs e)
{
@ -1300,9 +1296,7 @@ namespace BizHawk.Client.EmuHawk
}
private void InvisibleEmulationCheckBox_CheckedChanged(object sender, EventArgs e)
{
Settings.InvisibleEmulation ^= true;
}
=> Settings.InvisibleEmulation = !Settings.InvisibleEmulation;
private void MaximizeAddressBox_TextChanged(object sender, EventArgs e)
{

View File

@ -575,18 +575,12 @@ namespace BizHawk.Client.EmuHawk
}
private void MiAutoSave_Click(object sender, EventArgs e)
{
CDLAutoSave ^= true;
}
=> CDLAutoSave = !CDLAutoSave;
private void MiAutoStart_Click(object sender, EventArgs e)
{
CDLAutoStart ^= true;
}
=> CDLAutoStart = !CDLAutoStart;
private void MiAutoResume_Click(object sender, EventArgs e)
{
CDLAutoResume ^= true;
}
=> CDLAutoResume = !CDLAutoResume;
}
}

View File

@ -505,19 +505,13 @@ namespace BizHawk.Client.EmuHawk
}
private void AlwaysLoadCheatsMenuItem_Click(object sender, EventArgs e)
{
Config.Cheats.LoadFileByGame ^= true;
}
=> Config.Cheats.LoadFileByGame = !Config.Cheats.LoadFileByGame;
private void AutoSaveCheatsMenuItem_Click(object sender, EventArgs e)
{
Config.Cheats.AutoSaveOnClose ^= true;
}
=> Config.Cheats.AutoSaveOnClose = !Config.Cheats.AutoSaveOnClose;
private void CheatsOnOffLoadMenuItem_Click(object sender, EventArgs e)
{
Config.Cheats.DisableOnLoad ^= true;
}
=> Config.Cheats.DisableOnLoad = !Config.Cheats.DisableOnLoad;
[RestoreDefaults]
private void RestoreDefaults()
@ -574,7 +568,7 @@ namespace BizHawk.Client.EmuHawk
MainForm.CheatList.Sort(column.Name, _sortReverse);
_sortedColumn = column.Name;
_sortReverse ^= true;
_sortReverse = !_sortReverse;
GeneralUpdate();
}

View File

@ -218,11 +218,7 @@ namespace BizHawk.Client.EmuHawk
var items = EditableItems.ToList();
if (items.Any())
{
foreach (var item in items)
{
item.Active ^= true;
}
foreach (var item in items) item.Active = !item.Active;
BreakpointView.VirtualListSize = _breakpoints.Count;
UpdateBreakpointRemoveButton();
UpdateStatsLabel();
@ -245,11 +241,7 @@ namespace BizHawk.Client.EmuHawk
private void ToggleButton_Click(object sender, EventArgs e)
{
foreach (var item in SelectedItems)
{
item.Active ^= true;
}
foreach (var item in SelectedItems) item.Active = !item.Active;
BreakpointView.VirtualListSize = _breakpoints.Count;
UpdateStatsLabel();
}

View File

@ -1574,7 +1574,7 @@ namespace BizHawk.Client.EmuHawk
private void BigEndianMenuItem_Click(object sender, EventArgs e)
{
BigEndian ^= true;
BigEndian = !BigEndian;
GeneralUpdate();
}

View File

@ -1094,19 +1094,14 @@ namespace BizHawk.Client.EmuHawk
}
private void DisableScriptsOnLoadMenuItem_Click(object sender, EventArgs e)
{
Settings.DisableLuaScriptsOnLoad ^= true;
}
=> Settings.DisableLuaScriptsOnLoad = !Settings.DisableLuaScriptsOnLoad;
private void ToggleAllIfNoneSelectedMenuItem_Click(object sender, EventArgs e)
{
Settings.ToggleAllIfNoneSelected ^= true;
}
=> Settings.ToggleAllIfNoneSelected = !Settings.ToggleAllIfNoneSelected;
private void ReloadWhenScriptFileChangesMenuItem_Click(object sender, EventArgs e)
{
Settings.ReloadOnScriptFileChange ^= true;
Settings.ReloadOnScriptFileChange = !Settings.ReloadOnScriptFileChange;
if (Settings.ReloadOnScriptFileChange)
{
AddFileWatches();

View File

@ -99,11 +99,7 @@ namespace BizHawk.Client.EmuHawk
get => _column;
set
{
if (_column == value)
{
Descending ^= true;
}
if (_column == value) Descending = !Descending;
_column = value;
}
}

View File

@ -804,9 +804,7 @@ namespace BizHawk.Client.EmuHawk
private readonly byte[] _chrRomCache = new byte[8192];
private void ChrROMTileViewerToolStripMenuItem_Click(object sender, EventArgs e)
{
ChrRomView ^= true;
}
=> ChrRomView = !ChrRomView;
private void CalculateFormSize()
{

View File

@ -1376,14 +1376,10 @@ namespace BizHawk.Client.EmuHawk
}
private void lblEnPrio2_Click(object sender, EventArgs e)
{
checkEN2_OBJ.Checked ^= true;
}
=> checkEN2_OBJ.Checked = !checkEN2_OBJ.Checked;
private void lblEnPrio3_Click(object sender, EventArgs e)
{
checkEN3_OBJ.Checked ^= true;
}
=> checkEN3_OBJ.Checked = !checkEN3_OBJ.Checked;
} //class SNESGraphicsDebugger
} //namespace BizHawk.Client.EmuHawk

View File

@ -95,26 +95,19 @@ namespace BizHawk.Client.EmuHawk
private void TurboSeekCheckbox_CheckedChanged(object sender, EventArgs e)
{
if (!_loading)
{
Tastudio.Config.TurboSeek ^= true;
}
if (!_loading) Tastudio.Config.TurboSeek = !Tastudio.Config.TurboSeek;
}
private void AutoRestoreCheckbox_CheckedChanged(object sender, EventArgs e)
{
if (!_loading)
{
Tastudio.Settings.AutoRestoreLastPosition ^= true;
}
if (!_loading) Tastudio.Settings.AutoRestoreLastPosition = !Tastudio.Settings.AutoRestoreLastPosition;
}
private void FollowCursorCheckbox_CheckedChanged(object sender, EventArgs e)
{
if (!_loading)
{
Tastudio.Settings.FollowCursor ^= true;
Tastudio.Settings.FollowCursor = !Tastudio.Settings.FollowCursor;
if (Tastudio.Settings.FollowCursor)
{
Tastudio.SetVisibleFrame();
@ -125,7 +118,7 @@ namespace BizHawk.Client.EmuHawk
private void RecordingModeCheckbox_MouseClick(object sender, MouseEventArgs e)
{
RecordingMode ^= true;
RecordingMode = !RecordingMode;
Tastudio.WasRecording = RecordingMode; // hard reset at manual click and hotkey
}

View File

@ -868,9 +868,7 @@ namespace BizHawk.Client.EmuHawk
}
private void CopyIncludesFrameNoMenuItem_Click(object sender, EventArgs e)
{
Settings.CopyIncludesFrameNo ^= true;
}
=> Settings.CopyIncludesFrameNo = !Settings.CopyIncludesFrameNo;
private void SetAutosaveIntervalMenuItem_Click(object sender, EventArgs e)
{
@ -895,19 +893,13 @@ namespace BizHawk.Client.EmuHawk
}
private void AutosaveAsBk2MenuItem_Click(object sender, EventArgs e)
{
Settings.AutosaveAsBk2 ^= true;
}
=> Settings.AutosaveAsBk2 = !Settings.AutosaveAsBk2;
private void AutosaveAsBackupFileMenuItem_Click(object sender, EventArgs e)
{
Settings.AutosaveAsBackupFile ^= true;
}
=> Settings.AutosaveAsBackupFile = !Settings.AutosaveAsBackupFile;
private void BackupPerFileSaveMenuItem_Click(object sender, EventArgs e)
{
Settings.BackupPerFileSave ^= true;
}
=> Settings.BackupPerFileSave = !Settings.BackupPerFileSave;
private void ApplyPatternToPaintedInputMenuItem_CheckedChanged(object sender, EventArgs e)
{
@ -915,9 +907,7 @@ namespace BizHawk.Client.EmuHawk
}
private void SingleClickAxisEditMenuItem_Click(object sender, EventArgs e)
{
Settings.SingleClickAxisEdit ^= true;
}
=> Settings.SingleClickAxisEdit = !Settings.SingleClickAxisEdit;
private void BindMarkersToInputMenuItem_Click(object sender, EventArgs e)
{
@ -925,14 +915,10 @@ namespace BizHawk.Client.EmuHawk
}
private void EmptyNewMarkerNotesMenuItem_Click(object sender, EventArgs e)
{
Settings.EmptyMarkers ^= true;
}
=> Settings.EmptyMarkers = !Settings.EmptyMarkers;
private void AutoPauseAtEndMenuItem_Click(object sender, EventArgs e)
{
Settings.AutoPause ^= true;
}
=> Settings.AutoPause = !Settings.AutoPause;
private void AutoHoldMenuItem_CheckedChanged(object sender, EventArgs e)
{
@ -985,14 +971,10 @@ namespace BizHawk.Client.EmuHawk
}
private void OldControlSchemeForBranchesMenuItem_Click(object sender, EventArgs e)
{
Settings.OldControlSchemeForBranches ^= true;
}
=> Settings.OldControlSchemeForBranches = !Settings.OldControlSchemeForBranches;
private void LoadBranchOnDoubleClickMenuItem_Click(object sender, EventArgs e)
{
Settings.LoadBranchOnDoubleClick ^= true;
}
=> Settings.LoadBranchOnDoubleClick = !Settings.LoadBranchOnDoubleClick;
private void HeaderMenuItem_Click(object sender, EventArgs e)
{
@ -1090,7 +1072,7 @@ namespace BizHawk.Client.EmuHawk
private void RotateMenuItem_Click(object sender, EventArgs e)
{
TasView.HorizontalOrientation ^= true;
TasView.HorizontalOrientation = !TasView.HorizontalOrientation;
CurrentTasMovie.FlagChanges();
}
@ -1102,9 +1084,7 @@ namespace BizHawk.Client.EmuHawk
}
private void HideWasLagFramesMenuItem_Click(object sender, EventArgs e)
{
TasView.HideWasLagFrames ^= true;
}
=> TasView.HideWasLagFrames = !TasView.HideWasLagFrames;
private void AlwaysScrollMenuItem_Click(object sender, EventArgs e)
{
@ -1287,7 +1267,7 @@ namespace BizHawk.Client.EmuHawk
{
foreach (ToolStripMenuItem menuItem in dummyObject1.DropDownItems)
{
menuItem.Checked ^= true;
menuItem.Checked = !menuItem.Checked;
}
CurrentTasMovie.FlagChanges();

View File

@ -703,7 +703,7 @@ namespace BizHawk.Client.EmuHawk
private void TastudioToggleReadOnly()
{
TasPlaybackBox.RecordingMode ^= true;
TasPlaybackBox.RecordingMode = !TasPlaybackBox.RecordingMode;
WasRecording = TasPlaybackBox.RecordingMode; // hard reset at manual click and hotkey
}

View File

@ -114,8 +114,7 @@ namespace BizHawk.Client.EmuHawk
private void ShowHotkeysMenuItem_Click(object sender, EventArgs e)
{
TI83ToolTips ^= true;
TI83ToolTips = !TI83ToolTips;
if (TI83ToolTips)
{
SetToolTips();

View File

@ -224,9 +224,7 @@ namespace BizHawk.Client.EmuHawk
}
private void StickyMenuItem_Click(object sender, EventArgs e)
{
StickyPads ^= true;
}
=> StickyPads = !StickyPads;
private void PadBoxContextMenu_Opening(object sender, System.ComponentModel.CancelEventArgs e)
{
@ -244,8 +242,6 @@ namespace BizHawk.Client.EmuHawk
}
private void ClearClearsAnalogInputMenuItem_Click(object sender, EventArgs e)
{
ClearAlsoClearsAnalog ^= true;
}
=> ClearAlsoClearsAnalog = !ClearAlsoClearsAnalog;
}
}

View File

@ -82,7 +82,7 @@ namespace BizHawk.Client.EmuHawk
if (!ReadOnly)
{
RightClicked = true;
Checked ^= true;
Checked = !Checked;
}
return;
case 0x0205: // WM_RBUTTONUP

View File

@ -1125,7 +1125,7 @@ namespace BizHawk.Client.EmuHawk
private void CheckMisalignedMenuItem_Click(object sender, EventArgs e)
{
_settings.CheckMisAligned ^= true;
_settings.CheckMisAligned = !_settings.CheckMisAligned;
SetReboot(true);
}
@ -1146,7 +1146,7 @@ namespace BizHawk.Client.EmuHawk
private void BigEndianMenuItem_Click(object sender, EventArgs e)
{
_settings.BigEndian ^= true;
_settings.BigEndian = !_settings.BigEndian;
_searches.SetEndian(_settings.BigEndian);
}
@ -1268,13 +1268,11 @@ namespace BizHawk.Client.EmuHawk
}
private void PreviewModeMenuItem_Click(object sender, EventArgs e)
{
Settings.PreviewMode ^= true;
}
=> Settings.PreviewMode = !Settings.PreviewMode;
private void AutoSearchMenuItem_Click(object sender, EventArgs e)
{
_autoSearch ^= true;
_autoSearch = !_autoSearch;
AutoSearchCheckBox.Checked = _autoSearch;
DoSearchToolButton.Enabled =
SearchButton.Enabled =
@ -1282,13 +1280,11 @@ namespace BizHawk.Client.EmuHawk
}
private void AutoSearchAccountForLagMenuItem_Click(object sender, EventArgs e)
{
Settings.AutoSearchTakeLagFramesIntoAccount ^= true;
}
=> Settings.AutoSearchTakeLagFramesIntoAccount = !Settings.AutoSearchTakeLagFramesIntoAccount;
private void ExcludeRamWatchMenuItem_Click(object sender, EventArgs e)
{
Settings.AlwaysExcludeRamWatch ^= true;
Settings.AlwaysExcludeRamWatch = !Settings.AlwaysExcludeRamWatch;
if (Settings.AlwaysExcludeRamWatch)
{
RemoveRamWatchesFromList();
@ -1297,7 +1293,7 @@ namespace BizHawk.Client.EmuHawk
private void UseUndoHistoryMenuItem_Click(object sender, EventArgs e)
{
_searches.UndoEnabled ^= true;
_searches.UndoEnabled = !_searches.UndoEnabled;
Settings.UseUndoHistory = _searches.UndoEnabled;
}
@ -1626,7 +1622,7 @@ namespace BizHawk.Client.EmuHawk
_searches.Sort(column.Name, _sortReverse);
_sortedColumn = column.Name;
_sortReverse ^= true;
_sortReverse = !_sortReverse;
WatchListView.Refresh();
}

View File

@ -580,7 +580,7 @@ namespace BizHawk.Client.EmuHawk
_watches.OrderWatches(column.Name, _sortReverse);
_sortedColumn = column.Name;
_sortReverse ^= true;
_sortReverse = !_sortReverse;
WatchListView.Refresh();
}
@ -1041,8 +1041,7 @@ namespace BizHawk.Client.EmuHawk
private void WatchesOnScreenMenuItem_Click(object sender, EventArgs e)
{
Config.DisplayRamWatch ^= true;
Config.DisplayRamWatch = !Config.DisplayRamWatch;
if (!Config.DisplayRamWatch)
{
DisplayManager.OSD.ClearRamWatches();

View File

@ -5,7 +5,7 @@
<Import Project="../MainSlnCommon.props" />
<PropertyGroup>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<NoWarn>$(NoWarn);CA1806;CA1825;CA2214;MA0060;MA0084;MA0090;MA0140;SA1100;SA1120;SA1129;SA1137;SA1205;SA1208;SA1400;SA1514;SA1517</NoWarn>
<NoWarn>$(NoWarn);BHI1104;CA1806;CA1825;CA2214;MA0060;MA0084;MA0090;MA0140;SA1100;SA1120;SA1129;SA1137;SA1205;SA1208;SA1400;SA1514;SA1517</NoWarn>
<Nullable>disable</Nullable>
</PropertyGroup>
<ItemGroup>