diff --git a/SabreTools.Helper/Tools/ArchiveTools.cs b/SabreTools.Helper/Tools/ArchiveTools.cs index 228779b4..1b517c15 100644 --- a/SabreTools.Helper/Tools/ArchiveTools.cs +++ b/SabreTools.Helper/Tools/ArchiveTools.cs @@ -1,6 +1,8 @@ -using SharpCompress.Common; +using SharpCompress.Archive; +using SharpCompress.Common; using SharpCompress.Reader; using System; +using System.Collections.Generic; using System.IO; using System.IO.Compression; using System.Linq; @@ -173,6 +175,59 @@ namespace SabreTools.Helper return !encounteredErrors; } + /// + /// Generate a list of RomData objects from the header values in an archive + /// + /// Input file to get data from + /// Logger object for file and console output + /// List of RomData objects representing the found data + public static List GetArchiveFileInfo(string input, Logger logger) + { + List roms = new List(); + string gamename = Path.GetFileNameWithoutExtension(input); + + // First get the archive type + ArchiveType? at = GetCurrentArchiveType(input, logger); + + // If we got back null, then it's not an archive, so we we return + if (at == null) + { + return roms; + } + + IReader reader = null; + try + { + reader = ReaderFactory.Open(File.OpenRead(input)); + logger.Log("Found archive of type: " + at); + + if (at != ArchiveType.Tar) + { + IArchiveEntry entry; + while ((entry = reader.Entry as IArchiveEntry) != null) + { + roms.Add(new RomData + { + Name = entry.Key, + Game = gamename, + Size = entry.Size, + CRC = entry.Crc.ToString("X"), + }); + } + } + } + catch (Exception ex) + { + logger.Error(ex.ToString()); + } + finally + { + reader?.Dispose(); + } + + return roms; + } + /// /// Retrieve file information for a single torrent GZ file ///