Fix remaining MA0098 code style warnings

"Use indexer instead of LINQ methods"
fixes 17df5673d, forgot I was in the middle of this when I pushed
This commit is contained in:
YoshiRulz 2022-07-22 04:17:02 +10:00
parent 17df5673d2
commit 3f2a07e582
No known key found for this signature in database
GPG Key ID: C4DE31C245353FB7
16 changed files with 47 additions and 61 deletions

View File

@ -162,7 +162,7 @@ namespace BizHawk.Client.Common
}
else
{
var message = _messages.Last();
var message = _messages[_messages.Count - 1];
DrawMessage(g, message, 0);
}
}

View File

@ -62,7 +62,7 @@ namespace BizHawk.Client.Common
if (recentlist.Count > MAX_RECENT_FILES)
{
recentlist.Remove(recentlist.Last());
recentlist.RemoveAt(recentlist.Count - 1);
}
}
}

View File

@ -6,6 +6,7 @@ using System.Xml;
using BizHawk.Common;
using BizHawk.Common.IOExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Common;
namespace BizHawk.Client.Common
@ -71,8 +72,8 @@ namespace BizHawk.Client.Common
else
{
// relative path
fullPath = Path.GetDirectoryName(f.CanonicalFullPath.Split('|').First()) ?? "";
fullPath = Path.Combine(fullPath, filename.Split('|').First());
fullPath = Path.GetDirectoryName(f.CanonicalFullPath.SubstringBefore('|')) ?? "";
fullPath = Path.Combine(fullPath, filename.SubstringBefore('|'));
try
{
using var hf = new HawkFile(fullPath);
@ -87,7 +88,7 @@ namespace BizHawk.Client.Common
}
else
{
data = File.ReadAllBytes(fullPath.Split('|').First());
data = File.ReadAllBytes(fullPath.SubstringBefore('|'));
}
}
catch (Exception e)

View File

@ -301,7 +301,7 @@ namespace BizHawk.Client.Common
}
else
{
scope = DebuggableCore.MemoryCallbacks.AvailableScopes.First();
scope = DebuggableCore.MemoryCallbacks.AvailableScopes[0];
}
}

View File

@ -46,6 +46,9 @@ namespace BizHawk.Client.Common
private int _totalSteps;
private bool _recordingBatch;
private List<IMovieAction> LatestBatch
=> _history[_history.Count - 1];
public List<string> Names { get; } = new List<string>();
public int UndoIndex { get; private set; } = -1;
@ -163,7 +166,7 @@ namespace BizHawk.Client.Common
}
_recordingBatch = false;
List<IMovieAction> last = _history.Last();
var last = LatestBatch;
if (last.Count == 0) // Remove batch if it's empty.
{
_history.RemoveAt(_history.Count - 1);
@ -328,8 +331,8 @@ namespace BizHawk.Client.Common
if (IsRecording || force)
{
AddMovieAction(name);
_history.Last().Add(new MovieAction(first, last, _movie));
_lastGeneral = _history.Last().Count - 1;
LatestBatch.Add(new MovieAction(first, last, _movie));
_lastGeneral = LatestBatch.Count - 1;
}
}
@ -337,7 +340,7 @@ namespace BizHawk.Client.Common
{
if (IsRecording || force)
{
(_history.Last()[_lastGeneral] as MovieAction).SetRedoLog(_movie);
((MovieAction) LatestBatch[_lastGeneral]).SetRedoLog(_movie);
}
}
@ -346,7 +349,7 @@ namespace BizHawk.Client.Common
if (IsRecording || force)
{
AddMovieAction(name);
_history.Last().Add(new MovieActionFrameEdit(frame, button, oldState, !oldState));
LatestBatch.Add(new MovieActionFrameEdit(frame, button, oldState, !oldState));
}
}
@ -355,7 +358,7 @@ namespace BizHawk.Client.Common
if (IsRecording || force)
{
AddMovieAction(name);
_history.Last().Add(new MovieActionFrameEdit(frame, button, oldState, newState));
LatestBatch.Add(new MovieActionFrameEdit(frame, button, oldState, newState));
}
}
@ -368,7 +371,7 @@ namespace BizHawk.Client.Common
: $"Remove Marker at frame {oldPosition}";
AddMovieAction(name);
_history.Last().Add(new MovieActionMarker(newMarker, oldPosition, oldMessage));
LatestBatch.Add(new MovieActionMarker(newMarker, oldPosition, oldMessage));
}
}
@ -377,7 +380,7 @@ namespace BizHawk.Client.Common
if (IsRecording || force)
{
AddMovieAction(name);
_history.Last().Add(new MovieActionBindInput(_movie, frame, isDelete));
LatestBatch.Add(new MovieActionBindInput(_movie, frame, isDelete));
}
}
@ -386,7 +389,7 @@ namespace BizHawk.Client.Common
if (IsRecording || force)
{
AddMovieAction(name);
_history.Last().Add(new MovieActionInsertFrames(frame, count));
LatestBatch.Add(new MovieActionInsertFrames(frame, count));
}
}
@ -395,7 +398,7 @@ namespace BizHawk.Client.Common
if (IsRecording || force)
{
AddMovieAction(name);
_history.Last().Add(new MovieActionInsertFrames(frame, newInputs));
LatestBatch.Add(new MovieActionInsertFrames(frame, newInputs));
}
}
@ -404,7 +407,7 @@ namespace BizHawk.Client.Common
if (IsRecording || force)
{
AddMovieAction(name);
_history.Last().Add(new MovieActionRemoveFrames(removeStart, removeUpTo, oldInputs, removedMarkers));
LatestBatch.Add(new MovieActionRemoveFrames(removeStart, removeUpTo, oldInputs, removedMarkers));
}
}
}

