diff --git a/SabreTools.Library/FileTypes/RarArchive.cs b/SabreTools.Library/FileTypes/RarArchive.cs index 6e479b3b..9cc96753 100644 --- a/SabreTools.Library/FileTypes/RarArchive.cs +++ b/SabreTools.Library/FileTypes/RarArchive.cs @@ -185,30 +185,29 @@ namespace SabreTools.Library.FileTypes SharpCompress.Archives.Rar.RarArchive ra = SharpCompress.Archives.Rar.RarArchive.Open(FileExtensions.TryOpenRead(this.Filename)); foreach (RarArchiveEntry entry in ra.Entries.Where(e => e != null && !e.IsDirectory)) { + // Create a blank item for the entry + BaseFile rarEntryRom = new BaseFile(); + // Perform a quickscan, if flagged to if (QuickScan) { - found.Add(new BaseFile - { - Filename = entry.Key, - Size = entry.Size, - CRC = BitConverter.GetBytes(entry.Crc), - Date = (entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null), - - Parent = gamename, - }); + rarEntryRom.Size = entry.Size; + rarEntryRom.CRC = BitConverter.GetBytes(entry.Crc); } // Otherwise, use the stream directly else { - Stream entryStream = entry.OpenEntryStream(); - BaseFile rarEntryRom = entryStream.GetInfo(size: entry.Size); - rarEntryRom.Filename = entry.Key; - rarEntryRom.Parent = gamename; - rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss"); - found.Add(rarEntryRom); - entryStream.Dispose(); + using (Stream entryStream = entry.OpenEntryStream()) + { + rarEntryRom = entryStream.GetInfo(size: entry.Size); + } } + + // Fill in comon details and add to the list + rarEntryRom.Filename = entry.Key; + rarEntryRom.Parent = gamename; + rarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss"); + found.Add(rarEntryRom); } // Dispose of the archive diff --git a/SabreTools.Library/FileTypes/SevenZipArchive.cs b/SabreTools.Library/FileTypes/SevenZipArchive.cs index c9be1868..f3753435 100644 --- a/SabreTools.Library/FileTypes/SevenZipArchive.cs +++ b/SabreTools.Library/FileTypes/SevenZipArchive.cs @@ -295,30 +295,25 @@ namespace SabreTools.Library.FileTypes continue; } + // Create a blank item for the entry + BaseFile zipEntryRom = new BaseFile(); + // Perform a quickscan, if flagged to if (QuickScan) { - string newname = zf.Filename(i); - long newsize = (long)zf.UncompressedSize(i); - byte[] newcrc = zf.CRC32(i); - - found.Add(new BaseFile - { - Filename = newname, - Size = newsize, - CRC = newcrc, - - Parent = gamename, - }); + zipEntryRom.Size = (long)zf.UncompressedSize(i); + zipEntryRom.CRC = zf.CRC32(i); } // Otherwise, use the stream directly else { - BaseFile zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), keepReadOpen: true); - zipEntryRom.Filename = zf.Filename(i); - zipEntryRom.Parent = gamename; - found.Add(zipEntryRom); + zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), keepReadOpen: true); } + + // Fill in comon details and add to the list + zipEntryRom.Filename = zf.Filename(i); + zipEntryRom.Parent = gamename; + found.Add(zipEntryRom); } // Dispose of the archive diff --git a/SabreTools.Library/FileTypes/TapeArchive.cs b/SabreTools.Library/FileTypes/TapeArchive.cs index eae373dc..8e05ddc9 100644 --- a/SabreTools.Library/FileTypes/TapeArchive.cs +++ b/SabreTools.Library/FileTypes/TapeArchive.cs @@ -190,30 +190,29 @@ namespace SabreTools.Library.FileTypes TarArchive ta = TarArchive.Open(FileExtensions.TryOpenRead(this.Filename)); foreach (TarArchiveEntry entry in ta.Entries.Where(e => e != null && !e.IsDirectory)) { + // Create a blank item for the entry + BaseFile tarEntryRom = new BaseFile(); + // Perform a quickscan, if flagged to if (QuickScan) { - found.Add(new BaseFile - { - Filename = entry.Key, - Size = entry.Size, - CRC = BitConverter.GetBytes(entry.Crc), - Date = (entry.LastModifiedTime != null ? entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss") : null), - - Parent = gamename, - }); + tarEntryRom.Size = entry.Size; + tarEntryRom.CRC = BitConverter.GetBytes(entry.Crc); } // Otherwise, use the stream directly else { - Stream entryStream = entry.OpenEntryStream(); - BaseFile tarEntryRom = entryStream.GetInfo(size: entry.Size); - tarEntryRom.Filename = entry.Key; - tarEntryRom.Parent = gamename; - tarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss"); - found.Add(tarEntryRom); - entryStream.Dispose(); + using (Stream entryStream = entry.OpenEntryStream()) + { + tarEntryRom = entryStream.GetInfo(size: entry.Size); + } } + + // Fill in comon details and add to the list + tarEntryRom.Filename = entry.Key; + tarEntryRom.Parent = gamename; + tarEntryRom.Date = entry.LastModifiedTime?.ToString("yyyy/MM/dd hh:mm:ss"); + found.Add(tarEntryRom); } // Dispose of the archive diff --git a/SabreTools.Library/FileTypes/ZipArchive.cs b/SabreTools.Library/FileTypes/ZipArchive.cs index e43bf1e0..e59d1c86 100644 --- a/SabreTools.Library/FileTypes/ZipArchive.cs +++ b/SabreTools.Library/FileTypes/ZipArchive.cs @@ -296,34 +296,26 @@ namespace SabreTools.Library.FileTypes continue; } + // Create a blank item for the entry + BaseFile zipEntryRom = new BaseFile(); + // Perform a quickscan, if flagged to if (QuickScan) { - string newname = zf.Filename(i); - long newsize = (long)zf.UncompressedSize(i); - byte[] newcrc = zf.CRC32(i); - string convertedDate = zf.LastModified(i).ToString("yyyy/MM/dd hh:mm:ss"); - - found.Add(new BaseFile - { - Filename = newname, - Size = newsize, - CRC = newcrc, - Date = convertedDate, - - Parent = gamename, - }); + zipEntryRom.Size = (long)zf.UncompressedSize(i); + zipEntryRom.CRC = zf.CRC32(i); } // Otherwise, use the stream directly else { - BaseFile zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), keepReadOpen: true); - zipEntryRom.Filename = zf.Filename(i); - zipEntryRom.Parent = gamename; - string convertedDate = zf.LastModified(i).ToString("yyyy/MM/dd hh:mm:ss"); - zipEntryRom.Date = convertedDate; - found.Add(zipEntryRom); + zipEntryRom = readStream.GetInfo(size: (long)zf.UncompressedSize(i), keepReadOpen: true); } + + // Fill in comon details and add to the list + zipEntryRom.Filename = zf.Filename(i); + zipEntryRom.Parent = gamename; + zipEntryRom.Date = zf.LastModified(i).ToString("yyyy/MM/dd hh:mm:ss"); + found.Add(zipEntryRom); } // Dispose of the archive