Fix colection/LINQ usage in DiscSystem

except the garbage that is byte[].Skip().Take(), I CBB fixing that
This commit is contained in:
YoshiRulz 2020-05-19 18:12:57 +10:00 committed by James Groom
parent 0ccf30396d
commit d436b9b9aa
5 changed files with 24 additions and 39 deletions

View File

@ -122,12 +122,8 @@ namespace BizHawk.Emulation.DiscSystem
tabs += " ";
}
// Get the names and sort
string[] names = this.Children.Keys.ToArray();
Array.Sort(names);
// Print the directory names recursively
foreach (string s in names)
// Print the directory names recursively, sorted alphabetically
foreach (string s in this.Children.Keys.OrderBy(s => s))
{
ISONode n = this.Children[s];
Console.WriteLine(tabs + s);

View File

@ -156,25 +156,16 @@ namespace BizHawk.Emulation.DiscSystem
public List<KeyValuePair<string, ISOFileNode>> EnumerateAllFilesRecursively()
{
fileNodes = new List<KeyValuePair<string, ISOFileNode>>();
if (Root.Children == null) return fileNodes;
dirsParsed = new List<ISODirectoryNode>();
if (Root.Children == null)
return fileNodes;
// get all folders
var dirs = (from a in Root.Children where a.Value.GetType() == typeof(ISODirectoryNode) select a);
// iterate through each folder
foreach (var d in dirs)
foreach (var idn in Root.Children.Values.OfType<ISODirectoryNode>()) // iterate through each folder
{
// process all files in this directory (and recursively process files in sub folders
ISODirectoryNode idn = (ISODirectoryNode) d.Value;
if (dirsParsed.Where(a => a == idn).Count() > 0)
continue;
// process all files in this directory (and recursively process files in subfolders)
if (dirsParsed.Contains(idn)) continue;
dirsParsed.Add(idn);
ProcessDirectoryFiles(idn.Children);
}
return fileNodes.Distinct().ToList();
}
@ -184,7 +175,7 @@ namespace BizHawk.Emulation.DiscSystem
{
if (n.Value is ISODirectoryNode subdirNode)
{
if (dirsParsed.Where(a => a == subdirNode).Count() > 0) continue;
if (dirsParsed.Contains(subdirNode)) continue;
dirsParsed.Add(subdirNode);
ProcessDirectoryFiles(subdirNode.Children);
}

View File

@ -94,7 +94,8 @@ namespace BizHawk.Emulation.DiscSystem
throw new Blob_WaveFile_Exception("Not a valid RIFF WAVE file (missing fmt chunk");
}
if (1 != rm.riff.subchunks.Count(chunk => chunk.tag == "data"))
var dataChunks = rm.riff.subchunks.Where(chunk => chunk.tag == "data").ToList();
if (dataChunks.Count != 1)
{
//later, we could make a Stream which would make an index of data chunks and walk around them
throw new Blob_WaveFile_Exception("Multi-data-chunk WAVE files not supported");
@ -111,7 +112,7 @@ namespace BizHawk.Emulation.DiscSystem
}
//acquire the start of the data chunk
var dataChunk = (RiffMaster.RiffSubchunk) rm.riff.subchunks.First(chunk => chunk.tag == "data");
var dataChunk = (RiffMaster.RiffSubchunk) dataChunks[0];
waveDataStreamPos = dataChunk.Position;
mDataLength = dataChunk.Length;
}

View File

@ -720,9 +720,8 @@ namespace BizHawk.Emulation.DiscSystem
{
int relMSF = -1;
var track = mdsf.TOCEntries.Where(t => t.Point == i).FirstOrDefault();
if (track == null)
break;
var track = mdsf.TOCEntries.FirstOrDefault(t => t.Point == i);
if (track == null) break;
// ignore the info entries
if (track.Point == 0xA0 ||
@ -733,10 +732,12 @@ namespace BizHawk.Emulation.DiscSystem
}
// get the blob(s) for this track
// its probably a safe assumption that there will be only one blob per track,
// but i'm still not 100% sure on this
// it's probably a safe assumption that there will be only one blob per track, but I'm still not 100% sure on this
var tr = mdsf.TOCEntries.FirstOrDefault(a => a.Point == i) ?? throw new MDSParseException("BLOB Error!");
#if true
if (tr.ImageFileNamePaths.Count == 0) throw new MDSParseException("BLOB Error!");
#else // this is the worst use of lists and LINQ I've seen in this god-forsaken codebase, I hope for all our sakes that it's not a workaround for some race condition --yoshi
List<string> blobstrings = new List<string>();
foreach (var t in tr.ImageFileNamePaths)
{
@ -752,6 +753,7 @@ namespace BizHawk.Emulation.DiscSystem
// is the currBlob valid for this track, or do we need to increment?
string bString = tBlobs.First();
#endif
IBlob mdfBlob = null;

View File

@ -203,20 +203,15 @@ namespace BizHawk.Emulation.DiscSystem
if (sysId == "ASAHI-CDV")
return DiscType.Playdia;
if (sysId == "CDTV" || sysId == "AMIGA")
if (sysId == "CDTV" || sysId == "AMIGA"
|| iso.Root.Children.Keys.Any(k => k.ToLowerInvariant().Contains("cd32")))
{
return DiscType.Amiga;
foreach (var f in iso.Root.Children)
if (f.Key.ToLower().Contains("cd32"))
return DiscType.Amiga;
}
// NeoGeoCD Check
var absTxt = iso.Root.Children.Where(a => a.Key.Contains("ABS.TXT")).ToList();
if (absTxt.Count > 0)
{
if (SectorContains("abstracted by snk", Convert.ToInt32(absTxt.First().Value.Offset)))
return DiscType.NeoGeoCD;
}
var absTxt = iso.Root.Children.Where(kvp => kvp.Key.Contains("ABS.TXT")).Select(kvp => kvp.Value).FirstOrDefault();
if (absTxt != null && SectorContains("abstracted by snk", Convert.ToInt32(absTxt.Offset))) return DiscType.NeoGeoCD;
return DiscType.UnknownCDFS;
}