bump AnalysisModeGlobalization to Recommended

fixes CA1304, CA1309, CA1310, CA1311

temporarily silences CA1305

reduce severity of CA2101
This commit is contained in:
Morilli 2023-06-08 18:42:50 +02:00 committed by Moritz Bender
parent 4c00ec54e7
commit 8e557b0b9d
125 changed files with 404 additions and 354 deletions

View File

@ -11,3 +11,7 @@ csharp_new_line_before_finally = true
csharp_indent_switch_labels = true csharp_indent_switch_labels = true
csharp_indent_case_contents = true csharp_indent_case_contents = true
csharp_indent_labels = one_less_than_current csharp_indent_labels = one_less_than_current
# Globalization rules
dotnet_diagnostic.CA1305.severity = silent
dotnet_diagnostic.CA2101.severity = suggestion

View File

@ -1,6 +1,7 @@
<Project> <Project>
<PropertyGroup> <PropertyGroup>
<AnalysisLevel>6</AnalysisLevel> <AnalysisLevel>6</AnalysisLevel>
<AnalysisModeGlobalization>Recommended</AnalysisModeGlobalization>
<CodeAnalysisRuleSet>$(MSBuildProjectDirectory)/../../Common.ruleset</CodeAnalysisRuleSet> <CodeAnalysisRuleSet>$(MSBuildProjectDirectory)/../../Common.ruleset</CodeAnalysisRuleSet>
<ContinuousIntegrationBuild Condition=" '$(GITLAB_CI)' != '' Or '$(APPVEYOR)' != '' ">true</ContinuousIntegrationBuild> <ContinuousIntegrationBuild Condition=" '$(GITLAB_CI)' != '' Or '$(APPVEYOR)' != '' ">true</ContinuousIntegrationBuild>
<EnableNETAnalyzers>true</EnableNETAnalyzers> <EnableNETAnalyzers>true</EnableNETAnalyzers>

View File

@ -48,7 +48,7 @@ namespace BizHawk.SrcGen.ReflectionCache
}; };
if (_namespace != null || syntaxNode is not NamespaceDeclarationSyntax syn) return; if (_namespace != null || syntaxNode is not NamespaceDeclarationSyntax syn) return;
var newNS = Ser(syn.Name); var newNS = Ser(syn.Name);
if (!newNS.StartsWith("BizHawk.")) return; if (!newNS.StartsWith("BizHawk.", StringComparison.Ordinal)) return;
_namespaces.Add(newNS); _namespaces.Add(newNS);
if (_namespaces.Count == SAMPLE_SIZE) _namespace = CalcNamespace(); if (_namespaces.Count == SAMPLE_SIZE) _namespace = CalcNamespace();
} }
@ -88,7 +88,7 @@ namespace {nSpace}
public static IEnumerable<string> EmbeddedResourceList(string extraPrefix) public static IEnumerable<string> EmbeddedResourceList(string extraPrefix)
{{ {{
var fullPrefix = EMBED_PREFIX + 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<string> EmbeddedResourceList() public static IEnumerable<string> EmbeddedResourceList()

View File

@ -160,17 +160,17 @@ namespace BizHawk.Client.Common
} }
public readonly ref struct LuaAutoUnlockHack public readonly ref struct LuaAutoUnlockHack
{ {
private readonly GuiApi _guiApi; private readonly GuiApi _guiApi;
internal LuaAutoUnlockHack(GuiApi guiApi) internal LuaAutoUnlockHack(GuiApi guiApi)
=> _guiApi = guiApi; => _guiApi = guiApi;
public void Dispose() public void Dispose()
{ {
_guiApi.UnlockSurface(DisplaySurfaceID.EmuCore); _guiApi.UnlockSurface(DisplaySurfaceID.EmuCore);
_guiApi.UnlockSurface(DisplaySurfaceID.Client); _guiApi.UnlockSurface(DisplaySurfaceID.Client);
} }
} }
public LuaAutoUnlockHack ThisIsTheLuaAutoUnlockHack() public LuaAutoUnlockHack ThisIsTheLuaAutoUnlockHack()
@ -491,7 +491,7 @@ namespace BizHawk.Client.Common
{ {
var family = fontfamily != null ? new FontFamily(fontfamily) : FontFamily.GenericMonospace; var family = fontfamily != null ? new FontFamily(fontfamily) : FontFamily.GenericMonospace;
var fstyle = fontstyle?.ToLower() switch var fstyle = fontstyle?.ToLowerInvariant() switch
{ {
"bold" => FontStyle.Bold, "bold" => FontStyle.Bold,
"italic" => FontStyle.Italic, "italic" => FontStyle.Italic,
@ -507,7 +507,7 @@ namespace BizHawk.Client.Common
var font = new Font(family, fontsize ?? 12, fstyle, GraphicsUnit.Pixel); var font = new Font(family, fontsize ?? 12, fstyle, GraphicsUnit.Pixel);
var sizeOfText = g.MeasureString(message, font, 0, new StringFormat(StringFormat.GenericDefault)).ToSize(); var sizeOfText = g.MeasureString(message, font, 0, new StringFormat(StringFormat.GenericDefault)).ToSize();
switch (horizalign?.ToLower()) switch (horizalign?.ToLowerInvariant())
{ {
default: default:
case "left": case "left":
@ -521,7 +521,7 @@ namespace BizHawk.Client.Common
break; break;
} }
switch (vertalign?.ToLower()) switch (vertalign?.ToLowerInvariant())
{ {
default: default:
case "top": case "top":
@ -644,4 +644,4 @@ namespace BizHawk.Client.Common
foreach (var brush in _pens.Values) brush.Dispose(); foreach (var brush in _pens.Values) brush.Dispose();
} }
} }
} }

View File

@ -98,7 +98,7 @@ namespace BizHawk.Client.Common
public int Length() => _movieSession.Movie.FrameCount; 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 = "") public bool PlayFromStart(string path = "")
{ {

View File

@ -7,6 +7,7 @@ using System.IO;
using System.Net.Sockets; using System.Net.Sockets;
using BizHawk.Common.CollectionExtensions; using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
@ -59,28 +60,28 @@ namespace BizHawk.Client.Common
continue; continue;
} }
var argDowncased = arg.ToLower(); var argDowncased = arg.ToLowerInvariant();
if (argDowncased.StartsWith("--load-slot=")) if (argDowncased.StartsWithOrdinal("--load-slot="))
{ {
cmdLoadSlot = argDowncased.Substring(argDowncased.IndexOf('=') + 1); cmdLoadSlot = argDowncased.Substring(argDowncased.IndexOf('=') + 1);
} }
else if (argDowncased.StartsWith("--load-state=")) else if (argDowncased.StartsWithOrdinal("--load-state="))
{ {
cmdLoadState = arg.Substring(arg.IndexOf('=') + 1); cmdLoadState = arg.Substring(arg.IndexOf('=') + 1);
} }
else if (argDowncased.StartsWith("--config=")) else if (argDowncased.StartsWithOrdinal("--config="))
{ {
cmdConfigFile = arg.Substring(arg.IndexOf('=') + 1); cmdConfigFile = arg.Substring(arg.IndexOf('=') + 1);
} }
else if (argDowncased.StartsWith("--movie=")) else if (argDowncased.StartsWithOrdinal("--movie="))
{ {
cmdMovie = arg.Substring(arg.IndexOf('=') + 1); cmdMovie = arg.Substring(arg.IndexOf('=') + 1);
} }
else if (argDowncased.StartsWith("--dump-type=")) else if (argDowncased.StartsWithOrdinal("--dump-type="))
{ {
cmdDumpType = argDowncased.Substring(argDowncased.IndexOf('=') + 1); 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 list = argDowncased.Substring(argDowncased.IndexOf('=') + 1);
string[] items = list.Split(','); string[] items = list.Split(',');
@ -93,78 +94,78 @@ namespace BizHawk.Client.Common
// automatically set dump length to maximum frame // automatically set dump length to maximum frame
autoDumpLength = currAviWriterFrameList.Order().Last(); autoDumpLength = currAviWriterFrameList.Order().Last();
} }
else if (argDowncased.StartsWith("--version")) else if (argDowncased.StartsWithOrdinal("--version"))
{ {
printVersion = true; printVersion = true;
} }
else if (argDowncased.StartsWith("--dump-name=")) else if (argDowncased.StartsWithOrdinal("--dump-name="))
{ {
cmdDumpName = arg.Substring(arg.IndexOf('=') + 1); 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; var len = int.TryParse(argDowncased.Substring(argDowncased.IndexOf('=') + 1), out var i1) ? i1 : default;
autoDumpLength = len; autoDumpLength = len;
} }
else if (argDowncased.StartsWith("--dump-close")) else if (argDowncased.StartsWithOrdinal("--dump-close"))
{ {
autoCloseOnDump = true; autoCloseOnDump = true;
} }
else if (argDowncased.StartsWith("--chromeless")) else if (argDowncased.StartsWithOrdinal("--chromeless"))
{ {
// chrome is never shown, even in windowed mode // chrome is never shown, even in windowed mode
chromeless = true; chromeless = true;
} }
else if (argDowncased.StartsWith("--fullscreen")) else if (argDowncased.StartsWithOrdinal("--fullscreen"))
{ {
startFullscreen = true; startFullscreen = true;
} }
else if (argDowncased.StartsWith("--lua=")) else if (argDowncased.StartsWithOrdinal("--lua="))
{ {
luaScript = arg.Substring(arg.IndexOf('=') + 1); luaScript = arg.Substring(arg.IndexOf('=') + 1);
luaConsole = true; luaConsole = true;
} }
else if (argDowncased.StartsWith("--luaconsole")) else if (argDowncased.StartsWithOrdinal("--luaconsole"))
{ {
luaConsole = true; 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; var port = int.TryParse(argDowncased.Substring(argDowncased.IndexOf('=') + 1), out var i1) ? i1 : default;
if (port > 0) socketPort = port; if (port > 0) socketPort = port;
} }
else if (argDowncased.StartsWith("--socket_ip=")) else if (argDowncased.StartsWithOrdinal("--socket_ip="))
{ {
socketIP = argDowncased.Substring(argDowncased.IndexOf('=') + 1); socketIP = argDowncased.Substring(argDowncased.IndexOf('=') + 1);
} }
else if (argDowncased.StartsWith("--socket_udp")) else if (argDowncased.StartsWithOrdinal("--socket_udp"))
{ {
socketProtocol = ProtocolType.Udp; socketProtocol = ProtocolType.Udp;
} }
else if (argDowncased.StartsWith("--mmf=")) else if (argDowncased.StartsWithOrdinal("--mmf="))
{ {
mmfFilename = arg.Substring(arg.IndexOf('=') + 1); mmfFilename = arg.Substring(arg.IndexOf('=') + 1);
} }
else if (argDowncased.StartsWith("--url_get=")) else if (argDowncased.StartsWithOrdinal("--url_get="))
{ {
urlGet = arg.Substring(arg.IndexOf('=') + 1); urlGet = arg.Substring(arg.IndexOf('=') + 1);
} }
else if (argDowncased.StartsWith("--url_post=")) else if (argDowncased.StartsWithOrdinal("--url_post="))
{ {
urlPost = arg.Substring(arg.IndexOf('=') + 1); urlPost = arg.Substring(arg.IndexOf('=') + 1);
} }
else if (argDowncased.StartsWith("--audiosync=")) else if (argDowncased.StartsWithOrdinal("--audiosync="))
{ {
audiosync = argDowncased.Substring(argDowncased.IndexOf('=') + 1) == "true"; 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: // the first ext. tool from ExternalToolManager.ToolStripMenu which satisfies both of these will be opened:
// - available (no load errors, correct system/rom, etc.) // - available (no load errors, correct system/rom, etc.)
// - dll path matches given string; or dll filename matches given string with or without `.dll` // - dll path matches given string; or dll filename matches given string with or without `.dll`
openExtToolDll = arg.Substring(20); openExtToolDll = arg.Substring(20);
} }
else if (argDowncased.StartsWith("--userdata=")) else if (argDowncased.StartsWithOrdinal("--userdata="))
{ {
userdataUnparsedPairs = new(); userdataUnparsedPairs = new();
foreach (var s in arg.Substring(11).Split(';')) foreach (var s in arg.Substring(11).Split(';'))

View File

@ -166,8 +166,7 @@ namespace BizHawk.Client.Common.Filters
value = value.Trim(); value = value.Trim();
} }
dict[key.ToLowerInvariant()] = value;
dict[key.ToLower()] = value;
} }
// process the keys // process the keys

