Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support for MsLz, added tests for cab, updated net version to 6… #64

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Benchmark/Benchmark.csproj
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFrameworks>netcoreapp3.1;net47</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<AssemblyTitle>Benchmark</AssemblyTitle>
<Product>Benchmark</Product>
<Copyright>Copyright © 2020</Copyright>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SevenZipExtractor\SevenZipExtractor.csproj" />
3 changes: 2 additions & 1 deletion Example/Example.csproj
Original file line number Diff line number Diff line change
@@ -3,11 +3,12 @@
<OutputType>Exe</OutputType>
<RootNamespace>ConsoleApplication86</RootNamespace>
<AssemblyName>ConsoleApplication86</AssemblyName>
<TargetFramework>net45</TargetFramework>
<TargetFrameworks>net6.0</TargetFrameworks>
<AssemblyTitle>ConsoleApplication86</AssemblyTitle>
<Product>ConsoleApplication86</Product>
<Copyright>Copyright © 2016</Copyright>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Nullable>enable</Nullable>
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\SevenZipExtractor\SevenZipExtractor.csproj" />
2 changes: 1 addition & 1 deletion Example/Program.cs
Original file line number Diff line number Diff line change
@@ -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();
2 changes: 1 addition & 1 deletion SevenZipExtractor.Tests/Crc32.cs
Original file line number Diff line number Diff line change
@@ -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;
Binary file added SevenZipExtractor.Tests/Resources/cab.cab
Binary file not shown.
Binary file added SevenZipExtractor.Tests/Resources/mslz.dl_
Binary file not shown.
13 changes: 6 additions & 7 deletions SevenZipExtractor.Tests/SevenZipExtractor.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net45</TargetFramework>
<TargetFrameworks>net6.0</TargetFrameworks>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<VSToolsPath Condition="'$(VSToolsPath)' == ''">$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)</VSToolsPath>
<ReferencePath>$(ProgramFiles)\Common Files\microsoft shared\VSTT\$(VisualStudioVersion)\UITestExtensionPackages</ReferencePath>
@@ -11,15 +11,14 @@
<Copyright>Copyright © 2019</Copyright>
<OutputPath>bin\$(Configuration)\</OutputPath>
<Platforms>AnyCPU;x64;x86</Platforms>
<PlatformTarget>x64</PlatformTarget>
<PlatformTarget>AnyCPU</PlatformTarget>
<Nullable>enable</Nullable>
</PropertyGroup>
<Import Project="$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets" Condition="Exists('$(VSToolsPath)\TeamTest\Microsoft.TestTools.targets')" />
<ItemGroup>
<PackageReference Include="MSTest.TestAdapter" Version="1.3.2" />
<PackageReference Include="MSTest.TestFramework" Version="1.3.2" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
<PackageReference Include="MSTest.TestAdapter" Version="2.0.0" />
<PackageReference Include="MSTest.TestFramework" Version="2.0.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.5.0" />
<PackageReference Include="MSTest.TestAdapter" Version="3.0.2" />
<PackageReference Include="MSTest.TestFramework" Version="3.0.2" />
</ItemGroup>
<ItemGroup>
<Compile Update="TestFiles.Designer.cs">
13 changes: 9 additions & 4 deletions SevenZipExtractor.Tests/TestBase.cs
Original file line number Diff line number Diff line change
@@ -23,15 +23,20 @@ public abstract class TestBase
new TestFileEntry { Name = "testFolder\\image3.jpg", IsFolder = false, MD5 = "24ffd227340432596fe61ef6300098ad"},
};

protected void TestExtractToStream(byte[] archiveBytes, IList<TestFileEntry> expected, SevenZipFormat? sevenZipFormat = null)
protected IList<TestFileEntry> TestSingleFile = new List<TestFileEntry>()
{
new TestFileEntry { Name = "image1.jpg", IsFolder = false, MD5 = "b3144b66569ab0052b4019a2b4c07a31"},
};

