Skip to content

Commit

Permalink
Enable BHI1001 and fix noncompliance
Browse files Browse the repository at this point in the history
"Do not use anonymous delegates"
  • Loading branch information
YoshiRulz committed Jul 13, 2022
1 parent 395aa07 commit 056db31
Show file tree
Hide file tree
Showing 15 changed files with 61 additions and 120 deletions.
2 changes: 1 addition & 1 deletion Common.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<RuleSet Name="BizHawk Rules" Description="Applies to all projects in the solution -- or, it will eventually." ToolsVersion="14.0">
<Rules AnalyzerId="BizHawk.Analyzer" RuleNamespace="BizHawk.Analyzer">
<!-- Do not use anonymous delegates -->
<Rule Id="BHI1001" Action="Hidden" />
<Rule Id="BHI1001" Action="Error" />

<!-- Do not use anonymous types (classes) -->
<Rule Id="BHI1002" Action="Hidden" />
Expand Down
27 changes: 9 additions & 18 deletions src/BizHawk.Client.Common/movie/bk2/Bk2Movie.IO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ protected virtual void LoadFields(ZipStateLoader bl, bool preload)

protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
{
bl.GetLump(BinaryStateLump.Movieheader, true, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Movieheader, abort: true, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
Expand All @@ -176,7 +176,7 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
}
});

bl.GetLump(BinaryStateLump.Input, true, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Input, abort: true, tr =>
{
IsCountingRerecords = false;
ExtractInputLog(tr, out _);
Expand All @@ -188,7 +188,7 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
return;
}

bl.GetLump(BinaryStateLump.Comments, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Comments, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
Expand All @@ -200,7 +200,7 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
}
});

bl.GetLump(BinaryStateLump.Subtitles, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Subtitles, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
Expand All @@ -214,7 +214,7 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
Subtitles.Sort();
});