View File

@ -71,7 +71,7 @@ namespace BizHawk.Client.Common
{ {
if (!Frozen) 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; return false;

View File

@ -65,7 +65,7 @@ namespace BizHawk.Client.Common
if (!string.IsNullOrWhiteSpace(GameInfo.Name) && GameInfo.Name == GameInfo.Name.ToUpperInvariant()) 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; return;

View File

@ -389,7 +389,7 @@ namespace BizHawk.Client.Common
return (int)CorePriority.UserPreference; return (int)CorePriority.UserPreference;
} }
if (string.Equals(c.Name, dbForcedCoreName, StringComparison.InvariantCultureIgnoreCase)) if (string.Equals(c.Name, dbForcedCoreName, StringComparison.OrdinalIgnoreCase))
{ {
return (int)CorePriority.GameDbPreference; return (int)CorePriority.GameDbPreference;
} }

View File

@ -1,4 +1,6 @@
using BizHawk.Emulation.Common; using System;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common.cheats namespace BizHawk.Client.Common.cheats
{ {
@ -50,7 +52,7 @@ namespace BizHawk.Client.Common.cheats
private static IDecodeResult GameBoy(string code) private static IDecodeResult GameBoy(string code)
{ {
// Game Genie // Game Genie
if (code.LastIndexOf("-") == 7 && code.IndexOf("-") == 3) if (code.LastIndexOf("-", StringComparison.Ordinal) == 7 && code.IndexOf("-", StringComparison.Ordinal) == 3)
{ {
return GbGgGameGenieDecoder.Decode(code); 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. // Problem: I don't know what the Non-FF Style codes are.
// TODO: Fix that. // TODO: Fix that.
if (code.StartsWith("FF") == false) if (code.StartsWithOrdinal("FF") == false)
{ {
return new InvalidCheatCode("This Action Replay Code, is not yet supported."); 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) private static IDecodeResult Sms(string code)
{ {
// Game Genie // Game Genie
if (code.LastIndexOf("-") == 7 && code.IndexOf("-") == 3) if (code.LastIndexOf("-", StringComparison.Ordinal) == 7 && code.IndexOf("-", StringComparison.Ordinal) == 3)
{ {
return GbGgGameGenieDecoder.Decode(code); return GbGgGameGenieDecoder.Decode(code);
} }
// Action Replay // Action Replay
if (code.IndexOf("-") == 3 && code.Length == 9) if (code.IndexOf("-", StringComparison.Ordinal) == 3 && code.Length == 9)
{ {
return SmsActionReplayDecoder.Decode(code); return SmsActionReplayDecoder.Decode(code);
} }

View File

@ -35,7 +35,7 @@ namespace BizHawk.Client.Common.cheats
throw new ArgumentNullException(nameof(_code)); 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."); return new InvalidCheatCode("All Master System Game Genie Codes need to have a dash after the third character and seventh character.");
} }

View File

@ -57,7 +57,7 @@ namespace BizHawk.Client.Common.cheats
code = Decrypt(code); 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."); return new InvalidCheatCode("All GBA GameShark Codes need to be 17 characters in length with a space after the first eight.");
} }

View File

@ -13,7 +13,7 @@ namespace BizHawk.Client.Common.cheats
throw new ArgumentNullException(nameof(code)); 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."); return new InvalidCheatCode("Action Replay/Pro Action Replay Codes need to contain a colon after the sixth character.");
} }

View File

@ -48,7 +48,7 @@ namespace BizHawk.Client.Common.cheats
throw new ArgumentNullException(nameof(code)); 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"); return new InvalidCheatCode("Game Genie Codes need to contain a dash after the fourth character");
} }

View File

@ -13,7 +13,7 @@ namespace BizHawk.Client.Common.cheats
throw new ArgumentNullException(nameof(code)); 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."); return new InvalidCheatCode("GameShark Codes need to contain a space after the eighth character.");
} }

View File

@ -14,7 +14,7 @@ namespace BizHawk.Client.Common.cheats
throw new ArgumentNullException(nameof(code)); 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."); return new InvalidCheatCode("All PSX GameShark Codes need to contain a space after the eighth character.");
} }

View File

@ -18,7 +18,7 @@ namespace BizHawk.Client.Common.cheats
throw new ArgumentNullException(nameof(code)); 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."); return new InvalidCheatCode("All Saturn GameShark Codes need to contain a space after the eighth character.");
} }

View File

@ -12,7 +12,7 @@ namespace BizHawk.Client.Common.cheats
throw new ArgumentNullException(nameof(code)); 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"); return new InvalidCheatCode("Action Replay Codes must be 9 characters with a dash after the third character");
} }

View File

@ -90,12 +90,12 @@ namespace BizHawk.Client.Common
if (path == "%recent%") return PathUtils.SpecialRecentsDir; if (path == "%recent%") return PathUtils.SpecialRecentsDir;
if (path.StartsWith("%exe%")) if (path.StartsWithOrdinal("%exe%"))
{ {
return PathUtils.ExeDirectoryPath + path.Substring(5); return PathUtils.ExeDirectoryPath + path.Substring(5);
} }
if (path.StartsWith("%rom%")) if (path.StartsWithOrdinal("%rom%"))
{ {
return collection.LastRomPath + path.Substring(5); return collection.LastRomPath + path.Substring(5);
} }

View File

@ -1,6 +1,7 @@
#nullable enable #nullable enable
using System.Linq; using System.Linq;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
@ -21,7 +22,7 @@ namespace BizHawk.Client.Common
if (state) return; if (state) return;
// when a button or modifier key is released, all modified key variants with it are released as well // 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 => 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()) .ToArray())
Buttons[k] = false; Buttons[k] = false;
} }

View File

@ -330,7 +330,7 @@ namespace BizHawk.Client.Common
[LuaMethodExample("local nlcliget = client.getavailabletools( );")] [LuaMethodExample("local nlcliget = client.getavailabletools( );")]
[LuaMethod("getavailabletools", "Returns a list of the tools currently open")] [LuaMethod("getavailabletools", "Returns a list of the tools currently open")]
public LuaTable GetAvailableTools() 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\" );")] [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")] [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")]

View File

@ -290,7 +290,7 @@ namespace BizHawk.Client.Common
.Replace("Uint", "uint ") .Replace("Uint", "uint ")
.Replace("Nullable`1[DrawingColor]", "Color? ") .Replace("Nullable`1[DrawingColor]", "Color? ")
.Replace("DrawingColor", "Color ") .Replace("DrawingColor", "Color ")
.ToLower(); .ToLowerInvariant();
} }
public string ReturnType public string ReturnType

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Text; using System.Text;
using BizHawk.Common.PathExtensions; using BizHawk.Common.PathExtensions;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
@ -78,7 +79,7 @@ namespace BizHawk.Client.Common
string line; string line;
while ((line = sr.ReadLine()) != null) while ((line = sr.ReadLine()) != null)
{ {
if (line.StartsWith("---")) if (line.StartsWithOrdinal("---"))
{ {
Add(LuaFile.SeparatorInstance); Add(LuaFile.SeparatorInstance);
} }

View File

@ -1,7 +1,7 @@
using System; using System;
using System.ComponentModel; using System.ComponentModel;
using System.Linq; using System.Linq;
using BizHawk.Common.StringExtensions;
using NLua; using NLua;
// ReSharper disable UnusedMember.Global // 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;")] [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")] [LuaMethod("startswith", "Returns whether str starts with str2")]
public static bool StartsWith(string str, string 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;")] [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")] [LuaMethod("endswith", "Returns whether str ends wth str2")]
public static bool EndsWith(string str, string 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\", \", \" );")] [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.")] [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.")]

View File

@ -18,7 +18,7 @@ namespace BizHawk.Client.Common
public static bool IsValidMovieExtension(string ext) 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) public static bool IsCurrentTasVersion(string movieVersion)
@ -35,7 +35,7 @@ namespace BizHawk.Client.Common
} }
var split = movieVersion var split = movieVersion
.ToLower() .ToLowerInvariant()
.Split(new[] {"tasproj"}, StringSplitOptions.RemoveEmptyEntries); .Split(new[] {"tasproj"}, StringSplitOptions.RemoveEmptyEntries);
if (split.Length == 1) if (split.Length == 1)

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
@ -307,7 +308,7 @@ namespace BizHawk.Client.Common
public IMovie Get(string path) public IMovie Get(string path)
{ {
// TODO: change IMovies to take HawkFiles only and not 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); return new TasMovie(this, path);
} }

View File

@ -23,7 +23,7 @@ namespace BizHawk.Client.Common
} }
var backupName = Filename; 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)); backupName = Path.Combine(Session.BackupDirectory, Path.GetFileName(backupName));
Write(backupName, isBackup: true); Write(backupName, isBackup: true);

View File