protected void TestExtractToStream(byte[] archiveBytes, IList<TestFileEntry> 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<TestFileEntry> exp

using (MemoryStream entryMemoryStream = new MemoryStream())
{
entry.Extract(entryMemoryStream);
entry!.Extract(entryMemoryStream);

if (testEntry.MD5 != null)
{
17 changes: 17 additions & 0 deletions SevenZipExtractor.Tests/TestCab.cs
Original file line number Diff line number Diff line change
@@ -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);
}
}
}
22 changes: 21 additions & 1 deletion SevenZipExtractor.Tests/TestFiles.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions SevenZipExtractor.Tests/TestFiles.resx
Original file line number Diff line number Diff line change
@@ -121,9 +121,15 @@
<data name="ansimate_arj" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\ansimate-arj.arj;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="cab" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>resources\cab.cab;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="lzh" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\lzh.lzh;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="mslz" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>resources\mslz.dl_;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
<data name="rar" type="System.Resources.ResXFileRef, System.Windows.Forms">
<value>Resources\rar.rar;System.Byte[], mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</data>
29 changes: 29 additions & 0 deletions SevenZipExtractor.Tests/TestMSCF.cs
Original file line number Diff line number Diff line change
@@ -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<TestFileEntry> TestSingleDllFile = new List<TestFileEntry>()
{
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_");
}
}
}
14 changes: 13 additions & 1 deletion SevenZipExtractor.Tests/TestZip.cs
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
89 changes: 64 additions & 25 deletions SevenZipExtractor/ArchiveFile.cs
Original file line number Diff line number Diff line change
@@ -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<Entry> entries;
private IList<Entry>? entries;

private string libraryFilePath;
private string? libraryFilePath;
/// <summary>
/// The current archive name, can change for multi volume archives
/// </summary>
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<Entry, string> getOutputPath)
public void Extract(Func<Entry, string?> getOutputPath)
{
IList<Stream> fileStreams = new List<Stream>();
IList<Stream?> fileStreams = new List<Stream?>();

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<Entry, string> getOutputPath)
continue;
}

string directoryName = Path.GetDirectoryName(outputPath);
string? directoryName = Path.GetDirectoryName(outputPath);

