diff --git a/.editorconfig b/.editorconfig index 3d0b97c090..43e76e23b0 100644 --- a/.editorconfig +++ b/.editorconfig @@ -11,3 +11,7 @@ csharp_new_line_before_finally = true csharp_indent_switch_labels = true csharp_indent_case_contents = true csharp_indent_labels = one_less_than_current + +# Globalization rules +dotnet_diagnostic.CA1305.severity = silent +dotnet_diagnostic.CA2101.severity = suggestion diff --git a/Common.props b/Common.props index 36c0d9057e..cb1276a48d 100644 --- a/Common.props +++ b/Common.props @@ -1,6 +1,7 @@ 6 + Recommended $(MSBuildProjectDirectory)/../../Common.ruleset true true diff --git a/ExternalProjects/BizHawk.SrcGen.ReflectionCache/ReflectionCacheGenerator.cs b/ExternalProjects/BizHawk.SrcGen.ReflectionCache/ReflectionCacheGenerator.cs index a99ee1ba80..4d01976c53 100644 --- a/ExternalProjects/BizHawk.SrcGen.ReflectionCache/ReflectionCacheGenerator.cs +++ b/ExternalProjects/BizHawk.SrcGen.ReflectionCache/ReflectionCacheGenerator.cs @@ -48,7 +48,7 @@ namespace BizHawk.SrcGen.ReflectionCache }; if (_namespace != null || syntaxNode is not NamespaceDeclarationSyntax syn) return; var newNS = Ser(syn.Name); - if (!newNS.StartsWith("BizHawk.")) return; + if (!newNS.StartsWith("BizHawk.", StringComparison.Ordinal)) return; _namespaces.Add(newNS); if (_namespaces.Count == SAMPLE_SIZE) _namespace = CalcNamespace(); } @@ -88,7 +88,7 @@ namespace {nSpace} public static IEnumerable EmbeddedResourceList(string extraPrefix) {{ var fullPrefix = EMBED_PREFIX + extraPrefix; - return Asm.GetManifestResourceNames().Where(s => s.StartsWith(fullPrefix)).Select(s => s.RemovePrefix(fullPrefix)); + return Asm.GetManifestResourceNames().Where(s => s.StartsWith(fullPrefix, StringComparison.Ordinal)).Select(s => s.RemovePrefix(fullPrefix)); }} public static IEnumerable EmbeddedResourceList() diff --git a/References/BizHawk.SrcGen.ReflectionCache.dll b/References/BizHawk.SrcGen.ReflectionCache.dll index 40d9ae6117..5d35562ca2 100644 Binary files a/References/BizHawk.SrcGen.ReflectionCache.dll and b/References/BizHawk.SrcGen.ReflectionCache.dll differ diff --git a/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs b/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs index 09626b3f17..3d1357b4ef 100644 --- a/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/GuiApi.cs @@ -160,17 +160,17 @@ namespace BizHawk.Client.Common } public readonly ref struct LuaAutoUnlockHack - { - private readonly GuiApi _guiApi; - - internal LuaAutoUnlockHack(GuiApi guiApi) - => _guiApi = guiApi; - - public void Dispose() - { - _guiApi.UnlockSurface(DisplaySurfaceID.EmuCore); - _guiApi.UnlockSurface(DisplaySurfaceID.Client); - } + { + private readonly GuiApi _guiApi; + + internal LuaAutoUnlockHack(GuiApi guiApi) + => _guiApi = guiApi; + + public void Dispose() + { + _guiApi.UnlockSurface(DisplaySurfaceID.EmuCore); + _guiApi.UnlockSurface(DisplaySurfaceID.Client); + } } public LuaAutoUnlockHack ThisIsTheLuaAutoUnlockHack() @@ -491,7 +491,7 @@ namespace BizHawk.Client.Common { var family = fontfamily != null ? new FontFamily(fontfamily) : FontFamily.GenericMonospace; - var fstyle = fontstyle?.ToLower() switch + var fstyle = fontstyle?.ToLowerInvariant() switch { "bold" => FontStyle.Bold, "italic" => FontStyle.Italic, @@ -507,7 +507,7 @@ namespace BizHawk.Client.Common var font = new Font(family, fontsize ?? 12, fstyle, GraphicsUnit.Pixel); var sizeOfText = g.MeasureString(message, font, 0, new StringFormat(StringFormat.GenericDefault)).ToSize(); - switch (horizalign?.ToLower()) + switch (horizalign?.ToLowerInvariant()) { default: case "left": @@ -521,7 +521,7 @@ namespace BizHawk.Client.Common break; } - switch (vertalign?.ToLower()) + switch (vertalign?.ToLowerInvariant()) { default: case "top": @@ -644,4 +644,4 @@ namespace BizHawk.Client.Common foreach (var brush in _pens.Values) brush.Dispose(); } } -} \ No newline at end of file +} diff --git a/src/BizHawk.Client.Common/Api/Classes/MovieApi.cs b/src/BizHawk.Client.Common/Api/Classes/MovieApi.cs index 0acc66213a..9840a6db49 100644 --- a/src/BizHawk.Client.Common/Api/Classes/MovieApi.cs +++ b/src/BizHawk.Client.Common/Api/Classes/MovieApi.cs @@ -98,7 +98,7 @@ namespace BizHawk.Client.Common public int Length() => _movieSession.Movie.FrameCount; - public string Mode() => (_movieSession.Movie?.Mode ?? MovieMode.Inactive).ToString().ToUpper(); + public string Mode() => (_movieSession.Movie?.Mode ?? MovieMode.Inactive).ToString().ToUpperInvariant(); public bool PlayFromStart(string path = "") { diff --git a/src/BizHawk.Client.Common/ArgParser.cs b/src/BizHawk.Client.Common/ArgParser.cs index 3b8c61d652..0d8350edd3 100644 --- a/src/BizHawk.Client.Common/ArgParser.cs +++ b/src/BizHawk.Client.Common/ArgParser.cs @@ -7,6 +7,7 @@ using System.IO; using System.Net.Sockets; using BizHawk.Common.CollectionExtensions; +using BizHawk.Common.StringExtensions; namespace BizHawk.Client.Common { @@ -59,28 +60,28 @@ namespace BizHawk.Client.Common continue; } - var argDowncased = arg.ToLower(); - if (argDowncased.StartsWith("--load-slot=")) + var argDowncased = arg.ToLowerInvariant(); + if (argDowncased.StartsWithOrdinal("--load-slot=")) { cmdLoadSlot = argDowncased.Substring(argDowncased.IndexOf('=') + 1); } - else if (argDowncased.StartsWith("--load-state=")) + else if (argDowncased.StartsWithOrdinal("--load-state=")) { cmdLoadState = arg.Substring(arg.IndexOf('=') + 1); } - else if (argDowncased.StartsWith("--config=")) + else if (argDowncased.StartsWithOrdinal("--config=")) { cmdConfigFile = arg.Substring(arg.IndexOf('=') + 1); } - else if (argDowncased.StartsWith("--movie=")) + else if (argDowncased.StartsWithOrdinal("--movie=")) { cmdMovie = arg.Substring(arg.IndexOf('=') + 1); } - else if (argDowncased.StartsWith("--dump-type=")) + else if (argDowncased.StartsWithOrdinal("--dump-type=")) { cmdDumpType = argDowncased.Substring(argDowncased.IndexOf('=') + 1); } - else if (argDowncased.StartsWith("--dump-frames=")) + else if (argDowncased.StartsWithOrdinal("--dump-frames=")) { string list = argDowncased.Substring(argDowncased.IndexOf('=') + 1); string[] items = list.Split(','); @@ -93,78 +94,78 @@ namespace BizHawk.Client.Common // automatically set dump length to maximum frame autoDumpLength = currAviWriterFrameList.Order().Last(); } - else if (argDowncased.StartsWith("--version")) + else if (argDowncased.StartsWithOrdinal("--version")) { printVersion = true; } - else if (argDowncased.StartsWith("--dump-name=")) + else if (argDowncased.StartsWithOrdinal("--dump-name=")) { cmdDumpName = arg.Substring(arg.IndexOf('=') + 1); } - else if (argDowncased.StartsWith("--dump-length=")) + else if (argDowncased.StartsWithOrdinal("--dump-length=")) { var len = int.TryParse(argDowncased.Substring(argDowncased.IndexOf('=') + 1), out var i1) ? i1 : default; autoDumpLength = len; } - else if (argDowncased.StartsWith("--dump-close")) + else if (argDowncased.StartsWithOrdinal("--dump-close")) { autoCloseOnDump = true; } - else if (argDowncased.StartsWith("--chromeless")) + else if (argDowncased.StartsWithOrdinal("--chromeless")) { // chrome is never shown, even in windowed mode chromeless = true; } - else if (argDowncased.StartsWith("--fullscreen")) + else if (argDowncased.StartsWithOrdinal("--fullscreen")) { startFullscreen = true; } - else if (argDowncased.StartsWith("--lua=")) + else if (argDowncased.StartsWithOrdinal("--lua=")) { luaScript = arg.Substring(arg.IndexOf('=') + 1); luaConsole = true; } - else if (argDowncased.StartsWith("--luaconsole")) + else if (argDowncased.StartsWithOrdinal("--luaconsole")) { luaConsole = true; } - else if (argDowncased.StartsWith("--socket_port=")) + else if (argDowncased.StartsWithOrdinal("--socket_port=")) { var port = int.TryParse(argDowncased.Substring(argDowncased.IndexOf('=') + 1), out var i1) ? i1 : default; if (port > 0) socketPort = port; } - else if (argDowncased.StartsWith("--socket_ip=")) + else if (argDowncased.StartsWithOrdinal("--socket_ip=")) { socketIP = argDowncased.Substring(argDowncased.IndexOf('=') + 1); } - else if (argDowncased.StartsWith("--socket_udp")) + else if (argDowncased.StartsWithOrdinal("--socket_udp")) { socketProtocol = ProtocolType.Udp; } - else if (argDowncased.StartsWith("--mmf=")) + else if (argDowncased.StartsWithOrdinal("--mmf=")) { mmfFilename = arg.Substring(arg.IndexOf('=') + 1); } - else if (argDowncased.StartsWith("--url_get=")) + else if (argDowncased.StartsWithOrdinal("--url_get=")) { urlGet = arg.Substring(arg.IndexOf('=') + 1); } - else if (argDowncased.StartsWith("--url_post=")) + else if (argDowncased.StartsWithOrdinal("--url_post=")) { urlPost = arg.Substring(arg.IndexOf('=') + 1); } - else if (argDowncased.StartsWith("--audiosync=")) + else if (argDowncased.StartsWithOrdinal("--audiosync=")) { audiosync = argDowncased.Substring(argDowncased.IndexOf('=') + 1) == "true"; } - else if (argDowncased.StartsWith("--open-ext-tool-dll=")) + else if (argDowncased.StartsWithOrdinal("--open-ext-tool-dll=")) { // the first ext. tool from ExternalToolManager.ToolStripMenu which satisfies both of these will be opened: // - available (no load errors, correct system/rom, etc.) // - dll path matches given string; or dll filename matches given string with or without `.dll` openExtToolDll = arg.Substring(20); } - else if (argDowncased.StartsWith("--userdata=")) + else if (argDowncased.StartsWithOrdinal("--userdata=")) { userdataUnparsedPairs = new(); foreach (var s in arg.Substring(11).Split(';')) diff --git a/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs b/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs index 8c4110482b..4ca419684a 100644 --- a/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs +++ b/src/BizHawk.Client.Common/DisplayManager/Filters/Retro.cs @@ -166,8 +166,7 @@ namespace BizHawk.Client.Common.Filters value = value.Trim(); } - - dict[key.ToLower()] = value; + dict[key.ToLowerInvariant()] = value; } // process the keys diff --git a/src/BizHawk.Client.Common/RecentFiles.cs b/src/BizHawk.Client.Common/RecentFiles.cs index 84ab49a945..ed6dcdf33b 100644 --- a/src/BizHawk.Client.Common/RecentFiles.cs +++ b/src/BizHawk.Client.Common/RecentFiles.cs @@ -71,7 +71,7 @@ namespace BizHawk.Client.Common { if (!Frozen) { - return recentlist.RemoveAll(recent => string.Compare(newFile, recent, StringComparison.CurrentCultureIgnoreCase) == 0) != 0; // none removed => return false + return recentlist.RemoveAll(recent => string.Compare(newFile, recent, StringComparison.OrdinalIgnoreCase) == 0) != 0; // none removed => return false } return false; diff --git a/src/BizHawk.Client.Common/RomGame.cs b/src/BizHawk.Client.Common/RomGame.cs index 8845a7d366..1b25517809 100644 --- a/src/BizHawk.Client.Common/RomGame.cs +++ b/src/BizHawk.Client.Common/RomGame.cs @@ -65,7 +65,7 @@ namespace BizHawk.Client.Common if (!string.IsNullOrWhiteSpace(GameInfo.Name) && GameInfo.Name == GameInfo.Name.ToUpperInvariant()) { - GameInfo.Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(GameInfo.Name.ToLower()); + GameInfo.Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(GameInfo.Name.ToLowerInvariant()); } return; diff --git a/src/BizHawk.Client.Common/RomLoader.cs b/src/BizHawk.Client.Common/RomLoader.cs index aa076db85f..d4411bc1bf 100644 --- a/src/BizHawk.Client.Common/RomLoader.cs +++ b/src/BizHawk.Client.Common/RomLoader.cs @@ -389,7 +389,7 @@ namespace BizHawk.Client.Common return (int)CorePriority.UserPreference; } - if (string.Equals(c.Name, dbForcedCoreName, StringComparison.InvariantCultureIgnoreCase)) + if (string.Equals(c.Name, dbForcedCoreName, StringComparison.OrdinalIgnoreCase)) { return (int)CorePriority.GameDbPreference; } diff --git a/src/BizHawk.Client.Common/cheats/GameSharkDecoder.cs b/src/BizHawk.Client.Common/cheats/GameSharkDecoder.cs index ea426ba55b..54ac105888 100644 --- a/src/BizHawk.Client.Common/cheats/GameSharkDecoder.cs +++ b/src/BizHawk.Client.Common/cheats/GameSharkDecoder.cs @@ -1,4 +1,6 @@ -using BizHawk.Emulation.Common; +using System; +using BizHawk.Common.StringExtensions; +using BizHawk.Emulation.Common; namespace BizHawk.Client.Common.cheats { @@ -50,7 +52,7 @@ namespace BizHawk.Client.Common.cheats private static IDecodeResult GameBoy(string code) { // Game Genie - if (code.LastIndexOf("-") == 7 && code.IndexOf("-") == 3) + if (code.LastIndexOf("-", StringComparison.Ordinal) == 7 && code.IndexOf("-", StringComparison.Ordinal) == 3) { return GbGgGameGenieDecoder.Decode(code); } @@ -87,7 +89,7 @@ namespace BizHawk.Client.Common.cheats { // Problem: I don't know what the Non-FF Style codes are. // TODO: Fix that. - if (code.StartsWith("FF") == false) + if (code.StartsWithOrdinal("FF") == false) { return new InvalidCheatCode("This Action Replay Code, is not yet supported."); } @@ -109,13 +111,13 @@ namespace BizHawk.Client.Common.cheats private static IDecodeResult Sms(string code) { // Game Genie - if (code.LastIndexOf("-") == 7 && code.IndexOf("-") == 3) + if (code.LastIndexOf("-", StringComparison.Ordinal) == 7 && code.IndexOf("-", StringComparison.Ordinal) == 3) { return GbGgGameGenieDecoder.Decode(code); } // Action Replay - if (code.IndexOf("-") == 3 && code.Length == 9) + if (code.IndexOf("-", StringComparison.Ordinal) == 3 && code.Length == 9) { return SmsActionReplayDecoder.Decode(code); } diff --git a/src/BizHawk.Client.Common/cheats/GbGgGameGenieDecoder.cs b/src/BizHawk.Client.Common/cheats/GbGgGameGenieDecoder.cs index 96573dd702..849fea2ce3 100644 --- a/src/BizHawk.Client.Common/cheats/GbGgGameGenieDecoder.cs +++ b/src/BizHawk.Client.Common/cheats/GbGgGameGenieDecoder.cs @@ -35,7 +35,7 @@ namespace BizHawk.Client.Common.cheats throw new ArgumentNullException(nameof(_code)); } - if (_code.LastIndexOf("-") != 7 || _code.IndexOf("-") != 3) + if (_code.LastIndexOf("-", StringComparison.Ordinal) != 7 || _code.IndexOf("-", StringComparison.Ordinal) != 3) { return new InvalidCheatCode("All Master System Game Genie Codes need to have a dash after the third character and seventh character."); } diff --git a/src/BizHawk.Client.Common/cheats/GbaGameSharkDecoder.cs b/src/BizHawk.Client.Common/cheats/GbaGameSharkDecoder.cs index cbe0ffee3f..6b94b732f9 100644 --- a/src/BizHawk.Client.Common/cheats/GbaGameSharkDecoder.cs +++ b/src/BizHawk.Client.Common/cheats/GbaGameSharkDecoder.cs @@ -57,7 +57,7 @@ namespace BizHawk.Client.Common.cheats code = Decrypt(code); } - if (code.IndexOf(" ") != 8 || code.Length != 17) // not a redundant length check, `code` was overwritten + if (code.IndexOf(" ", StringComparison.Ordinal) != 8 || code.Length != 17) // not a redundant length check, `code` was overwritten { return new InvalidCheatCode("All GBA GameShark Codes need to be 17 characters in length with a space after the first eight."); } diff --git a/src/BizHawk.Client.Common/cheats/GenesisActionReplayDecoder.cs b/src/BizHawk.Client.Common/cheats/GenesisActionReplayDecoder.cs index af97cfd93a..ee61b0a935 100644 --- a/src/BizHawk.Client.Common/cheats/GenesisActionReplayDecoder.cs +++ b/src/BizHawk.Client.Common/cheats/GenesisActionReplayDecoder.cs @@ -13,7 +13,7 @@ namespace BizHawk.Client.Common.cheats throw new ArgumentNullException(nameof(code)); } - if (code.IndexOf(":") != 6) + if (code.IndexOf(":", StringComparison.Ordinal) != 6) { return new InvalidCheatCode("Action Replay/Pro Action Replay Codes need to contain a colon after the sixth character."); } diff --git a/src/BizHawk.Client.Common/cheats/GenesisGameGenieDecoder.cs b/src/BizHawk.Client.Common/cheats/GenesisGameGenieDecoder.cs index a198330f63..290db9c097 100644 --- a/src/BizHawk.Client.Common/cheats/GenesisGameGenieDecoder.cs +++ b/src/BizHawk.Client.Common/cheats/GenesisGameGenieDecoder.cs @@ -48,7 +48,7 @@ namespace BizHawk.Client.Common.cheats throw new ArgumentNullException(nameof(code)); } - if (code.IndexOf("-") != 4) + if (code.IndexOf("-", StringComparison.Ordinal) != 4) { return new InvalidCheatCode("Game Genie Codes need to contain a dash after the fourth character"); } diff --git a/src/BizHawk.Client.Common/cheats/N64GameSharkDecoder.cs b/src/BizHawk.Client.Common/cheats/N64GameSharkDecoder.cs index 4bd15924b7..2d42fcc523 100644 --- a/src/BizHawk.Client.Common/cheats/N64GameSharkDecoder.cs +++ b/src/BizHawk.Client.Common/cheats/N64GameSharkDecoder.cs @@ -13,7 +13,7 @@ namespace BizHawk.Client.Common.cheats throw new ArgumentNullException(nameof(code)); } - if (code.IndexOf(" ") != 8) + if (code.IndexOf(" ", StringComparison.Ordinal) != 8) { return new InvalidCheatCode("GameShark Codes need to contain a space after the eighth character."); } diff --git a/src/BizHawk.Client.Common/cheats/PsxGameSharkDecoder.cs b/src/BizHawk.Client.Common/cheats/PsxGameSharkDecoder.cs index 9cbc1d6965..3298a37227 100644 --- a/src/BizHawk.Client.Common/cheats/PsxGameSharkDecoder.cs +++ b/src/BizHawk.Client.Common/cheats/PsxGameSharkDecoder.cs @@ -14,7 +14,7 @@ namespace BizHawk.Client.Common.cheats throw new ArgumentNullException(nameof(code)); } - if (code.IndexOf(" ") != 8) + if (code.IndexOf(" ", StringComparison.Ordinal) != 8) { return new InvalidCheatCode("All PSX GameShark Codes need to contain a space after the eighth character."); } diff --git a/src/BizHawk.Client.Common/cheats/SaturnGameSharkDecoder.cs b/src/BizHawk.Client.Common/cheats/SaturnGameSharkDecoder.cs index 2cae6ae21d..06fd435547 100644 --- a/src/BizHawk.Client.Common/cheats/SaturnGameSharkDecoder.cs +++ b/src/BizHawk.Client.Common/cheats/SaturnGameSharkDecoder.cs @@ -18,7 +18,7 @@ namespace BizHawk.Client.Common.cheats throw new ArgumentNullException(nameof(code)); } - if (code.IndexOf(" ") != 8) + if (code.IndexOf(" ", StringComparison.Ordinal) != 8) { return new InvalidCheatCode("All Saturn GameShark Codes need to contain a space after the eighth character."); } diff --git a/src/BizHawk.Client.Common/cheats/SmsActionReplayDecoder.cs b/src/BizHawk.Client.Common/cheats/SmsActionReplayDecoder.cs index 8f6b83529f..c3ef9867a5 100644 --- a/src/BizHawk.Client.Common/cheats/SmsActionReplayDecoder.cs +++ b/src/BizHawk.Client.Common/cheats/SmsActionReplayDecoder.cs @@ -12,7 +12,7 @@ namespace BizHawk.Client.Common.cheats throw new ArgumentNullException(nameof(code)); } - if (code.IndexOf("-") != 3 && code.Length != 9) + if (code.IndexOf("-", StringComparison.Ordinal) != 3 && code.Length != 9) { return new InvalidCheatCode("Action Replay Codes must be 9 characters with a dash after the third character"); } diff --git a/src/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs b/src/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs index 0d0bcfbccf..9ae93cdf6a 100644 --- a/src/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs +++ b/src/BizHawk.Client.Common/config/PathEntryCollectionExtensions.cs @@ -90,12 +90,12 @@ namespace BizHawk.Client.Common if (path == "%recent%") return PathUtils.SpecialRecentsDir; - if (path.StartsWith("%exe%")) + if (path.StartsWithOrdinal("%exe%")) { return PathUtils.ExeDirectoryPath + path.Substring(5); } - if (path.StartsWith("%rom%")) + if (path.StartsWithOrdinal("%rom%")) { return collection.LastRomPath + path.Substring(5); } diff --git a/src/BizHawk.Client.Common/input/InputCoalescerControllers.cs b/src/BizHawk.Client.Common/input/InputCoalescerControllers.cs index 9537d0f011..fb4bca3261 100644 --- a/src/BizHawk.Client.Common/input/InputCoalescerControllers.cs +++ b/src/BizHawk.Client.Common/input/InputCoalescerControllers.cs @@ -1,6 +1,7 @@ #nullable enable using System.Linq; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Client.Common @@ -21,7 +22,7 @@ namespace BizHawk.Client.Common if (state) return; // when a button or modifier key is released, all modified key variants with it are released as well foreach (var k in Buttons.Keys.Where(k => - k.EndsWith($"+{ie.LogicalButton.Button}") || k.StartsWith($"{ie.LogicalButton.Button}+") || k.Contains($"+{ie.LogicalButton.Button}+")) + k.EndsWithOrdinal($"+{ie.LogicalButton.Button}") || k.StartsWithOrdinal($"{ie.LogicalButton.Button}+") || k.Contains($"+{ie.LogicalButton.Button}+")) .ToArray()) Buttons[k] = false; } diff --git a/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs b/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs index 2a05a2b35e..6619ea5907 100644 --- a/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/CommonLibs/ClientLuaLibrary.cs @@ -330,7 +330,7 @@ namespace BizHawk.Client.Common [LuaMethodExample("local nlcliget = client.getavailabletools( );")] [LuaMethod("getavailabletools", "Returns a list of the tools currently open")] public LuaTable GetAvailableTools() - => _th.EnumerateToLuaTable(APIs.Tool.AvailableTools.Select(tool => tool.Name.ToLower()), indexFrom: 0); + => _th.EnumerateToLuaTable(APIs.Tool.AvailableTools.Select(tool => tool.Name.ToLowerInvariant()), indexFrom: 0); [LuaMethodExample("local nlcliget = client.gettool( \"Tool name\" );")] [LuaMethod("gettool", "Returns an object that represents a tool of the given name (not case sensitive). If the tool is not open, it will be loaded if available. Use getavailabletools to get a list of names")] diff --git a/src/BizHawk.Client.Common/lua/LuaDocumentation.cs b/src/BizHawk.Client.Common/lua/LuaDocumentation.cs index b06d8dbf37..fb6d7dd6cd 100644 --- a/src/BizHawk.Client.Common/lua/LuaDocumentation.cs +++ b/src/BizHawk.Client.Common/lua/LuaDocumentation.cs @@ -290,7 +290,7 @@ namespace BizHawk.Client.Common .Replace("Uint", "uint ") .Replace("Nullable`1[DrawingColor]", "Color? ") .Replace("DrawingColor", "Color ") - .ToLower(); + .ToLowerInvariant(); } public string ReturnType diff --git a/src/BizHawk.Client.Common/lua/LuaFileList.cs b/src/BizHawk.Client.Common/lua/LuaFileList.cs index 0910bc9805..689a16e88e 100644 --- a/src/BizHawk.Client.Common/lua/LuaFileList.cs +++ b/src/BizHawk.Client.Common/lua/LuaFileList.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.IO; using System.Text; using BizHawk.Common.PathExtensions; +using BizHawk.Common.StringExtensions; namespace BizHawk.Client.Common { @@ -78,7 +79,7 @@ namespace BizHawk.Client.Common string line; while ((line = sr.ReadLine()) != null) { - if (line.StartsWith("---")) + if (line.StartsWithOrdinal("---")) { Add(LuaFile.SeparatorInstance); } diff --git a/src/BizHawk.Client.Common/lua/LuaHelperLibs/StringLuaLibrary.cs b/src/BizHawk.Client.Common/lua/LuaHelperLibs/StringLuaLibrary.cs index d6672a7209..c70b37a194 100644 --- a/src/BizHawk.Client.Common/lua/LuaHelperLibs/StringLuaLibrary.cs +++ b/src/BizHawk.Client.Common/lua/LuaHelperLibs/StringLuaLibrary.cs @@ -1,7 +1,7 @@ using System; using System.ComponentModel; using System.Linq; - +using BizHawk.Common.StringExtensions; using NLua; // ReSharper disable UnusedMember.Global @@ -127,12 +127,12 @@ namespace BizHawk.Client.Common [LuaMethodExample("if ( bizstring.startswith( \"Some string\", \"Some\") ) then\r\n\tconsole.log( \"Returns whether str starts with str2\" );\r\nend;")] [LuaMethod("startswith", "Returns whether str starts with str2")] public static bool StartsWith(string str, string str2) - => !string.IsNullOrEmpty(str) && str.StartsWith(str2); // don't bother fixing encoding, will match (or not match) regardless + => !string.IsNullOrEmpty(str) && str.StartsWithOrdinal(str2); // don't bother fixing encoding, will match (or not match) regardless [LuaMethodExample("if ( bizstring.endswith( \"Some string\", \"string\") ) then\r\n\tconsole.log( \"Returns whether str ends wth str2\" );\r\nend;")] [LuaMethod("endswith", "Returns whether str ends wth str2")] public static bool EndsWith(string str, string str2) - => !string.IsNullOrEmpty(str) && str.EndsWith(str2); // don't bother fixing encoding, will match (or not match) regardless + => !string.IsNullOrEmpty(str) && str.EndsWithOrdinal(str2); // don't bother fixing encoding, will match (or not match) regardless [LuaMethodExample("local nlbizspl = bizstring.split( \"Some, string\", \", \" );")] [LuaMethod("split", "Splits str into a Lua-style array using the given separator (consecutive separators in str will NOT create empty entries in the array). If the separator is not a string exactly one char long, ',' will be used.")] diff --git a/src/BizHawk.Client.Common/movie/MovieService.cs b/src/BizHawk.Client.Common/movie/MovieService.cs index 3cd93c1aeb..a7f43490f6 100644 --- a/src/BizHawk.Client.Common/movie/MovieService.cs +++ b/src/BizHawk.Client.Common/movie/MovieService.cs @@ -18,7 +18,7 @@ namespace BizHawk.Client.Common public static bool IsValidMovieExtension(string ext) { - return MovieExtensions.Contains(ext.ToLower().Replace(".", "")); + return MovieExtensions.Contains(ext.Replace(".", ""), StringComparer.OrdinalIgnoreCase); } public static bool IsCurrentTasVersion(string movieVersion) @@ -35,7 +35,7 @@ namespace BizHawk.Client.Common } var split = movieVersion - .ToLower() + .ToLowerInvariant() .Split(new[] {"tasproj"}, StringSplitOptions.RemoveEmptyEntries); if (split.Length == 1) diff --git a/src/BizHawk.Client.Common/movie/MovieSession.cs b/src/BizHawk.Client.Common/movie/MovieSession.cs index d430004ff4..daca7532f3 100644 --- a/src/BizHawk.Client.Common/movie/MovieSession.cs +++ b/src/BizHawk.Client.Common/movie/MovieSession.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.IO; using System.Linq; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Client.Common @@ -307,7 +308,7 @@ namespace BizHawk.Client.Common public IMovie Get(string path) { // TODO: change IMovies to take HawkFiles only and not path - if (Path.GetExtension(path)?.EndsWith("tasproj") ?? false) + if (Path.GetExtension(path)?.EndsWithOrdinal("tasproj") ?? false) { return new TasMovie(this, path); } diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs index 4441908e01..3f5d53e0d7 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs @@ -23,7 +23,7 @@ namespace BizHawk.Client.Common } var backupName = Filename; - backupName = backupName.Insert(Filename.LastIndexOf("."), $".{DateTime.Now:yyyy-MM-dd HH.mm.ss}"); + backupName = backupName.Insert(Filename.LastIndexOf(".", StringComparison.Ordinal), $".{DateTime.Now:yyyy-MM-dd HH.mm.ss}"); backupName = Path.Combine(Session.BackupDirectory, Path.GetFileName(backupName)); Write(backupName, isBackup: true); diff --git a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs index d8c89c32f7..9b407f3d49 100644 --- a/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs +++ b/src/BizHawk.Client.Common/movie/bk2/Bk2Movie.InputLog.cs @@ -58,7 +58,7 @@ namespace BizHawk.Client.Common { Log.Add(line); } - else if (line.StartsWith("Frame ")) + else if (line.StartsWithOrdinal("Frame ")) { var strs = line.Split(' '); try @@ -71,7 +71,7 @@ namespace BizHawk.Client.Common return false; } } - else if (line.StartsWith("LogKey:")) + else if (line.StartsWithOrdinal("LogKey:")) { LogKey = line.Replace("LogKey:", ""); } @@ -122,7 +122,7 @@ namespace BizHawk.Client.Common { newLog.Add(line); } - else if (line.StartsWith("Frame ")) + else if (line.StartsWithOrdinal("Frame ")) { var strs = line.Split(' '); try diff --git a/src/BizHawk.Client.Common/movie/import/DsmImport.cs b/src/BizHawk.Client.Common/movie/import/DsmImport.cs index 11cc8ea89e..d2831687df 100644 --- a/src/BizHawk.Client.Common/movie/import/DsmImport.cs +++ b/src/BizHawk.Client.Common/movie/import/DsmImport.cs @@ -2,6 +2,7 @@ using System.Globalization; using System.Linq; using BizHawk.Common; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores; using BizHawk.Emulation.Cores.Consoles.Nintendo.NDS; @@ -41,40 +42,40 @@ namespace BizHawk.Client.Common { ImportInputFrame(line); } - else if (line.StartsWith("rerecordCount")) + else if (line.StartsWithOrdinal("rerecordCount")) { Result.Movie.Rerecords = (ulong) (int.TryParse(ParseHeader(line, "rerecordCount"), out var rerecordCount) ? rerecordCount : default); } - else if (line.StartsWith("firmNickname")) + else if (line.StartsWithOrdinal("firmNickname")) { syncSettings.FirmwareUsername = ParseHeader(line, "firmNickname"); } - else if (line.StartsWith("firmFavColour")) + else if (line.StartsWithOrdinal("firmFavColour")) { syncSettings.FirmwareFavouriteColour = (NDS.NDSSyncSettings.Color)byte.Parse(ParseHeader(line, "firmFavColour")); } - else if (line.StartsWith("firmBirthDay")) + else if (line.StartsWithOrdinal("firmBirthDay")) { syncSettings.FirmwareBirthdayDay = byte.Parse(ParseHeader(line, "firmBirthDay")); } - else if (line.StartsWith("firmBirthMonth")) + else if (line.StartsWithOrdinal("firmBirthMonth")) { syncSettings.FirmwareBirthdayMonth = (NDS.NDSSyncSettings.Month)byte.Parse(ParseHeader(line, "firmBirthMonth")); } - else if (line.StartsWith("rtcStartNew")) + else if (line.StartsWithOrdinal("rtcStartNew")) { string rtcTime = ParseHeader(line, "rtcStartNew"); syncSettings.InitialTime = DateTime.ParseExact(rtcTime, "yyyy'-'MMM'-'dd' 'HH':'mm':'ss':'fff", DateTimeFormatInfo.InvariantInfo); } - else if (line.StartsWith("comment author")) + else if (line.StartsWithOrdinal("comment author")) { Result.Movie.HeaderEntries[HeaderKeys.Author] = ParseHeader(line, "comment author"); } - else if (line.StartsWith("comment")) + else if (line.StartsWithOrdinal("comment")) { Result.Movie.Comments.Add(ParseHeader(line, "comment")); } - else if (line.ToLower().StartsWith("guid")) + else if (line.StartsWith("guid", StringComparison.OrdinalIgnoreCase)) { // We no longer care to keep this info } diff --git a/src/BizHawk.Client.Common/movie/import/FcmImport.cs b/src/BizHawk.Client.Common/movie/import/FcmImport.cs index ef0d919639..7e3946c1cf 100644 --- a/src/BizHawk.Client.Common/movie/import/FcmImport.cs +++ b/src/BizHawk.Client.Common/movie/import/FcmImport.cs @@ -107,7 +107,7 @@ namespace BizHawk.Client.Common.movie.import // 020 16-byte md5sum of the ROM used byte[] md5 = r.ReadBytes(16); - Result.Movie.HeaderEntries[HeaderKeys.Md5] = md5.BytesToHexString().ToLower(); + Result.Movie.HeaderEntries[HeaderKeys.Md5] = md5.BytesToHexString().ToLowerInvariant(); // 030 4-byte little-endian unsigned int: version of the emulator used uint emuVersion = r.ReadUInt32(); diff --git a/src/BizHawk.Client.Common/movie/import/Fm2Import.cs b/src/BizHawk.Client.Common/movie/import/Fm2Import.cs index df81b59dcf..95a7d3d918 100644 --- a/src/BizHawk.Client.Common/movie/import/Fm2Import.cs +++ b/src/BizHawk.Client.Common/movie/import/Fm2Import.cs @@ -44,7 +44,7 @@ namespace BizHawk.Client.Common { ImportInputFrame(line); } - else if (line.ToLower().StartsWith("sub")) + else if (line.StartsWith("sub", StringComparison.OrdinalIgnoreCase)) { var subtitle = ImportTextSubtitle(line); @@ -53,11 +53,11 @@ namespace BizHawk.Client.Common Result.Movie.Subtitles.AddFromString(subtitle); } } - else if (line.ToLower().StartsWith("emuversion")) + else if (line.StartsWith("emuversion", StringComparison.OrdinalIgnoreCase)) { Result.Movie.Comments.Add($"{EmulationOrigin} {emulator} version {ParseHeader(line, "emuVersion")}"); } - else if (line.ToLower().StartsWith("version")) + else if (line.StartsWith("version", StringComparison.OrdinalIgnoreCase)) { string version = ParseHeader(line, "version"); @@ -70,40 +70,40 @@ namespace BizHawk.Client.Common Result.Movie.Comments.Add($"{MovieOrigin} .fm2 version 3"); } } - else if (line.ToLower().StartsWith("romfilename")) + else if (line.StartsWith("romfilename", StringComparison.OrdinalIgnoreCase)) { Result.Movie.HeaderEntries[HeaderKeys.GameName] = ParseHeader(line, "romFilename"); } - else if (line.ToLower().StartsWith("cdgamename")) + else if (line.StartsWith("cdgamename", StringComparison.OrdinalIgnoreCase)) { Result.Movie.HeaderEntries[HeaderKeys.GameName] = ParseHeader(line, "cdGameName"); } - else if (line.ToLower().StartsWith("romchecksum")) + else if (line.StartsWith("romchecksum", StringComparison.OrdinalIgnoreCase)) { string blob = ParseHeader(line, "romChecksum"); byte[] md5 = DecodeBlob(blob); if (md5 != null && md5.Length == 16) { - Result.Movie.HeaderEntries[HeaderKeys.Md5] = md5.BytesToHexString().ToLower(); + Result.Movie.HeaderEntries[HeaderKeys.Md5] = md5.BytesToHexString().ToLowerInvariant(); } else { Result.Warnings.Add("Bad ROM checksum."); } } - else if (line.ToLower().StartsWith("comment author")) + else if (line.StartsWith("comment author", StringComparison.OrdinalIgnoreCase)) { Result.Movie.HeaderEntries[HeaderKeys.Author] = ParseHeader(line, "comment author"); } - else if (line.ToLower().StartsWith("rerecordcount")) + else if (line.StartsWith("rerecordcount", StringComparison.OrdinalIgnoreCase)) { Result.Movie.Rerecords = (ulong) (int.TryParse(ParseHeader(line, "rerecordCount"), out var rerecordCount) ? rerecordCount : default); } - else if (line.ToLower().StartsWith("guid")) + else if (line.StartsWith("guid", StringComparison.OrdinalIgnoreCase)) { // We no longer care to keep this info } - else if (line.ToLower().StartsWith("startsfromsavestate")) + else if (line.StartsWith("startsfromsavestate", StringComparison.OrdinalIgnoreCase)) { // If this movie starts from a savestate, we can't support it. if (ParseHeader(line, "StartsFromSavestate") == "1") @@ -112,11 +112,11 @@ namespace BizHawk.Client.Common break; } } - else if (line.ToLower().StartsWith("palflag")) + else if (line.StartsWith("palflag", StringComparison.OrdinalIgnoreCase)) { Result.Movie.HeaderEntries[HeaderKeys.Pal] = ParseHeader(line, "palFlag"); } - else if (line.ToLower().StartsWith("port0")) + else if (line.StartsWith("port0", StringComparison.OrdinalIgnoreCase)) { if (ParseHeader(line, "port0") == "1") { @@ -124,7 +124,7 @@ namespace BizHawk.Client.Common _deck = controllerSettings.Instantiate((x, y) => false).AddSystemToControllerDef(); } } - else if (line.ToLower().StartsWith("port1")) + else if (line.StartsWith("port1", StringComparison.OrdinalIgnoreCase)) { if (ParseHeader(line, "port1") == "1") { @@ -132,14 +132,14 @@ namespace BizHawk.Client.Common _deck = controllerSettings.Instantiate((x, y) => false).AddSystemToControllerDef(); } } - else if (line.ToLower().StartsWith("port2")) + else if (line.StartsWith("port2", StringComparison.OrdinalIgnoreCase)) { if (ParseHeader(line, "port2") == "1") { Result.Warnings.Add("Famicom port detected but not yet supported, ignoring"); } } - else if (line.ToLower().StartsWith("fourscore")) + else if (line.StartsWith("fourscore", StringComparison.OrdinalIgnoreCase)) { bool fourscore = ParseHeader(line, "fourscore") == "1"; if (fourscore) @@ -162,7 +162,7 @@ namespace BizHawk.Client.Common } private IControllerDeck _deck; - + private readonly string[] _buttons = { "Right", "Left", "Down", "Up", "Start", "Select", "B", "A" }; private void ImportInputFrame(string line) { @@ -244,7 +244,7 @@ namespace BizHawk.Client.Common } // base64 - if (!blob.ToLower().StartsWith("base64:")) + if (!blob.StartsWith("base64:", StringComparison.OrdinalIgnoreCase)) { return null; } diff --git a/src/BizHawk.Client.Common/movie/import/IMovieImport.cs b/src/BizHawk.Client.Common/movie/import/IMovieImport.cs index dcfaa7e286..b3a5e8576b 100644 --- a/src/BizHawk.Client.Common/movie/import/IMovieImport.cs +++ b/src/BizHawk.Client.Common/movie/import/IMovieImport.cs @@ -117,8 +117,7 @@ namespace BizHawk.Client.Common protected static string ParseHeader(string line, string headerName) { // Case-insensitive search. - int x = line.ToLower().LastIndexOf( - headerName.ToLower()) + headerName.Length; + int x = line.LastIndexOf(headerName, StringComparison.OrdinalIgnoreCase) + headerName.Length; string str = line.Substring(x + 1, line.Length - x - 1); return str.Trim(); } diff --git a/src/BizHawk.Client.Common/movie/import/LsmvImport.cs b/src/BizHawk.Client.Common/movie/import/LsmvImport.cs index 564e9f6192..f05c6099bc 100644 --- a/src/BizHawk.Client.Common/movie/import/LsmvImport.cs +++ b/src/BizHawk.Client.Common/movie/import/LsmvImport.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; @@ -177,7 +178,7 @@ namespace BizHawk.Client.Common.movie.import } Result.Movie.AppendFrame(_previousControllers); } - else if (item.FullName.StartsWith("moviesram.")) + else if (item.FullName.StartsWithOrdinal("moviesram.")) { using var stream = item.Open(); byte[] movieSram = stream.ReadAllBytes(); @@ -212,7 +213,7 @@ namespace BizHawk.Client.Common.movie.import Result.Movie.Rerecords = rerecordCount; } - else if (item.FullName.EndsWith(".sha256")) + else if (item.FullName.EndsWithOrdinal(".sha256")) { using var stream = item.Open(); string sha256Hash = Encoding.UTF8.GetString(stream.ReadAllBytes()).Trim(); @@ -318,7 +319,7 @@ namespace BizHawk.Client.Common.movie.import if (player > _playerCount) break; IReadOnlyList buttons = controllers.Definition.ControlsOrdered[player]; - if (buttons[0].EndsWith("Up")) // hack to identify gamepad / multitap which have a different button order in bizhawk compared to lsnes + if (buttons[0].EndsWithOrdinal("Up")) // hack to identify gamepad / multitap which have a different button order in bizhawk compared to lsnes { buttons = new[] { "B", "Y", "Select", "Start", "Up", "Down", "Left", "Right", "A", "X", "L", "R" } .Select(button => $"P{player} {button}") diff --git a/src/BizHawk.Client.Common/movie/import/Mc2Import.cs b/src/BizHawk.Client.Common/movie/import/Mc2Import.cs index ca5ade3fa6..edf9fc3f58 100644 --- a/src/BizHawk.Client.Common/movie/import/Mc2Import.cs +++ b/src/BizHawk.Client.Common/movie/import/Mc2Import.cs @@ -1,4 +1,5 @@ -using BizHawk.Emulation.Common; +using System; +using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.PCEngine; namespace BizHawk.Client.Common.movie.import @@ -43,8 +44,7 @@ namespace BizHawk.Client.Common.movie.import { ImportTextFrame(line); } - else if (line.ToLower() - .StartsWith("ports")) + else if (line.StartsWith("ports", StringComparison.OrdinalIgnoreCase)) { var portNumStr = ParseHeader(line, "ports"); if (int.TryParse(portNumStr, out int ports)) @@ -83,32 +83,32 @@ namespace BizHawk.Client.Common.movie.import ss.Port5); } } - else if (line.ToLower().StartsWith("pcecd")) + else if (line.StartsWith("pcecd", StringComparison.OrdinalIgnoreCase)) { Result.Movie.HeaderEntries[HeaderKeys.Platform] = VSystemID.Raw.PCECD; } - else if (line.ToLower().StartsWith("emuversion")) + else if (line.StartsWith("emuversion", StringComparison.OrdinalIgnoreCase)) { Result.Movie.Comments.Add($"{EmulationOrigin} Mednafen/PCEjin version {ParseHeader(line, "emuVersion")}"); } - else if (line.ToLower().StartsWith("version")) + else if (line.StartsWith("version", StringComparison.OrdinalIgnoreCase)) { string version = ParseHeader(line, "version"); Result.Movie.Comments.Add($"{MovieOrigin} .mc2 version {version}"); } - else if (line.ToLower().StartsWith("romfilename")) + else if (line.StartsWith("romfilename", StringComparison.OrdinalIgnoreCase)) { Result.Movie.HeaderEntries[HeaderKeys.GameName] = ParseHeader(line, "romFilename"); } - else if (line.ToLower().StartsWith("cdgamename")) + else if (line.StartsWith("cdgamename", StringComparison.OrdinalIgnoreCase)) { Result.Movie.HeaderEntries[HeaderKeys.GameName] = ParseHeader(line, "cdGameName"); } - else if (line.ToLower().StartsWith("comment author")) + else if (line.StartsWith("comment author", StringComparison.OrdinalIgnoreCase)) { Result.Movie.HeaderEntries[HeaderKeys.Author] = ParseHeader(line, "comment author"); } - else if (line.ToLower().StartsWith("rerecordcount")) + else if (line.StartsWith("rerecordcount", StringComparison.OrdinalIgnoreCase)) { int rerecordCount; @@ -124,7 +124,7 @@ namespace BizHawk.Client.Common.movie.import Result.Movie.Rerecords = (ulong)rerecordCount; } - else if (line.ToLower().StartsWith("startsfromsavestate")) + else if (line.StartsWith("startsfromsavestate", StringComparison.OrdinalIgnoreCase)) { // If this movie starts from a savestate, we can't support it. if (ParseHeader(line, "StartsFromSavestate") == "1") diff --git a/src/BizHawk.Client.Common/movie/import/MmvImport.cs b/src/BizHawk.Client.Common/movie/import/MmvImport.cs index 22ec738295..7e05ebb698 100644 --- a/src/BizHawk.Client.Common/movie/import/MmvImport.cs +++ b/src/BizHawk.Client.Common/movie/import/MmvImport.cs @@ -35,7 +35,7 @@ namespace BizHawk.Client.Common.movie.import uint rerecordCount = r.ReadUInt32(); Result.Movie.Rerecords = rerecordCount; - + // 0010: 4-byte little endian flag: begin from reset? uint reset = r.ReadUInt32(); if (reset == 0) @@ -92,7 +92,7 @@ namespace BizHawk.Client.Common.movie.import // 00e4-00f3: binary: rom MD5 digest byte[] md5 = r.ReadBytes(16); - Result.Movie.HeaderEntries[HeaderKeys.Md5] = md5.BytesToHexString().ToLower(); + Result.Movie.HeaderEntries[HeaderKeys.Md5] = md5.BytesToHexString().ToLowerInvariant(); var ss = new SMS.SmsSyncSettings(); var cd = new SMSControllerDeck(ss.Port1, ss.Port2, isGameGear, ss.UseKeyboard); diff --git a/src/BizHawk.Client.Common/movie/import/PjmImport.cs b/src/BizHawk.Client.Common/movie/import/PjmImport.cs index ddcd8d2276..c7bc19c1fe 100644 --- a/src/BizHawk.Client.Common/movie/import/PjmImport.cs +++ b/src/BizHawk.Client.Common/movie/import/PjmImport.cs @@ -1,5 +1,5 @@ using System.IO; - +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Sony.PSX; @@ -315,7 +315,7 @@ namespace BizHawk.Client.Common } // Gross, if not CR LF, this will fail, but will the PSXjin? - if (!mnemonicStr.EndsWith("|\r\n")) + if (!mnemonicStr.EndsWithOrdinal("|\r\n")) { Result.Errors.Add("Unable to parse text input, unknown configuration"); } diff --git a/src/BizHawk.Client.Common/movie/import/YmvImport.cs b/src/BizHawk.Client.Common/movie/import/YmvImport.cs index 1f3c35d5e6..20c1b39b89 100644 --- a/src/BizHawk.Client.Common/movie/import/YmvImport.cs +++ b/src/BizHawk.Client.Common/movie/import/YmvImport.cs @@ -45,20 +45,20 @@ namespace BizHawk.Client.Common.movie.import { ImportTextFrame(line); } - else if (line.ToLower().StartsWith("emuversion")) + else if (line.StartsWith("emuversion", StringComparison.OrdinalIgnoreCase)) { Result.Movie.Comments.Add($"{EmulationOrigin} Yabause version {ParseHeader(line, "emuVersion")}"); } - else if (line.ToLower().StartsWith("version")) + else if (line.StartsWith("version", StringComparison.OrdinalIgnoreCase)) { string version = ParseHeader(line, "version"); Result.Movie.Comments.Add($"{MovieOrigin} .ymv version {version}"); } - else if (line.ToLower().StartsWith("cdGameName")) + else if (line.StartsWith("cdGameName", StringComparison.OrdinalIgnoreCase)) { Result.Movie.HeaderEntries[HeaderKeys.GameName] = ParseHeader(line, "romFilename"); } - else if (line.ToLower().StartsWith("rerecordcount")) + else if (line.StartsWith("rerecordcount", StringComparison.OrdinalIgnoreCase)) { int rerecordCount; @@ -74,7 +74,7 @@ namespace BizHawk.Client.Common.movie.import Result.Movie.Rerecords = (ulong)rerecordCount; } - else if (line.ToLower().StartsWith("startsfromsavestate")) + else if (line.StartsWith("startsfromsavestate", StringComparison.OrdinalIgnoreCase)) { // If this movie starts from a savestate, we can't support it. if (ParseHeader(line, "StartsFromSavestate") == "1") @@ -82,7 +82,7 @@ namespace BizHawk.Client.Common.movie.import Result.Errors.Add("Movies that begin with a savestate are not supported."); } } - else if (line.ToLower().StartsWith("ispal")) + else if (line.StartsWith("ispal", StringComparison.OrdinalIgnoreCase)) { bool pal = ParseHeader(line, "isPal") == "1"; Result.Movie.HeaderEntries[HeaderKeys.Pal] = pal.ToString(); diff --git a/src/BizHawk.Client.Common/movie/import/bkm/BkmHeader.cs b/src/BizHawk.Client.Common/movie/import/bkm/BkmHeader.cs index 24e8a4945b..db21ab7405 100644 --- a/src/BizHawk.Client.Common/movie/import/bkm/BkmHeader.cs +++ b/src/BizHawk.Client.Common/movie/import/bkm/BkmHeader.cs @@ -56,11 +56,11 @@ namespace BizHawk.Client.Common { Add(splitLine[0], splitLine[1]); } - else if (line.StartsWith("subtitle") || line.StartsWith("sub")) + else if (line.StartsWithOrdinal("subtitle") || line.StartsWithOrdinal("sub")) { Subtitles.AddFromString(line); } - else if (line.StartsWith("comment")) + else if (line.StartsWithOrdinal("comment")) { Comments.Add(line.Substring(8, line.Length - 8)); } diff --git a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs index 20199cb1c3..f3101ab9e8 100644 --- a/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs +++ b/src/BizHawk.Client.Common/movie/tasproj/TasMovie.cs @@ -238,7 +238,7 @@ namespace BizHawk.Client.Common counter++; } - else if (line.StartsWith("Frame ")) + else if (line.StartsWithOrdinal("Frame ")) { var split = line.Split(' '); try @@ -251,7 +251,7 @@ namespace BizHawk.Client.Common return false; } } - else if (line.StartsWith("LogKey:")) + else if (line.StartsWithOrdinal("LogKey:")) { LogKey = line.Replace("LogKey:", ""); } @@ -327,7 +327,7 @@ namespace BizHawk.Client.Common if (_changes != value) { _changes = value; - OnPropertyChanged("Changes"); + OnPropertyChanged(nameof(Changes)); } } } diff --git a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchAddressComparer.cs b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchAddressComparer.cs index 81e1f826d1..f756fe269c 100644 --- a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchAddressComparer.cs +++ b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchAddressComparer.cs @@ -32,12 +32,12 @@ namespace BizHawk.Client.Common if (x.Address.Equals(y.Address)) { - if (x.Domain.Name.Equals(y.Domain.Name)) + if (x.Domain.Name.Equals(y.Domain.Name, System.StringComparison.Ordinal)) { return x.Size.CompareTo(y.Size); } - return x.Domain.Name.CompareTo(y.Domain.Name); + return string.CompareOrdinal(x.Domain.Name, y.Domain.Name); } return x.Address.CompareTo(y.Address); diff --git a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchDomainComparer.cs b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchDomainComparer.cs index fc27c28485..c8e9a02593 100644 --- a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchDomainComparer.cs +++ b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchDomainComparer.cs @@ -30,7 +30,7 @@ namespace BizHawk.Client.Common return 0; } - if (x.Domain.Name.Equals(y.Domain.Name)) + if (x.Domain.Name.Equals(y.Domain.Name, System.StringComparison.Ordinal)) { if (x.Address.Equals(y.Address)) { @@ -40,7 +40,7 @@ namespace BizHawk.Client.Common return x.Address.CompareTo(y.Address); } - return x.Domain.Name.CompareTo(y.Domain.Name); + return string.CompareOrdinal(x.Domain.Name, y.Domain.Name); } } } diff --git a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchNoteComparer.cs b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchNoteComparer.cs index f24cbe37f4..faf5353a6e 100644 --- a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchNoteComparer.cs +++ b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchNoteComparer.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; namespace BizHawk.Client.Common { @@ -31,7 +32,7 @@ namespace BizHawk.Client.Common return 0; } - if (string.Compare(x.Notes, y.Notes, true) == 0) + if (string.Compare(x.Notes, y.Notes, StringComparison.OrdinalIgnoreCase) == 0) { if (x.Address.Equals(y.Address)) { @@ -41,7 +42,7 @@ namespace BizHawk.Client.Common return x.Address.CompareTo(y.Address); } - return string.Compare(x.Notes, y.Notes, true); + return string.Compare(x.Notes, y.Notes, StringComparison.OrdinalIgnoreCase); } } } diff --git a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchValueDifferenceComparer.cs b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchValueDifferenceComparer.cs index 48ba01c61d..ceb6bd0d65 100644 --- a/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchValueDifferenceComparer.cs +++ b/src/BizHawk.Client.Common/tools/Watch/WatchList/WatchValueDifferenceComparer.cs @@ -30,7 +30,7 @@ namespace BizHawk.Client.Common return 0; } - if (x.Diff.Equals(y.Diff)) + if (x.Diff.Equals(y.Diff, System.StringComparison.Ordinal)) { if (x.Address.Equals(y.Address)) { @@ -40,7 +40,7 @@ namespace BizHawk.Client.Common return x.Address.CompareTo(y.Address); } - return x.Diff.CompareTo(y.Diff); + return string.CompareOrdinal(x.Diff, y.Diff); } } } diff --git a/src/BizHawk.Client.EmuHawk/AVOut/ImageSequenceWriter.cs b/src/BizHawk.Client.EmuHawk/AVOut/ImageSequenceWriter.cs index ec75c167a3..3139a7b802 100644 --- a/src/BizHawk.Client.EmuHawk/AVOut/ImageSequenceWriter.cs +++ b/src/BizHawk.Client.EmuHawk/AVOut/ImageSequenceWriter.cs @@ -50,11 +50,11 @@ namespace BizHawk.Client.EmuHawk var name = Path.Combine(dir!, $"{fileNoExt}_{_frame}{ext}"); BitmapBuffer bb = new BitmapBuffer(source.BufferWidth, source.BufferHeight, source.GetVideoBuffer()); using var bmp = bb.ToSysdrawingBitmap(); - if (ext.ToUpper() == ".PNG") + if (ext.ToUpperInvariant() == ".PNG") { bmp.Save(name, ImageFormat.Png); } - else if (ext.ToUpper() == ".JPG") + else if (ext.ToUpperInvariant() == ".JPG") { bmp.Save(name, ImageFormat.Jpeg); } diff --git a/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs b/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs index bd23341e73..b14a7e2d8a 100644 --- a/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs +++ b/src/BizHawk.Client.EmuHawk/AVOut/JMDWriter.cs @@ -602,7 +602,7 @@ namespace BizHawk.Client.EmuHawk public void OpenFile(string baseName) { string ext = Path.GetExtension(baseName); - if (ext == null || ext.ToLower() != ".jmd") + if (ext == null || ext.ToLowerInvariant() != ".jmd") { baseName += ".jmd"; } diff --git a/src/BizHawk.Client.EmuHawk/AVOut/NumericTextBox.cs b/src/BizHawk.Client.EmuHawk/AVOut/NumericTextBox.cs index 16b23f05c0..83baf86af3 100644 --- a/src/BizHawk.Client.EmuHawk/AVOut/NumericTextBox.cs +++ b/src/BizHawk.Client.EmuHawk/AVOut/NumericTextBox.cs @@ -23,15 +23,15 @@ namespace BizHawk.Client.EmuHawk { // Digits are OK } - else if (keyInput.Equals(decimalSeparator) && AllowDecimal) + else if (keyInput.Equals(decimalSeparator, System.StringComparison.Ordinal) && AllowDecimal) { // Decimal separator is OK } - else if (keyInput.Equals(negativeSign) && AllowNegative) + else if (keyInput.Equals(negativeSign, System.StringComparison.Ordinal) && AllowNegative) { // Negative is OK } - else if (keyInput.Equals(groupSeparator)) + else if (keyInput.Equals(groupSeparator, System.StringComparison.Ordinal)) { // group separator is ok } diff --git a/src/BizHawk.Client.EmuHawk/ArchiveChooser.cs b/src/BizHawk.Client.EmuHawk/ArchiveChooser.cs index 9ef09281c6..ba04e1a64c 100644 --- a/src/BizHawk.Client.EmuHawk/ArchiveChooser.cs +++ b/src/BizHawk.Client.EmuHawk/ArchiveChooser.cs @@ -35,7 +35,7 @@ namespace BizHawk.Client.EmuHawk lvi.Text = item.Name; long size = item.Size; var extension = Path.GetExtension(item.Name); - if (extension != null && size % 1024 == 16 && extension.ToUpper() == ".NES") + if (extension != null && size % 1024 == 16 && extension.ToUpperInvariant() == ".NES") size -= 16; lvi.SubItems[1].Text = Util.FormatFileSize(size); _archiveItems.Add(lvi); @@ -206,7 +206,7 @@ namespace BizHawk.Client.EmuHawk public string[] Keys { get; set; } public bool Matches(ListViewItem value) { - string searchedStr = value.Text.ToLower(); + string searchedStr = value.Text.ToLowerInvariant(); foreach (string key in Keys) { if (!searchedStr.Contains(key)) @@ -234,7 +234,7 @@ namespace BizHawk.Client.EmuHawk { return new SimpleMatcher { - Keys = searchKey.ToLower().Split(Array.Empty(), StringSplitOptions.RemoveEmptyEntries) // splits on all whitespace chars + Keys = searchKey.ToLowerInvariant().Split(Array.Empty(), StringSplitOptions.RemoveEmptyEntries) // splits on all whitespace chars }; } else diff --git a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/Cell.cs b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/Cell.cs index d5984006c8..7d850c28c1 100644 --- a/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/Cell.cs +++ b/src/BizHawk.Client.EmuHawk/CustomControls/InputRoll/Cell.cs @@ -71,7 +71,7 @@ namespace BizHawk.Client.EmuHawk { int row = c1.RowIndex.Value.CompareTo(c2.RowIndex.Value); return row == 0 - ? string.Compare(c1.Column?.Name, c2.Column?.Name) + ? string.CompareOrdinal(c1.Column?.Name, c2.Column?.Name) : row; } @@ -83,7 +83,7 @@ namespace BizHawk.Client.EmuHawk return -1; } - return c1.Column.Name.CompareTo(c2.Column.Name); + return string.CompareOrdinal(c1.Column.Name, c2.Column.Name); } } diff --git a/src/BizHawk.Client.EmuHawk/EmuHawkUtil.cs b/src/BizHawk.Client.EmuHawk/EmuHawkUtil.cs index 2e9c6088ec..9137c484d0 100644 --- a/src/BizHawk.Client.EmuHawk/EmuHawkUtil.cs +++ b/src/BizHawk.Client.EmuHawk/EmuHawkUtil.cs @@ -15,7 +15,7 @@ namespace BizHawk.Client.EmuHawk /// http://stackoverflow.com/questions/139010/how-to-resolve-a-lnk-in-c-sharp public static string ResolveShortcut(string filename) { - if (filename.Contains("|") || OSTailoredCode.IsUnixHost || !".lnk".Equals(Path.GetExtension(filename), StringComparison.InvariantCultureIgnoreCase)) return filename; // archive internal files are never shortcuts (and choke when analyzing any further) + if (filename.Contains("|") || OSTailoredCode.IsUnixHost || !".lnk".Equals(Path.GetExtension(filename), StringComparison.OrdinalIgnoreCase)) return filename; // archive internal files are never shortcuts (and choke when analyzing any further) var link = new ShellLinkImports.ShellLink(); const uint STGM_READ = 0; ((ShellLinkImports.IPersistFile) link).Load(filename, STGM_READ); diff --git a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs index 74d86322a9..5de92d5308 100644 --- a/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs +++ b/src/BizHawk.Client.EmuHawk/Extensions/ControlExtensions.cs @@ -250,7 +250,7 @@ namespace BizHawk.Client.EmuHawk initFileName: $"{game.FilesystemSafeName()}-{suffix}"); if (result is null) return; FileInfo file = new(result); - string extension = file.Extension.ToUpper(); + string extension = file.Extension.ToUpperInvariant(); ImageFormat i = extension switch { ".BMP" => ImageFormat.Bmp, diff --git a/src/BizHawk.Client.EmuHawk/MainForm.cs b/src/BizHawk.Client.EmuHawk/MainForm.cs index 98da8daac5..925fca98be 100644 --- a/src/BizHawk.Client.EmuHawk/MainForm.cs +++ b/src/BizHawk.Client.EmuHawk/MainForm.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Drawing; using System.Drawing.Imaging; +using System.Globalization; using System.IO; using System.Linq; using System.Reflection; @@ -1109,7 +1110,7 @@ namespace BizHawk.Client.EmuHawk { if (ie.LogicalButton.Button.Length == 1) { - var c = ie.LogicalButton.Button.ToLower()[0]; + var c = ie.LogicalButton.Button.ToLowerInvariant()[0]; if ((c >= 'a' && c <= 'z') || c == ' ') { SendAltKeyChar(c); @@ -1308,7 +1309,7 @@ namespace BizHawk.Client.EmuHawk using (var bb = Config.ScreenshotCaptureOsd ? CaptureOSD() : MakeScreenshotImage()) { using var img = bb.ToSysdrawingBitmap(); - if (Path.GetExtension(path).ToUpper() == ".JPG") + if (Path.GetExtension(path).ToUpperInvariant() == ".JPG") { img.Save(fi.FullName, ImageFormat.Jpeg); } @@ -2448,7 +2449,8 @@ namespace BizHawk.Client.EmuHawk BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance, null, MainformMenu, - new object/*?*/[] { c }); + new object/*?*/[] { c }, + CultureInfo.InvariantCulture); public static readonly FilesystemFilterSet ConfigFileFSFilterSet = new(new FilesystemFilter("Config File", new[] { "ini" })) { diff --git a/src/BizHawk.Client.EmuHawk/PlatformChooser.cs b/src/BizHawk.Client.EmuHawk/PlatformChooser.cs index d755208f46..92aa384cf4 100644 --- a/src/BizHawk.Client.EmuHawk/PlatformChooser.cs +++ b/src/BizHawk.Client.EmuHawk/PlatformChooser.cs @@ -32,7 +32,7 @@ namespace BizHawk.Client.EmuHawk ? $"{RomGame.RomData.Length / 1024 / 1024:n0}mb" : $"{RomGame.RomData.Length / 1024:n0}kb"; - ExtensionLabel.Text = RomGame.Extension.ToLower(); + ExtensionLabel.Text = RomGame.Extension.ToLowerInvariant(); HashBox.Text = RomGame.GameInfo.Hash; int count = 0; int spacing = 25; @@ -67,7 +67,7 @@ namespace BizHawk.Client.EmuHawk if (AlwaysCheckbox.Checked) { - _config.PreferredPlatformsForExtensions[RomGame.Extension.ToLower()] = PlatformChoice; + _config.PreferredPlatformsForExtensions[RomGame.Extension.ToLowerInvariant()] = PlatformChoice; } Close(); diff --git a/src/BizHawk.Client.EmuHawk/RetroAchievements/RAIntegration.Update.cs b/src/BizHawk.Client.EmuHawk/RetroAchievements/RAIntegration.Update.cs index d9d778a93f..79fc6dfd3b 100644 --- a/src/BizHawk.Client.EmuHawk/RetroAchievements/RAIntegration.Update.cs +++ b/src/BizHawk.Client.EmuHawk/RetroAchievements/RAIntegration.Update.cs @@ -7,6 +7,7 @@ using Newtonsoft.Json; using BizHawk.BizInvoke; using BizHawk.Common; using BizHawk.Client.Common; +using BizHawk.Common.StringExtensions; namespace BizHawk.Client.EmuHawk { @@ -46,7 +47,7 @@ namespace BizHawk.Client.EmuHawk private static bool DownloadDll(string url) { - if (url.StartsWith("http:")) + if (url.StartsWithOrdinal("http:")) { // force https url = url.Replace("http:", "https:"); diff --git a/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.GameVerification.cs b/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.GameVerification.cs index d3b4e1dac5..42e5a2c49c 100644 --- a/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.GameVerification.cs +++ b/src/BizHawk.Client.EmuHawk/RetroAchievements/RetroAchievements.GameVerification.cs @@ -108,7 +108,7 @@ namespace BizHawk.Client.EmuHawk exePath = Encoding.ASCII.GetString(buf2048); // "BOOT = cdrom:" precedes the path - var index = exePath.IndexOf("BOOT = cdrom:"); + var index = exePath.IndexOf("BOOT = cdrom:", StringComparison.Ordinal); if (index < -1) break; exePath = exePath.Remove(0, index + 13); diff --git a/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs b/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs index 7a35c1b07e..c1d4832e03 100644 --- a/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/FirmwaresConfig.cs @@ -113,7 +113,7 @@ namespace BizHawk.Client.EmuHawk { var lva = (ListViewItem)a; var lvb = (ListViewItem)b; - return Sign * string.Compare(lva.SubItems[Column].Text, lvb.SubItems[Column].Text); + return Sign * string.CompareOrdinal(lva.SubItems[Column].Text, lvb.SubItems[Column].Text); } } diff --git a/src/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs b/src/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs index 4ac71f7dad..3ea5af69f5 100644 --- a/src/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs +++ b/src/BizHawk.Client.EmuHawk/config/HotkeyConfig.cs @@ -203,7 +203,7 @@ namespace BizHawk.Client.EmuHawk { if (e.IsPressed(Keys.Enter) || e.IsPressed(Keys.Tab)) { - var k = HotkeyInfo.AllHotkeys.FirstOrNull(kvp => string.Compare(kvp.Value.DisplayName, SearchBox.Text, true) is 0)?.Key; + var k = HotkeyInfo.AllHotkeys.FirstOrNull(kvp => string.Compare(kvp.Value.DisplayName, SearchBox.Text, StringComparison.OrdinalIgnoreCase) is 0)?.Key; // Found if (k is not null) diff --git a/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs b/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs index cbe9545338..a1ab8b52cc 100644 --- a/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs +++ b/src/BizHawk.Client.EmuHawk/movie/PlayMovie.cs @@ -210,7 +210,7 @@ namespace BizHawk.Client.EmuHawk { foreach (var ext in MovieService.MovieExtensions) { - if ($".{ext}".Equals(Path.GetExtension(_movieList[indices[i]].Filename), StringComparison.InvariantCultureIgnoreCase)) + if ($".{ext}".Equals(Path.GetExtension(_movieList[indices[i]].Filename), StringComparison.OrdinalIgnoreCase)) { tas.Add(i); } diff --git a/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs b/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs index 6108fc4511..89d1f6b666 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Debugger/BreakpointControl.cs @@ -6,6 +6,7 @@ using System.Windows.Forms; using BizHawk.Client.Common; using BizHawk.Client.EmuHawk.Properties; using BizHawk.Common.NumberExtensions; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Client.EmuHawk @@ -64,7 +65,7 @@ namespace BizHawk.Client.EmuHawk { BreakpointCallback(addr, value, flags); - var seekBreakpoint = _breakpoints.FirstOrDefault(x => x.Name.StartsWith(SeekName)); + var seekBreakpoint = _breakpoints.FirstOrDefault(x => x.Name.StartsWithOrdinal(SeekName)); if (seekBreakpoint != null) { @@ -166,7 +167,7 @@ namespace BizHawk.Client.EmuHawk public void RemoveCurrentSeek() { - var seekBreakpoint = _breakpoints.FirstOrDefault(x => x.Name.StartsWith(SeekName)); + var seekBreakpoint = _breakpoints.FirstOrDefault(x => x.Name.StartsWithOrdinal(SeekName)); if (seekBreakpoint != null) { diff --git a/src/BizHawk.Client.EmuHawk/tools/GameShark.cs b/src/BizHawk.Client.EmuHawk/tools/GameShark.cs index 171419b71a..8505337727 100644 --- a/src/BizHawk.Client.EmuHawk/tools/GameShark.cs +++ b/src/BizHawk.Client.EmuHawk/tools/GameShark.cs @@ -44,7 +44,7 @@ namespace BizHawk.Client.EmuHawk { try { - var code = l.ToUpper().Trim(); + var code = l.ToUpperInvariant().Trim(); var decoder = new GameSharkDecoder(MemoryDomains, Emulator.SystemId); var result = decoder.Decode(code); var domain = decoder.CheatDomain(); @@ -82,4 +82,4 @@ namespace BizHawk.Client.EmuHawk } } } -} \ No newline at end of file +} diff --git a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs index e8c9bea0bd..75a80c03b9 100644 --- a/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs +++ b/src/BizHawk.Client.EmuHawk/tools/HexEditor/HexEditor.cs @@ -281,7 +281,7 @@ namespace BizHawk.Client.EmuHawk { long found = -1; - var search = value.Replace(" ", "").ToUpper(); + var search = value.Replace(" ", "").ToUpperInvariant(); if (string.IsNullOrEmpty(search)) { return; @@ -341,7 +341,7 @@ namespace BizHawk.Client.EmuHawk { long found = -1; - var search = value.Replace(" ", "").ToUpper(); + var search = value.Replace(" ", "").ToUpperInvariant(); if (string.IsNullOrEmpty(search)) { return; diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs index 15ffb6508c..2e44ba1124 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/Libraries/FormsLuaLibrary.cs @@ -1456,7 +1456,7 @@ namespace BizHawk.Client.EmuHawk textbox.Multiline = multiline; if (scrollbars != null) { - switch (scrollbars.ToUpper()) + switch (scrollbars.ToUpperInvariant()) { case "VERTICAL": textbox.ScrollBars = ScrollBars.Vertical; @@ -1489,7 +1489,7 @@ namespace BizHawk.Client.EmuHawk if (boxtype != null) { - switch (boxtype.ToUpper()) + switch (boxtype.ToUpperInvariant()) { case "HEX": case "HEXADECIMAL": diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs index 6cb9ee25ac..c269c3ed27 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaConsole.cs @@ -14,6 +14,7 @@ using BizHawk.Client.EmuHawk.ToolExtensions; using BizHawk.Common; using BizHawk.Common.CollectionExtensions; using BizHawk.Common.PathExtensions; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Client.EmuHawk @@ -446,7 +447,7 @@ namespace BizHawk.Client.EmuHawk private string DressUpRelative(string path) { - return path.StartsWith(".\\") ? path.Replace(".\\", "") : path; + return path.StartsWithOrdinal(".\\") ? path.Replace(".\\", "") : path; } private void UpdateNumberOfScripts() @@ -1267,12 +1268,12 @@ namespace BizHawk.Client.EmuHawk { foreach (var path in filePaths) { - if (Path.GetExtension(path)?.ToLower() == ".lua" || Path.GetExtension(path)?.ToLower() == ".txt") + if (Path.GetExtension(path)?.ToLowerInvariant() == ".lua" || Path.GetExtension(path)?.ToLowerInvariant() == ".txt") { LoadLuaFile(path); UpdateDialog(); } - else if (Path.GetExtension(path)?.ToLower() == ".luases") + else if (Path.GetExtension(path)?.ToLowerInvariant() == ".luases") { LoadLuaSession(path); return; diff --git a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs index c1f5fef621..91e7118690 100644 --- a/src/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs +++ b/src/BizHawk.Client.EmuHawk/tools/Lua/LuaPictureBox.cs @@ -283,7 +283,7 @@ namespace BizHawk.Client.EmuHawk var fStyle = FontStyle.Regular; if (fontStyle != null) { - switch (fontStyle.ToLower()) + switch (fontStyle.ToLowerInvariant()) { default: case "regular": @@ -311,7 +311,7 @@ namespace BizHawk.Client.EmuHawk if (horizAlign != null) { - switch (horizAlign.ToLower()) + switch (horizAlign.ToLowerInvariant()) { default: case "left": @@ -328,7 +328,7 @@ namespace BizHawk.Client.EmuHawk if (vertAlign != null) { - switch (vertAlign.ToLower()) + switch (vertAlign.ToLowerInvariant()) { default: case "top": diff --git a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs index 5a848c22c1..9ea13ecaeb 100644 --- a/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs +++ b/src/BizHawk.Client.EmuHawk/tools/MultiDiskBundler/MultiDiskBundler.cs @@ -62,7 +62,7 @@ namespace BizHawk.Client.EmuHawk AddButton_Click(null, null); AddButton_Click(null, null); - if (!Game.IsNullInstance() && !MainForm.CurrentlyOpenRom.EndsWith(".xml")) + if (!Game.IsNullInstance() && !MainForm.CurrentlyOpenRom.EndsWithOrdinal(".xml")) { if (MainForm.CurrentlyOpenRom.Contains("|")) { diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs index 94db383cd9..e5d170c6b9 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.MenuItems.cs @@ -99,12 +99,12 @@ namespace BizHawk.Client.EmuHawk public bool LoadMovieFile(string filename, bool askToSave = true) { if (askToSave && !AskSaveChanges()) return false; - if (filename.EndsWith(MovieService.TasMovieExtension)) + if (filename.EndsWithOrdinal(MovieService.TasMovieExtension)) { LoadFileWithFallback(filename); return true; //TODO should this return false if it fell back to a new project? } - if (filename.EndsWith(MovieService.StandardMovieExtension)) + if (filename.EndsWithOrdinal(MovieService.StandardMovieExtension)) { if (!DialogController.ShowMessageBox2( caption: "Convert movie", @@ -1209,7 +1209,7 @@ namespace BizHawk.Client.EmuHawk int workingHeight = Screen.FromControl(this).WorkingArea.Height; int rowHeight = ColumnsSubMenu.Height + 4; int maxRows = workingHeight / rowHeight; - int keyCount = columns.Count(c => c.Name.StartsWith("Key ")); + int keyCount = columns.Count(c => c.Name.StartsWithOrdinal("Key ")); int keysMenusCount = (int)Math.Ceiling((double)keyCount / maxRows); var keysMenus = new ToolStripMenuItem[keysMenusCount]; @@ -1248,7 +1248,7 @@ namespace BizHawk.Client.EmuHawk ((ToolStripMenuItem)sender.OwnerItem).ShowDropDown(); }; - if (column.Name.StartsWith("Key ")) + if (column.Name.StartsWithOrdinal("Key ")) { keysMenus .First(m => m.DropDownItems.Count < maxRows) diff --git a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs index 710cbf84b1..46e8e49169 100644 --- a/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs +++ b/src/BizHawk.Client.EmuHawk/tools/TAStudio/TAStudio.cs @@ -9,6 +9,7 @@ using BizHawk.Client.Common; using BizHawk.Client.EmuHawk.ToolExtensions; using BizHawk.Client.EmuHawk.Properties; using BizHawk.Common; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Nintendo.N64; @@ -383,29 +384,29 @@ namespace BizHawk.Client.EmuHawk || c.Name == "Light Sensor" || c.Name == "Disc Select" || c.Name == "Disk Index" - || c.Name.StartsWith("Tilt") - || c.Name.StartsWith("Key ") - || c.Name.StartsWith("Open") - || c.Name.StartsWith("Close") - || c.Name.EndsWith("Tape") - || c.Name.EndsWith("Disk") - || c.Name.EndsWith("Block") - || c.Name.EndsWith("Status")); + || c.Name.StartsWithOrdinal("Tilt") + || c.Name.StartsWithOrdinal("Key ") + || c.Name.StartsWithOrdinal("Open") + || c.Name.StartsWithOrdinal("Close") + || c.Name.EndsWithOrdinal("Tape") + || c.Name.EndsWithOrdinal("Disk") + || c.Name.EndsWithOrdinal("Block") + || c.Name.EndsWithOrdinal("Status")); if (Emulator.SystemId is VSystemID.Raw.N64) { foreach (var c in TasView.AllColumns - .Where(static c => c.Name.EndsWith(" C Up") || c.Name.EndsWith(" C Down") - || c.Name.EndsWith(" C Left") || c.Name.EndsWith(" C Right"))) + .Where(static c => c.Name.EndsWithOrdinal(" C Up") || c.Name.EndsWithOrdinal(" C Down") + || c.Name.EndsWithOrdinal(" C Left") || c.Name.EndsWithOrdinal(" C Right"))) { c.Text = $"c{c.Text.ToUpperInvariant()}"; // prepend 'c' to differentiate from L/R buttons -- only affects table header } var fakeAnalogControls = TasView.AllColumns .Where(c => - c.Name.EndsWith("A Up") - || c.Name.EndsWith("A Down") - || c.Name.EndsWith("A Left") - || c.Name.EndsWith("A Right")); + c.Name.EndsWithOrdinal("A Up") + || c.Name.EndsWithOrdinal("A Down") + || c.Name.EndsWithOrdinal("A Left") + || c.Name.EndsWithOrdinal("A Right")); columnsToHide = columnsToHide.Concat(fakeAnalogControls); } diff --git a/src/BizHawk.Common/Extensions/PathExtensions.cs b/src/BizHawk.Common/Extensions/PathExtensions.cs index 2f47cdee2c..c00bcbef2d 100644 --- a/src/BizHawk.Common/Extensions/PathExtensions.cs +++ b/src/BizHawk.Common/Extensions/PathExtensions.cs @@ -14,14 +14,14 @@ namespace BizHawk.Common.PathExtensions public static bool IsSubfolderOf(this string? childPath, string? parentPath) { if (childPath == null || parentPath == null) return false; - if (childPath == parentPath || childPath.StartsWith($"{parentPath}{Path.DirectorySeparatorChar}")) return true; + if (childPath == parentPath || childPath.StartsWithOrdinal($"{parentPath}{Path.DirectorySeparatorChar}")) return true; if (OSTailoredCode.IsUnixHost) { #if true var c = OSTailoredCode.SimpleSubshell("realpath", $"-Lm \"{childPath}\"", $"invalid path {childPath} or missing realpath binary"); var p = OSTailoredCode.SimpleSubshell("realpath", $"-Lm \"{parentPath}\"", $"invalid path {parentPath} or missing realpath binary"); - return c == p || c.StartsWith($"{p}/"); + return c == p || c.StartsWithOrdinal($"{p}/"); #else // written for Unix port but may be useful for Windows when moving to .NET Core var parentUriPath = new Uri(parentPath.TrimEnd('.')).AbsolutePath.TrimEnd('/'); try @@ -72,7 +72,7 @@ namespace BizHawk.Common.PathExtensions if (OSTailoredCode.IsUnixHost) { var realpathOutput = OSTailoredCode.SimpleSubshell("realpath", $"--relative-to=\"{fromPath}\" \"{toPath}\"", $"invalid path {toPath}, invalid path {fromPath}, or missing realpath binary"); - return !realpathOutput.StartsWith("../") && realpathOutput != "." && realpathOutput != ".." ? $"./{realpathOutput}" : realpathOutput; + return !realpathOutput.StartsWithOrdinal("../") && realpathOutput != "." && realpathOutput != ".." ? $"./{realpathOutput}" : realpathOutput; } //TODO merge this with the Windows implementation in MakeRelativeTo @@ -97,14 +97,14 @@ namespace BizHawk.Common.PathExtensions { if (path.IsAbsolute()) return path; - else - { - // FileInfo for normalisation ("C:\a\b\..\c" => "C:\a\c") - var mycwd = cwd ?? (OSTailoredCode.IsUnixHost ? Environment.CurrentDirectory : CWDHacks.Get()); - var finalpath = $"{mycwd}/{path}"; - var fi = new FileInfo(finalpath); - return fi.FullName; - } + else + { + // FileInfo for normalisation ("C:\a\b\..\c" => "C:\a\c") + var mycwd = cwd ?? (OSTailoredCode.IsUnixHost ? Environment.CurrentDirectory : CWDHacks.Get()); + var finalpath = $"{mycwd}/{path}"; + var fi = new FileInfo(finalpath); + return fi.FullName; + } } /// the absolute path equivalent to which contains %exe% (expanded) as a prefix @@ -126,7 +126,7 @@ namespace BizHawk.Common.PathExtensions if (!OSTailoredCode.IsUnixHost) return absolutePath.Replace(basePath, ".").RemoveSuffix(Path.DirectorySeparatorChar); #if true // Unix implementation using realpath var realpathOutput = OSTailoredCode.SimpleSubshell("realpath", $"--relative-base=\"{basePath}\" \"{absolutePath}\"", $"invalid path {absolutePath}, invalid path {basePath}, or missing realpath binary"); - return !realpathOutput.StartsWith("../") && realpathOutput != "." && realpathOutput != ".." ? $"./{realpathOutput}" : realpathOutput; + return !realpathOutput.StartsWithOrdinal("../") && realpathOutput != "." && realpathOutput != ".." ? $"./{realpathOutput}" : realpathOutput; #else // for some reason there were two Unix implementations in the codebase before me? --yoshi // alt. #1 if (!IsSubfolder(basePath, absolutePath)) return OSTailoredCode.IsUnixHost && basePath.TrimEnd('.') == $"{absolutePath}/" ? "." : absolutePath; diff --git a/src/BizHawk.Common/Extensions/StringExtensions.cs b/src/BizHawk.Common/Extensions/StringExtensions.cs index 0bc604e122..ec78797793 100644 --- a/src/BizHawk.Common/Extensions/StringExtensions.cs +++ b/src/BizHawk.Common/Extensions/StringExtensions.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Runtime.CompilerServices; @@ -20,7 +21,7 @@ namespace BizHawk.Common.StringExtensions /// if appears in (case-insensitive) /// public static bool In(this string str, params string[] options) => - options.Any(opt => string.Equals(opt, str, StringComparison.InvariantCultureIgnoreCase)); + options.Any(opt => string.Equals(opt, str, StringComparison.OrdinalIgnoreCase)); /// /// with the first char removed, or @@ -88,7 +89,7 @@ namespace BizHawk.Common.StringExtensions /// public static string SubstringAfter(this string str, string delimiter, string notFoundValue) { - var index = str.IndexOf(delimiter); + var index = str.IndexOf(delimiter, StringComparison.Ordinal); return index < 0 ? notFoundValue : str.Substring(index + delimiter.Length, str.Length - index - delimiter.Length); } @@ -147,7 +148,7 @@ namespace BizHawk.Common.StringExtensions /// public static string? SubstringBeforeOrNull(this string str, string delimiter) { - var index = str.IndexOf(delimiter); + var index = str.IndexOf(delimiter, StringComparison.Ordinal); return index < 0 ? null : str.Substring(0, index); } @@ -165,5 +166,9 @@ namespace BizHawk.Common.StringExtensions /// "abc,def,ghi".TransformFields(',', s => s.Reverse()) == "cba,fed,ihg" public static string TransformFields(this string str, char delimiter, Func transform) => string.Join(delimiter.ToString(), str.Split(delimiter).Select(transform)); + + public static bool StartsWithOrdinal(this string str, string value) => str.StartsWith(value, StringComparison.Ordinal); + + public static bool EndsWithOrdinal(this string str, string value) => str.EndsWith(value, StringComparison.Ordinal); } } diff --git a/src/BizHawk.Common/HawkFile/HawkFile.cs b/src/BizHawk.Common/HawkFile/HawkFile.cs index 3c15b49dfc..d6a6a793c7 100644 --- a/src/BizHawk.Common/HawkFile/HawkFile.cs +++ b/src/BizHawk.Common/HawkFile/HawkFile.cs @@ -142,7 +142,7 @@ namespace BizHawk.Common } for (int i = 0, l = scanResults.Count; i < l; i++) { - if (string.Equals(scanResults[i].Name, autobind, StringComparison.InvariantCultureIgnoreCase)) + if (string.Equals(scanResults[i].Name, autobind, StringComparison.OrdinalIgnoreCase)) { BindArchiveMember(i); return; diff --git a/src/BizHawk.Common/PropertyGridConverters/DescribableEnumConverter.cs b/src/BizHawk.Common/PropertyGridConverters/DescribableEnumConverter.cs index a763eb8b73..463e4d6385 100644 --- a/src/BizHawk.Common/PropertyGridConverters/DescribableEnumConverter.cs +++ b/src/BizHawk.Common/PropertyGridConverters/DescribableEnumConverter.cs @@ -26,7 +26,7 @@ namespace BizHawk.Common return Enum.Parse( enumType, enumType.GetFields(BindingFlags.Public | BindingFlags.Static) - .FirstOrDefault(fi => valueStr.Equals((fi.GetCustomAttribute(typeof(DisplayAttribute)) as DisplayAttribute)?.Name))?.Name + .FirstOrDefault(fi => valueStr.Equals((fi.GetCustomAttribute(typeof(DisplayAttribute)) as DisplayAttribute)?.Name, StringComparison.Ordinal))?.Name ?? valueStr ); } diff --git a/src/BizHawk.Common/TempFileManager.cs b/src/BizHawk.Common/TempFileManager.cs index 9a0e585b1f..2beb37408a 100644 --- a/src/BizHawk.Common/TempFileManager.cs +++ b/src/BizHawk.Common/TempFileManager.cs @@ -34,7 +34,7 @@ namespace BizHawk.Common { var (dir, filename) = path.SplitPathToDirAndFile(); _ = dir ?? throw new InvalidOperationException(); - if (!filename.StartsWith("biz-")) + if (!filename.StartsWith("biz-", StringComparison.Ordinal)) { throw new InvalidOperationException(); } @@ -128,4 +128,4 @@ namespace BizHawk.Common Environment.SetEnvironmentVariable("TEMP", path); } } -} \ No newline at end of file +} diff --git a/src/BizHawk.Common/Util.cs b/src/BizHawk.Common/Util.cs index 2f0d24d490..39b8a2f9a6 100644 --- a/src/BizHawk.Common/Util.cs +++ b/src/BizHawk.Common/Util.cs @@ -108,7 +108,7 @@ namespace BizHawk.Common /// all Types with the name /// adapted from https://stackoverflow.com/a/13727044/7467292 public static IList GetTypeByName(string className) => AppDomain.CurrentDomain.GetAssemblies() - .SelectMany(asm => asm.GetTypesWithoutLoadErrors().Where(type => className.Equals(type.Name, StringComparison.InvariantCultureIgnoreCase))).ToList(); + .SelectMany(asm => asm.GetTypesWithoutLoadErrors().Where(type => className.Equals(type.Name, StringComparison.OrdinalIgnoreCase))).ToList(); /// TODO replace this with GetTypes (i.e. the try block) when VB.NET dep is properly removed public static IEnumerable GetTypesWithoutLoadErrors(this Assembly assembly) diff --git a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs index ad86188165..c69a735fe8 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/ControllerDefinition.cs @@ -8,6 +8,7 @@ using System.Text.RegularExpressions; using BizHawk.Common; using BizHawk.Common.CollectionExtensions; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Common { @@ -147,7 +148,7 @@ namespace BizHawk.Emulation.Common } // Hack for things like gameboy/ti-83 as opposed to genesis with no controllers plugged in - return allNames.Exists(static b => b.StartsWith("Up")) ? 1 : 0; + return allNames.Exists(static b => b.StartsWithOrdinal("Up")) ? 1 : 0; } } diff --git a/src/BizHawk.Emulation.Common/Base Implementations/LinkedDebuggable.cs b/src/BizHawk.Emulation.Common/Base Implementations/LinkedDebuggable.cs index d6dde3a173..8182008bce 100644 --- a/src/BizHawk.Emulation.Common/Base Implementations/LinkedDebuggable.cs +++ b/src/BizHawk.Emulation.Common/Base Implementations/LinkedDebuggable.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Common { @@ -37,7 +38,7 @@ namespace BizHawk.Emulation.Common { for (int i = 0; i < _numCores; i++) { - if (register.StartsWith($"P{i + 1} ")) + if (register.StartsWithOrdinal($"P{i + 1} ")) { _linkedCores[i].AsDebuggable().SetCpuRegister(register.Replace($"P{i + 1} ", ""), value); } diff --git a/src/BizHawk.Emulation.Common/DSKIdentifier.cs b/src/BizHawk.Emulation.Common/DSKIdentifier.cs index 98176c4796..153eae1396 100644 --- a/src/BizHawk.Emulation.Common/DSKIdentifier.cs +++ b/src/BizHawk.Emulation.Common/DSKIdentifier.cs @@ -3,6 +3,7 @@ using System; using System.Linq; using System.Text; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Common { @@ -40,7 +41,7 @@ namespace BizHawk.Emulation.Common private void ParseDskImage() { - string ident = Encoding.ASCII.GetString(_data, 0, 16).ToUpper(); + string ident = Encoding.ASCII.GetString(_data, 0, 16).ToUpperInvariant(); if (ident.Contains("MV - CPC")) { ParseDsk(); @@ -81,8 +82,8 @@ namespace BizHawk.Emulation.Common if (s.SectorData == null || s.SectorData.Length == 0) continue; - string str = Encoding.ASCII.GetString(s.SectorData, 0, s.SectorData.Length).ToUpper(); - if (str.Contains("PLUS3DOS")) + string str = Encoding.ASCII.GetString(s.SectorData, 0, s.SectorData.Length); + if (str.Contains("PLUS3DOS", StringComparison.OrdinalIgnoreCase)) { IdentifiedSystem = VSystemID.Raw.ZXSpectrum; return; diff --git a/src/BizHawk.Emulation.Common/Database/Database.cs b/src/BizHawk.Emulation.Common/Database/Database.cs index 55ede880b3..585c30a05e 100644 --- a/src/BizHawk.Emulation.Common/Database/Database.cs +++ b/src/BizHawk.Emulation.Common/Database/Database.cs @@ -423,7 +423,7 @@ namespace BizHawk.Emulation.Common // If filename is all-caps, then attempt to proper-case the title. if (!string.IsNullOrWhiteSpace(game.Name) && game.Name == game.Name.ToUpperInvariant()) { - game.Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(game.Name.ToLower()); + game.Name = Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(game.Name.ToLowerInvariant()); } return game; diff --git a/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs b/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs index f825f4d3b5..52e2ad6dcb 100644 --- a/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs +++ b/src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.cs @@ -47,17 +47,17 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME text + (text == "" ? "" : "\r\n") + string.Join("\r\n", _romHashes.Select(static r => $"{r.Value} - {r.Key}")); - if (text.ToLower().Contains("imperfect")) + if (text.Contains("imperfect", StringComparison.OrdinalIgnoreCase)) { lp.Game.Status = RomStatus.Imperfect; } - if (text.ToLower().Contains("unemulated")) + if (text.Contains("unemulated", StringComparison.OrdinalIgnoreCase)) { lp.Game.Status = RomStatus.Unimplemented; } - if (text.ToLower().Contains("doesn't work")) + if (text.Contains("doesn't work", StringComparison.OrdinalIgnoreCase)) { lp.Game.Status = RomStatus.NotWorking; } @@ -94,7 +94,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME var hashes = string.Concat(_romHashes.Values .Where(static s => s.Contains("SHA:")) .Select(static s => s.Split(' ') - .First(static s => s.StartsWith("SHA:")) + .First(static s => s.StartsWithOrdinal("SHA:")) .RemovePrefix("SHA:"))); lp.Game.Name = _gameFullName; diff --git a/src/BizHawk.Emulation.Cores/CPUs/FairchildF8/F3850.Disassembler.cs b/src/BizHawk.Emulation.Cores/CPUs/FairchildF8/F3850.Disassembler.cs index 985ad532ed..8b4ad69ed7 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/FairchildF8/F3850.Disassembler.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/FairchildF8/F3850.Disassembler.cs @@ -15,17 +15,17 @@ namespace BizHawk.Emulation.Cores.Components.FairchildF8 //n immediate succeeds the opcode and the displacement (if present) //nn immediately succeeds the opcode and the displacement (if present) - if (format.IndexOf("nn") != -1) + if (format.IndexOf("nn", StringComparison.Ordinal) != -1) { format = format.Replace("nn", read(addr++) .ToString("X2") + read(addr++) .ToString("X2") + "h"); // MSB is read first } - if (format.IndexOf("n") != -1) format = format.Replace("n", $"{read(addr++):X2}h"); + if (format.IndexOf("n", StringComparison.Ordinal) != -1) format = format.Replace("n", $"{read(addr++):X2}h"); - if (format.IndexOf("+d") != -1) format = format.Replace("+d", "d"); - if (format.IndexOf("d") != -1) + if (format.IndexOf("+d", StringComparison.Ordinal) != -1) format = format.Replace("+d", "d"); + if (format.IndexOf("d", StringComparison.Ordinal) != -1) { var b = unchecked((sbyte)read(addr++)); format = format.Replace("d", $"{(b < 0 ? '-' : '+')}{(b < 0 ? -b : b):X2}h"); diff --git a/src/BizHawk.Emulation.Cores/CPUs/FairchildF8/F3850.Registers.cs b/src/BizHawk.Emulation.Cores/CPUs/FairchildF8/F3850.Registers.cs index a695e1c847..f5b0deeca0 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/FairchildF8/F3850.Registers.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/FairchildF8/F3850.Registers.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Components.FairchildF8 @@ -274,7 +275,7 @@ namespace BizHawk.Emulation.Cores.Components.FairchildF8 public void SetCpuRegister(string register, int value) { - if (register.StartsWith("SPR")) + if (register.StartsWithOrdinal("SPR")) { var reg = Convert.ToInt32(register.Replace("SPR", "")); diff --git a/src/BizHawk.Emulation.Cores/CPUs/HuC6280/Execute.cs b/src/BizHawk.Emulation.Cores/CPUs/HuC6280/Execute.cs index 9b24d0735d..9806634fbb 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/HuC6280/Execute.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/HuC6280/Execute.cs @@ -1,4 +1,5 @@ using System; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; // Do not modify this file directly! This is GENERATED code. @@ -2339,7 +2340,7 @@ namespace BizHawk.Emulation.Cores.Components.H6280 case 0xF4: // SET int a; // TODO remove these extra checks string b = Disassemble(PC, out a); - if (b.StartsWith("ADC") == false && b.StartsWith("EOR") == false && b.StartsWith("AND") == false && b.StartsWith("ORA") == false) + if (b.StartsWithOrdinal("ADC") == false && b.StartsWithOrdinal("EOR") == false && b.StartsWithOrdinal("AND") == false && b.StartsWithOrdinal("ORA") == false) Console.WriteLine("SETTING T FLAG, NEXT INSTRUCTION IS UNHANDLED: {0}", b); FlagT = true; PendingCycles -= 2; diff --git a/src/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs b/src/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs index 0c39a2be33..56b9416026 100644 --- a/src/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs +++ b/src/BizHawk.Emulation.Cores/CPUs/Z80A/NewDisassembler.cs @@ -13,11 +13,11 @@ namespace BizHawk.Emulation.Cores.Components.Z80A //n immediate succeeds the opcode and the displacement (if present) //nn immediately succeeds the opcode and the displacement (if present) - if (format.IndexOf("nn") != -1) format = format.Replace("nn", $"{read(addr++) + (read(addr++) << 8):X4}h"); // LSB is read first - if (format.IndexOf("n") != -1) format = format.Replace("n", $"{read(addr++):X2}h"); + if (format.IndexOf("nn", StringComparison.Ordinal) != -1) format = format.Replace("nn", $"{read(addr++) + (read(addr++) << 8):X4}h"); // LSB is read first + if (format.IndexOf("n", StringComparison.Ordinal) != -1) format = format.Replace("n", $"{read(addr++):X2}h"); - if (format.IndexOf("+d") != -1) format = format.Replace("+d", "d"); - if (format.IndexOf("d") != -1) + if (format.IndexOf("+d", StringComparison.Ordinal) != -1) format = format.Replace("+d", "d"); + if (format.IndexOf("d", StringComparison.Ordinal) != -1) { var b = unchecked ((sbyte) read(addr++)); format = format.Replace("d", $"{(b < 0 ? '-' : '+')}{(b < 0 ? -b : b):X2}h"); diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Input.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Input.cs index 421a51b8a0..d947398c1f 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Input.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Input.cs @@ -1,4 +1,6 @@ -namespace BizHawk.Emulation.Cores.Computers.AmstradCPC +using BizHawk.Common.StringExtensions; + +namespace BizHawk.Emulation.Cores.Computers.AmstradCPC { /// /// The abstract class that all emulated models will inherit from @@ -64,7 +66,7 @@ // non matrix keys (J2) foreach (string k in KeyboardDevice.NonMatrixKeys) { - if (!k.StartsWith("P2")) + if (!k.StartsWithOrdinal("P2")) continue; bool currState = CPC._controller.IsPressed(k); diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Media.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Media.cs index 1d091c2c30..02dc1620eb 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Media.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Machine/CPCBase.Media.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.AmstradCPC { @@ -232,7 +233,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC string hdr = Encoding.ASCII.GetString(data.Take(16).ToArray()); // disk checking first - if (hdr.ToUpper().Contains("EXTENDED CPC DSK") || hdr.ToUpper().Contains("MV - CPC")) + if (hdr.Contains("EXTENDED CPC DSK", StringComparison.OrdinalIgnoreCase) || hdr.Contains("MV - CPC", StringComparison.OrdinalIgnoreCase)) { // amstrad .dsk disk file // check for number of sides @@ -244,7 +245,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC } // tape checking - if (hdr.ToUpper().StartsWith("ZXTAPE!")) + if (hdr.StartsWith("ZXTAPE!", StringComparison.OrdinalIgnoreCase)) { // cdt tape file return CPCMediaType.Tape; @@ -263,4 +264,3 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC DiskDoubleSided } } - diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/CPCExtendedFloppyDisk.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/CPCExtendedFloppyDisk.cs index f045be5df5..3193db72be 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/CPCExtendedFloppyDisk.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/CPCExtendedFloppyDisk.cs @@ -2,6 +2,7 @@ using BizHawk.Common; using System; using System.Collections.Generic; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.AmstradCPC { @@ -27,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC // look for standard magic string string ident = Encoding.ASCII.GetString(data, 0, 16); - if (!ident.ToUpper().Contains("EXTENDED CPC DSK")) + if (!ident.Contains("EXTENDED CPC DSK", StringComparison.OrdinalIgnoreCase)) { // incorrect format return false; @@ -152,7 +153,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC { // look for standard magic string string ident = Encoding.ASCII.GetString(data, 0, 16); - if (!ident.ToUpper().Contains("EXTENDED CPC DSK")) + if (!ident.Contains("EXTENDED CPC DSK", StringComparison.OrdinalIgnoreCase)) { // incorrect format return false; diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/CPCFloppyDisk.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/CPCFloppyDisk.cs index 214c0fced0..43029789b4 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/CPCFloppyDisk.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/CPCFloppyDisk.cs @@ -2,6 +2,7 @@ using BizHawk.Common; using System.Collections.Generic; using System; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.AmstradCPC { @@ -27,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC // look for standard magic string string ident = Encoding.ASCII.GetString(data, 0, 16); - if (!ident.ToUpper().Contains("MV - CPC")) + if (!ident.Contains("MV - CPC", StringComparison.OrdinalIgnoreCase)) { // incorrect format return false; @@ -158,7 +159,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC { // look for standard magic string string ident = Encoding.ASCII.GetString(data, 0, 16); - if (!ident.ToUpper().Contains("MV - CPC")) + if (!ident.Contains("MV - CPC", StringComparison.OrdinalIgnoreCase)) { // incorrect format return false; diff --git a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/FloppyDisk.cs b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/FloppyDisk.cs index d4b4bf3f6a..539c907807 100644 --- a/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/FloppyDisk.cs +++ b/src/BizHawk.Emulation.Cores/Computers/AmstradCPC/Media/Disk/FloppyDisk.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.AmstradCPC { @@ -235,7 +236,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC // check for SPEEDLOCK ident in sector 0 string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[0].SectorData, 0, DiskTracks[0].Sectors[0].SectorData.Length); - if (!ident.ToUpper().Contains("SPEEDLOCK")) + if (!ident.Contains("SPEEDLOCK", StringComparison.OrdinalIgnoreCase)) return false; // check for correct sector 0 lengths @@ -297,7 +298,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC // check for ALKATRAZ ident in sector 0 string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[0].SectorData, 0, DiskTracks[0].Sectors[0].SectorData.Length); - if (!ident.ToUpper().Contains("ALKATRAZ PROTECTION SYSTEM")) + if (!ident.Contains("ALKATRAZ PROTECTION SYSTEM", StringComparison.OrdinalIgnoreCase)) return false; // ALKATRAZ NOTES (-asni 2018-05-01) @@ -338,7 +339,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC // check for PAUL OWENS ident in sector 2 string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[2].SectorData, 0, DiskTracks[0].Sectors[2].SectorData.Length); - if (!ident.ToUpper().Contains("PAUL OWENS")) + if (!ident.Contains("PAUL OWENS", StringComparison.OrdinalIgnoreCase)) return false; // Paul Owens Disk Protection Notes (-asni 2018-05-01) @@ -380,7 +381,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC // check for Hexagon ident in sector 8 string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[8].SectorData, 0, DiskTracks[0].Sectors[8].SectorData.Length); - if (ident.ToUpper().Contains("GON DISK PROT")) + if (ident.Contains("GON DISK PROT", StringComparison.OrdinalIgnoreCase)) return true; // hexagon protection may not be labelled as such diff --git a/src/BizHawk.Emulation.Cores/Computers/Commodore64/C64FormatFinder.cs b/src/BizHawk.Emulation.Cores/Computers/Commodore64/C64FormatFinder.cs index ac3df6e62f..9573e87371 100644 --- a/src/BizHawk.Emulation.Cores/Computers/Commodore64/C64FormatFinder.cs +++ b/src/BizHawk.Emulation.Cores/Computers/Commodore64/C64FormatFinder.cs @@ -1,5 +1,6 @@ using System.IO; using System.Text; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.Commodore64 { @@ -12,37 +13,36 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64 return C64Format.Unknown; } - using (var mem = new MemoryStream(data)) + using (var reader = new BinaryReader(new MemoryStream(data))) { - var reader = new BinaryReader(mem); var header = Encoding.GetEncoding(437).GetString(reader.ReadBytes(0x10)); - if (header.StartsWith("C64 CARTRIDGE ")) + if (header.StartsWithOrdinal("C64 CARTRIDGE ")) { return C64Format.CRT; } - if (header.StartsWith("GCR-1541")) + if (header.StartsWithOrdinal("GCR-1541")) { return C64Format.G64; } - if (header.StartsWith("C64S tape image ") || header.StartsWith("C64 tape image f")) + if (header.StartsWithOrdinal("C64S tape image ") || header.StartsWithOrdinal("C64 tape image f")) { return C64Format.T64; } - if (header.StartsWith("C64-TAPE-RAW")) + if (header.StartsWithOrdinal("C64-TAPE-RAW")) { return C64Format.TAP; } - if (header.StartsWith("C64File")) + if (header.StartsWithOrdinal("C64File")) { return C64Format.P00; // poo :) } - if (header.StartsWith("P64-1541")) + if (header.StartsWithOrdinal("P64-1541")) { return C64Format.P64; } diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs index 62b88532de..60a1730e8c 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Input.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { @@ -66,7 +67,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // non matrix keys foreach (string k in KeyboardDevice.NonMatrixKeys) { - if (!k.StartsWith("Key")) + if (!k.StartsWithOrdinal("Key")) continue; bool currState = Spectrum._controller.IsPressed(k); @@ -337,4 +338,3 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum } } } - diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs index a39b02a0e3..61cfe4295f 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Machine/SpectrumBase.Media.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { @@ -245,7 +246,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum string hdr = Encoding.ASCII.GetString(data.Take(16).ToArray()); // disk checking first - if (hdr.ToUpper().Contains("EXTENDED CPC DSK") || hdr.ToUpper().Contains("MV - CPC")) + if (hdr.Contains("EXTENDED CPC DSK", StringComparison.OrdinalIgnoreCase) || hdr.Contains("MV - CPC", StringComparison.OrdinalIgnoreCase)) { // spectrum .dsk disk file // check for number of sides @@ -255,20 +256,20 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum else return SpectrumMediaType.DiskDoubleSided; } - if (hdr.ToUpper().StartsWith("FDI")) + if (hdr.StartsWith("FDI", StringComparison.OrdinalIgnoreCase)) { // spectrum .fdi disk file return SpectrumMediaType.Disk; } - if (hdr.ToUpper().StartsWith("CAPS")) + if (hdr.StartsWith("CAPS", StringComparison.OrdinalIgnoreCase)) { // IPF format file return SpectrumMediaType.Disk; } - if (hdr.ToUpper().StartsWith("UDI!") && data[0x08] == 0) + if (hdr.StartsWith("UDI!", StringComparison.OrdinalIgnoreCase) && data[0x08] == 0) { // UDI v1.0 - if (hdr.StartsWith("udi!")) + if (hdr.StartsWithOrdinal("udi!")) { throw new NotSupportedException("ZXHawk currently does not supported UDIv1.0 with compression."); } @@ -282,22 +283,22 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum } // tape checking - if (hdr.ToUpper().StartsWith("ZXTAPE!")) + if (hdr.StartsWith("ZXTAPE!", StringComparison.OrdinalIgnoreCase)) { // spectrum .tzx tape file return SpectrumMediaType.Tape; } - if (hdr.ToUpper().StartsWith("PZXT")) + if (hdr.StartsWith("PZXT", StringComparison.OrdinalIgnoreCase)) { // spectrum .tzx tape file return SpectrumMediaType.Tape; } - if (hdr.ToUpper().StartsWith("COMPRESSED SQ")) + if (hdr.StartsWith("COMPRESSED SQ", StringComparison.OrdinalIgnoreCase)) { // spectrum .tzx tape file return SpectrumMediaType.Tape; } - if (hdr.ToUpper().Contains("WAVE")) + if (hdr.Contains("WAVE", StringComparison.OrdinalIgnoreCase)) { // spectrum .tzx tape file return SpectrumMediaType.Tape; diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/CPCFormat/CPCExtendedFloppyDisk.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/CPCFormat/CPCExtendedFloppyDisk.cs index 3407d88e16..da3b4446b7 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/CPCFormat/CPCExtendedFloppyDisk.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/CPCFormat/CPCExtendedFloppyDisk.cs @@ -2,6 +2,7 @@ using BizHawk.Common; using System; using System.Collections.Generic; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { @@ -27,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // look for standard magic string string ident = Encoding.ASCII.GetString(data, 0, 16); - if (!ident.ToUpper().Contains("EXTENDED CPC DSK")) + if (!ident.Contains("EXTENDED CPC DSK", StringComparison.OrdinalIgnoreCase)) { // incorrect format return false; @@ -163,7 +164,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { // look for standard magic string string ident = Encoding.ASCII.GetString(data, 0, 16); - if (!ident.ToUpper().Contains("EXTENDED CPC DSK")) + if (!ident.Contains("EXTENDED CPC DSK", StringComparison.OrdinalIgnoreCase)) { // incorrect format return false; diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/CPCFormat/CPCFloppyDisk.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/CPCFormat/CPCFloppyDisk.cs index c9acb48fe4..a78ed1515f 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/CPCFormat/CPCFloppyDisk.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/CPCFormat/CPCFloppyDisk.cs @@ -2,6 +2,7 @@ using BizHawk.Common; using System; using System.Collections.Generic; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { @@ -27,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // look for standard magic string string ident = Encoding.ASCII.GetString(data, 0, 16); - if (!ident.ToUpper().Contains("MV - CPC")) + if (!ident.Contains("MV - CPC", StringComparison.OrdinalIgnoreCase)) { // incorrect format return false; @@ -168,7 +169,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { // look for standard magic string string ident = Encoding.ASCII.GetString(data, 0, 16); - if (!ident.ToUpper().Contains("MV - CPC")) + if (!ident.Contains("MV - CPC", StringComparison.OrdinalIgnoreCase)) { // incorrect format return false; diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs index a94f1e6e9c..a0a9ca1e41 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/FloppyDisk.cs @@ -3,6 +3,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { @@ -235,7 +236,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // check for SPEEDLOCK ident in sector 0 string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[0].SectorData, 0, DiskTracks[0].Sectors[0].SectorData.Length); - if (!ident.ToUpper().Contains("SPEEDLOCK")) + if (!ident.Contains("SPEEDLOCK", StringComparison.OrdinalIgnoreCase)) return false; // check for correct sector 0 lengths @@ -297,7 +298,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // check for ALKATRAZ ident in sector 0 string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[0].SectorData, 0, DiskTracks[0].Sectors[0].SectorData.Length); - if (!ident.ToUpper().Contains("ALKATRAZ PROTECTION SYSTEM")) + if (!ident.Contains("ALKATRAZ PROTECTION SYSTEM", StringComparison.OrdinalIgnoreCase)) return false; // ALKATRAZ NOTES (-asni 2018-05-01) @@ -338,7 +339,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // check for PAUL OWENS ident in sector 2 string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[2].SectorData, 0, DiskTracks[0].Sectors[2].SectorData.Length); - if (!ident.ToUpper().Contains("PAUL OWENS")) + if (!ident.Contains("PAUL OWENS", StringComparison.OrdinalIgnoreCase)) return false; // Paul Owens Disk Protection Notes (-asni 2018-05-01) @@ -380,7 +381,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // check for Hexagon ident in sector 8 string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[8].SectorData, 0, DiskTracks[0].Sectors[8].SectorData.Length); - if (ident.ToUpper().Contains("GON DISK PROT")) + if (ident.Contains("GON DISK PROT", StringComparison.OrdinalIgnoreCase)) return true; // hexagon protection may not be labelled as such diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/IPFFormat/IPFFloppyDisk.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/IPFFormat/IPFFloppyDisk.cs index fa80538db6..4bd90bd437 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/IPFFormat/IPFFloppyDisk.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/IPFFormat/IPFFloppyDisk.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Text; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { @@ -26,7 +27,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // look for standard magic string string ident = Encoding.ASCII.GetString(data, 0, 16); - if (!ident.ToUpper().Contains("CAPS")) + if (!ident.Contains("CAPS", StringComparison.OrdinalIgnoreCase)) { // incorrect format return false; diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/UDIFormat/UDI1_0FloppyDisk.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/UDIFormat/UDI1_0FloppyDisk.cs index 547a92c595..232435898b 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/UDIFormat/UDI1_0FloppyDisk.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Disk/UDIFormat/UDI1_0FloppyDisk.cs @@ -4,6 +4,7 @@ using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum { @@ -26,7 +27,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // look for standard magic string string ident = Encoding.ASCII.GetString(data, 0, 4); - if (!ident.StartsWith("UDI!") && !ident.StartsWith("udi!")) + if (!ident.StartsWithOrdinal("UDI!") && !ident.StartsWithOrdinal("udi!")) { // incorrect format return false; @@ -83,7 +84,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // look for standard magic string string ident = Encoding.ASCII.GetString(data, 0, 4); - if (!ident.StartsWith("UDI!") && !ident.StartsWith("udi!")) + if (!ident.StartsWithOrdinal("UDI!") && !ident.StartsWithOrdinal("udi!")) { // incorrect format return false; diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/CSW/CswConverter.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/CSW/CswConverter.cs index a9dff3ce7e..86c0643e2a 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/CSW/CswConverter.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/CSW/CswConverter.cs @@ -57,7 +57,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum int majorVer = data[8]; int minorVer = data[9]; - if (ident.ToUpper() != "COMPRESSED SQUARE WAVE") + if (ident.ToUpperInvariant() != "COMPRESSED SQUARE WAVE") { // this is not a valid CSW format file return false; @@ -80,7 +80,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // (first 22 bytes of the file) string ident = Encoding.ASCII.GetString(data, 0, 22); - if (ident.ToUpper() != "COMPRESSED SQUARE WAVE") + if (ident.ToUpperInvariant() != "COMPRESSED SQUARE WAVE") { // this is not a valid CSW format file throw new Exception($"{nameof(CswConverter)}: This is not a valid CSW format file"); diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs index 37c3333207..5393316afb 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/PZX/PzxConverter.cs @@ -67,7 +67,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum int majorVer = data[8]; int minorVer = data[9]; - if (ident.ToUpper() != "PZXT") + if (ident.ToUpperInvariant() != "PZXT") { // this is not a valid PZX format file return false; @@ -96,7 +96,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // check whether this is a valid pzx format file by looking at the identifier in the header block string ident = Encoding.ASCII.GetString(data, 0, 4); - if (ident.ToUpper() != "PZXT") + if (ident.ToUpperInvariant() != "PZXT") { // this is not a valid TZX format file throw new Exception($"{nameof(PzxConverter)}: This is not a valid PZX format file"); diff --git a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/WAV/WavConverter.cs b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/WAV/WavConverter.cs index 9b9f8365fb..2b092d2897 100644 --- a/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/WAV/WavConverter.cs +++ b/src/BizHawk.Emulation.Cores/Computers/SinclairSpectrum/Media/Tape/WAV/WavConverter.cs @@ -52,7 +52,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // check whether this is a valid wav format file by looking at the identifier in the header string ident = Encoding.ASCII.GetString(data, 8, 4); - if (ident.ToUpper() != "WAVE") + if (ident.ToUpperInvariant() != "WAVE") { // this is not a valid WAV format file return false; @@ -74,7 +74,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum // check whether this is a valid pzx format file by looking at the identifier in the header block string ident = Encoding.ASCII.GetString(data, 8, 4); - if (ident.ToUpper() != "WAVE") + if (ident.ToUpperInvariant() != "WAVE") { // this is not a valid TZX format file throw new Exception($"{nameof(WavConverter)}: This is not a valid WAV format file"); diff --git a/src/BizHawk.Emulation.Cores/Computers/TIC80/TIC80.cs b/src/BizHawk.Emulation.Cores/Computers/TIC80/TIC80.cs index 224e3562c9..8bd6843335 100644 --- a/src/BizHawk.Emulation.Cores/Computers/TIC80/TIC80.cs +++ b/src/BizHawk.Emulation.Cores/Computers/TIC80/TIC80.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using BizHawk.Common; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Waterbox; @@ -119,7 +120,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80 foreach (var n in ret.BoolButtons) { - if (n.StartsWith("Mouse")) + if (n.StartsWithOrdinal("Mouse")) { ret.CategoryLabels[n] = "Mouse"; } @@ -127,7 +128,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80 foreach (var n in ret.Axes.Keys) { - if (n.StartsWith("Mouse")) + if (n.StartsWithOrdinal("Mouse")) { ret.CategoryLabels[n] = "Mouse"; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Atari/jaguar/VirtualJaguar.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Atari/jaguar/VirtualJaguar.IDebuggable.cs index 663a169136..3b80276e41 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Atari/jaguar/VirtualJaguar.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Atari/jaguar/VirtualJaguar.IDebuggable.cs @@ -45,14 +45,14 @@ namespace BizHawk.Emulation.Cores.Atari.Jaguar public void SetCpuRegister(string register, int value) { register = register.ToUpperInvariant(); - if (register.StartsWith("M68K ")) + if (register.StartsWithOrdinal("M68K ")) { var reg = Enum.Parse(typeof(LibVirtualJaguar.M68KRegisters), register.Remove(0, 5)); _core.SetRegister((int)reg, value); } - else if (register.StartsWith("GPU ") || register.StartsWith("DSP ")) + else if (register.StartsWithOrdinal("GPU ") || register.StartsWithOrdinal("DSP ")) { - bool gpu = register.StartsWith("GPU "); + bool gpu = register.StartsWithOrdinal("GPU "); var regName = register.Remove(0, 4); if (regName == "PC") diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs index 513cf2b0f6..20e40fb15f 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/BSNES/BsnesApi.cs @@ -8,6 +8,7 @@ using BizHawk.Emulation.Cores.Waterbox; using BizHawk.BizInvoke; using BizHawk.Emulation.Common; using System.Linq; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Nintendo.BSNES { @@ -284,12 +285,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.BSNES public void Seal() { exe.Seal(); - foreach (string s in _readonlyFiles.Where(s => !s.StartsWith("msu1/"))) + foreach (string s in _readonlyFiles.Where(s => !s.StartsWithOrdinal("msu1/"))) { exe.RemoveReadonlyFile(s); } - _readonlyFiles.RemoveAll(s => !s.StartsWith("msu1/")); + _readonlyFiles.RemoveAll(s => !s.StartsWithOrdinal("msu1/")); } // private int serializedSize; diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IDebuggable.cs index 4c1bfa1298..f09a6eb44c 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBA/MGBAHawk.IDebuggable.cs @@ -22,7 +22,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBA public void SetCpuRegister(string register, int value) { - int index = register?.ToUpper() switch + int index = register?.ToUpperInvariant() switch { "R0" => 0, "R1" => 1, diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IDebuggable.cs index 7a90684480..56e271f6cf 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink/GBHawkLink.IDebuggable.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink @@ -20,11 +21,11 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink public void SetCpuRegister(string register, int value) { - if (register.StartsWith("Left ")) + if (register.StartsWithOrdinal("Left ")) { L.SetCpuRegister(register.Replace("Left ", ""), value); } - else if (register.StartsWith("Right ")) + else if (register.StartsWithOrdinal("Right ")) { R.SetCpuRegister(register.Replace("Right ", ""), value); } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IDebuggable.cs index 4807ec60b0..e4e6efbbec 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink3x/GBHawkLink3x.IDebuggable.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x @@ -23,15 +24,15 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink3x public void SetCpuRegister(string register, int value) { - if (register.StartsWith("Left ")) + if (register.StartsWithOrdinal("Left ")) { L.SetCpuRegister(register.Replace("Left ", ""), value); } - else if (register.StartsWith("Center ")) + else if (register.StartsWithOrdinal("Center ")) { C.SetCpuRegister(register.Replace("Center ", ""), value); } - else if (register.StartsWith("Right ")) + else if (register.StartsWithOrdinal("Right ")) { R.SetCpuRegister(register.Replace("Right ", ""), value); } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IDebuggable.cs index 5b275e55f3..ca8081ef7d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/GBHawkLink4x/GBHawkLink4x.IDebuggable.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x @@ -26,19 +27,19 @@ namespace BizHawk.Emulation.Cores.Nintendo.GBHawkLink4x public void SetCpuRegister(string register, int value) { - if (register.StartsWith("A ")) + if (register.StartsWithOrdinal("A ")) { A.SetCpuRegister(register.Replace("A ", ""), value); } - else if (register.StartsWith("B ")) + else if (register.StartsWithOrdinal("B ")) { B.SetCpuRegister(register.Replace("B ", ""), value); } - else if (register.StartsWith("C ")) + else if (register.StartsWithOrdinal("C ")) { C.SetCpuRegister(register.Replace("C ", ""), value); } - else if (register.StartsWith("D ")) + else if (register.StartsWithOrdinal("D ")) { C.SetCpuRegister(register.Replace("D ", ""), value); } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/BootGodDB.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/BootGodDB.cs index 6fd6db068b..d1b772f8ea 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/BootGodDB.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/NES/BootGodDB.cs @@ -5,6 +5,7 @@ using System.IO; using System.Xml; using System.Threading; using BizHawk.Common; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Nintendo.NES { @@ -40,7 +41,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.NES private int ParseSize(string str) { int temp = 0; - if(validate) if (!str.EndsWith("k")) throw new Exception(); + if(validate) if (!str.EndsWithOrdinal("k")) throw new Exception(); int len = str.Length - 1; for (int i = 0; i < len; i++) { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs index b98715a4e9..f9548ef40c 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SNES/LibsnesCore.cs @@ -280,7 +280,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES // every rom requests msu1.rom... why? who knows. // also handle msu-1 pcm files here bool isMsu1Rom = hint == "msu1.rom"; - bool isMsu1Pcm = Path.GetExtension(hint).ToLower() == ".pcm"; + bool isMsu1Pcm = Path.GetExtension(hint).ToLowerInvariant() == ".pcm"; if (isMsu1Rom || isMsu1Pcm) { // well, check if we have an msu-1 xml @@ -362,12 +362,12 @@ namespace BizHawk.Emulation.Cores.Nintendo.SNES } else if (which == (uint)LibsnesApi.eTRACE.SMP) { - int idx = msg.IndexOf("YA:"); + int idx = msg.IndexOf("YA:", StringComparison.Ordinal); _tracer.Put(new(disassembly: msg.Substring(0, idx).TrimEnd(), registerInfo: msg.Substring(idx))); } else if (which == (uint)LibsnesApi.eTRACE.GB) { - int idx = msg.IndexOf("AF:"); + int idx = msg.IndexOf("AF:", StringComparison.Ordinal); _tracer.Put(new(disassembly: msg.Substring(0, idx).TrimEnd(), registerInfo: msg.Substring(idx))); } } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IDebuggable.cs index f242e71761..17fa17a5c1 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Nintendo/SameBoy/SameBoy.IDebuggable.cs @@ -29,7 +29,7 @@ namespace BizHawk.Emulation.Cores.Nintendo.Sameboy public void SetCpuRegister(string register, int value) { - LibSameboy.sameboy_setreg(SameboyState, register.ToUpper() switch + LibSameboy.sameboy_setreg(SameboyState, register.ToUpperInvariant() switch { "PC" => 0, "A" => 1, diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs index 9aac3847fa..adbdff3c3d 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/SMS/SMS.cs @@ -293,17 +293,17 @@ namespace BizHawk.Emulation.Cores.Sega.MasterSystem { if (gameRegion == null) return SmsSyncSettings.Regions.Export; - if (gameRegion.IndexOf("USA") >= 0) + if (gameRegion.IndexOf("USA", StringComparison.Ordinal) >= 0) return SmsSyncSettings.Regions.Export; - if (gameRegion.IndexOf("Europe") >= 0) + if (gameRegion.IndexOf("Europe", StringComparison.Ordinal) >= 0) return SmsSyncSettings.Regions.Export; - if (gameRegion.IndexOf("World") >= 0) + if (gameRegion.IndexOf("World", StringComparison.Ordinal) >= 0) return SmsSyncSettings.Regions.Export; - if (gameRegion.IndexOf("Brazil") >= 0) + if (gameRegion.IndexOf("Brazil", StringComparison.Ordinal) >= 0) return SmsSyncSettings.Regions.Export; - if (gameRegion.IndexOf("Australia") >= 0) + if (gameRegion.IndexOf("Australia", StringComparison.Ordinal) >= 0) return SmsSyncSettings.Regions.Export; - if (gameRegion.IndexOf("Korea") >= 0) + if (gameRegion.IndexOf("Korea", StringComparison.Ordinal) >= 0) return SmsSyncSettings.Regions.Korea; return SmsSyncSettings.Regions.Japan; } diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IDebuggable.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IDebuggable.cs index 9235960e4b..6647386c46 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IDebuggable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.IDebuggable.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Runtime.InteropServices; using BizHawk.Common; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx @@ -23,7 +24,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx // el hacko string name = Marshal.PtrToStringAnsi(regs[i].Name); byte size = 32; - if (name.Contains("68K SR") || name.StartsWith("Z80")) + if (name.Contains("68K SR") || name.StartsWithOrdinal("Z80")) size = 16; ret[name] = new RegisterValue((ulong)regs[i].Value, size); diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ITraceable.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ITraceable.cs index 50500d7e6a..3b87df9915 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ITraceable.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GPGX.ITraceable.cs @@ -1,5 +1,6 @@ using System.Text; using BizHawk.Common.NumberExtensions; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx @@ -25,7 +26,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx foreach (var r in regs) { - if (r.Key.StartsWith("M68K")) // drop Z80 regs until it has its own debugger/tracer + if (r.Key.StartsWithOrdinal("M68K")) // drop Z80 regs until it has its own debugger/tracer { if (r.Key != "M68K SP" && r.Key != "M68K ISP" && // copies of a7 r.Key != "M68K PC" && // already present in every line start diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GenDbgHlp.cs b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GenDbgHlp.cs index 0fc56a0c36..cfeec6d251 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GenDbgHlp.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sega/gpgx64/GenDbgHlp.cs @@ -4,6 +4,7 @@ using System.Runtime.InteropServices; using System.IO; using BizHawk.Common; +using BizHawk.Common.StringExtensions; namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx { @@ -167,7 +168,7 @@ namespace BizHawk.Emulation.Cores.Consoles.Sega.gpgx string[] ss = s.Split(','); if (ss.Length != 4) throw new Exception(); - if (!ss[1].StartsWith("0x")) + if (!ss[1].StartsWithOrdinal("0x")) throw new Exception(); Symbol ret = new Symbol { diff --git a/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Nymashock.cs b/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Nymashock.cs index 22612b2dc4..a83c3a4155 100644 --- a/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Nymashock.cs +++ b/src/BizHawk.Emulation.Cores/Consoles/Sony/PSX/Nymashock.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using BizHawk.Common; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Waterbox; @@ -17,8 +18,8 @@ namespace BizHawk.Emulation.Cores.Sony.PSX ref ControllerThunk thunk, int thunkWriteOffset) { - if (name.EndsWith(" Left Stick Up / Down") || name.EndsWith(" Left Stick Left / Right") - || name.EndsWith(" Right Stick Up / Down") || name.EndsWith(" Right Stick Left / Right")) + if (name.EndsWithOrdinal(" Left Stick Up / Down") || name.EndsWithOrdinal(" Left Stick Left / Right") + || name.EndsWithOrdinal(" Right Stick Up / Down") || name.EndsWithOrdinal(" Right Stick Left / Right")) { ret.AddAxis(name, 0.RangeTo(0xFF), 0x80, isReversed); thunk = (c, b) => diff --git a/src/BizHawk.Emulation.Cores/FileID.cs b/src/BizHawk.Emulation.Cores/FileID.cs index 4c2699a7ae..59a7746467 100644 --- a/src/BizHawk.Emulation.Cores/FileID.cs +++ b/src/BizHawk.Emulation.Cores/FileID.cs @@ -154,7 +154,7 @@ namespace BizHawk.Emulation.Cores string ext = p.Extension; if(ext != null) { - ext = ext.TrimStart('.').ToUpper(); + ext = ext.TrimStart('.').ToUpperInvariant(); job.Extension = ext; } diff --git a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs index 1a272af833..3feaf61454 100644 --- a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs +++ b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Controller.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using BizHawk.Common; +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; using NymaTypes; @@ -165,7 +166,7 @@ namespace BizHawk.Emulation.Cores.Waterbox switchPreviousFrame.Add(0); var names = data.Positions.Select(p => $"{name}: Set {p.Name}").ToArray(); - if (!input.Name.StartsWith("AF ") && !input.Name.EndsWith(" AF") && !input.Name.StartsWith("Autofire ")) // hack: don't support some devices + if (!input.Name.StartsWithOrdinal("AF ") && !input.Name.EndsWithOrdinal(" AF") && !input.Name.StartsWithOrdinal("Autofire ")) // hack: don't support some devices { foreach (var n in names) { diff --git a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Settings.ComponentModel.cs b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Settings.ComponentModel.cs index 49fc20db8b..54b996bf84 100644 --- a/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Settings.ComponentModel.cs +++ b/src/BizHawk.Emulation.Cores/Waterbox/NymaCore.Settings.ComponentModel.cs @@ -279,7 +279,7 @@ namespace BizHawk.Emulation.Cores.Waterbox } private static ulong Parse(string s) { - if (s.StartsWith("0x")) + if (s.StartsWith("0x", StringComparison.Ordinal)) { return ulong.Parse(s.Substring(2), NumberStyles.HexNumber); } diff --git a/src/BizHawk.Emulation.Cores/vpads_schemata/NesSchema.cs b/src/BizHawk.Emulation.Cores/vpads_schemata/NesSchema.cs index 77f29aa8bd..0673f65b8f 100644 --- a/src/BizHawk.Emulation.Cores/vpads_schemata/NesSchema.cs +++ b/src/BizHawk.Emulation.Cores/vpads_schemata/NesSchema.cs @@ -2,7 +2,7 @@ using System.Collections.Generic; using System.Drawing; using System.Linq; - +using BizHawk.Common.StringExtensions; using BizHawk.Emulation.Common; using BizHawk.Emulation.Cores.Nintendo.NES; using BizHawk.Emulation.Cores.Nintendo.SubNESHawk; @@ -25,13 +25,13 @@ namespace BizHawk.Emulation.Cores { ss = nesHawk.GetSyncSettings(); isFds = nesHawk.IsFDS; - fdsButtonCount = nesHawk.ControllerDefinition.BoolButtons.Count(b => b.StartsWith("FDS Insert ")); + fdsButtonCount = nesHawk.ControllerDefinition.BoolButtons.Count(b => b.StartsWithOrdinal("FDS Insert ")); } else if (core is SubNESHawk subNesHawk) { ss = subNesHawk.GetSyncSettings(); isFds = subNesHawk.IsFds; - fdsButtonCount = subNesHawk.ControllerDefinition.BoolButtons.Count(b => b.StartsWith("FDS Insert ")); + fdsButtonCount = subNesHawk.ControllerDefinition.BoolButtons.Count(b => b.StartsWithOrdinal("FDS Insert ")); } if (ss.Controls.Famicom) diff --git a/src/BizHawk.Emulation.DiscSystem/DiscDecoding.cs b/src/BizHawk.Emulation.DiscSystem/DiscDecoding.cs index bdd5003898..af214f7cba 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscDecoding.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscDecoding.cs @@ -36,14 +36,14 @@ namespace BizHawk.Emulation.DiscSystem //first, look for the file type we actually asked for foreach (var fi in fis) { - if (fi.FullName.ToUpper() == audioPath.ToUpper()) + if (string.Equals(fi.FullName, audioPath, StringComparison.OrdinalIgnoreCase)) if (CheckForAudio(fi.FullName)) return fi.FullName; } //then look for any other type foreach (var fi in fis) { - if (Path.GetFileNameWithoutExtension(fi.FullName).ToUpper() == basePath.ToUpper()) + if (string.Equals(Path.GetFileNameWithoutExtension(fi.FullName), basePath, StringComparison.OrdinalIgnoreCase)) { if (CheckForAudio(fi.FullName)) { diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CCD_format.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CCD_format.cs index dd578e34a1..b947327d2f 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CCD_format.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CCD_format.cs @@ -194,7 +194,7 @@ namespace BizHawk.Emulation.DiscSystem { currSection = new() { - Name = line.Trim('[', ']').ToUpper() + Name = line.Trim('[', ']').ToUpperInvariant() }; sections.Add(currSection); } @@ -205,7 +205,7 @@ namespace BizHawk.Emulation.DiscSystem var parts = line.Split('='); if (parts.Length != 2) throw new CCDParseException("Malformed or unexpected CCD format: parsing item into two parts"); - if (parts[0].ToUpper() == "FLAGS") + if (parts[0].ToUpperInvariant() == "FLAGS") { // flags are a space-separated collection of symbolic constants: // https://www.gnu.org/software/ccd2cue/manual/html_node/FLAGS-_0028Compact-Disc-fields_0029.html#FLAGS-_0028Compact-Disc-fields_0029 @@ -213,11 +213,11 @@ namespace BizHawk.Emulation.DiscSystem continue; } int val; - if (parts[1].StartsWith("0x") || parts[1].StartsWith("0X")) + if (parts[1].StartsWith("0x", StringComparison.OrdinalIgnoreCase)) val = int.Parse(parts[1].Substring(2), NumberStyles.HexNumber); else val = int.Parse(parts[1]); - currSection[parts[0].ToUpper()] = val; + currSection[parts[0].ToUpperInvariant()] = val; } } @@ -268,7 +268,7 @@ namespace BizHawk.Emulation.DiscSystem for (var i = 2; i < sections.Count; i++) { var section = sections[i]; - if (section.Name.StartsWith("SESSION")) + if (section.Name.StartsWithOrdinal("SESSION")) { var sesnum = int.Parse(section.Name.Split(' ')[1]); var session = new CCDSession(sesnum); @@ -278,7 +278,7 @@ namespace BizHawk.Emulation.DiscSystem session.PregapMode = section.FetchOrDefault(0, "PREGAPMODE"); session.PregapSubcode = section.FetchOrDefault(0, "PREGAPSUBC"); } - else if (section.Name.StartsWith("ENTRY")) + else if (section.Name.StartsWithOrdinal("ENTRY")) { var entryNum = int.Parse(section.Name.Split(' ')[1]); var entry = new CCDTocEntry(entryNum); @@ -305,7 +305,7 @@ namespace BizHawk.Emulation.DiscSystem if (new Timestamp(entry.PMin, entry.PSec, entry.PFrame).Sector != entry.PLBA + 150) throw new CCDParseException("Warning: inconsistency in CCD PLBA vs computed P MSF"); } - else if (section.Name.StartsWith("TRACK")) + else if (section.Name.StartsWithOrdinal("TRACK")) { var entryNum = int.Parse(section.Name.Split(' ')[1]); var track = new CCDTrack(entryNum); @@ -314,7 +314,7 @@ namespace BizHawk.Emulation.DiscSystem foreach (var (k, v) in section) { if (k == "MODE") track.Mode = v; - else if (k.StartsWith("INDEX")) track.Indexes[int.Parse(k.Split(' ')[1])] = v; + else if (k.StartsWithOrdinal("INDEX")) track.Indexes[int.Parse(k.Split(' ')[1])] = v; } } } @@ -640,4 +640,4 @@ namespace BizHawk.Emulation.DiscSystem return disc; } } -} \ No newline at end of file +} diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Parse.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Parse.cs index 39cab23779..6831187ed2 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Parse.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CUE_Parse.cs @@ -1,5 +1,6 @@ //TODO - object initialization syntax cleanup +using System; using System.Text.RegularExpressions; using System.IO; @@ -312,7 +313,7 @@ namespace BizHawk.Emulation.DiscSystem.CUE // cues don't support multiple sessions themselves, but it is common for rips to put SESSION # in REM fields // so, if we have such a REM, we'll check if the comment starts with SESSION, and interpret that as a session "command" var trimmed = comment.Trim(); - if (trimmed.ToUpperInvariant().StartsWith("SESSION ") && int.TryParse(trimmed.Substring(8), out var number) && number > 0) + if (trimmed.StartsWith("SESSION ", StringComparison.OrdinalIgnoreCase) && int.TryParse(trimmed.Substring(8), out var number) && number > 0) { OUT_CueFile.Commands.Add(new CUE_File.Command.SESSION(number)); break; @@ -393,4 +394,4 @@ namespace BizHawk.Emulation.DiscSystem.CUE LoadFromString(); } } -} \ No newline at end of file +} diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CueFileResolver.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CueFileResolver.cs index 4ec7ac10cd..e5b83baf6d 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CueFileResolver.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/CUE/CueFileResolver.cs @@ -1,3 +1,4 @@ +using System; using System.IO; using System.Collections.Generic; using System.Linq; @@ -107,14 +108,14 @@ namespace BizHawk.Emulation.DiscSystem.CUE var fragment = Path.GetFileNameWithoutExtension(fi.FullName); //match files with differing extensions - var cmp = string.Compare(fragment, targetFragment, !caseSensitive); + var cmp = string.Compare(fragment, targetFragment, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase); if (cmp != 0) //match files with another extension added on (likely to be mygame.bin.ecm) - cmp = string.Compare(fragment, targetFile, !caseSensitive); + cmp = string.Compare(fragment, targetFile, caseSensitive ? StringComparison.Ordinal : StringComparison.OrdinalIgnoreCase); if (cmp == 0) { //take care to add an exact match at the beginning - if (fi.FullName.ToLowerInvariant() == Path.Combine(baseDir, path).ToLowerInvariant()) + if (string.Equals(fi.FullName, Path.Combine(baseDir, path), StringComparison.OrdinalIgnoreCase)) results.Insert(0, fi.FileInfo); else results.Add(fi.FileInfo); @@ -124,4 +125,4 @@ namespace BizHawk.Emulation.DiscSystem.CUE return results.Select(fi => fi.FullName).ToList(); } } -} \ No newline at end of file +} diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/M3U_file.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/M3U_file.cs index 3c003a906c..c9cb887183 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/M3U_file.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/M3U_file.cs @@ -30,7 +30,7 @@ namespace BizHawk.Emulation.DiscSystem ext = true; continue; } - if (line.StartsWith("#EXTINF:")) + if (line.StartsWithOrdinal("#EXTINF:")) { //TODO - maybe we shouldn't be so harsh. should probably add parse options. if (!ext) continue; @@ -93,5 +93,3 @@ namespace BizHawk.Emulation.DiscSystem } } } - - diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs index 025858a569..74958d6a08 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs @@ -482,7 +482,7 @@ namespace BizHawk.Emulation.DiscSystem var (dir, fileNoExt, _) = aFile.MDSPath.SplitPathToDirFileAndExt(); if (f.FilenameOffset == 0 || - string.Compare(fileName, "*.mdf", StringComparison.InvariantCultureIgnoreCase) == 0) + string.Compare(fileName, "*.mdf", StringComparison.OrdinalIgnoreCase) == 0) { fileName = $@"{dir}\{fileNoExt}.mdf"; } @@ -955,4 +955,4 @@ namespace BizHawk.Emulation.DiscSystem return disc; } } -} \ No newline at end of file +} diff --git a/src/BizHawk.Emulation.DiscSystem/DiscIdentifier.cs b/src/BizHawk.Emulation.DiscSystem/DiscIdentifier.cs index 63d60956d3..80a14f51e8 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscIdentifier.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscIdentifier.cs @@ -4,7 +4,7 @@ using System.Linq; using System.Text; using BizHawk.Common; - +using BizHawk.Common.StringExtensions; using ISOParser; //disc type identification logic @@ -454,7 +454,7 @@ namespace BizHawk.Emulation.DiscSystem private bool SectorContains(string s, int lba = 0) { var data = ReadDataSectorCached(lba); - return data != null && Encoding.ASCII.GetString(data).ToLower().Contains(s.ToLower()); + return data != null && Encoding.ASCII.GetString(data).Contains(s, StringComparison.OrdinalIgnoreCase); } } -} \ No newline at end of file +}