@ -58,7 +58,7 @@ namespace BizHawk.Client.Common
{ {
Log.Add(line); Log.Add(line);
} }
else if (line.StartsWith("Frame ")) else if (line.StartsWithOrdinal("Frame "))
{ {
var strs = line.Split(' '); var strs = line.Split(' ');
try try
@ -71,7 +71,7 @@ namespace BizHawk.Client.Common
return false; return false;
} }
} }
else if (line.StartsWith("LogKey:")) else if (line.StartsWithOrdinal("LogKey:"))
{ {
LogKey = line.Replace("LogKey:", ""); LogKey = line.Replace("LogKey:", "");
} }
@ -122,7 +122,7 @@ namespace BizHawk.Client.Common
{ {
newLog.Add(line); newLog.Add(line);
} }
else if (line.StartsWith("Frame ")) else if (line.StartsWithOrdinal("Frame "))
{ {
var strs = line.Split(' '); var strs = line.Split(' ');
try try

View File

@ -2,6 +2,7 @@
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores; using BizHawk.Emulation.Cores;
using BizHawk.Emulation.Cores.Consoles.Nintendo.NDS; using BizHawk.Emulation.Cores.Consoles.Nintendo.NDS;
@ -41,40 +42,40 @@ namespace BizHawk.Client.Common
{ {
ImportInputFrame(line); 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); 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"); 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")); 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")); 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")); 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"); string rtcTime = ParseHeader(line, "rtcStartNew");
syncSettings.InitialTime = DateTime.ParseExact(rtcTime, "yyyy'-'MMM'-'dd' 'HH':'mm':'ss':'fff", DateTimeFormatInfo.InvariantInfo); 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"); 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")); 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 // We no longer care to keep this info
} }

View File

@ -107,7 +107,7 @@ namespace BizHawk.Client.Common.movie.import
// 020 16-byte md5sum of the ROM used // 020 16-byte md5sum of the ROM used
byte[] md5 = r.ReadBytes(16); 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 // 030 4-byte little-endian unsigned int: version of the emulator used
uint emuVersion = r.ReadUInt32(); uint emuVersion = r.ReadUInt32();

View File

@ -44,7 +44,7 @@ namespace BizHawk.Client.Common
{ {
ImportInputFrame(line); ImportInputFrame(line);
} }
else if (line.ToLower().StartsWith("sub")) else if (line.StartsWith("sub", StringComparison.OrdinalIgnoreCase))
{ {
var subtitle = ImportTextSubtitle(line); var subtitle = ImportTextSubtitle(line);
@ -53,11 +53,11 @@ namespace BizHawk.Client.Common
Result.Movie.Subtitles.AddFromString(subtitle); 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")}"); 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"); string version = ParseHeader(line, "version");
@ -70,40 +70,40 @@ namespace BizHawk.Client.Common
Result.Movie.Comments.Add($"{MovieOrigin} .fm2 version 3"); 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"); 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"); 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"); string blob = ParseHeader(line, "romChecksum");
byte[] md5 = DecodeBlob(blob); byte[] md5 = DecodeBlob(blob);
if (md5 != null && md5.Length == 16) if (md5 != null && md5.Length == 16)
{ {
Result.Movie.HeaderEntries[HeaderKeys.Md5] = md5.BytesToHexString().ToLower(); Result.Movie.HeaderEntries[HeaderKeys.Md5] = md5.BytesToHexString().ToLowerInvariant();
} }
else else
{ {
Result.Warnings.Add("Bad ROM checksum."); 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"); 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); 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 // 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 this movie starts from a savestate, we can't support it.
if (ParseHeader(line, "StartsFromSavestate") == "1") if (ParseHeader(line, "StartsFromSavestate") == "1")
@ -112,11 +112,11 @@ namespace BizHawk.Client.Common
break; break;
} }
} }
else if (line.ToLower().StartsWith("palflag")) else if (line.StartsWith("palflag", StringComparison.OrdinalIgnoreCase))
{ {
Result.Movie.HeaderEntries[HeaderKeys.Pal] = ParseHeader(line, "palFlag"); 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") if (ParseHeader(line, "port0") == "1")
{ {
@ -124,7 +124,7 @@ namespace BizHawk.Client.Common
_deck = controllerSettings.Instantiate((x, y) => false).AddSystemToControllerDef(); _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") if (ParseHeader(line, "port1") == "1")
{ {
@ -132,14 +132,14 @@ namespace BizHawk.Client.Common
_deck = controllerSettings.Instantiate((x, y) => false).AddSystemToControllerDef(); _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") if (ParseHeader(line, "port2") == "1")
{ {
Result.Warnings.Add("Famicom port detected but not yet supported, ignoring"); 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"; bool fourscore = ParseHeader(line, "fourscore") == "1";
if (fourscore) if (fourscore)
@ -162,7 +162,7 @@ namespace BizHawk.Client.Common
} }
private IControllerDeck _deck; private IControllerDeck _deck;
private readonly string[] _buttons = { "Right", "Left", "Down", "Up", "Start", "Select", "B", "A" }; private readonly string[] _buttons = { "Right", "Left", "Down", "Up", "Start", "Select", "B", "A" };
private void ImportInputFrame(string line) private void ImportInputFrame(string line)
{ {
@ -244,7 +244,7 @@ namespace BizHawk.Client.Common
} }
// base64 // base64
if (!blob.ToLower().StartsWith("base64:")) if (!blob.StartsWith("base64:", StringComparison.OrdinalIgnoreCase))
{ {
return null; return null;
} }

View File

@ -117,8 +117,7 @@ namespace BizHawk.Client.Common
protected static string ParseHeader(string line, string headerName) protected static string ParseHeader(string line, string headerName)
{ {
// Case-insensitive search. // Case-insensitive search.
int x = line.ToLower().LastIndexOf( int x = line.LastIndexOf(headerName, StringComparison.OrdinalIgnoreCase) + headerName.Length;
headerName.ToLower()) + headerName.Length;
string str = line.Substring(x + 1, line.Length - x - 1); string str = line.Substring(x + 1, line.Length - x - 1);
return str.Trim(); return str.Trim();
} }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using System.IO; using System.IO;
using System.IO.Compression; using System.IO.Compression;
using System.Linq; using System.Linq;
@ -177,7 +178,7 @@ namespace BizHawk.Client.Common.movie.import
} }
Result.Movie.AppendFrame(_previousControllers); Result.Movie.AppendFrame(_previousControllers);
} }
else if (item.FullName.StartsWith("moviesram.")) else if (item.FullName.StartsWithOrdinal("moviesram."))
{ {
using var stream = item.Open(); using var stream = item.Open();
byte[] movieSram = stream.ReadAllBytes(); byte[] movieSram = stream.ReadAllBytes();
@ -212,7 +213,7 @@ namespace BizHawk.Client.Common.movie.import
Result.Movie.Rerecords = rerecordCount; Result.Movie.Rerecords = rerecordCount;
} }
else if (item.FullName.EndsWith(".sha256")) else if (item.FullName.EndsWithOrdinal(".sha256"))
{ {
using var stream = item.Open(); using var stream = item.Open();
string sha256Hash = Encoding.UTF8.GetString(stream.ReadAllBytes()).Trim(); string sha256Hash = Encoding.UTF8.GetString(stream.ReadAllBytes()).Trim();
@ -318,7 +319,7 @@ namespace BizHawk.Client.Common.movie.import
if (player > _playerCount) break; if (player > _playerCount) break;
IReadOnlyList<string> buttons = controllers.Definition.ControlsOrdered[player]; IReadOnlyList<string> 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" } buttons = new[] { "B", "Y", "Select", "Start", "Up", "Down", "Left", "Right", "A", "X", "L", "R" }
.Select(button => $"P{player} {button}") .Select(button => $"P{player} {button}")

View File

@ -1,4 +1,5 @@
using BizHawk.Emulation.Common; using System;
using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.PCEngine; using BizHawk.Emulation.Cores.PCEngine;
namespace BizHawk.Client.Common.movie.import namespace BizHawk.Client.Common.movie.import
@ -43,8 +44,7 @@ namespace BizHawk.Client.Common.movie.import
{ {
ImportTextFrame(line); ImportTextFrame(line);
} }
else if (line.ToLower() else if (line.StartsWith("ports", StringComparison.OrdinalIgnoreCase))
.StartsWith("ports"))
{ {
var portNumStr = ParseHeader(line, "ports"); var portNumStr = ParseHeader(line, "ports");
if (int.TryParse(portNumStr, out int ports)) if (int.TryParse(portNumStr, out int ports))
@ -83,32 +83,32 @@ namespace BizHawk.Client.Common.movie.import
ss.Port5); ss.Port5);
} }
} }
else if (line.ToLower().StartsWith("pcecd")) else if (line.StartsWith("pcecd", StringComparison.OrdinalIgnoreCase))
{ {
Result.Movie.HeaderEntries[HeaderKeys.Platform] = VSystemID.Raw.PCECD; 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")}"); 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"); string version = ParseHeader(line, "version");
Result.Movie.Comments.Add($"{MovieOrigin} .mc2 version {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"); 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"); 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"); Result.Movie.HeaderEntries[HeaderKeys.Author] = ParseHeader(line, "comment author");
} }
else if (line.ToLower().StartsWith("rerecordcount")) else if (line.StartsWith("rerecordcount", StringComparison.OrdinalIgnoreCase))
{ {
int rerecordCount; int rerecordCount;
@ -124,7 +124,7 @@ namespace BizHawk.Client.Common.movie.import
Result.Movie.Rerecords = (ulong)rerecordCount; 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 this movie starts from a savestate, we can't support it.
if (ParseHeader(line, "StartsFromSavestate") == "1") if (ParseHeader(line, "StartsFromSavestate") == "1")

View File

@ -35,7 +35,7 @@ namespace BizHawk.Client.Common.movie.import
uint rerecordCount = r.ReadUInt32(); uint rerecordCount = r.ReadUInt32();
Result.Movie.Rerecords = rerecordCount; Result.Movie.Rerecords = rerecordCount;
// 0010: 4-byte little endian flag: begin from reset? // 0010: 4-byte little endian flag: begin from reset?
uint reset = r.ReadUInt32(); uint reset = r.ReadUInt32();
if (reset == 0) if (reset == 0)
@ -92,7 +92,7 @@ namespace BizHawk.Client.Common.movie.import
// 00e4-00f3: binary: rom MD5 digest // 00e4-00f3: binary: rom MD5 digest
byte[] md5 = r.ReadBytes(16); 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 ss = new SMS.SmsSyncSettings();
var cd = new SMSControllerDeck(ss.Port1, ss.Port2, isGameGear, ss.UseKeyboard); var cd = new SMSControllerDeck(ss.Port1, ss.Port2, isGameGear, ss.UseKeyboard);

View File

@ -1,5 +1,5 @@
using System.IO; using System.IO;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Sony.PSX; 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? // 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"); Result.Errors.Add("Unable to parse text input, unknown configuration");
} }

View File