if (!string.IsNullOrWhiteSpace(directoryName))
{
@@ -132,7 +153,7 @@ public void Extract(Func<Entry, string> getOutputPath)
}
finally
{
foreach (Stream stream in fileStreams)
foreach (Stream? stream in fileStreams)
{
if (stream != null)
{
@@ -152,7 +173,7 @@ public IList<Entry> 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<Entry> Entries

for (uint fileIndex = 0; fileIndex < itemsCount; fileIndex++)
{
string fileName = this.GetProperty<string>(fileIndex, ItemPropId.kpidPath);
string? fileName = this.GetProperty<string>(fileIndex, ItemPropId.kpidPath);
bool isFolder = this.GetProperty<bool>(fileIndex, ItemPropId.kpidIsFolder);
bool isEncrypted = this.GetProperty<bool>(fileIndex, ItemPropId.kpidEncrypted);
ulong size = this.GetProperty<ulong>(fileIndex, ItemPropId.kpidSize);
@@ -175,9 +196,9 @@ public IList<Entry> Entries
DateTime lastAccessTime = this.GetPropertySafe<DateTime>(fileIndex, ItemPropId.kpidLastAccessTime);
uint crc = this.GetPropertySafe<uint>(fileIndex, ItemPropId.kpidCRC);
uint attributes = this.GetPropertySafe<uint>(fileIndex, ItemPropId.kpidAttributes);
string comment = this.GetPropertySafe<string>(fileIndex, ItemPropId.kpidComment);
string hostOS = this.GetPropertySafe<string>(fileIndex, ItemPropId.kpidHostOS);
string method = this.GetPropertySafe<string>(fileIndex, ItemPropId.kpidMethod);
string? comment = this.GetPropertySafe<string>(fileIndex, ItemPropId.kpidComment);
string? hostOS = this.GetPropertySafe<string>(fileIndex, ItemPropId.kpidHostOS);
string? method = this.GetPropertySafe<string>(fileIndex, ItemPropId.kpidMethod);

bool isSplitBefore = this.GetPropertySafe<bool>(fileIndex, ItemPropId.kpidSplitBefore);
bool isSplitAfter = this.GetPropertySafe<bool>(fileIndex, ItemPropId.kpidSplitAfter);
@@ -206,42 +227,42 @@ public IList<Entry> Entries
}
}

private T GetPropertySafe<T>(uint fileIndex, ItemPropId name)
private T? GetPropertySafe<T>(uint fileIndex, ItemPropId name)
{
try
{
return this.GetProperty<T>(fileIndex, name);
}
catch (InvalidCastException)
{
return default(T);
return default;
}
}

private T GetProperty<T>(uint fileIndex, ItemPropId name)
private T? GetProperty<T>(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()
{
8 changes: 4 additions & 4 deletions SevenZipExtractor/ArchiveFileCallback.cs
Original file line number Diff line number Diff line change
@@ -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,15 +23,15 @@ 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))
{
outStream = null;
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();
}
}
}
2 changes: 1 addition & 1 deletion SevenZipExtractor/ArchiveStreamCallback.cs
Original file line number Diff line number Diff line change
@@ -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))
{
8 changes: 4 additions & 4 deletions SevenZipExtractor/ArchiveStreamsCallback.cs
Original file line number Diff line number Diff line change
@@ -5,9 +5,9 @@ namespace SevenZipExtractor
{
internal class ArchiveStreamsCallback : IArchiveExtractCallback
{
private readonly IList<Stream> streams;
private readonly IList<Stream?> streams;

public ArchiveStreamsCallback(IList<Stream> streams)
public ArchiveStreamsCallback(IList<Stream?> 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)
{
10 changes: 5 additions & 5 deletions SevenZipExtractor/Entry.cs
Original file line number Diff line number Diff line change
@@ -17,7 +17,7 @@ internal Entry(IInArchive archive, uint index)
/// <summary>
/// Name of the file with its relative path within the archive
/// </summary>
public string FileName { get; internal set; }
public string? FileName { get; internal set; }
/// <summary>
/// True if entry is a folder, false if it is a file
/// </summary>
@@ -64,17 +64,17 @@ internal Entry(IInArchive archive, uint index)
/// <summary>
/// Comment of the entry
/// </summary>
public string Comment { get; internal set; }
public string? Comment { get; internal set; }

/// <summary>
/// Compression method of the entry
/// </summary>
public string Method { get; internal set; }
public string? Method { get; internal set; }

/// <summary>
/// Host operating system of the entry
/// </summary>
public string HostOS { get; internal set; }
public string? HostOS { get; internal set; }

/// <summary>
/// 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))
{
3 changes: 2 additions & 1 deletion SevenZipExtractor/Formats.cs
Original file line number Diff line number Diff line change
@@ -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 } },
};
}
}
2 changes: 1 addition & 1 deletion SevenZipExtractor/IArchiveExtractCallback.cs
Original file line number Diff line number Diff line change
@@ -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

1 change: 0 additions & 1 deletion SevenZipExtractor/SafeLibraryHandle.cs
Original file line number Diff line number Diff line change
@@ -12,7 +12,6 @@ public SafeLibraryHandle() : base(true)

/// <summary>Release library handle</summary>
/// <returns>true if the handle was released</returns>
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
protected override bool ReleaseHandle()
{
return Kernel32Dll.FreeLibrary(this.handle);
3 changes: 2 additions & 1 deletion SevenZipExtractor/SevenZipExtractor.csproj
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>net45;netstandard2.0</TargetFrameworks>
<TargetFrameworks>net6.0</TargetFrameworks>
<AssemblyTitle>SevenZipWrapper</AssemblyTitle>
<Product>SevenZipWrapper</Product>
<Description>C# wrapper for 7z.dll (included)</Description>
@@ -12,6 +12,7 @@
<PackageProjectUrl>https://github.com/adoconnection/SevenZipExtractor</PackageProjectUrl>
<PackageTags>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</PackageTags>
<PackageVersion>1.0.17</PackageVersion>
<Nullable>enable</Nullable>
</PropertyGroup>

<ItemGroup>
4 changes: 2 additions & 2 deletions SevenZipExtractor/SevenZipHandle.cs
Original file line number Diff line number Diff line change
@@ -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)
{
29 changes: 16 additions & 13 deletions SevenZipExtractor/SevenZipInterface.cs
Original file line number Diff line number Diff line change
@@ -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);