diff --git a/Benchmark/Benchmark.csproj b/Benchmark/Benchmark.csproj index cf76311..a261d2e 100644 --- a/Benchmark/Benchmark.csproj +++ b/Benchmark/Benchmark.csproj @@ -1,12 +1,13 @@  Exe - netcoreapp3.1;net47 + net6.0 true Benchmark Benchmark Copyright © 2020 bin\$(Configuration)\ + enable diff --git a/Example/Example.csproj b/Example/Example.csproj index 0861735..050a953 100644 --- a/Example/Example.csproj +++ b/Example/Example.csproj @@ -3,11 +3,12 @@ Exe ConsoleApplication86 ConsoleApplication86 - net45 + net6.0 ConsoleApplication86 ConsoleApplication86 Copyright © 2016 bin\$(Configuration)\ + enable diff --git a/Example/Program.cs b/Example/Program.cs index 3c7f052..f572adf 100644 --- a/Example/Program.cs +++ b/Example/Program.cs @@ -22,7 +22,7 @@ static void Main(string[] args) Console.WriteLine(entry.FileName); // extract to file - entry.Extract(entry.FileName); + entry.Extract(entry.FileName ?? "NoFileName"); // extract to stream MemoryStream memoryStream = new MemoryStream(); diff --git a/SevenZipExtractor.Tests/Crc32.cs b/SevenZipExtractor.Tests/Crc32.cs index 055830b..eaf2eb5 100644 --- a/SevenZipExtractor.Tests/Crc32.cs +++ b/SevenZipExtractor.Tests/Crc32.cs @@ -15,7 +15,7 @@ public sealed class Crc32 : HashAlgorithm public const UInt32 DefaultPolynomial = 0xedb88320u; public const UInt32 DefaultSeed = 0xffffffffu; - static UInt32[] defaultTable; + static UInt32[]? defaultTable; readonly UInt32 seed; readonly UInt32[] table; diff --git a/SevenZipExtractor.Tests/Resources/cab.cab b/SevenZipExtractor.Tests/Resources/cab.cab new file mode 100644 index 0000000..67869fe Binary files /dev/null and b/SevenZipExtractor.Tests/Resources/cab.cab differ diff --git a/SevenZipExtractor.Tests/Resources/mslz.dl_ b/SevenZipExtractor.Tests/Resources/mslz.dl_ new file mode 100644 index 0000000..e0c42b1 Binary files /dev/null and b/SevenZipExtractor.Tests/Resources/mslz.dl_ differ diff --git a/SevenZipExtractor.Tests/SevenZipExtractor.Tests.csproj b/SevenZipExtractor.Tests/SevenZipExtractor.Tests.csproj index 0015c42..461d7d7 100644 --- a/SevenZipExtractor.Tests/SevenZipExtractor.Tests.csproj +++ b/SevenZipExtractor.Tests/SevenZipExtractor.Tests.csproj @@ -1,6 +1,6 @@  - net45 + net6.0 {3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) $(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages @@ -11,15 +11,14 @@ Copyright © 2019 bin\$(Configuration)\ AnyCPU;x64;x86 - x64 + AnyCPU + enable - - - - - + + + diff --git a/SevenZipExtractor.Tests/TestBase.cs b/SevenZipExtractor.Tests/TestBase.cs index 00bb63c..be4f3d8 100644 --- a/SevenZipExtractor.Tests/TestBase.cs +++ b/SevenZipExtractor.Tests/TestBase.cs @@ -23,15 +23,20 @@ public abstract class TestBase new TestFileEntry { Name = "testFolder\\image3.jpg", IsFolder = false, MD5 = "24ffd227340432596fe61ef6300098ad"}, }; - protected void TestExtractToStream(byte[] archiveBytes, IList expected, SevenZipFormat? sevenZipFormat = null) + protected IList TestSingleFile = new List() +{ + new TestFileEntry { Name = "image1.jpg", IsFolder = false, MD5 = "b3144b66569ab0052b4019a2b4c07a31"}, + }; + + protected void TestExtractToStream(byte[] archiveBytes, IList expected, SevenZipFormat? sevenZipFormat = null, string? fileName = null) { MemoryStream memoryStream = new MemoryStream(archiveBytes); - using (ArchiveFile archiveFile = new ArchiveFile(memoryStream, sevenZipFormat)) + using (ArchiveFile archiveFile = new ArchiveFile(memoryStream, sevenZipFormat, null, fileName)) { foreach (TestFileEntry testEntry in expected) { - Entry entry = archiveFile.Entries.FirstOrDefault(e => e.FileName == testEntry.Name && e.IsFolder == testEntry.IsFolder); + Entry? entry = archiveFile.Entries.FirstOrDefault(e => e.FileName == testEntry.Name && e.IsFolder == testEntry.IsFolder); Assert.IsNotNull(entry, "Entry not found: " + testEntry.Name); @@ -42,7 +47,7 @@ protected void TestExtractToStream(byte[] archiveBytes, IList exp using (MemoryStream entryMemoryStream = new MemoryStream()) { - entry.Extract(entryMemoryStream); + entry!.Extract(entryMemoryStream); if (testEntry.MD5 != null) { diff --git a/SevenZipExtractor.Tests/TestCab.cs b/SevenZipExtractor.Tests/TestCab.cs new file mode 100644 index 0000000..8b1cadf --- /dev/null +++ b/SevenZipExtractor.Tests/TestCab.cs @@ -0,0 +1,17 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SevenZipExtractor; + +namespace SevenZipExtractor.Tests { + [TestClass] + public class TestCab : TestBase { + [TestMethod] + public void TestGuessAndExtractToStream_OK() { + this.TestExtractToStream(Resources.TestFiles.cab, this.TestSingleFile); + } + + [TestMethod] + public void TestKnownFormatAndExtractToStream_OK() { + this.TestExtractToStream(Resources.TestFiles.cab, this.TestSingleFile, SevenZipFormat.Cab); + } + } +} diff --git a/SevenZipExtractor.Tests/TestFiles.Designer.cs b/SevenZipExtractor.Tests/TestFiles.Designer.cs index 4933327..a9e531a 100644 --- a/SevenZipExtractor.Tests/TestFiles.Designer.cs +++ b/SevenZipExtractor.Tests/TestFiles.Designer.cs @@ -19,7 +19,7 @@ namespace Resources { // class via a tool like ResGen or Visual Studio. // To add or remove a member, edit your .ResX file then rerun ResGen // with the /str option, or rebuild your VS project. - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "16.0.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] internal class TestFiles { @@ -70,6 +70,16 @@ internal static byte[] ansimate_arj { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] cab { + get { + object obj = ResourceManager.GetObject("cab", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// @@ -80,6 +90,16 @@ internal static byte[] lzh { } } + /// + /// Looks up a localized resource of type System.Byte[]. + /// + internal static byte[] mslz { + get { + object obj = ResourceManager.GetObject("mslz", resourceCulture); + return ((byte[])(obj)); + } + } + /// /// Looks up a localized resource of type System.Byte[]. /// diff --git a/SevenZipExtractor.Tests/TestFiles.resx b/SevenZipExtractor.Tests/TestFiles.resx index e6558c1..4f55c10 100644 --- a/SevenZipExtractor.Tests/TestFiles.resx +++ b/SevenZipExtractor.Tests/TestFiles.resx @@ -121,9 +121,15 @@ Resources\ansimate-arj.arj;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + resources\cab.cab;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Resources\lzh.lzh;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + resources\mslz.dl_;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + Resources\rar.rar;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/SevenZipExtractor.Tests/TestMSCF.cs b/SevenZipExtractor.Tests/TestMSCF.cs new file mode 100644 index 0000000..00538b1 --- /dev/null +++ b/SevenZipExtractor.Tests/TestMSCF.cs @@ -0,0 +1,29 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; +using SevenZipExtractor; +using SevenZipExtractor.Tests; +using System.Collections.Generic; +using System.Linq; + +namespace SevenZipExtractor.Tests +{ + [TestClass] + public class TestMSCF : TestBase { + + protected IList TestSingleDllFile = new List() + { + new TestFileEntry { Name = "mslz.dll", IsFolder = false, MD5 = "b3144b66569ab0052b4019a2b4c07a31"}, + }; + + [TestMethod] + public void TestGuessAndExtractToStream_OK() + { + this.TestExtractToStream(Resources.TestFiles.mslz, TestSingleDllFile, null, "mslz.dl_"); + } + + [TestMethod] + public void TestKnownFormatAndExtractToStream_OK() + { + this.TestExtractToStream(Resources.TestFiles.mslz, TestSingleDllFile, SevenZipFormat.Mslz, "mslz.dl_"); + } + } +} \ No newline at end of file diff --git a/SevenZipExtractor.Tests/TestZip.cs b/SevenZipExtractor.Tests/TestZip.cs index de71bf3..7763841 100644 --- a/SevenZipExtractor.Tests/TestZip.cs +++ b/SevenZipExtractor.Tests/TestZip.cs @@ -3,7 +3,7 @@ namespace SevenZipExtractor.Tests { [TestClass] - public class TestZip : TestBase + public class TestZip : TestBase { [TestMethod] public void TestGuessAndExtractToStream_OK() @@ -16,5 +16,17 @@ public void TestKnownFormatAndExtractToStream_OK() { this.TestExtractToStream(Resources.TestFiles.zip, this.TestEntriesWithFolder, SevenZipFormat.Zip); } + + [TestMethod] + public void TestGuessAndExtractToStreamWithFileName_OK() + { + this.TestExtractToStream(Resources.TestFiles.zip, this.TestEntriesWithFolder, null, "zip.zip"); + } + + [TestMethod] + public void TestKnownFormatAndExtractToStreamWithFileName_OK() + { + this.TestExtractToStream(Resources.TestFiles.zip, this.TestEntriesWithFolder, SevenZipFormat.Zip, "zip.zip"); + } } } \ No newline at end of file diff --git a/SevenZipExtractor/ArchiveFile.cs b/SevenZipExtractor/ArchiveFile.cs index 8ccf66b..d9604b1 100644 --- a/SevenZipExtractor/ArchiveFile.cs +++ b/SevenZipExtractor/ArchiveFile.cs @@ -6,16 +6,20 @@ namespace SevenZipExtractor { - public class ArchiveFile : IDisposable + public class ArchiveFile : IDisposable, IArchiveOpenVolumeCallback, IArchiveOpenCallback { private SevenZipHandle sevenZipHandle; private readonly IInArchive archive; private readonly InStreamWrapper archiveStream; - private IList entries; + private IList? entries; - private string libraryFilePath; + private string? libraryFilePath; + /// + /// The current archive name, can change for multi volume archives + /// + public string? CurrentArchiveName { get; set; } - public ArchiveFile(string archiveFilePath, string libraryFilePath = null) + public ArchiveFile(string archiveFilePath, string? libraryFilePath = null) { this.libraryFilePath = libraryFilePath; @@ -25,6 +29,7 @@ public ArchiveFile(string archiveFilePath, string libraryFilePath = null) { throw new SevenZipException("Archive file not found"); } + CurrentArchiveName = Path.GetFileName(archiveFilePath); SevenZipFormat format; string extension = Path.GetExtension(archiveFilePath); @@ -42,11 +47,16 @@ public ArchiveFile(string archiveFilePath, string libraryFilePath = null) throw new SevenZipException(Path.GetFileName(archiveFilePath) + " is not a known archive type"); } - this.archive = this.sevenZipHandle.CreateInArchive(Formats.FormatGuidMapping[format]); + var newArchiver = this.sevenZipHandle!.CreateInArchive(Formats.FormatGuidMapping[format]); + if (newArchiver == null) { + throw new SevenZipException("Could not create archiv instance"); + } + this.archive = newArchiver; + this.archiveStream = new InStreamWrapper(File.OpenRead(archiveFilePath)); } - public ArchiveFile(Stream archiveStream, SevenZipFormat? format = null, string libraryFilePath = null) + public ArchiveFile(Stream archiveStream, SevenZipFormat? format = null, string? libraryFilePath = null, string? fileName = null) { this.libraryFilePath = libraryFilePath; @@ -56,6 +66,7 @@ public ArchiveFile(Stream archiveStream, SevenZipFormat? format = null, string l { throw new SevenZipException("archiveStream is null"); } + CurrentArchiveName = fileName; if (format == null) { @@ -71,7 +82,17 @@ public ArchiveFile(Stream archiveStream, SevenZipFormat? format = null, string l } } - this.archive = this.sevenZipHandle.CreateInArchive(Formats.FormatGuidMapping[format.Value]); + if (format == null) + { + throw new SevenZipException("Unable to guess format automatically"); + } + + var newArchiver = this.sevenZipHandle!.CreateInArchive(Formats.FormatGuidMapping[(SevenZipFormat) format]); + if (newArchiver == null) + { + throw new SevenZipException("Could not create archiv instance"); + } + this.archive = newArchiver; this.archiveStream = new InStreamWrapper(archiveStream); } @@ -95,15 +116,15 @@ public void Extract(string outputFolder, bool overwrite = false) }); } - public void Extract(Func getOutputPath) + public void Extract(Func getOutputPath) { - IList fileStreams = new List(); + IList fileStreams = new List(); try { foreach (Entry entry in Entries) { - string outputPath = getOutputPath(entry); + string? outputPath = getOutputPath(entry); if (outputPath == null) // getOutputPath = null means SKIP { @@ -118,7 +139,7 @@ public void Extract(Func getOutputPath) continue; } - string directoryName = Path.GetDirectoryName(outputPath); + string? directoryName = Path.GetDirectoryName(outputPath); if (!string.IsNullOrWhiteSpace(directoryName)) { @@ -132,7 +153,7 @@ public void Extract(Func getOutputPath) } finally { - foreach (Stream stream in fileStreams) + foreach (Stream? stream in fileStreams) { if (stream != null) { @@ -152,7 +173,7 @@ public IList Entries } ulong checkPos = 32 * 1024; - int open = this.archive.Open(this.archiveStream, ref checkPos, null); + int open = this.archive.Open(this.archiveStream, ref checkPos, CurrentArchiveName != null ? this : null); if (open != 0) { @@ -165,7 +186,7 @@ public IList Entries for (uint fileIndex = 0; fileIndex < itemsCount; fileIndex++) { - string fileName = this.GetProperty(fileIndex, ItemPropId.kpidPath); + string? fileName = this.GetProperty(fileIndex, ItemPropId.kpidPath); bool isFolder = this.GetProperty(fileIndex, ItemPropId.kpidIsFolder); bool isEncrypted = this.GetProperty(fileIndex, ItemPropId.kpidEncrypted); ulong size = this.GetProperty(fileIndex, ItemPropId.kpidSize); @@ -175,9 +196,9 @@ public IList Entries DateTime lastAccessTime = this.GetPropertySafe(fileIndex, ItemPropId.kpidLastAccessTime); uint crc = this.GetPropertySafe(fileIndex, ItemPropId.kpidCRC); uint attributes = this.GetPropertySafe(fileIndex, ItemPropId.kpidAttributes); - string comment = this.GetPropertySafe(fileIndex, ItemPropId.kpidComment); - string hostOS = this.GetPropertySafe(fileIndex, ItemPropId.kpidHostOS); - string method = this.GetPropertySafe(fileIndex, ItemPropId.kpidMethod); + string? comment = this.GetPropertySafe(fileIndex, ItemPropId.kpidComment); + string? hostOS = this.GetPropertySafe(fileIndex, ItemPropId.kpidHostOS); + string? method = this.GetPropertySafe(fileIndex, ItemPropId.kpidMethod); bool isSplitBefore = this.GetPropertySafe(fileIndex, ItemPropId.kpidSplitBefore); bool isSplitAfter = this.GetPropertySafe(fileIndex, ItemPropId.kpidSplitAfter); @@ -206,7 +227,7 @@ public IList Entries } } - private T GetPropertySafe(uint fileIndex, ItemPropId name) + private T? GetPropertySafe(uint fileIndex, ItemPropId name) { try { @@ -214,34 +235,34 @@ private T GetPropertySafe(uint fileIndex, ItemPropId name) } catch (InvalidCastException) { - return default(T); + return default; } } - private T GetProperty(uint fileIndex, ItemPropId name) + private T? GetProperty(uint fileIndex, ItemPropId name) { PropVariant propVariant = new PropVariant(); this.archive.GetProperty(fileIndex, name, ref propVariant); - object value = propVariant.GetObject(); + object? value = propVariant.GetObject(); if (propVariant.VarType == VarEnum.VT_EMPTY) { propVariant.Clear(); - return default(T); + return default; } propVariant.Clear(); if (value == null) { - return default(T); + return default; } Type type = typeof(T); bool isNullable = type.IsGenericType && type.GetGenericTypeDefinition() == typeof(Nullable<>); - Type underlyingType = isNullable ? Nullable.GetUnderlyingType(type) : type; + Type? underlyingType = isNullable ? Nullable.GetUnderlyingType(type) : type; - T result = (T)Convert.ChangeType(value.ToString(), underlyingType); + T? result = (T?)Convert.ChangeType(value.ToString(), underlyingType); return result; } @@ -362,6 +383,24 @@ private bool GuessFormatFromSignature(Stream stream, out SevenZipFormat format) format = SevenZipFormat.Undefined; return false; } + public void GetProperty(ItemPropId propID, ref PropVariant value) { + if (propID == ItemPropId.kpidName && CurrentArchiveName != null) { + value.Clear(); + value.VarType = VarEnum.VT_BSTR; + value.pointerValue = Marshal.StringToBSTR(CurrentArchiveName); + } + } + public int GetStream(string name, out IInStream? inStream) { + // not supported + inStream = null; + return -2147467259; // E_FAIL + } + + public void SetTotal(IntPtr files, IntPtr bytes) { + } + + public void SetCompleted(IntPtr files, IntPtr bytes) { + } ~ArchiveFile() { diff --git a/SevenZipExtractor/ArchiveFileCallback.cs b/SevenZipExtractor/ArchiveFileCallback.cs index 4f82230..0a2a6c9 100644 --- a/SevenZipExtractor/ArchiveFileCallback.cs +++ b/SevenZipExtractor/ArchiveFileCallback.cs @@ -7,7 +7,7 @@ internal class ArchiveFileCallback : IArchiveExtractCallback { private readonly string fileName; private readonly uint fileNumber; - private OutStreamWrapper fileStream; // to be removed + private OutStreamWrapper? fileStream; // to be removed public ArchiveFileCallback(uint fileNumber, string fileName) { @@ -23,7 +23,7 @@ public void SetCompleted(ref ulong completeValue) { } - public int GetStream(uint index, out ISequentialOutStream outStream, AskMode askExtractMode) + public int GetStream(uint index, out ISequentialOutStream? outStream, AskMode askExtractMode) { if ((index != this.fileNumber) || (askExtractMode != AskMode.kExtract)) { @@ -31,7 +31,7 @@ public int GetStream(uint index, out ISequentialOutStream outStream, AskMode ask return 0; } - string fileDir = Path.GetDirectoryName(this.fileName); + string? fileDir = Path.GetDirectoryName(this.fileName); if (!string.IsNullOrEmpty(fileDir)) { @@ -51,7 +51,7 @@ public void PrepareOperation(AskMode askExtractMode) public void SetOperationResult(OperationResult resultEOperationResult) { - this.fileStream.Dispose(); + this.fileStream?.Dispose(); } } } \ No newline at end of file diff --git a/SevenZipExtractor/ArchiveStreamCallback.cs b/SevenZipExtractor/ArchiveStreamCallback.cs index e71e225..2dbae97 100644 --- a/SevenZipExtractor/ArchiveStreamCallback.cs +++ b/SevenZipExtractor/ArchiveStreamCallback.cs @@ -21,7 +21,7 @@ public void SetCompleted(ref ulong completeValue) { } - public int GetStream(uint index, out ISequentialOutStream outStream, AskMode askExtractMode) + public int GetStream(uint index, out ISequentialOutStream? outStream, AskMode askExtractMode) { if ((index != this.fileNumber) || (askExtractMode != AskMode.kExtract)) { diff --git a/SevenZipExtractor/ArchiveStreamsCallback.cs b/SevenZipExtractor/ArchiveStreamsCallback.cs index b8f1fca..d4fa266 100644 --- a/SevenZipExtractor/ArchiveStreamsCallback.cs +++ b/SevenZipExtractor/ArchiveStreamsCallback.cs @@ -5,9 +5,9 @@ namespace SevenZipExtractor { internal class ArchiveStreamsCallback : IArchiveExtractCallback { - private readonly IList streams; + private readonly IList streams; - public ArchiveStreamsCallback(IList streams) + public ArchiveStreamsCallback(IList streams) { this.streams = streams; } @@ -20,7 +20,7 @@ public void SetCompleted(ref ulong completeValue) { } - public int GetStream(uint index, out ISequentialOutStream outStream, AskMode askExtractMode) + public int GetStream(uint index, out ISequentialOutStream? outStream, AskMode askExtractMode) { if (askExtractMode != AskMode.kExtract) { @@ -34,7 +34,7 @@ public int GetStream(uint index, out ISequentialOutStream outStream, AskMode ask return 0; } - Stream stream = this.streams[(int) index]; + Stream? stream = this.streams[(int) index]; if (stream == null) { diff --git a/SevenZipExtractor/Entry.cs b/SevenZipExtractor/Entry.cs index 13220b0..c0238a5 100644 --- a/SevenZipExtractor/Entry.cs +++ b/SevenZipExtractor/Entry.cs @@ -17,7 +17,7 @@ internal Entry(IInArchive archive, uint index) /// /// Name of the file with its relative path within the archive /// - public string FileName { get; internal set; } + public string? FileName { get; internal set; } /// /// True if entry is a folder, false if it is a file /// @@ -64,17 +64,17 @@ internal Entry(IInArchive archive, uint index) /// /// Comment of the entry /// - public string Comment { get; internal set; } + public string? Comment { get; internal set; } /// /// Compression method of the entry /// - public string Method { get; internal set; } + public string? Method { get; internal set; } /// /// Host operating system of the entry /// - public string HostOS { get; internal set; } + public string? HostOS { get; internal set; } /// /// True if there are parts of this file in previous split archive parts @@ -94,7 +94,7 @@ public void Extract(string fileName, bool preserveTimestamp = true) return; } - string directoryName = Path.GetDirectoryName(fileName); + string? directoryName = Path.GetDirectoryName(fileName); if (!string.IsNullOrWhiteSpace(directoryName)) { diff --git a/SevenZipExtractor/Formats.cs b/SevenZipExtractor/Formats.cs index 994b54e..623b6c7 100644 --- a/SevenZipExtractor/Formats.cs +++ b/SevenZipExtractor/Formats.cs @@ -107,7 +107,8 @@ public class Formats {SevenZipFormat.Zip, new byte[] { 0x50, 0x4b }}, {SevenZipFormat.Arj, new byte[] { 0x60, 0xEA }}, {SevenZipFormat.Lzh, new byte[] { 0x2D, 0x6C, 0x68 }}, - {SevenZipFormat.SquashFS, new byte[] {0x68, 0x73, 0x71, 0x73}} + {SevenZipFormat.SquashFS, new byte[] {0x68, 0x73, 0x71, 0x73}}, + {SevenZipFormat.Mslz, new byte[] { 0x53, 0x5a, 0x44, 0x44 } }, }; } } diff --git a/SevenZipExtractor/IArchiveExtractCallback.cs b/SevenZipExtractor/IArchiveExtractCallback.cs index 085841c..f89f2f2 100644 --- a/SevenZipExtractor/IArchiveExtractCallback.cs +++ b/SevenZipExtractor/IArchiveExtractCallback.cs @@ -13,7 +13,7 @@ internal interface IArchiveExtractCallback //: IProgress [PreserveSig] int GetStream( uint index, - [MarshalAs(UnmanagedType.Interface)] out ISequentialOutStream outStream, + [MarshalAs(UnmanagedType.Interface)] out ISequentialOutStream? outStream, AskMode askExtractMode); // GetStream OUT: S_OK - OK, S_FALSE - skeep this file diff --git a/SevenZipExtractor/SafeLibraryHandle.cs b/SevenZipExtractor/SafeLibraryHandle.cs index 74185a8..0bfd570 100644 --- a/SevenZipExtractor/SafeLibraryHandle.cs +++ b/SevenZipExtractor/SafeLibraryHandle.cs @@ -12,7 +12,6 @@ public SafeLibraryHandle() : base(true) /// Release library handle /// true if the handle was released - [ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)] protected override bool ReleaseHandle() { return Kernel32Dll.FreeLibrary(this.handle); diff --git a/SevenZipExtractor/SevenZipExtractor.csproj b/SevenZipExtractor/SevenZipExtractor.csproj index 9b632f2..f42d491 100644 --- a/SevenZipExtractor/SevenZipExtractor.csproj +++ b/SevenZipExtractor/SevenZipExtractor.csproj @@ -1,6 +1,6 @@  - net45;netstandard2.0 + net6.0 SevenZipWrapper SevenZipWrapper C# wrapper for 7z.dll (included) @@ -12,6 +12,7 @@ https://github.com/adoconnection/SevenZipExtractor 7Zip APM Arj BZip2 Cab Chm Compound Cpio CramFS Deb Dll Dmg Exe Fat Flv GZip Hfs Iso Lzh Lzma Lzma86 Mach-O Mbr Mub Nsis Ntfs Ppmd Rar Rar5 Rpm Split SquashFS Swf Swfc Tar TE Udf UEFIc UEFIs Vhd Wim Xar XZ Z Zip 1.0.17 + enable diff --git a/SevenZipExtractor/SevenZipHandle.cs b/SevenZipExtractor/SevenZipHandle.cs index bf9a02d..d38ed84 100644 --- a/SevenZipExtractor/SevenZipHandle.cs +++ b/SevenZipExtractor/SevenZipHandle.cs @@ -6,7 +6,7 @@ namespace SevenZipExtractor { internal class SevenZipHandle : IDisposable { - private SafeLibraryHandle sevenZipSafeHandle; + private SafeLibraryHandle? sevenZipSafeHandle; public SevenZipHandle(string sevenZipLibPath) { @@ -48,7 +48,7 @@ public void Dispose() GC.SuppressFinalize(this); } - public IInArchive CreateInArchive(Guid classId) + public IInArchive? CreateInArchive(Guid classId) { if (this.sevenZipSafeHandle == null) { diff --git a/SevenZipExtractor/SevenZipInterface.cs b/SevenZipExtractor/SevenZipInterface.cs index 710e1cd..a37ec70 100644 --- a/SevenZipExtractor/SevenZipInterface.cs +++ b/SevenZipExtractor/SevenZipInterface.cs @@ -10,14 +10,14 @@ namespace SevenZipExtractor { [StructLayout(LayoutKind.Sequential)] - internal struct PropArray + public struct PropArray { uint length; IntPtr pointerValues; } [StructLayout(LayoutKind.Explicit)] - internal struct PropVariant + public struct PropVariant { [DllImport("ole32.dll")] private static extern int PropVariantClear(ref PropVariant pvar); @@ -35,6 +35,9 @@ public VarEnum VarType { return (VarEnum) this.vt; } + set { + this.vt = (ushort) value; + } } public void Clear() @@ -73,7 +76,7 @@ public void Clear() } } - public object GetObject() + public object? GetObject() { switch (this.VarType) { @@ -115,12 +118,12 @@ internal interface IArchiveOpenCallback // ref ulong replaced with IntPtr because handlers ofter pass null value // read actual value with Marshal.ReadInt64 void SetTotal( - IntPtr files, // [In] ref ulong files, can use 'ulong* files' but it is unsafe - IntPtr bytes); // [In] ref ulong bytes + [In] IntPtr files, // [In] ref ulong files, can use 'ulong* files' but it is unsafe + [In] IntPtr bytes); // [In] ref ulong bytes void SetCompleted( - IntPtr files, // [In] ref ulong files - IntPtr bytes); // [In] ref ulong bytes + [In] IntPtr files, // [In] ref ulong files + [In] IntPtr bytes); // [In] ref ulong bytes } [ComImport] @@ -158,12 +161,12 @@ internal interface IArchiveOpenVolumeCallback { void GetProperty( ItemPropId propID, // PROPID - IntPtr value); // PROPVARIANT + [In] ref PropVariant value); // PROPVARIANT [PreserveSig] int GetStream( [MarshalAs(UnmanagedType.LPWStr)] string name, - [MarshalAs(UnmanagedType.Interface)] out IInStream inStream); + [MarshalAs(UnmanagedType.Interface)] out IInStream? inStream); } [ComImport] @@ -220,7 +223,7 @@ This function is allowed to write less than "size". [ComImport] [Guid("23170F69-40C1-278A-0000-000300030000")] [InterfaceType(ComInterfaceType.InterfaceIsIUnknown)] - internal interface IInStream //: ISequentialInStream + public interface IInStream //: ISequentialInStream { //[PreserveSig] //int Read( @@ -260,7 +263,7 @@ void Seek( int SetSize(long newSize); } - internal enum ItemPropId : uint + public enum ItemPropId : uint { kpidNoProperty = 0, @@ -316,7 +319,7 @@ internal interface IInArchive int Open( IInStream stream, /*[MarshalAs(UnmanagedType.U8)]*/ [In] ref ulong maxCheckStartPosition, - [MarshalAs(UnmanagedType.Interface)] IArchiveOpenCallback openArchiveCallback); + [MarshalAs(UnmanagedType.Interface)] IArchiveOpenCallback? openArchiveCallback); void Close(); //void GetNumberOfItems([In] ref uint numItem); @@ -329,7 +332,7 @@ void GetProperty( [PreserveSig] int Extract( - [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] uint[] indices, //[In] ref uint indices, + [MarshalAs(UnmanagedType.LPArray, SizeParamIndex = 1)] uint[]? indices, //[In] ref uint indices, uint numItems, int testMode, [MarshalAs(UnmanagedType.Interface)] IArchiveExtractCallback extractCallback);