diff --git a/src/BizHawk.Emulation.DiscSystem/CDFS/ISODirectoryNode.cs b/src/BizHawk.Emulation.DiscSystem/CDFS/ISODirectoryNode.cs index c22a9973f8..23f61a8183 100644 --- a/src/BizHawk.Emulation.DiscSystem/CDFS/ISODirectoryNode.cs +++ b/src/BizHawk.Emulation.DiscSystem/CDFS/ISODirectoryNode.cs @@ -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); diff --git a/src/BizHawk.Emulation.DiscSystem/CDFS/ISOFile.cs b/src/BizHawk.Emulation.DiscSystem/CDFS/ISOFile.cs index 950584b2db..e3080c6d6b 100644 --- a/src/BizHawk.Emulation.DiscSystem/CDFS/ISOFile.cs +++ b/src/BizHawk.Emulation.DiscSystem/CDFS/ISOFile.cs @@ -156,25 +156,16 @@ namespace BizHawk.Emulation.DiscSystem public List> EnumerateAllFilesRecursively() { fileNodes = new List>(); + if (Root.Children == null) return fileNodes; + dirsParsed = new List(); - - 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()) // 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); } diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/Blobs/Blob_WaveFile.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/Blobs/Blob_WaveFile.cs index ff1085b7aa..2a8cd1ab7d 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/Blobs/Blob_WaveFile.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/Blobs/Blob_WaveFile.cs @@ -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; } diff --git a/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs b/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs index 21b842c35c..b77b504633 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscFormats/MDS_Format.cs @@ -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 blobstrings = new List(); 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; diff --git a/src/BizHawk.Emulation.DiscSystem/DiscIdentifier.cs b/src/BizHawk.Emulation.DiscSystem/DiscIdentifier.cs index 190dc10e03..43a73ff6f7 100644 --- a/src/BizHawk.Emulation.DiscSystem/DiscIdentifier.cs +++ b/src/BizHawk.Emulation.DiscSystem/DiscIdentifier.cs @@ -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; }