@ -45,20 +45,20 @@ namespace BizHawk.Client.Common.movie.import
{ {
ImportTextFrame(line); 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")}"); 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"); string version = ParseHeader(line, "version");
Result.Movie.Comments.Add($"{MovieOrigin} .ymv version {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"); Result.Movie.HeaderEntries[HeaderKeys.GameName] = ParseHeader(line, "romFilename");
} }
else if (line.ToLower().StartsWith("rerecordcount")) else if (line.StartsWith("rerecordcount", StringComparison.OrdinalIgnoreCase))
{ {
int rerecordCount; int rerecordCount;
@ -74,7 +74,7 @@ namespace BizHawk.Client.Common.movie.import
Result.Movie.Rerecords = (ulong)rerecordCount; 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 this movie starts from a savestate, we can't support it.
if (ParseHeader(line, "StartsFromSavestate") == "1") 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."); 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"; bool pal = ParseHeader(line, "isPal") == "1";
Result.Movie.HeaderEntries[HeaderKeys.Pal] = pal.ToString(); Result.Movie.HeaderEntries[HeaderKeys.Pal] = pal.ToString();

View File

@ -56,11 +56,11 @@ namespace BizHawk.Client.Common
{ {
Add(splitLine[0], splitLine[1]); Add(splitLine[0], splitLine[1]);
} }
else if (line.StartsWith("subtitle") || line.StartsWith("sub")) else if (line.StartsWithOrdinal("subtitle") || line.StartsWithOrdinal("sub"))
{ {
Subtitles.AddFromString(line); Subtitles.AddFromString(line);
} }
else if (line.StartsWith("comment")) else if (line.StartsWithOrdinal("comment"))
{ {
Comments.Add(line.Substring(8, line.Length - 8)); Comments.Add(line.Substring(8, line.Length - 8));
} }

View File

@ -238,7 +238,7 @@ namespace BizHawk.Client.Common
counter++; counter++;
} }
else if (line.StartsWith("Frame ")) else if (line.StartsWithOrdinal("Frame "))
{ {
var split = line.Split(' '); var split = line.Split(' ');
try try
@ -251,7 +251,7 @@ namespace BizHawk.Client.Common
return false; return false;
} }
} }
else if (line.StartsWith("LogKey:")) else if (line.StartsWithOrdinal("LogKey:"))
{ {
LogKey = line.Replace("LogKey:", ""); LogKey = line.Replace("LogKey:", "");
} }
@ -327,7 +327,7 @@ namespace BizHawk.Client.Common
if (_changes != value) if (_changes != value)
{ {
_changes = value; _changes = value;
OnPropertyChanged("Changes"); OnPropertyChanged(nameof(Changes));
} }
} }
} }

View File

@ -32,12 +32,12 @@ namespace BizHawk.Client.Common
if (x.Address.Equals(y.Address)) 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.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); return x.Address.CompareTo(y.Address);

View File

@ -30,7 +30,7 @@ namespace BizHawk.Client.Common
return 0; 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)) if (x.Address.Equals(y.Address))
{ {
@ -40,7 +40,7 @@ namespace BizHawk.Client.Common
return x.Address.CompareTo(y.Address); return x.Address.CompareTo(y.Address);
} }
return x.Domain.Name.CompareTo(y.Domain.Name); return string.CompareOrdinal(x.Domain.Name, y.Domain.Name);
} }
} }
} }

View File

@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
namespace BizHawk.Client.Common namespace BizHawk.Client.Common
{ {
@ -31,7 +32,7 @@ namespace BizHawk.Client.Common
return 0; 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)) if (x.Address.Equals(y.Address))
{ {
@ -41,7 +42,7 @@ namespace BizHawk.Client.Common
return x.Address.CompareTo(y.Address); return x.Address.CompareTo(y.Address);
} }
return string.Compare(x.Notes, y.Notes, true); return string.Compare(x.Notes, y.Notes, StringComparison.OrdinalIgnoreCase);
} }
} }
} }

View File

@ -30,7 +30,7 @@ namespace BizHawk.Client.Common
return 0; return 0;
} }
if (x.Diff.Equals(y.Diff)) if (x.Diff.Equals(y.Diff, System.StringComparison.Ordinal))
{ {
if (x.Address.Equals(y.Address)) if (x.Address.Equals(y.Address))
{ {
@ -40,7 +40,7 @@ namespace BizHawk.Client.Common
return x.Address.CompareTo(y.Address); return x.Address.CompareTo(y.Address);
} }
return x.Diff.CompareTo(y.Diff); return string.CompareOrdinal(x.Diff, y.Diff);
} }
} }
} }

View File

@ -50,11 +50,11 @@ namespace BizHawk.Client.EmuHawk
var name = Path.Combine(dir!, $"{fileNoExt}_{_frame}{ext}"); var name = Path.Combine(dir!, $"{fileNoExt}_{_frame}{ext}");
BitmapBuffer bb = new BitmapBuffer(source.BufferWidth, source.BufferHeight, source.GetVideoBuffer()); BitmapBuffer bb = new BitmapBuffer(source.BufferWidth, source.BufferHeight, source.GetVideoBuffer());
using var bmp = bb.ToSysdrawingBitmap(); using var bmp = bb.ToSysdrawingBitmap();
if (ext.ToUpper() == ".PNG") if (ext.ToUpperInvariant() == ".PNG")
{ {
bmp.Save(name, ImageFormat.Png); bmp.Save(name, ImageFormat.Png);
} }
else if (ext.ToUpper() == ".JPG") else if (ext.ToUpperInvariant() == ".JPG")
{ {
bmp.Save(name, ImageFormat.Jpeg); bmp.Save(name, ImageFormat.Jpeg);
} }

View File

@ -602,7 +602,7 @@ namespace BizHawk.Client.EmuHawk
public void OpenFile(string baseName) public void OpenFile(string baseName)
{ {
string ext = Path.GetExtension(baseName); string ext = Path.GetExtension(baseName);
if (ext == null || ext.ToLower() != ".jmd") if (ext == null || ext.ToLowerInvariant() != ".jmd")
{ {
baseName += ".jmd"; baseName += ".jmd";
} }

View File

@ -23,15 +23,15 @@ namespace BizHawk.Client.EmuHawk
{ {
// Digits are OK // Digits are OK
} }
else if (keyInput.Equals(decimalSeparator) && AllowDecimal) else if (keyInput.Equals(decimalSeparator, System.StringComparison.Ordinal) && AllowDecimal)
{ {
// Decimal separator is OK // Decimal separator is OK
} }
else if (keyInput.Equals(negativeSign) && AllowNegative) else if (keyInput.Equals(negativeSign, System.StringComparison.Ordinal) && AllowNegative)
{ {
// Negative is OK // Negative is OK
} }
else if (keyInput.Equals(groupSeparator)) else if (keyInput.Equals(groupSeparator, System.StringComparison.Ordinal))
{ {
// group separator is ok // group separator is ok
} }

View File

@ -35,7 +35,7 @@ namespace BizHawk.Client.EmuHawk
lvi.Text = item.Name; lvi.Text = item.Name;
long size = item.Size; long size = item.Size;
var extension = Path.GetExtension(item.Name); 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; size -= 16;
lvi.SubItems[1].Text = Util.FormatFileSize(size); lvi.SubItems[1].Text = Util.FormatFileSize(size);
_archiveItems.Add(lvi); _archiveItems.Add(lvi);
@ -206,7 +206,7 @@ namespace BizHawk.Client.EmuHawk
public string[] Keys { get; set; } public string[] Keys { get; set; }
public bool Matches(ListViewItem value) public bool Matches(ListViewItem value)
{ {
string searchedStr = value.Text.ToLower(); string searchedStr = value.Text.ToLowerInvariant();
foreach (string key in Keys) foreach (string key in Keys)
{ {
if (!searchedStr.Contains(key)) if (!searchedStr.Contains(key))
@ -234,7 +234,7 @@ namespace BizHawk.Client.EmuHawk
{ {
return new SimpleMatcher return new SimpleMatcher
{ {
Keys = searchKey.ToLower().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries) // splits on all whitespace chars Keys = searchKey.ToLowerInvariant().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries) // splits on all whitespace chars
}; };
} }
else else

View File

@ -71,7 +71,7 @@ namespace BizHawk.Client.EmuHawk
{ {
int row = c1.RowIndex.Value.CompareTo(c2.RowIndex.Value); int row = c1.RowIndex.Value.CompareTo(c2.RowIndex.Value);
return row == 0 return row == 0
? string.Compare(c1.Column?.Name, c2.Column?.Name) ? string.CompareOrdinal(c1.Column?.Name, c2.Column?.Name)
: row; : row;
} }
@ -83,7 +83,7 @@ namespace BizHawk.Client.EmuHawk
return -1; return -1;
} }
return c1.Column.Name.CompareTo(c2.Column.Name); return string.CompareOrdinal(c1.Column.Name, c2.Column.Name);
} }
} }

View File

@ -15,7 +15,7 @@ namespace BizHawk.Client.EmuHawk
/// <remarks>http://stackoverflow.com/questions/139010/how-to-resolve-a-lnk-in-c-sharp</remarks> /// <remarks>http://stackoverflow.com/questions/139010/how-to-resolve-a-lnk-in-c-sharp</remarks>
public static string ResolveShortcut(string filename) 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(); var link = new ShellLinkImports.ShellLink();
const uint STGM_READ = 0; const uint STGM_READ = 0;
((ShellLinkImports.IPersistFile) link).Load(filename, STGM_READ); ((ShellLinkImports.IPersistFile) link).Load(filename, STGM_READ);

View File

