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 += " "; tabs += " ";
} }
// Get the names and sort // Print the directory names recursively, sorted alphabetically
string[] names = this.Children.Keys.ToArray(); foreach (string s in this.Children.Keys.OrderBy(s => s))
Array.Sort(names);
// Print the directory names recursively
foreach (string s in names)
{ {
ISONode n = this.Children[s]; ISONode n = this.Children[s];
Console.WriteLine(tabs + s); Console.WriteLine(tabs + s);

View File

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

View File

@ -720,9 +720,8 @@ namespace BizHawk.Emulation.DiscSystem
{ {
int relMSF = -1; int relMSF = -1;
var track = mdsf.TOCEntries.Where(t => t.Point == i).FirstOrDefault(); var track = mdsf.TOCEntries.FirstOrDefault(t => t.Point == i);
if (track == null) if (track == null) break;
break;
// ignore the info entries // ignore the info entries
if (track.Point == 0xA0 || if (track.Point == 0xA0 ||
@ -733,10 +732,12 @@ namespace BizHawk.Emulation.DiscSystem
} }
// get the blob(s) for this track // get the blob(s) for this track
// its probably a safe assumption that there will be only one blob per track, // it's probably a safe assumption that there will be only one blob per track, but I'm still not 100% sure on this
// but i'm still not 100% sure on this
var tr = mdsf.TOCEntries.FirstOrDefault(a => a.Point == i) ?? throw new MDSParseException("BLOB Error!"); 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>(); List<string> blobstrings = new List<string>();
foreach (var t in tr.ImageFileNamePaths) 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? // is the currBlob valid for this track, or do we need to increment?
string bString = tBlobs.First(); string bString = tBlobs.First();
#endif
IBlob mdfBlob = null; IBlob mdfBlob = null;

View File

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