View File

@ -266,7 +266,7 @@ namespace BizHawk.Client.EmuHawk
case 0:
break;
case 1:
var fileInformation = sortedFiles[value].First();
var fileInformation = sortedFiles[value][0];
string filename = Path.Combine(new[] { fileInformation.DirectoryName, fileInformation.FileName });
switch (value)

View File

@ -1,5 +1,4 @@
using System;
using System.Linq;
using System.Windows.Forms;
using BizHawk.Client.Common;
@ -56,46 +55,46 @@ namespace BizHawk.Client.EmuHawk
bool selectionValid = true;
var j1 = Port1ComboBox.SelectedItem.ToString();
if (j1 != _possibleControllers.First())
if (j1 != _possibleControllers[0])
{
if (j1 == Port2ComboBox.SelectedItem.ToString())
{
Port2ComboBox.SelectedItem = _possibleControllers.First();
Port2ComboBox.SelectedItem = _possibleControllers[0];
selectionValid = false;
}
if (j1 == Port3ComboBox.SelectedItem.ToString())
{
Port3ComboBox.SelectedItem = _possibleControllers.First();
Port3ComboBox.SelectedItem = _possibleControllers[0];
selectionValid = false;
}
}
var j2 = Port2ComboBox.SelectedItem.ToString();
if (j2 != _possibleControllers.First())
if (j2 != _possibleControllers[0])
{
if (j2 == Port1ComboBox.SelectedItem.ToString())
{
Port1ComboBox.SelectedItem = _possibleControllers.First();
Port1ComboBox.SelectedItem = _possibleControllers[0];
selectionValid = false;
}
if (j2 == Port3ComboBox.SelectedItem.ToString())
{
Port3ComboBox.SelectedItem = _possibleControllers.First();
Port3ComboBox.SelectedItem = _possibleControllers[0];
selectionValid = false;
}
}
var j3 = Port3ComboBox.SelectedItem.ToString();
if (j3 != _possibleControllers.First())
if (j3 != _possibleControllers[0])
{
if (j3 == Port1ComboBox.SelectedItem.ToString())
{
Port1ComboBox.SelectedItem = _possibleControllers.First();
Port1ComboBox.SelectedItem = _possibleControllers[0];
selectionValid = false;
}
if (j3 == Port2ComboBox.SelectedItem.ToString())
{
Port2ComboBox.SelectedItem = _possibleControllers.First();
Port2ComboBox.SelectedItem = _possibleControllers[0];
selectionValid = false;
}
}

View File

