From e3646595abb4c5b005fadb8b727e913219263731 Mon Sep 17 00:00:00 2001 From: RoosterDragon Date: Fri, 11 Aug 2023 19:43:15 +0100 Subject: [PATCH] Fix RCS1218 --- .editorconfig | 3 +++ OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs | 7 +------ OpenRA.Platforms.Default/OpenAlSoundEngine.cs | 7 ++----- 3 files changed, 6 insertions(+), 11 deletions(-) diff --git a/.editorconfig b/.editorconfig index 5a446e4c9d..293df0f9e7 100644 --- a/.editorconfig +++ b/.editorconfig @@ -1097,6 +1097,9 @@ dotnet_diagnostic.RCS1215.severity = warning # Unnecessary unsafe context. dotnet_diagnostic.RCS1216.severity = warning +# Simplify code branching. +dotnet_diagnostic.RCS1218.severity = warning + # Use pattern matching instead of combination of 'is' operator and cast operator. dotnet_diagnostic.RCS1220.severity = warning diff --git a/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs b/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs index 65d4e8d10d..6e689e1ff3 100644 --- a/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs +++ b/OpenRA.Mods.Common/Widgets/Logic/GameSaveBrowserLogic.cs @@ -105,13 +105,8 @@ namespace OpenRA.Mods.Common.Widgets.Logic defaultSaveFilename = world.Map.Title; var filenameAttempt = 0; - while (true) - { - if (!File.Exists(Path.Combine(baseSavePath, defaultSaveFilename + ".orasav"))) - break; - + while (File.Exists(Path.Combine(baseSavePath, defaultSaveFilename + ".orasav"))) defaultSaveFilename = world.Map.Title + $" ({++filenameAttempt})"; - } var saveButton = panel.Get("SAVE_BUTTON"); saveButton.IsDisabled = () => string.IsNullOrWhiteSpace(saveTextField.Text); diff --git a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs index 13c4db3649..7291dc6d99 100644 --- a/OpenRA.Platforms.Default/OpenAlSoundEngine.cs +++ b/OpenRA.Platforms.Default/OpenAlSoundEngine.cs @@ -73,7 +73,7 @@ namespace OpenRA.Platforms.Default var buffer = new List(); var offset = 0; - while (true) + do { var b = Marshal.ReadByte(devicesPtr, offset++); if (b != 0) @@ -85,11 +85,8 @@ namespace OpenRA.Platforms.Default // A null indicates termination of that string, so add that to our list. devices.Add(Encoding.UTF8.GetString(buffer.ToArray())); buffer.Clear(); - - // Two successive nulls indicates the end of the list. - if (Marshal.ReadByte(devicesPtr, offset) == 0) - break; } + while (Marshal.ReadByte(devicesPtr, offset) != 0); // Two successive nulls indicates the end of the list. return devices.ToArray(); }