From b3d344b0025a801d55c7d722badcd94e7d66d87f Mon Sep 17 00:00:00 2001 From: YoshiRulz Date: Mon, 30 May 2022 07:27:21 +1000 Subject: [PATCH] Fix conflated indices in `SharpCompressArchiveFile` fixes 6cc4b0e28 --- src/BizHawk.Client.Common/SharpCompressArchiveFile.cs | 9 +++++---- src/BizHawk.Common/HawkFile/HawkFile.cs | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/BizHawk.Client.Common/SharpCompressArchiveFile.cs b/src/BizHawk.Client.Common/SharpCompressArchiveFile.cs index 3555f50f66..9c8f55e95f 100644 --- a/src/BizHawk.Client.Common/SharpCompressArchiveFile.cs +++ b/src/BizHawk.Client.Common/SharpCompressArchiveFile.cs @@ -16,10 +16,11 @@ namespace BizHawk.Client.Common { private IArchive? _archive; - private IEnumerable EnumerateArchiveFiles() + private IEnumerable<(IArchiveEntry Entry, int ArchiveIndex)> EnumerateArchiveFiles() { if (_archive == null) throw new ObjectDisposedException(nameof(SharpCompressArchiveFile)); - return _archive.Entries.Where(e => !e.IsDirectory); + return _archive.Entries.Select(static (e, i) => (Entry: e, ArchiveIndex: i)) + .Where(static tuple => !tuple.Entry.IsDirectory); } public SharpCompressArchiveFile(string path) => _archive = ArchiveFactory.Open(path, new()); @@ -47,9 +48,9 @@ namespace BizHawk.Client.Common var entries = EnumerateArchiveFiles().ToList(); for (var i = 0; i < entries.Count; i++) { - var entry = entries[i]; + var (entry, archiveIndex) = entries[i]; if (entry.Key == null) return null; - outFiles.Add(new HawkArchiveFileItem(entry.Key.Replace('\\', '/'), entry.Size, i, i)); + outFiles.Add(new HawkArchiveFileItem(entry.Key.Replace('\\', '/'), size: entry.Size, index: i, archiveIndex: archiveIndex)); } return outFiles; } diff --git a/src/BizHawk.Common/HawkFile/HawkFile.cs b/src/BizHawk.Common/HawkFile/HawkFile.cs index aad5e57ef2..0876477ca9 100644 --- a/src/BizHawk.Common/HawkFile/HawkFile.cs +++ b/src/BizHawk.Common/HawkFile/HawkFile.cs @@ -170,7 +170,7 @@ namespace BizHawk.Common ArchiveMemberPath = _archiveItems[index].Name; // TODO - maybe go through our own list of names? maybe not, its indices don't match... Util.DebugWriteLine($"{nameof(HawkFile)} bound {CanonicalFullPath}"); if (_boundStream.Length is 0) Console.WriteLine("bound file is 0 bytes long?"); - BoundIndex = archiveIndex; + BoundIndex = index; return this; }