@ -221,7 +221,7 @@ namespace BizHawk.Client.EmuHawk
// Final tie breaker - Last used file
var file = new FileInfo(_movieList[indices[0]].Filename);
var time = file.LastAccessTime;
var mostRecent = indices.First();
var mostRecent = indices[0];
for (var i = 1; i < indices.Count; i++)
{
file = new FileInfo(_movieList[indices[0]].Filename);

View File

@ -448,7 +448,8 @@ namespace BizHawk.Client.EmuHawk
private void MoveDownMenuItem_Click(object sender, EventArgs e)
{
var indices = SelectedIndices.ToList();
if (indices.Count == 0 || indices.Last() == MainForm.CheatList.Count - 1)
if (indices.Count == 0
|| indices[indices.Count - 1] == MainForm.CheatList.Count - 1) // at end already
{
return;
}

View File

@ -133,7 +133,7 @@ namespace BizHawk.Client.EmuHawk
private void IncrementCurrentAddress()
{
_currentDisassemblerAddress += (uint)_disassemblyLines.First().Size;
_currentDisassemblerAddress += (uint) _disassemblyLines[0].Size;
if (_currentDisassemblerAddress >= BusMaxValue)
{
_currentDisassemblerAddress = (uint)(BusMaxValue - 1);

View File

@ -898,13 +898,7 @@ namespace BizHawk.Client.EmuHawk
{
return "";
}
if (path.Contains("|"))
{
path = path.Split('|').First();
}
return Path.GetDirectoryName(path);
return Path.GetDirectoryName(path.SubstringBefore('|'));
}
}
@ -918,13 +912,7 @@ namespace BizHawk.Client.EmuHawk
{
return "";
}
if (path.Contains("|"))
{
path = path.Split('|').Last();
}
return Path.GetFileName(path);
return Path.GetFileName(path.SubstringAfterLast('|'));
}
}
@ -1328,9 +1316,7 @@ namespace BizHawk.Client.EmuHawk
private void LoadTableFileMenuItem_Click(object sender, EventArgs e)
{
string initialDirectory = Config.PathEntries.ToolsAbsolutePath();
var romName = Config.RecentRoms.MostRecent.Contains('|')
? Config.RecentRoms.MostRecent.Split('|').Last()
: Config.RecentRoms.MostRecent;
var romName = Config.RecentRoms.MostRecent.SubstringAfterLast('|');
using var ofd = new OpenFileDialog
{

View File

@ -1063,7 +1063,8 @@ namespace BizHawk.Client.EmuHawk
private void MoveDownMenuItem_Click(object sender, EventArgs e)
{
var indices = LuaListView.SelectedRows.ToList();
if (indices.Count == 0 || indices.Last() == LuaImp.ScriptList.Count - 1)
if (indices.Count == 0
|| indices[indices.Count - 1] == LuaImp.ScriptList.Count - 1) // at end already
{
return;
}

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Linq;
using System.Reflection;
using System.Threading;
using NLua;
@ -73,14 +74,7 @@ namespace BizHawk.Client.EmuHawk
foreach (var lib in Client.Common.ReflectionCache.Types.Concat(EmuHawk.ReflectionCache.Types)
.Where(t => typeof(LuaLibraryBase).IsAssignableFrom(t) && t.IsSealed && ServiceInjector.IsAvailable(serviceProvider, t)))
{
bool addLibrary = true;
var attributes = lib.GetCustomAttributes(typeof(LuaLibraryAttribute), false);
if (attributes.Any())
{
addLibrary = VersionInfo.DeveloperBuild || ((LuaLibraryAttribute)attributes.First()).Released;
}
if (addLibrary)
if (VersionInfo.DeveloperBuild || lib.GetCustomAttribute<LuaLibraryAttribute>(inherit: false)?.Released == true)
{
var instance = (LuaLibraryBase) Activator.CreateInstance(lib, this, _apiContainer, (Action<string>) LogToLuaConsole);
ServiceInjector.UpdateServices(serviceProvider, instance);

View File

@ -11,6 +11,7 @@ using BizHawk.Emulation.Common;
using BizHawk.Client.Common;
using BizHawk.Common;
using BizHawk.Common.PathExtensions;
using BizHawk.Common.StringExtensions;
using BizHawk.Emulation.Cores.Sega.MasterSystem;
namespace BizHawk.Client.EmuHawk
@ -199,8 +200,7 @@ namespace BizHawk.Client.EmuHawk
throw new Exception("System Id can not be blank");
}
var basePath = Path.GetDirectoryName(name.Split('|').First());
var basePath = Path.GetDirectoryName(name.SubstringBefore('|'));
if (string.IsNullOrEmpty(basePath))
{
var fileInfo = new FileInfo(name);

View File

@ -877,7 +877,8 @@ namespace BizHawk.Client.EmuHawk
private void MoveDownMenuItem_Click(object sender, EventArgs e)
{
var indices = SelectedIndices.ToList();
if (indices.Count == 0 || indices.Last() == _watches.Count - 1)
if (indices.Count == 0
|| indices[indices.Count - 1] == _watches.Count - 1) // at end already
{
return;
}

View File

@ -142,7 +142,7 @@ namespace BizHawk.Emulation.Cores.Computers.AmstradCPC
}
// are all the sample lengths the same?
var firstEntry = SoundProviders.First();
var firstEntry = SoundProviders[0];
bool sameCount = SoundProviders.All(s => s.NSamp == firstEntry.NSamp);
if (!sameCount)