SharpCompressArchiveFile: fix support for solid rar

This commit is contained in:
zeromus 2021-01-20 15:21:52 -05:00
parent c5d908cc69
commit 6cc4b0e28f
1 changed files with 24 additions and 9 deletions

View File

@ -1,5 +1,3 @@
#nullable enable
using System;
using System.Collections.Generic;
using System.IO;
@ -14,24 +12,41 @@ namespace BizHawk.Client.Common
/// <see cref="SharpCompressDearchivalMethod"/>
public class SharpCompressArchiveFile : IHawkArchiveFile
{
private IArchive? _archive;
private IArchive _archive;
private IEnumerable<IArchiveEntry> ArchiveFiles => (_archive ?? throw new ObjectDisposedException(nameof(SharpCompressArchiveFile))).Entries.Where(e => !e.IsDirectory);
private IEnumerable<IArchiveEntry> EnumerateArchiveFiles()
{
if (_archive == null)
throw new ObjectDisposedException(nameof(SharpCompressArchiveFile));
return _archive.Entries.Where(e => !e.IsDirectory);
}
public SharpCompressArchiveFile(string path) => _archive = ArchiveFactory.Open(path);
public SharpCompressArchiveFile(string path)
{
var readerOptions = new SharpCompress.Readers.ReaderOptions();
_archive = ArchiveFactory.Open(path, readerOptions);
}
public void Dispose()
{
_archive?.Dispose();
_archive.Dispose();
_archive = null;
}
public void ExtractFile(int index, Stream stream)
{
using var entryStream = ArchiveFiles.ElementAt(index).OpenEntryStream();
{
var reader = _archive.ExtractAllEntries();
for(int i=0;i<=index;i++)
reader.MoveToNextEntry();
using var entryStream = reader.OpenEntryStream();
entryStream.CopyTo(stream);
}
public List<HawkArchiveFileItem> Scan() => ArchiveFiles.Select((e, i) => new HawkArchiveFileItem(e.Key.Replace('\\', '/'), e.Size, i, i)).ToList();
public List<HawkArchiveFileItem> Scan()
{
var files = EnumerateArchiveFiles();
return files.Select((e, i) => new HawkArchiveFileItem(e.Key.Replace('\\', '/'), e.Size, i, i)).ToList();
}
}
}