bl.GetLump(BinaryStateLump.SyncSettings, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.SyncSettings, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
Expand All @@ -229,16 +229,10 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
if (StartsFromSavestate)
{
bl.GetCoreState(
delegate(BinaryReader br, long length)
{
BinarySavestate = br.ReadBytes((int)length);
},
delegate(TextReader tr)
{
TextSavestate = tr.ReadToEnd();
});
(br, length) => BinarySavestate = br.ReadBytes((int) length),
tr => TextSavestate = tr.ReadToEnd());
bl.GetLump(BinaryStateLump.Framebuffer, false,
delegate(BinaryReader br, long length)
(br, length) =>
{
SavestateFramebuffer = new int[length / sizeof(int)];
for (int i = 0; i < SavestateFramebuffer.Length; i++)
Expand All @@ -250,10 +244,7 @@ protected void LoadBk2Fields(ZipStateLoader bl, bool preload)
else if (StartsFromSaveRam)
{
bl.GetLump(BinaryStateLump.MovieSaveRam, false,
delegate(BinaryReader br, long length)
{
SaveRam = br.ReadBytes((int)length);
});
(br, length) => SaveRam = br.ReadBytes((int) length));
}
}
}
Expand Down
37 changes: 14 additions & 23 deletions src/BizHawk.Client.Common/movie/tasproj/TasBranch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ public void Save(ZipStateSaver bs)
var nusertext = new IndexedStateLump(BinaryStateLump.BranchUserText);
foreach (var b in this)
{
bs.PutLump(nheader, delegate(TextWriter tw)
bs.PutLump(nheader, tw =>
{
// if this header needs more stuff in it, handle it sensibly
tw.WriteLine(JsonConvert.SerializeObject(new
Expand All @@ -134,12 +134,9 @@ public void Save(ZipStateSaver bs)
}));
});

bs.PutLump(ncore, delegate(Stream s)
{
s.Write(b.CoreData, 0, b.CoreData.Length);
});
bs.PutLump(ncore, (Stream s) => s.Write(b.CoreData, 0, b.CoreData.Length));

bs.PutLump(ninput, delegate(TextWriter tw)
bs.PutLump(ninput, tw =>
{
int todo = b.InputLog.Count;
for (int i = 0; i < todo; i++)
Expand All @@ -148,27 +145,21 @@ public void Save(ZipStateSaver bs)
}
});

bs.PutLump(nframebuffer, delegate(Stream s)
bs.PutLump(nframebuffer, s =>
{
var vp = new BitmapBufferVideoProvider(b.OSDFrameBuffer);
_quickBmpFile.Save(vp, s, b.OSDFrameBuffer.Width, b.OSDFrameBuffer.Height);
});

bs.PutLump(ncoreframebuffer, delegate(Stream s)
bs.PutLump(ncoreframebuffer, s =>
{
var vp = new BitmapBufferVideoProvider(b.CoreFrameBuffer);
_quickBmpFile.Save(vp, s, b.CoreFrameBuffer.Width, b.CoreFrameBuffer.Height);
});

bs.PutLump(nmarkers, delegate(TextWriter tw)
{
tw.WriteLine(b.Markers.ToString());
});
bs.PutLump(nmarkers, tw => tw.WriteLine(b.Markers.ToString()));

bs.PutLump(nusertext, delegate(TextWriter tw)
{
tw.WriteLine(b.UserText);
});
bs.PutLump(nusertext, tw => tw.WriteLine(b.UserText));

nheader.Increment();
ncore.Increment();
Expand Down Expand Up @@ -196,7 +187,7 @@ public void Load(ZipStateLoader bl, ITasMovie movie)
{
var b = new TasBranch();

if (!bl.GetLump(nheader, false, delegate(TextReader tr)
if (!bl.GetLump(nheader, abort: false, tr =>
{
var header = (dynamic)JsonConvert.DeserializeObject(tr.ReadLine());
b.Frame = (int)header.Frame;
Expand Down Expand Up @@ -226,13 +217,13 @@ public void Load(ZipStateLoader bl, ITasMovie movie)
return;
}

bl.GetLump(ncore, true, delegate(Stream s, long length)
bl.GetLump(ncore, abort: true, (Stream s, long length) =>
{
b.CoreData = new byte[length];
s.Read(b.CoreData, 0, b.CoreData.Length);
});

bl.GetLump(ninput, true, delegate(TextReader tr)
bl.GetLump(ninput, abort: true, tr =>
{
b.InputLog = StringLogUtil.MakeStringLog();
string line;
Expand All @@ -242,20 +233,20 @@ public void Load(ZipStateLoader bl, ITasMovie movie)
}
});

bl.GetLump(nframebuffer, true, delegate(Stream s, long length)
bl.GetLump(nframebuffer, abort: true, (s, _) =>
{
_quickBmpFile.LoadAuto(s, out var vp);
b.OSDFrameBuffer = new BitmapBuffer(vp.BufferWidth, vp.BufferHeight, vp.GetVideoBuffer());
});

bl.GetLump(ncoreframebuffer, false, delegate(Stream s, long length)
bl.GetLump(ncoreframebuffer, abort: false, (s, _) =>
{
_quickBmpFile.LoadAuto(s, out var vp);
b.CoreFrameBuffer = new BitmapBuffer(vp.BufferWidth, vp.BufferHeight, vp.GetVideoBuffer());
});

b.Markers = new TasMovieMarkerList(movie);
bl.GetLump(nmarkers, false, delegate(TextReader tr)
bl.GetLump(nmarkers, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
Expand All @@ -267,7 +258,7 @@ public void Load(ZipStateLoader bl, ITasMovie movie)
}
});

bl.GetLump(nusertext, false, delegate(TextReader tr)
bl.GetLump(nusertext, abort: false, tr =>
{
string line;
if ((line = tr.ReadLine()) != null)
Expand Down
17 changes: 7 additions & 10 deletions src/BizHawk.Client.Common/movie/tasproj/TasMovie.IO.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,9 @@ protected override void LoadFields(ZipStateLoader bl, bool preload)

private void LoadTasprojExtras(ZipStateLoader bl)
{
bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
{
LagLog.Load(tr);
});
bl.GetLump(BinaryStateLump.LagLog, abort: false, tr => LagLog.Load(tr));

bl.GetLump(BinaryStateLump.Markers, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Markers, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
Expand All @@ -101,7 +98,7 @@ private void LoadTasprojExtras(ZipStateLoader bl)
if (GetClientSettingsOnLoad != null)
{
string clientSettings = "";
bl.GetLump(BinaryStateLump.ClientSettings, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.ClientSettings, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
Expand All @@ -119,7 +116,7 @@ private void LoadTasprojExtras(ZipStateLoader bl)
}
}

bl.GetLump(BinaryStateLump.VerificationLog, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.VerificationLog, abort: false, tr =>
{
VerificationLog.Clear();
while (true)
Expand All @@ -139,7 +136,7 @@ private void LoadTasprojExtras(ZipStateLoader bl)

Branches.Load(bl, this);

bl.GetLump(BinaryStateLump.Session, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.Session, abort: false, tr =>
{
var json = tr.ReadToEnd();
try
Expand All @@ -153,7 +150,7 @@ private void LoadTasprojExtras(ZipStateLoader bl)
});

ZwinderStateManagerSettings settings = new ZwinderStateManagerSettings();
bl.GetLump(BinaryStateLump.StateHistorySettings, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.StateHistorySettings, abort: false, tr =>
{
var json = tr.ReadToEnd();
try
Expand All @@ -166,7 +163,7 @@ private void LoadTasprojExtras(ZipStateLoader bl)
}
});

bl.GetLump(BinaryStateLump.StateHistory, false, delegate(BinaryReader br, long length)
bl.GetLump(BinaryStateLump.StateHistory, abort: false, (br, _) =>
{
try
{
Expand Down
17 changes: 5 additions & 12 deletions src/BizHawk.Client.Common/savestates/SavestateFile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public void Create(string filename, SaveStateConfig config)
if (_movieSession.Movie.IsActive())
{
bs.PutLump(BinaryStateLump.Input,
delegate(TextWriter tw)
tw =>
{
// this never should have been a core's responsibility
tw.WriteLine("Frame {0}", _emulator.Frame);
Expand All @@ -108,7 +108,7 @@ public void Create(string filename, SaveStateConfig config)
if (_userBag.Any())
{
bs.PutLump(BinaryStateLump.UserData,
delegate(TextWriter tw)
tw =>
{
var data = ConfigService.SaveWithType(_userBag);
tw.WriteLine(data);
Expand All @@ -117,11 +117,7 @@ public void Create(string filename, SaveStateConfig config)

if (_movieSession.Movie.IsActive() && _movieSession.Movie is ITasMovie)
{
bs.PutLump(BinaryStateLump.LagLog,
delegate(TextWriter tw)
{
((ITasMovie)_movieSession.Movie).LagLog.Save(tw);
});
bs.PutLump(BinaryStateLump.LagLog, tw => ((ITasMovie) _movieSession.Movie).LagLog.Save(tw));
}
}

Expand Down Expand Up @@ -177,7 +173,7 @@ public bool Load(string path, IDialogParent dialogParent)
}

string userData = "";
bl.GetLump(BinaryStateLump.UserData, false, delegate(TextReader tr)
bl.GetLump(BinaryStateLump.UserData, abort: false, tr =>
{
string line;
while ((line = tr.ReadLine()) != null)
Expand All @@ -198,10 +194,7 @@ public bool Load(string path, IDialogParent dialogParent)

if (_movieSession.Movie.IsActive() && _movieSession.Movie is ITasMovie)
{
bl.GetLump(BinaryStateLump.LagLog, false, delegate(TextReader tr)
{
((ITasMovie)_movieSession.Movie).LagLog.Load(tr);
});
bl.GetLump(BinaryStateLump.LagLog, abort: false, tr => ((ITasMovie) _movieSession.Movie).LagLog.Load(tr));
}

return true;
Expand Down
24 changes: 3 additions & 21 deletions src/BizHawk.Client.Common/savestates/ZipStateLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,31 +123,13 @@ public bool GetLump(BinaryStateLump lump, bool abort, Action<Stream, long> callb
}

public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader> callback)
{
return GetLump(lump, abort, delegate(Stream s, long unused)
{
var br = new BinaryReader(s);
callback(br);
});
}
=> GetLump(lump, abort, (s, _) => callback(new(s)));

public bool GetLump(BinaryStateLump lump, bool abort, Action<BinaryReader, long> callback)
{
return GetLump(lump, abort, delegate(Stream s, long length)
{
var br = new BinaryReader(s);
callback(br, length);
});
}
=> GetLump(lump, abort, (s, length) => callback(new(s), length));

public bool GetLump(BinaryStateLump lump, bool abort, Action<TextReader> callback)
{
return GetLump(lump, abort, delegate(Stream s, long unused)
{
var tr = new StreamReader(s);
callback(tr);
});
}
=> GetLump(lump, abort, (s, _) => callback(new StreamReader(s)));

/// <exception cref="Exception">couldn't find Binary or Text savestate</exception>
public void GetCoreState(Action<BinaryReader, long> callbackBinary, Action<TextReader> callbackText)
Expand Down
4 changes: 2 additions & 2 deletions src/BizHawk.Client.Common/savestates/ZipStateSaver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void PutLump(BinaryStateLump lump, Action<Stream> callback)

public void PutLump(BinaryStateLump lump, Action<BinaryWriter> callback)
{
PutLump(lump, delegate(Stream s)
PutLump(lump, s =>
{
var bw = new BinaryWriter(s);
callback(bw);
Expand All @@ -52,7 +52,7 @@ public void PutLump(BinaryStateLump lump, Action<BinaryWriter> callback)

public void PutLump(BinaryStateLump lump, Action<TextWriter> callback)
{
PutLump(lump, delegate(Stream s)
PutLump(lump, s =>
{
TextWriter tw = new StreamWriter(s);
callback(tw);
Expand Down
10 changes: 2 additions & 8 deletions src/BizHawk.Emulation.Cores/Arcades/MAME/MAME.MemoryDomains.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,7 @@ private void InitMemoryDomains()
var name = $"{ deviceName } : { read } : 0x{ firstOffset:X}-0x{ lastOffset:X}";

domains.Add(new MemoryDomainDelegate(name, lastOffset - firstOffset + 1, endian,
delegate (long addr)
{
return _peek(addr, firstOffset, size);
},
addr => _peek(addr, firstOffset, size),
read == "rom"
? null
: (long addr, byte val) => _poke(addr, val, firstOffset, size),
Expand All @@ -99,10 +96,7 @@ private void InitMemoryDomains()
}

domains.Add(new MemoryDomainDelegate(deviceName + " : System Bus", size, endian,
delegate (long addr)
{
return _peek(addr, 0, size);
},
addr => _peek(addr, 0, size),
null, dataWidth));

_memoryDomains = new MemoryDomainList(domains);
Expand Down
Loading

0 comments on commit 056db31

Please sign in to comment.