@ -250,7 +250,7 @@ namespace BizHawk.Client.EmuHawk
initFileName: $"{game.FilesystemSafeName()}-{suffix}"); initFileName: $"{game.FilesystemSafeName()}-{suffix}");
if (result is null) return; if (result is null) return;
FileInfo file = new(result); FileInfo file = new(result);
string extension = file.Extension.ToUpper(); string extension = file.Extension.ToUpperInvariant();
ImageFormat i = extension switch ImageFormat i = extension switch
{ {
".BMP" => ImageFormat.Bmp, ".BMP" => ImageFormat.Bmp,

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Drawing; using System.Drawing;
using System.Drawing.Imaging; using System.Drawing.Imaging;
using System.Globalization;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using System.Reflection; using System.Reflection;
@ -1109,7 +1110,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (ie.LogicalButton.Button.Length == 1) 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 == ' ') if ((c >= 'a' && c <= 'z') || c == ' ')
{ {
SendAltKeyChar(c); SendAltKeyChar(c);
@ -1308,7 +1309,7 @@ namespace BizHawk.Client.EmuHawk
using (var bb = Config.ScreenshotCaptureOsd ? CaptureOSD() : MakeScreenshotImage()) using (var bb = Config.ScreenshotCaptureOsd ? CaptureOSD() : MakeScreenshotImage())
{ {
using var img = bb.ToSysdrawingBitmap(); using var img = bb.ToSysdrawingBitmap();
if (Path.GetExtension(path).ToUpper() == ".JPG") if (Path.GetExtension(path).ToUpperInvariant() == ".JPG")
{ {
img.Save(fi.FullName, ImageFormat.Jpeg); img.Save(fi.FullName, ImageFormat.Jpeg);
} }
@ -2448,7 +2449,8 @@ namespace BizHawk.Client.EmuHawk
BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance, BindingFlags.NonPublic | BindingFlags.InvokeMethod | BindingFlags.Instance,
null, null,
MainformMenu, MainformMenu,
new object/*?*/[] { c }); new object/*?*/[] { c },
CultureInfo.InvariantCulture);
public static readonly FilesystemFilterSet ConfigFileFSFilterSet = new(new FilesystemFilter("Config File", new[] { "ini" })) public static readonly FilesystemFilterSet ConfigFileFSFilterSet = new(new FilesystemFilter("Config File", new[] { "ini" }))
{ {

View File

@ -32,7 +32,7 @@ namespace BizHawk.Client.EmuHawk
? $"{RomGame.RomData.Length / 1024 / 1024:n0}mb" ? $"{RomGame.RomData.Length / 1024 / 1024:n0}mb"
: $"{RomGame.RomData.Length / 1024:n0}kb"; : $"{RomGame.RomData.Length / 1024:n0}kb";
ExtensionLabel.Text = RomGame.Extension.ToLower(); ExtensionLabel.Text = RomGame.Extension.ToLowerInvariant();
HashBox.Text = RomGame.GameInfo.Hash; HashBox.Text = RomGame.GameInfo.Hash;
int count = 0; int count = 0;
int spacing = 25; int spacing = 25;
@ -67,7 +67,7 @@ namespace BizHawk.Client.EmuHawk
if (AlwaysCheckbox.Checked) if (AlwaysCheckbox.Checked)
{ {
_config.PreferredPlatformsForExtensions[RomGame.Extension.ToLower()] = PlatformChoice; _config.PreferredPlatformsForExtensions[RomGame.Extension.ToLowerInvariant()] = PlatformChoice;
} }
Close(); Close();

View File

@ -7,6 +7,7 @@ using Newtonsoft.Json;
using BizHawk.BizInvoke; using BizHawk.BizInvoke;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
{ {
@ -46,7 +47,7 @@ namespace BizHawk.Client.EmuHawk
private static bool DownloadDll(string url) private static bool DownloadDll(string url)
{ {
if (url.StartsWith("http:")) if (url.StartsWithOrdinal("http:"))
{ {
// force https // force https
url = url.Replace("http:", "https:"); url = url.Replace("http:", "https:");

View File

@ -108,7 +108,7 @@ namespace BizHawk.Client.EmuHawk
exePath = Encoding.ASCII.GetString(buf2048); exePath = Encoding.ASCII.GetString(buf2048);
// "BOOT = cdrom:" precedes the path // "BOOT = cdrom:" precedes the path
var index = exePath.IndexOf("BOOT = cdrom:"); var index = exePath.IndexOf("BOOT = cdrom:", StringComparison.Ordinal);
if (index < -1) break; if (index < -1) break;
exePath = exePath.Remove(0, index + 13); exePath = exePath.Remove(0, index + 13);

View File

@ -113,7 +113,7 @@ namespace BizHawk.Client.EmuHawk
{ {
var lva = (ListViewItem)a; var lva = (ListViewItem)a;
var lvb = (ListViewItem)b; 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);
} }
} }

View File

@ -203,7 +203,7 @@ namespace BizHawk.Client.EmuHawk
{ {
if (e.IsPressed(Keys.Enter) || e.IsPressed(Keys.Tab)) 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 // Found
if (k is not null) if (k is not null)

View File

@ -210,7 +210,7 @@ namespace BizHawk.Client.EmuHawk
{ {
foreach (var ext in MovieService.MovieExtensions) 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); tas.Add(i);
} }

View File

@ -6,6 +6,7 @@ using System.Windows.Forms;
using BizHawk.Client.Common; using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.Properties; using BizHawk.Client.EmuHawk.Properties;
using BizHawk.Common.NumberExtensions; using BizHawk.Common.NumberExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
@ -64,7 +65,7 @@ namespace BizHawk.Client.EmuHawk
{ {
BreakpointCallback(addr, value, flags); 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) if (seekBreakpoint != null)
{ {
@ -166,7 +167,7 @@ namespace BizHawk.Client.EmuHawk
public void RemoveCurrentSeek() public void RemoveCurrentSeek()
{ {
var seekBreakpoint = _breakpoints.FirstOrDefault(x => x.Name.StartsWith(SeekName)); var seekBreakpoint = _breakpoints.FirstOrDefault(x => x.Name.StartsWithOrdinal(SeekName));
if (seekBreakpoint != null) if (seekBreakpoint != null)
{ {

View File

@ -44,7 +44,7 @@ namespace BizHawk.Client.EmuHawk
{ {
try try
{ {
var code = l.ToUpper().Trim(); var code = l.ToUpperInvariant().Trim();
var decoder = new GameSharkDecoder(MemoryDomains, Emulator.SystemId); var decoder = new GameSharkDecoder(MemoryDomains, Emulator.SystemId);
var result = decoder.Decode(code); var result = decoder.Decode(code);
var domain = decoder.CheatDomain(); var domain = decoder.CheatDomain();
@ -82,4 +82,4 @@ namespace BizHawk.Client.EmuHawk
} }
} }
} }
} }

View File

@ -281,7 +281,7 @@ namespace BizHawk.Client.EmuHawk
{ {
long found = -1; long found = -1;
var search = value.Replace(" ", "").ToUpper(); var search = value.Replace(" ", "").ToUpperInvariant();
if (string.IsNullOrEmpty(search)) if (string.IsNullOrEmpty(search))
{ {
return; return;
@ -341,7 +341,7 @@ namespace BizHawk.Client.EmuHawk
{ {
long found = -1; long found = -1;
var search = value.Replace(" ", "").ToUpper(); var search = value.Replace(" ", "").ToUpperInvariant();
if (string.IsNullOrEmpty(search)) if (string.IsNullOrEmpty(search))
{ {
return; return;

View File

@ -1456,7 +1456,7 @@ namespace BizHawk.Client.EmuHawk
textbox.Multiline = multiline; textbox.Multiline = multiline;
if (scrollbars != null) if (scrollbars != null)
{ {
switch (scrollbars.ToUpper()) switch (scrollbars.ToUpperInvariant())
{ {
case "VERTICAL": case "VERTICAL":
textbox.ScrollBars = ScrollBars.Vertical; textbox.ScrollBars = ScrollBars.Vertical;
@ -1489,7 +1489,7 @@ namespace BizHawk.Client.EmuHawk
if (boxtype != null) if (boxtype != null)
{ {
switch (boxtype.ToUpper()) switch (boxtype.ToUpperInvariant())
{ {
case "HEX": case "HEX":
case "HEXADECIMAL": case "HEXADECIMAL":

View File

@ -14,6 +14,7 @@ using BizHawk.Client.EmuHawk.ToolExtensions;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.CollectionExtensions; using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.PathExtensions; using BizHawk.Common.PathExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk namespace BizHawk.Client.EmuHawk
@ -446,7 +447,7 @@ namespace BizHawk.Client.EmuHawk
private string DressUpRelative(string path) private string DressUpRelative(string path)
{ {
return path.StartsWith(".\\") ? path.Replace(".\\", "") : path; return path.StartsWithOrdinal(".\\") ? path.Replace(".\\", "") : path;
} }
private void UpdateNumberOfScripts() private void UpdateNumberOfScripts()
@ -1267,12 +1268,12 @@ namespace BizHawk.Client.EmuHawk
{ {
foreach (var path in filePaths) 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); LoadLuaFile(path);
UpdateDialog(); UpdateDialog();
} }
else if (Path.GetExtension(path)?.ToLower() == ".luases") else if (Path.GetExtension(path)?.ToLowerInvariant() == ".luases")
{ {
LoadLuaSession(path); LoadLuaSession(path);
return; return;

View File

@ -283,7 +283,7 @@ namespace BizHawk.Client.EmuHawk
var fStyle = FontStyle.Regular; var fStyle = FontStyle.Regular;
if (fontStyle != null) if (fontStyle != null)
{ {
switch (fontStyle.ToLower()) switch (fontStyle.ToLowerInvariant())
{ {
default: default:
case "regular": case "regular":
@ -311,7 +311,7 @@ namespace BizHawk.Client.EmuHawk
if (horizAlign != null) if (horizAlign != null)
{ {
switch (horizAlign.ToLower()) switch (horizAlign.ToLowerInvariant())
{ {
default: default:
case "left": case "left":
@ -328,7 +328,7 @@ namespace BizHawk.Client.EmuHawk
if (vertAlign != null) if (vertAlign != null)
{ {
switch (vertAlign.ToLower()) switch (vertAlign.ToLowerInvariant())
{ {
default: default:
case "top": case "top":

View File

@ -62,7 +62,7 @@ namespace BizHawk.Client.EmuHawk
AddButton_Click(null, null); AddButton_Click(null, null);
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("|")) if (MainForm.CurrentlyOpenRom.Contains("|"))
{ {

View File

@ -99,12 +99,12 @@ namespace BizHawk.Client.EmuHawk
public bool LoadMovieFile(string filename, bool askToSave = true) public bool LoadMovieFile(string filename, bool askToSave = true)
{ {
if (askToSave && !AskSaveChanges()) return false; if (askToSave && !AskSaveChanges()) return false;
if (filename.EndsWith(MovieService.TasMovieExtension)) if (filename.EndsWithOrdinal(MovieService.TasMovieExtension))
{ {
LoadFileWithFallback(filename); LoadFileWithFallback(filename);
return true; //TODO should this return false if it fell back to a new project? 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( if (!DialogController.ShowMessageBox2(
caption: "Convert movie", caption: "Convert movie",
@ -1209,7 +1209,7 @@ namespace BizHawk.Client.EmuHawk
int workingHeight = Screen.FromControl(this).WorkingArea.Height; int workingHeight = Screen.FromControl(this).WorkingArea.Height;
int rowHeight = ColumnsSubMenu.Height + 4; int rowHeight = ColumnsSubMenu.Height + 4;
int maxRows = workingHeight / rowHeight; 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); int keysMenusCount = (int)Math.Ceiling((double)keyCount / maxRows);
var keysMenus = new ToolStripMenuItem[keysMenusCount]; var keysMenus = new ToolStripMenuItem[keysMenusCount];
@ -1248,7 +1248,7 @@ namespace BizHawk.Client.EmuHawk
((ToolStripMenuItem)sender.OwnerItem).ShowDropDown(); ((ToolStripMenuItem)sender.OwnerItem).ShowDropDown();
}; };
if (column.Name.StartsWith("Key ")) if (column.Name.StartsWithOrdinal("Key "))
{ {
keysMenus keysMenus
.First(m => m.DropDownItems.Count < maxRows) .First(m => m.DropDownItems.Count < maxRows)

View File

@ -9,6 +9,7 @@ using BizHawk.Client.Common;
using BizHawk.Client.EmuHawk.ToolExtensions; using BizHawk.Client.EmuHawk.ToolExtensions;
using BizHawk.Client.EmuHawk.Properties; using BizHawk.Client.EmuHawk.Properties;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Nintendo.N64; using BizHawk.Emulation.Cores.Nintendo.N64;
@ -383,29 +384,29 @@ namespace BizHawk.Client.EmuHawk
|| c.Name == "Light Sensor" || c.Name == "Light Sensor"
|| c.Name == "Disc Select" || c.Name == "Disc Select"
|| c.Name == "Disk Index" || c.Name == "Disk Index"
|| c.Name.StartsWith("Tilt") || c.Name.StartsWithOrdinal("Tilt")
|| c.Name.StartsWith("Key ") || c.Name.StartsWithOrdinal("Key ")
|| c.Name.StartsWith("Open") || c.Name.StartsWithOrdinal("Open")
|| c.Name.StartsWith("Close") || c.Name.StartsWithOrdinal("Close")
|| c.Name.EndsWith("Tape") || c.Name.EndsWithOrdinal("Tape")
|| c.Name.EndsWith("Disk") || c.Name.EndsWithOrdinal("Disk")
|| c.Name.EndsWith("Block") || c.Name.EndsWithOrdinal("Block")
|| c.Name.EndsWith("Status")); || c.Name.EndsWithOrdinal("Status"));
if (Emulator.SystemId is VSystemID.Raw.N64) if (Emulator.SystemId is VSystemID.Raw.N64)
{ {
foreach (var c in TasView.AllColumns foreach (var c in TasView.AllColumns
.Where(static c => c.Name.EndsWith(" C Up") || c.Name.EndsWith(" C Down") .Where(static c => c.Name.EndsWithOrdinal(" C Up") || c.Name.EndsWithOrdinal(" C Down")
|| c.Name.EndsWith(" C Left") || c.Name.EndsWith(" C Right"))) || 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 c.Text = $"c{c.Text.ToUpperInvariant()}"; // prepend 'c' to differentiate from L/R buttons -- only affects table header
} }
var fakeAnalogControls = TasView.AllColumns var fakeAnalogControls = TasView.AllColumns
.Where(c => .Where(c =>
c.Name.EndsWith("A Up") c.Name.EndsWithOrdinal("A Up")
|| c.Name.EndsWith("A Down") || c.Name.EndsWithOrdinal("A Down")
|| c.Name.EndsWith("A Left") || c.Name.EndsWithOrdinal("A Left")
|| c.Name.EndsWith("A Right")); || c.Name.EndsWithOrdinal("A Right"));
columnsToHide = columnsToHide.Concat(fakeAnalogControls); columnsToHide = columnsToHide.Concat(fakeAnalogControls);
} }

View File

@ -14,14 +14,14 @@ namespace BizHawk.Common.PathExtensions
public static bool IsSubfolderOf(this string? childPath, string? parentPath) public static bool IsSubfolderOf(this string? childPath, string? parentPath)
{ {
if (childPath == null || parentPath == null) return false; 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 (OSTailoredCode.IsUnixHost)
{ {
#if true #if true
var c = OSTailoredCode.SimpleSubshell("realpath", $"-Lm \"{childPath}\"", $"invalid path {childPath} or missing realpath binary"); 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"); 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 #else // written for Unix port but may be useful for Windows when moving to .NET Core
var parentUriPath = new Uri(parentPath.TrimEnd('.')).AbsolutePath.TrimEnd('/'); var parentUriPath = new Uri(parentPath.TrimEnd('.')).AbsolutePath.TrimEnd('/');
try try
@ -72,7 +72,7 @@ namespace BizHawk.Common.PathExtensions
if (OSTailoredCode.IsUnixHost) if (OSTailoredCode.IsUnixHost)
{ {
var realpathOutput = OSTailoredCode.SimpleSubshell("realpath", $"--relative-to=\"{fromPath}\" \"{toPath}\"", $"invalid path {toPath}, invalid path {fromPath}, or missing realpath binary"); 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 //TODO merge this with the Windows implementation in MakeRelativeTo
@ -97,14 +97,14 @@ namespace BizHawk.Common.PathExtensions
{ {
if (path.IsAbsolute()) if (path.IsAbsolute())
return path; return path;
else else
{ {
// FileInfo for normalisation ("C:\a\b\..\c" => "C:\a\c") // FileInfo for normalisation ("C:\a\b\..\c" => "C:\a\c")
var mycwd = cwd ?? (OSTailoredCode.IsUnixHost ? Environment.CurrentDirectory : CWDHacks.Get()); var mycwd = cwd ?? (OSTailoredCode.IsUnixHost ? Environment.CurrentDirectory : CWDHacks.Get());
var finalpath = $"{mycwd}/{path}"; var finalpath = $"{mycwd}/{path}";
var fi = new FileInfo(finalpath); var fi = new FileInfo(finalpath);
return fi.FullName; return fi.FullName;
} }
} }
/// <returns>the absolute path equivalent to <paramref name="path"/> which contains <c>%exe%</c> (expanded) as a prefix</returns> /// <returns>the absolute path equivalent to <paramref name="path"/> which contains <c>%exe%</c> (expanded) as a prefix</returns>
@ -126,7 +126,7 @@ namespace BizHawk.Common.PathExtensions
if (!OSTailoredCode.IsUnixHost) return absolutePath.Replace(basePath, ".").RemoveSuffix(Path.DirectorySeparatorChar); if (!OSTailoredCode.IsUnixHost) return absolutePath.Replace(basePath, ".").RemoveSuffix(Path.DirectorySeparatorChar);
#if true // Unix implementation using realpath #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"); 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 #else // for some reason there were two Unix implementations in the codebase before me? --yoshi
// alt. #1 // alt. #1
if (!IsSubfolder(basePath, absolutePath)) return OSTailoredCode.IsUnixHost && basePath.TrimEnd('.') == $"{absolutePath}/" ? "." : absolutePath; if (!IsSubfolder(basePath, absolutePath)) return OSTailoredCode.IsUnixHost && basePath.TrimEnd('.') == $"{absolutePath}/" ? "." : absolutePath;

View File

@ -1,4 +1,5 @@
using System; using System;
using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Runtime.CompilerServices; using System.Runtime.CompilerServices;
@ -20,7 +21,7 @@ namespace BizHawk.Common.StringExtensions
/// <see langword="true"/> if <paramref name="str"/> appears in <paramref name="options"/> (case-insensitive) /// <see langword="true"/> if <paramref name="str"/> appears in <paramref name="options"/> (case-insensitive)
/// </returns> /// </returns>
public static bool In(this string str, params string[] options) => 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));
/// <returns> /// <returns>
/// <paramref name="str"/> with the first char removed, or /// <paramref name="str"/> with the first char removed, or
@ -88,7 +89,7 @@ namespace BizHawk.Common.StringExtensions
/// </returns> /// </returns>
public static string SubstringAfter(this string str, string delimiter, string notFoundValue) 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); return index < 0 ? notFoundValue : str.Substring(index + delimiter.Length, str.Length - index - delimiter.Length);
} }
@ -147,7 +148,7 @@ namespace BizHawk.Common.StringExtensions
/// </returns> /// </returns>
public static string? SubstringBeforeOrNull(this string str, string delimiter) 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); return index < 0 ? null : str.Substring(0, index);
} }
@ -165,5 +166,9 @@ namespace BizHawk.Common.StringExtensions
/// <remarks><c>"abc,def,ghi".TransformFields(',', s => s.Reverse()) == "cba,fed,ihg"</c></remarks> /// <remarks><c>"abc,def,ghi".TransformFields(',', s => s.Reverse()) == "cba,fed,ihg"</c></remarks>
public static string TransformFields(this string str, char delimiter, Func<string, string> transform) public static string TransformFields(this string str, char delimiter, Func<string, string> transform)
=> string.Join(delimiter.ToString(), str.Split(delimiter).Select(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);
} }
} }

View File

@ -142,7 +142,7 @@ namespace BizHawk.Common
} }
for (int i = 0, l = scanResults.Count; i < l; i++) 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); BindArchiveMember(i);
return; return;

View File

@ -26,7 +26,7 @@ namespace BizHawk.Common
return Enum.Parse( return Enum.Parse(
enumType, enumType,
enumType.GetFields(BindingFlags.Public | BindingFlags.Static) 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 ?? valueStr
); );
} }

View File

@ -34,7 +34,7 @@ namespace BizHawk.Common
{ {
var (dir, filename) = path.SplitPathToDirAndFile(); var (dir, filename) = path.SplitPathToDirAndFile();
_ = dir ?? throw new InvalidOperationException(); _ = dir ?? throw new InvalidOperationException();
if (!filename.StartsWith("biz-")) if (!filename.StartsWith("biz-", StringComparison.Ordinal))
{ {
throw new InvalidOperationException(); throw new InvalidOperationException();
} }
@ -128,4 +128,4 @@ namespace BizHawk.Common
Environment.SetEnvironmentVariable("TEMP", path); Environment.SetEnvironmentVariable("TEMP", path);
} }
} }
} }

View File

@ -108,7 +108,7 @@ namespace BizHawk.Common
/// <returns>all <see cref="Type">Types</see> with the name <paramref name="className"/></returns> /// <returns>all <see cref="Type">Types</see> with the name <paramref name="className"/></returns>
/// <remarks>adapted from https://stackoverflow.com/a/13727044/7467292</remarks> /// <remarks>adapted from https://stackoverflow.com/a/13727044/7467292</remarks>
public static IList<Type> GetTypeByName(string className) => AppDomain.CurrentDomain.GetAssemblies() public static IList<Type> 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();
/// <remarks>TODO replace this with GetTypes (i.e. the try block) when VB.NET dep is properly removed</remarks> /// <remarks>TODO replace this with GetTypes (i.e. the try block) when VB.NET dep is properly removed</remarks>
public static IEnumerable<Type> GetTypesWithoutLoadErrors(this Assembly assembly) public static IEnumerable<Type> GetTypesWithoutLoadErrors(this Assembly assembly)

View File

@ -8,6 +8,7 @@ using System.Text.RegularExpressions;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.CollectionExtensions; using BizHawk.Common.CollectionExtensions;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Common 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 // 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;
} }
} }

View File

@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
@ -37,7 +38,7 @@ namespace BizHawk.Emulation.Common
{ {
for (int i = 0; i < _numCores; i++) 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); _linkedCores[i].AsDebuggable().SetCpuRegister(register.Replace($"P{i + 1} ", ""), value);
} }

View File

@ -3,6 +3,7 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Common namespace BizHawk.Emulation.Common
{ {
@ -40,7 +41,7 @@ namespace BizHawk.Emulation.Common
private void ParseDskImage() 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")) if (ident.Contains("MV - CPC"))
{ {
ParseDsk(); ParseDsk();
@ -81,8 +82,8 @@ namespace BizHawk.Emulation.Common
if (s.SectorData == null || s.SectorData.Length == 0) if (s.SectorData == null || s.SectorData.Length == 0)
continue; continue;
string str = Encoding.ASCII.GetString(s.SectorData, 0, s.SectorData.Length).ToUpper(); string str = Encoding.ASCII.GetString(s.SectorData, 0, s.SectorData.Length);
if (str.Contains("PLUS3DOS")) if (str.Contains("PLUS3DOS", StringComparison.OrdinalIgnoreCase))
{ {
IdentifiedSystem = VSystemID.Raw.ZXSpectrum; IdentifiedSystem = VSystemID.Raw.ZXSpectrum;
return; return;

View File

@ -423,7 +423,7 @@ namespace BizHawk.Emulation.Common
// If filename is all-caps, then attempt to proper-case the title. // If filename is all-caps, then attempt to proper-case the title.
if (!string.IsNullOrWhiteSpace(game.Name) && game.Name == game.Name.ToUpperInvariant()) 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; return game;

View File

@ -47,17 +47,17 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
text + (text == "" ? "" : "\r\n") + text + (text == "" ? "" : "\r\n") +
string.Join("\r\n", _romHashes.Select(static r => $"{r.Value} - {r.Key}")); 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; lp.Game.Status = RomStatus.Imperfect;
} }
if (text.ToLower().Contains("unemulated")) if (text.Contains("unemulated", StringComparison.OrdinalIgnoreCase))
{ {
lp.Game.Status = RomStatus.Unimplemented; 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; lp.Game.Status = RomStatus.NotWorking;
} }
@ -94,7 +94,7 @@ namespace BizHawk.Emulation.Cores.Arcades.MAME
var hashes = string.Concat(_romHashes.Values var hashes = string.Concat(_romHashes.Values
.Where(static s => s.Contains("SHA:")) .Where(static s => s.Contains("SHA:"))
.Select(static s => s.Split(' ') .Select(static s => s.Split(' ')
.First(static s => s.StartsWith("SHA:")) .First(static s => s.StartsWithOrdinal("SHA:"))
.RemovePrefix("SHA:"))); .RemovePrefix("SHA:")));
lp.Game.Name = _gameFullName; lp.Game.Name = _gameFullName;

View File

@ -15,17 +15,17 @@ namespace BizHawk.Emulation.Cores.Components.FairchildF8
//n immediate succeeds the opcode and the displacement (if present) //n immediate succeeds the opcode and the displacement (if present)
//nn immediately 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++) format = format.Replace("nn", read(addr++)
.ToString("X2") + read(addr++) .ToString("X2") + read(addr++)
.ToString("X2") + "h"); // MSB is read first .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", StringComparison.Ordinal) != -1) format = format.Replace("+d", "d");
if (format.IndexOf("d") != -1) if (format.IndexOf("d", StringComparison.Ordinal) != -1)
{ {
var b = unchecked((sbyte)read(addr++)); var b = unchecked((sbyte)read(addr++));
format = format.Replace("d", $"{(b < 0 ? '-' : '+')}{(b < 0 ? -b : b):X2}h"); format = format.Replace("d", $"{(b < 0 ? '-' : '+')}{(b < 0 ? -b : b):X2}h");

View File

@ -1,5 +1,6 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
namespace BizHawk.Emulation.Cores.Components.FairchildF8 namespace BizHawk.Emulation.Cores.Components.FairchildF8
@ -274,7 +275,7 @@ namespace BizHawk.Emulation.Cores.Components.FairchildF8
public void SetCpuRegister(string register, int value) public void SetCpuRegister(string register, int value)
{ {
if (register.StartsWith("SPR")) if (register.StartsWithOrdinal("SPR"))
{ {
var reg = Convert.ToInt32(register.Replace("SPR", "")); var reg = Convert.ToInt32(register.Replace("SPR", ""));

View File

@ -1,4 +1,5 @@
using System; using System;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
// Do not modify this file directly! This is GENERATED code. // Do not modify this file directly! This is GENERATED code.
@ -2339,7 +2340,7 @@ namespace BizHawk.Emulation.Cores.Components.H6280
case 0xF4: // SET case 0xF4: // SET
int a; // TODO remove these extra checks int a; // TODO remove these extra checks
string b = Disassemble(PC, out a); 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); Console.WriteLine("SETTING T FLAG, NEXT INSTRUCTION IS UNHANDLED: {0}", b);
FlagT = true; FlagT = true;
PendingCycles -= 2; PendingCycles -= 2;

View File

@ -13,11 +13,11 @@ namespace BizHawk.Emulation.Cores.Components.Z80A
//n immediate succeeds the opcode and the displacement (if present) //n immediate succeeds the opcode and the displacement (if present)
//nn immediately 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("nn", StringComparison.Ordinal) != -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("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", StringComparison.Ordinal) != -1) format = format.Replace("+d", "d");
if (format.IndexOf("d") != -1) if (format.IndexOf("d", StringComparison.Ordinal) != -1)
{ {
var b = unchecked ((sbyte) read(addr++)); var b = unchecked ((sbyte) read(addr++));
format = format.Replace("d", $"{(b < 0 ? '-' : '+')}{(b < 0 ? -b : b):X2}h"); format = format.Replace("d", $"{(b < 0 ? '-' : '+')}{(b < 0 ? -b : b):X2}h");

View File

@ -1,4 +1,6 @@
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
/// <summary> /// <summary>
/// The abstract class that all emulated models will inherit from /// The abstract class that all emulated models will inherit from
@ -64,7 +66,7 @@
// non matrix keys (J2) // non matrix keys (J2)
foreach (string k in KeyboardDevice.NonMatrixKeys) foreach (string k in KeyboardDevice.NonMatrixKeys)
{ {
if (!k.StartsWith("P2")) if (!k.StartsWithOrdinal("P2"))
continue; continue;
bool currState = CPC._controller.IsPressed(k); bool currState = CPC._controller.IsPressed(k);

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC 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()); string hdr = Encoding.ASCII.GetString(data.Take(16).ToArray());
// disk checking first // 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 // amstrad .dsk disk file
// check for number of sides // check for number of sides
@ -244,7 +245,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
} }
// tape checking // tape checking
if (hdr.ToUpper().StartsWith("ZXTAPE!")) if (hdr.StartsWith("ZXTAPE!", StringComparison.OrdinalIgnoreCase))
{ {
// cdt tape file // cdt tape file
return CPCMediaType.Tape; return CPCMediaType.Tape;
@ -263,4 +264,3 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
DiskDoubleSided DiskDoubleSided
} }
} }

View File

@ -2,6 +2,7 @@
using BizHawk.Common; using BizHawk.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
@ -27,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// look for standard magic string // look for standard magic string
string ident = Encoding.ASCII.GetString(data, 0, 16); 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 // incorrect format
return false; return false;
@ -152,7 +153,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
// look for standard magic string // look for standard magic string
string ident = Encoding.ASCII.GetString(data, 0, 16); 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 // incorrect format
return false; return false;

View File

@ -2,6 +2,7 @@
using BizHawk.Common; using BizHawk.Common;
using System.Collections.Generic; using System.Collections.Generic;
using System; using System;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
@ -27,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// look for standard magic string // look for standard magic string
string ident = Encoding.ASCII.GetString(data, 0, 16); string ident = Encoding.ASCII.GetString(data, 0, 16);
if (!ident.ToUpper().Contains("MV - CPC")) if (!ident.Contains("MV - CPC", StringComparison.OrdinalIgnoreCase))
{ {
// incorrect format // incorrect format
return false; return false;
@ -158,7 +159,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
// look for standard magic string // look for standard magic string
string ident = Encoding.ASCII.GetString(data, 0, 16); string ident = Encoding.ASCII.GetString(data, 0, 16);
if (!ident.ToUpper().Contains("MV - CPC")) if (!ident.Contains("MV - CPC", StringComparison.OrdinalIgnoreCase))
{ {
// incorrect format // incorrect format
return false; return false;

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.AmstradCPC namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
{ {
@ -235,7 +236,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// check for SPEEDLOCK ident in sector 0 // check for SPEEDLOCK ident in sector 0
string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[0].SectorData, 0, DiskTracks[0].Sectors[0].SectorData.Length); 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; return false;
// check for correct sector 0 lengths // check for correct sector 0 lengths
@ -297,7 +298,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// check for ALKATRAZ ident in sector 0 // check for ALKATRAZ ident in sector 0
string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[0].SectorData, 0, DiskTracks[0].Sectors[0].SectorData.Length); 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; return false;
// ALKATRAZ NOTES (-asni 2018-05-01) // ALKATRAZ NOTES (-asni 2018-05-01)
@ -338,7 +339,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
// check for PAUL OWENS ident in sector 2 // 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); 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; return false;
// Paul Owens Disk Protection Notes (-asni 2018-05-01) // 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 // check for Hexagon ident in sector 8
string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[8].SectorData, 0, DiskTracks[0].Sectors[8].SectorData.Length); 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; return true;
// hexagon protection may not be labelled as such // hexagon protection may not be labelled as such

View File

@ -1,5 +1,6 @@
using System.IO; using System.IO;
using System.Text; using System.Text;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.Commodore64 namespace BizHawk.Emulation.Cores.Computers.Commodore64
{ {
@ -12,37 +13,36 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64
return C64Format.Unknown; 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)); var header = Encoding.GetEncoding(437).GetString(reader.ReadBytes(0x10));
if (header.StartsWith("C64 CARTRIDGE ")) if (header.StartsWithOrdinal("C64 CARTRIDGE "))
{ {
return C64Format.CRT; return C64Format.CRT;
} }
if (header.StartsWith("GCR-1541")) if (header.StartsWithOrdinal("GCR-1541"))
{ {
return C64Format.G64; 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; return C64Format.T64;
} }
if (header.StartsWith("C64-TAPE-RAW")) if (header.StartsWithOrdinal("C64-TAPE-RAW"))
{ {
return C64Format.TAP; return C64Format.TAP;
} }
if (header.StartsWith("C64File")) if (header.StartsWithOrdinal("C64File"))
{ {
return C64Format.P00; // poo :) return C64Format.P00; // poo :)
} }
if (header.StartsWith("P64-1541")) if (header.StartsWithOrdinal("P64-1541"))
{ {
return C64Format.P64; return C64Format.P64;
} }

View File

@ -1,5 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
@ -66,7 +67,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// non matrix keys // non matrix keys
foreach (string k in KeyboardDevice.NonMatrixKeys) foreach (string k in KeyboardDevice.NonMatrixKeys)
{ {
if (!k.StartsWith("Key")) if (!k.StartsWithOrdinal("Key"))
continue; continue;
bool currState = Spectrum._controller.IsPressed(k); bool currState = Spectrum._controller.IsPressed(k);
@ -337,4 +338,3 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
} }
} }
} }

View File

@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum 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()); string hdr = Encoding.ASCII.GetString(data.Take(16).ToArray());
// disk checking first // 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 // spectrum .dsk disk file
// check for number of sides // check for number of sides
@ -255,20 +256,20 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
else else
return SpectrumMediaType.DiskDoubleSided; return SpectrumMediaType.DiskDoubleSided;
} }
if (hdr.ToUpper().StartsWith("FDI")) if (hdr.StartsWith("FDI", StringComparison.OrdinalIgnoreCase))
{ {
// spectrum .fdi disk file // spectrum .fdi disk file
return SpectrumMediaType.Disk; return SpectrumMediaType.Disk;
} }
if (hdr.ToUpper().StartsWith("CAPS")) if (hdr.StartsWith("CAPS", StringComparison.OrdinalIgnoreCase))
{ {
// IPF format file // IPF format file
return SpectrumMediaType.Disk; return SpectrumMediaType.Disk;
} }
if (hdr.ToUpper().StartsWith("UDI!") && data[0x08] == 0) if (hdr.StartsWith("UDI!", StringComparison.OrdinalIgnoreCase) && data[0x08] == 0)
{ {
// UDI v1.0 // UDI v1.0
if (hdr.StartsWith("udi!")) if (hdr.StartsWithOrdinal("udi!"))
{ {
throw new NotSupportedException("ZXHawk currently does not supported UDIv1.0 with compression."); throw new NotSupportedException("ZXHawk currently does not supported UDIv1.0 with compression.");
} }
@ -282,22 +283,22 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
} }
// tape checking // tape checking
if (hdr.ToUpper().StartsWith("ZXTAPE!")) if (hdr.StartsWith("ZXTAPE!", StringComparison.OrdinalIgnoreCase))
{ {
// spectrum .tzx tape file // spectrum .tzx tape file
return SpectrumMediaType.Tape; return SpectrumMediaType.Tape;
} }
if (hdr.ToUpper().StartsWith("PZXT")) if (hdr.StartsWith("PZXT", StringComparison.OrdinalIgnoreCase))
{ {
// spectrum .tzx tape file // spectrum .tzx tape file
return SpectrumMediaType.Tape; return SpectrumMediaType.Tape;
} }
if (hdr.ToUpper().StartsWith("COMPRESSED SQ")) if (hdr.StartsWith("COMPRESSED SQ", StringComparison.OrdinalIgnoreCase))
{ {
// spectrum .tzx tape file // spectrum .tzx tape file
return SpectrumMediaType.Tape; return SpectrumMediaType.Tape;
} }
if (hdr.ToUpper().Contains("WAVE")) if (hdr.Contains("WAVE", StringComparison.OrdinalIgnoreCase))
{ {
// spectrum .tzx tape file // spectrum .tzx tape file
return SpectrumMediaType.Tape; return SpectrumMediaType.Tape;

View File

@ -2,6 +2,7 @@
using BizHawk.Common; using BizHawk.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
@ -27,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// look for standard magic string // look for standard magic string
string ident = Encoding.ASCII.GetString(data, 0, 16); 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 // incorrect format
return false; return false;
@ -163,7 +164,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
// look for standard magic string // look for standard magic string
string ident = Encoding.ASCII.GetString(data, 0, 16); 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 // incorrect format
return false; return false;

View File

@ -2,6 +2,7 @@
using BizHawk.Common; using BizHawk.Common;
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
@ -27,7 +28,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// look for standard magic string // look for standard magic string
string ident = Encoding.ASCII.GetString(data, 0, 16); string ident = Encoding.ASCII.GetString(data, 0, 16);
if (!ident.ToUpper().Contains("MV - CPC")) if (!ident.Contains("MV - CPC", StringComparison.OrdinalIgnoreCase))
{ {
// incorrect format // incorrect format
return false; return false;
@ -168,7 +169,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
// look for standard magic string // look for standard magic string
string ident = Encoding.ASCII.GetString(data, 0, 16); string ident = Encoding.ASCII.GetString(data, 0, 16);
if (!ident.ToUpper().Contains("MV - CPC")) if (!ident.Contains("MV - CPC", StringComparison.OrdinalIgnoreCase))
{ {
// incorrect format // incorrect format
return false; return false;

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
@ -235,7 +236,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// check for SPEEDLOCK ident in sector 0 // check for SPEEDLOCK ident in sector 0
string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[0].SectorData, 0, DiskTracks[0].Sectors[0].SectorData.Length); 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; return false;
// check for correct sector 0 lengths // check for correct sector 0 lengths
@ -297,7 +298,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// check for ALKATRAZ ident in sector 0 // check for ALKATRAZ ident in sector 0
string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[0].SectorData, 0, DiskTracks[0].Sectors[0].SectorData.Length); 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; return false;
// ALKATRAZ NOTES (-asni 2018-05-01) // ALKATRAZ NOTES (-asni 2018-05-01)
@ -338,7 +339,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// check for PAUL OWENS ident in sector 2 // 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); 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; return false;
// Paul Owens Disk Protection Notes (-asni 2018-05-01) // 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 // check for Hexagon ident in sector 8
string ident = Encoding.ASCII.GetString(DiskTracks[0].Sectors[8].SectorData, 0, DiskTracks[0].Sectors[8].SectorData.Length); 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; return true;
// hexagon protection may not be labelled as such // hexagon protection may not be labelled as such

View File

@ -4,6 +4,7 @@ using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
@ -26,7 +27,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// look for standard magic string // look for standard magic string
string ident = Encoding.ASCII.GetString(data, 0, 16); string ident = Encoding.ASCII.GetString(data, 0, 16);
if (!ident.ToUpper().Contains("CAPS")) if (!ident.Contains("CAPS", StringComparison.OrdinalIgnoreCase))
{ {
// incorrect format // incorrect format
return false; return false;

View File

@ -4,6 +4,7 @@ using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Text; using System.Text;
using BizHawk.Common.StringExtensions;
namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
{ {
@ -26,7 +27,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// look for standard magic string // look for standard magic string
string ident = Encoding.ASCII.GetString(data, 0, 4); string ident = Encoding.ASCII.GetString(data, 0, 4);
if (!ident.StartsWith("UDI!") && !ident.StartsWith("udi!")) if (!ident.StartsWithOrdinal("UDI!") && !ident.StartsWithOrdinal("udi!"))
{ {
// incorrect format // incorrect format
return false; return false;
@ -83,7 +84,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// look for standard magic string // look for standard magic string
string ident = Encoding.ASCII.GetString(data, 0, 4); string ident = Encoding.ASCII.GetString(data, 0, 4);
if (!ident.StartsWith("UDI!") && !ident.StartsWith("udi!")) if (!ident.StartsWithOrdinal("UDI!") && !ident.StartsWithOrdinal("udi!"))
{ {
// incorrect format // incorrect format
return false; return false;

View File

@ -57,7 +57,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
int majorVer = data[8]; int majorVer = data[8];
int minorVer = data[9]; int minorVer = data[9];
if (ident.ToUpper() != "COMPRESSED SQUARE WAVE") if (ident.ToUpperInvariant() != "COMPRESSED SQUARE WAVE")
{ {
// this is not a valid CSW format file // this is not a valid CSW format file
return false; return false;
@ -80,7 +80,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// (first 22 bytes of the file) // (first 22 bytes of the file)
string ident = Encoding.ASCII.GetString(data, 0, 22); 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 // this is not a valid CSW format file
throw new Exception($"{nameof(CswConverter)}: This is not a valid CSW format file"); throw new Exception($"{nameof(CswConverter)}: This is not a valid CSW format file");

View File

@ -67,7 +67,7 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
int majorVer = data[8]; int majorVer = data[8];
int minorVer = data[9]; int minorVer = data[9];
if (ident.ToUpper() != "PZXT") if (ident.ToUpperInvariant() != "PZXT")
{ {
// this is not a valid PZX format file // this is not a valid PZX format file
return false; 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 // 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); string ident = Encoding.ASCII.GetString(data, 0, 4);
if (ident.ToUpper() != "PZXT") if (ident.ToUpperInvariant() != "PZXT")
{ {
// this is not a valid TZX format file // this is not a valid TZX format file
throw new Exception($"{nameof(PzxConverter)}: This is not a valid PZX format file"); throw new Exception($"{nameof(PzxConverter)}: This is not a valid PZX format file");

View File

@ -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 // 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); string ident = Encoding.ASCII.GetString(data, 8, 4);
if (ident.ToUpper() != "WAVE") if (ident.ToUpperInvariant() != "WAVE")
{ {
// this is not a valid WAV format file // this is not a valid WAV format file
return false; 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 // 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); string ident = Encoding.ASCII.GetString(data, 8, 4);
if (ident.ToUpper() != "WAVE") if (ident.ToUpperInvariant() != "WAVE")
{ {
// this is not a valid TZX format file // this is not a valid TZX format file
throw new Exception($"{nameof(WavConverter)}: This is not a valid WAV format file"); throw new Exception($"{nameof(WavConverter)}: This is not a valid WAV format file");

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Collections.ObjectModel; using System.Collections.ObjectModel;
using BizHawk.Common; using BizHawk.Common;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common; using BizHawk.Emulation.Common;
using BizHawk.Emulation.Cores.Waterbox; using BizHawk.Emulation.Cores.Waterbox;
@ -119,7 +120,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
foreach (var n in ret.BoolButtons) foreach (var n in ret.BoolButtons)
{ {
if (n.StartsWith("Mouse")) if (n.StartsWithOrdinal("Mouse"))
{ {
ret.CategoryLabels[n] = "Mouse"; ret.CategoryLabels[n] = "Mouse";
} }
@ -127,7 +128,7 @@ namespace BizHawk.Emulation.Cores.Computers.TIC80
foreach (var n in ret.Axes.Keys) foreach (var n in ret.Axes.Keys)
{ {
if (n.StartsWith("Mouse")) if (n.StartsWithOrdinal("Mouse"))
{ {
ret.CategoryLabels[n] = "Mouse"; ret.CategoryLabels[n] = "Mouse";
} }

Some files were not shown because too many files have changed in this diff Show More