mirror of
https://github.com/claunia/SabreTools.git
synced 2025-12-16 19:14:27 +00:00
[ArchiveTools] Add method to get rom info from archive file headers
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
using SharpCompress.Common;
|
using SharpCompress.Archive;
|
||||||
|
using SharpCompress.Common;
|
||||||
using SharpCompress.Reader;
|
using SharpCompress.Reader;
|
||||||
using System;
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.IO.Compression;
|
using System.IO.Compression;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
@@ -173,6 +175,59 @@ namespace SabreTools.Helper
|
|||||||
return !encounteredErrors;
|
return !encounteredErrors;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Generate a list of RomData objects from the header values in an archive
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="input">Input file to get data from</param>
|
||||||
|
/// <param name="logger">Logger object for file and console output</param>
|
||||||
|
/// <returns>List of RomData objects representing the found data</returns>
|
||||||
|
public static List<RomData> GetArchiveFileInfo(string input, Logger logger)
|
||||||
|
{
|
||||||
|
List<RomData> roms = new List<RomData>();
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Retrieve file information for a single torrent GZ file
|
/// Retrieve file information for a single torrent GZ file
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user