From a140e1c444c27fbbd607a22711d8f56602c62c88 Mon Sep 17 00:00:00 2001 From: Matt Nadareski Date: Thu, 21 Jan 2021 11:54:05 -0800 Subject: [PATCH] Fix MPQ extraction (fixes #16) --- BurnOutSharp/FileType/MPQ.cs | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/BurnOutSharp/FileType/MPQ.cs b/BurnOutSharp/FileType/MPQ.cs index d69e389e..846ca338 100644 --- a/BurnOutSharp/FileType/MPQ.cs +++ b/BurnOutSharp/FileType/MPQ.cs @@ -26,17 +26,25 @@ namespace BurnOutSharp.FileType using (MpqArchive mpqArchive = new MpqArchive(file, FileAccess.Read)) { + // Try to open the listfile string listfile = null; MpqFileStream listStream = mpqArchive.OpenFile("(listfile)"); - bool canRead = listStream.CanRead; + + // If we can't read the listfile, we just return + if (!listStream.CanRead) + return null; + // Read the listfile in for processing using (StreamReader sr = new StreamReader(listStream)) { listfile = sr.ReadToEnd(); } - string sub = string.Empty; - while ((sub = listfile) != null) + // Split the listfile by newlines + string[] listfileLines = listfile.Replace("\r\n", "\n").Split('\n'); + + // Loop over each entry + foreach (string sub in listfileLines) { // If an individual entry fails try