Misc. refactors, reverting some code style "fixes"

This commit is contained in:
YoshiRulz 2024-05-30 06:51:36 +10:00
parent ea15126fe1
commit 01bea49ee0
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
26 changed files with 53 additions and 77 deletions

View File

@ -6,6 +6,7 @@ using System.Windows.Forms;
using BizHawk.Bizware.Graphics;
using BizHawk.Client.Common;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.EmuHawk
@ -50,13 +51,9 @@ namespace BizHawk.Client.EmuHawk
string framesDir = "";
foreach (var line in lines)
{
int idx = line.IndexOf('=');
string key = line[..idx];
string value = line[(idx + 1)..];
if (key == "framesdir")
{
framesDir = value;
}
const string KEY = "framesdir=";
if (line.StartsWithOrdinal(KEY)) framesDir = line.Substring(startIndex: KEY.Length);
// and continue
}
_mFramesDirectory = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(_mSynclessConfigFile)), framesDir);

View File

@ -136,7 +136,7 @@ namespace BizHawk.Client.EmuHawk
catch (ArgumentException ex)
{
string errMsg = ex.Message;
errMsg = errMsg[(errMsg.IndexOf('-') + 2)..];
errMsg = errMsg.Substring(startIndex: errMsg.IndexOf('-') + 2);
// Balloon is bugged on first invocation
_errorBalloon.Show($"Error parsing RegEx: {errMsg}", tb);

View File

@ -27,7 +27,9 @@ namespace BizHawk.Client.EmuHawk
private readonly HashSet<Control> _wantingMouseFocus = new HashSet<Control>();
public static Input Instance { get; set; }
#pragma warning disable CA2211 // public field
public static Input Instance;
#pragma warning restore CA2211
private readonly Thread _updateThread;

View File

@ -124,7 +124,7 @@ namespace BizHawk.Client.EmuHawk
// end of the path has ;
var end = exePath.IndexOf(';');
if (end < 0) break;
exePath = exePath[index..end];
exePath = exePath.Substring(startIndex: index, length: end - index);
}
buffer.AddRange(Encoding.ASCII.GetBytes(exePath));

View File

@ -184,7 +184,7 @@ namespace BizHawk.Client.EmuHawk
lvFirmwares.Groups.Add(
key: sysID,
headerText: SystemGroupNames.TryGetValue(sysID, out var name) ? name : "FIX ME (FirmwaresConfig.cs)");
return lvFirmwares.Groups[^1];
return lvFirmwares.Groups[lvFirmwares.Groups.Count - 1];
}
// we'll use this font for displaying the hash, so they don't look all jagged in a long list

View File

@ -192,7 +192,9 @@ namespace BizHawk.Client.EmuHawk
try
{
lines.Add(line[..i], int.Parse(line[(i + 1)..]));
lines.Add(
line.Substring(startIndex: 0, length: i),
int.Parse(line.Substring(startIndex: i + 1)));
}
catch (FormatException)
{

View File

@ -162,7 +162,9 @@ namespace BizHawk.Client.EmuHawk
try
{
lines.Add(line[..i], int.Parse(line[(i + 1)..]));
lines.Add(
line.Substring(startIndex: 0, length: i),
int.Parse(line.Substring(startIndex: i + 1)));
}
catch (FormatException)
{

View File

@ -23,7 +23,7 @@ namespace BizHawk.Client.EmuHawk.ForDebugging
public FirmwareAutopatchDebugToolForm()
{
static string LabelFragment(string hash)
=> $"{hash[..8]}... {FirmwareDatabase.FirmwareFilesByHash[hash].RecommendedName}";
=> $"{hash.Substring(startIndex: 0, length: 8)}... {FirmwareDatabase.FirmwareFilesByHash[hash].RecommendedName}";
List<(string Label, FirmwarePatchOption PatchOption)> patches = FirmwareDatabase.AllPatches
.Select(static fpo => ($"{LabelFragment(fpo.BaseHash)} --> {LabelFragment(fpo.TargetHash)}", fpo)).ToList();
patches.Sort(static (a, b) => string.CompareOrdinal(a.Label, b.Label));

View File

@ -451,7 +451,7 @@ namespace BizHawk.Client.EmuHawk
{
var indices = SelectedIndices.ToList();
if (indices.Count == 0
|| indices[^1] == MainForm.CheatList.Count - 1) // at end already
|| indices[indices.Count - 1] == MainForm.CheatList.Count - 1) // at end already
{
return;
}

View File

@ -1395,10 +1395,7 @@ namespace BizHawk.Client.EmuHawk
}
// and add HighlightedAddress if present
if (_highlightedAddress.HasValue)
{
addresses[^1] = _highlightedAddress.Value;
}
if (_highlightedAddress is long l) addresses[addresses.Length - 1] = l;
// these need to be sorted. it's not just for HighlightedAddress, _secondaryHighlightedAddresses can even be jumbled
Array.Sort(addresses);

View File

@ -386,7 +386,7 @@ namespace BizHawk.Client.EmuHawk
{
while (LuaImp.ScriptList.Count > 0)
{
RemoveLuaFile(LuaImp.ScriptList[^1]);
RemoveLuaFile(LuaImp.ScriptList[LuaImp.ScriptList.Count - 1]);
}
}
@ -1028,7 +1028,7 @@ namespace BizHawk.Client.EmuHawk
{
var indices = LuaListView.SelectedRows.ToList();
if (indices.Count == 0
|| indices[^1] == LuaImp.ScriptList.Count - 1) // at end already
|| indices[indices.Count - 1] == LuaImp.ScriptList.Count - 1) // at end already
{
return;
}
@ -1333,7 +1333,7 @@ namespace BizHawk.Client.EmuHawk
var split = words[0].Split(Path.DirectorySeparatorChar);
luaListTemp.Add(LuaImp.ScriptList[i]);
luaListTemp[i].Name = split[^1];
luaListTemp[i].Name = split[split.Length - 1];
}
// Script, Path

View File

@ -58,10 +58,7 @@ namespace BizHawk.Client.EmuHawk
key = key.Replace($"{box.Text}|", "");
}
}
key = key[..^1];
SelectedZone.InputKey = key;
SelectedZone.InputKey = key.Substring(startIndex: 0, length: key.Length - 1); // drop final char
}
private void PositionBoxes()

