diff --git a/src/BizHawk.Client.Common/SharpCompressArchiveFile.cs b/src/BizHawk.Client.Common/SharpCompressArchiveFile.cs index d58dfc279c..8a02fa6b6f 100644 --- a/src/BizHawk.Client.Common/SharpCompressArchiveFile.cs +++ b/src/BizHawk.Client.Common/SharpCompressArchiveFile.cs @@ -1,3 +1,5 @@ +#nullable enable + using System; using System.Collections.Generic; using System.IO; @@ -12,41 +14,34 @@ namespace BizHawk.Client.Common /// public class SharpCompressArchiveFile : IHawkArchiveFile { - private IArchive _archive; + private IArchive? _archive; - private IEnumerable EnumerateArchiveFiles() + private IEnumerable EnumerateArchiveFiles() { - if (_archive == null) - throw new ObjectDisposedException(nameof(SharpCompressArchiveFile)); - return _archive.Entries.Where(e => !e.IsDirectory); + if (_archive == null) throw new ObjectDisposedException(nameof(SharpCompressArchiveFile)); + return _archive.Entries.Where(e => !e.IsDirectory); } - public SharpCompressArchiveFile(string path) - { - var readerOptions = new SharpCompress.Readers.ReaderOptions(); - _archive = ArchiveFactory.Open(path, readerOptions); - } + public SharpCompressArchiveFile(string path) => _archive = ArchiveFactory.Open(path, new()); public void Dispose() { - _archive.Dispose(); + _archive?.Dispose(); _archive = null; } public void ExtractFile(int index, Stream stream) - { - var reader = _archive.ExtractAllEntries(); - for(int i=0;i<=index;i++) - reader.MoveToNextEntry(); - + { + var reader = _archive!.ExtractAllEntries(); + for (var i = 0; i <= index; i++) reader.MoveToNextEntry(); using var entryStream = reader.OpenEntryStream(); entryStream.CopyTo(stream); } - public List Scan() + public List Scan() { var files = EnumerateArchiveFiles(); - return files.Select((e, i) => new HawkArchiveFileItem(e.Key.Replace('\\', '/'), e.Size, i, i)).ToList(); + return files.Select((e, i) => new HawkArchiveFileItem(e.Key.Replace('\\', '/'), e.Size, i, i)).ToList(); } } } diff --git a/src/BizHawk.Client.Common/SharpCompressDearchivalMethod.cs b/src/BizHawk.Client.Common/SharpCompressDearchivalMethod.cs index 9b716ae838..a472ea6cb1 100644 --- a/src/BizHawk.Client.Common/SharpCompressDearchivalMethod.cs +++ b/src/BizHawk.Client.Common/SharpCompressDearchivalMethod.cs @@ -1,7 +1,9 @@ -using System.IO; -using System.Linq; +#nullable enable + using System.Collections.Generic; + using BizHawk.Common; + using SharpCompress.Archives; namespace BizHawk.Client.Common @@ -27,13 +29,10 @@ namespace BizHawk.Client.Common return true; // no exception? good enough } - public SharpCompressArchiveFile Construct(string path) => new SharpCompressArchiveFile(path); + public SharpCompressArchiveFile Construct(string path) => new(path); - public static readonly SharpCompressDearchivalMethod Instance = new SharpCompressDearchivalMethod(); - - //don't try any .tar.* formats, they don't work - static readonly IReadOnlyCollection archiveExts = new[] { ".zip", ".7z", ".rar", ".gz" }; + public static readonly SharpCompressDearchivalMethod Instance = new(); - public IReadOnlyCollection AllowedArchiveExtensions { get { return archiveExts; } } + public IReadOnlyCollection AllowedArchiveExtensions { get; } = new[] { ".zip", ".7z", ".rar", ".gz" }; // don't try any .tar.* formats, they don't work } } \ No newline at end of file