View File

@ -28,7 +28,7 @@ namespace BizHawk.Client.EmuHawk
}
key = key.Replace("LogKey:", "").Replace("#", "");
key = key[..^1];
key = key.Substring(startIndex: 0, length: key.Length - 1); // drop last char
_inputKey = key;
Length = length;
@ -41,7 +41,7 @@ namespace BizHawk.Client.EmuHawk
logGenerator.GenerateLogEntry(); // Reference and create all buttons.
string movieKey = logGenerator.GenerateLogKey().Replace("LogKey:", "").Replace("#", "");
movieKey = movieKey[..^1];
movieKey = movieKey.Substring(startIndex: 0, length: movieKey.Length - 1); // drop last char
if (key == movieKey)
{
for (int i = 0; i < length; i++)
@ -239,7 +239,7 @@ namespace BizHawk.Client.EmuHawk
var lg = _movieSession.Movie.LogGeneratorInstance(_movieSession.MovieController);
string key = lg.GenerateLogKey();
key = key.Replace("LogKey:", "").Replace("#", "");
key = key[..^1];
key = key.Substring(startIndex: 0, length: key.Length - 1); // drop last char
string[] emuKeys = key.Split('|');
string[] macroKeys = _inputKey.Split('|');
foreach (var macro in macroKeys)

View File

@ -302,7 +302,7 @@ namespace BizHawk.Client.EmuHawk
{
if (p[i] == lastValue)
{
_counts[^1]++;
_counts[_counts.Count - 1]++;
}
else
{
@ -335,7 +335,7 @@ namespace BizHawk.Client.EmuHawk
{
if (p[i] == lastValue)
{
_counts[^1]++;
_counts[_counts.Count - 1]++;
}
else
{

View File

@ -1313,7 +1313,7 @@ namespace BizHawk.Client.EmuHawk
else if (e.KeyCode == Keys.OemMinus || e.KeyCode == Keys.Subtract)
{
_axisTypedValue = _axisTypedValue.StartsWith('-')
? _axisTypedValue[1..]
? _axisTypedValue.Substring(startIndex: 1)
: $"-{_axisTypedValue}";
}
else if (e.KeyCode == Keys.Back)
@ -1323,7 +1323,7 @@ namespace BizHawk.Client.EmuHawk
_axisTypedValue = value.ToString(NumberFormatInfo.InvariantInfo);
}
_axisTypedValue = _axisTypedValue[..^1];
_axisTypedValue = _axisTypedValue.Substring(startIndex: 0, length: _axisTypedValue.Length - 1); // drop last char
if (_axisTypedValue == "" || _axisTypedValue == "-")
{
value = 0f;

View File

@ -468,7 +468,7 @@ namespace BizHawk.Client.EmuHawk
{
_tasClipboard.Clear();
int linesToPaste = lines.Length;
if (lines[^1] == "") linesToPaste--;
if (lines[lines.Length - 1].Length is 0) linesToPaste--;
for (int i = 0; i < linesToPaste; i++)
{
var line = ControllerFromMnemonicStr(lines[i]);
@ -510,7 +510,7 @@ namespace BizHawk.Client.EmuHawk
{
_tasClipboard.Clear();
int linesToPaste = lines.Length;
if (lines[^1] == "") linesToPaste--;
if (lines[lines.Length - 1].Length is 0) linesToPaste--;
for (int i = 0; i < linesToPaste; i++)
{
var line = ControllerFromMnemonicStr(lines[i]);

View File

@ -449,17 +449,16 @@ namespace BizHawk.Client.EmuHawk
BoolPatterns[i] = new AutoPatternBool(1, 1);
}
BoolPatterns[^2] = new AutoPatternBool(1, 0);
BoolPatterns[^1] = new AutoPatternBool(
Config.AutofireOn, Config.AutofireOff);
BoolPatterns[BoolPatterns.Length - 2] = new(1, 0);
BoolPatterns[BoolPatterns.Length - 1] = new(Config.AutofireOn, Config.AutofireOff);
for (int i = fStart; i < AxisPatterns.Length - 2; i++)
{
AxisPatterns[i] = new AutoPatternAxis(new[] { 1 });
}
AxisPatterns[^2] = new AutoPatternAxis(new[] { 1 });
AxisPatterns[^1] = new AutoPatternAxis(1, Config.AutofireOn, 0, Config.AutofireOff);
AxisPatterns[AxisPatterns.Length - 2] = new([ 1 ]);
AxisPatterns[AxisPatterns.Length - 1] = new(1, Config.AutofireOn, 0, Config.AutofireOff);
SetUpToolStripColumns();
}

View File

@ -928,7 +928,7 @@ namespace BizHawk.Client.EmuHawk
{
var indices = SelectedIndices.ToList();
if (indices.Count == 0
|| indices[^1] == _watches.Count - 1) // at end already
|| indices[indices.Count - 1] == _watches.Count - 1) // at end already
{
return;
}

View File

@ -39,7 +39,9 @@ namespace BizHawk.Common
}
// -------------- Logging Action Configuration --------------
public static readonly Action<string> LogAction = DefaultLogger;
#pragma warning disable CA2211 // public field
public static Action<string> LogAction = DefaultLogger;
#pragma warning restore CA2211
// NOTEs are only logged if the domain is enabled.
// ERRORs are logged regardless.

View File

@ -24,7 +24,7 @@ namespace BizHawk.Emulation.Cores.Components.H6280
{
string dis = DisassembleExt(
0,
out int unused,
out _,
addr => md.PeekByte(addr + i),
addr => md.PeekUshort(addr + i, bigEndian: false));
w.WriteLine("0x{0:x8}: {1}", i, dis);

View File

@ -100,9 +100,8 @@ namespace BizHawk.Emulation.Cores.Computers.Commodore64.Media
offsets.Add((int)trackMem.Length);
densities.Add(trackDensities[trackIndex]);
var data = trackData[trackIndex];
var buffer = Enumerable.Repeat(dataFillerValue, trackMaxLength).ToArray();
var dataBytes = data.Select(d => unchecked(d)).ToArray();
var dataBytes = trackData[trackIndex];
Array.Copy(dataBytes, buffer, dataBytes.Length);
trackMemWriter.Write((ushort)dataBytes.Length);
trackMemWriter.Write(buffer);

View File

@ -46,9 +46,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// if this is detected just return the kempston byte
if (lowByte == 0x1f)
{
if (LocateUniqueJoystick(JoystickType.Kempston) != null)
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston)).JoyLine;
//TODO lines swapped?
if (LocateUniqueJoystick(JoystickType.Kempston) is KempstonJoystick j) return (byte) j.JoyLine;
InputRead = true;
}
else

View File

@ -46,14 +46,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// if this is detected just return the kempston byte
if (lowByte == 0x1f)
{
if (LocateUniqueJoystick(JoystickType.Kempston) != null)
{
InputRead = true;
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston)).JoyLine;
}
InputRead = true;
}
InputRead = true;
if (LocateUniqueJoystick(JoystickType.Kempston) is KempstonJoystick j) return (byte) j.JoyLine;
}
else
{
if (KeyboardDevice.ReadPort(port, ref result))

View File

@ -27,14 +27,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// if this is detected just return the kempston byte
if (lowByte == 0x1f)
{
if (LocateUniqueJoystick(JoystickType.Kempston) != null)
{
InputRead = true;
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston)).JoyLine;
}
InputRead = true;
}
InputRead = true;
if (LocateUniqueJoystick(JoystickType.Kempston) is KempstonJoystick j) return (byte) j.JoyLine;
}
else
{
if (KeyboardDevice.ReadPort(port, ref result))

View File

@ -27,13 +27,8 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// if this is detected just return the kempston byte
if (lowByte == 0x1f)
{
if (LocateUniqueJoystick(JoystickType.Kempston) != null)
{
InputRead = true;
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston)).JoyLine;
}
InputRead = true;
InputRead = true;
if (LocateUniqueJoystick(JoystickType.Kempston) is KempstonJoystick j) return (byte) j.JoyLine;
}
else if (UPDDiskDevice.ReadPort(port, ref result))
{

View File

@ -22,14 +22,9 @@ namespace BizHawk.Emulation.Cores.Computers.SinclairSpectrum
// if this is detected just return the kempston byte
if (lowByte == 0x1f)
{
if (LocateUniqueJoystick(JoystickType.Kempston) != null)
{
InputRead = true;
return (byte)((KempstonJoystick)LocateUniqueJoystick(JoystickType.Kempston)).JoyLine;
}
// not a lag frame
InputRead = true;
if (LocateUniqueJoystick(JoystickType.Kempston) is KempstonJoystick j) return (byte) j.JoyLine;
}
// Even ports always address the ULA
else if (lowBitReset)