Skip to content
This repository has been archived by the owner on Apr 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #138 from squid-box/dev
Browse files Browse the repository at this point in the history
Release 1.5.0
  • Loading branch information
squid-box committed Aug 15, 2021
2 parents 76ddf5d + 028053f commit 1258e9b
Show file tree
Hide file tree
Showing 19 changed files with 591 additions and 347 deletions.
12 changes: 7 additions & 5 deletions SevenZip.Tests/MiscellaneousTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,21 @@ public class MiscellaneousTests : TestBase
[Test]
public void SerializationTest()
{
var ex = new ArgumentException("blahblah");
var bf = new BinaryFormatter();
var argumentException = new ArgumentException("blahblah");
var binaryFormatter = new BinaryFormatter();

using (var ms = new MemoryStream())
{
using (var fileStream = File.Create(TemporaryFile))
{
bf.Serialize(ms, ex);
SevenZipCompressor cmpr = new SevenZipCompressor();
cmpr.CompressStream(ms, fileStream);
binaryFormatter.Serialize(ms, argumentException);
var compressor = new SevenZipCompressor();
compressor.CompressStream(ms, fileStream);
}
}
}

#if SFX
[Test]
public void CreateSfxArchiveTest([Values]SfxModule sfxModule)
{
Expand Down Expand Up @@ -59,6 +60,7 @@ public void CreateSfxArchiveTest([Values]SfxModule sfxModule)
process?.Kill();
});
}
#endif

[Test]
public void LzmaEncodeDecodeTest()
Expand Down
18 changes: 11 additions & 7 deletions SevenZip.Tests/SevenZip.Tests.csproj
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
<TargetFrameworks>net45</TargetFrameworks>
<AssemblyTitle>SevenZip.Tests</AssemblyTitle>
<Product>SevenZipzTests</Product>
<Copyright>Copyright © 2018</Copyright>
<Product>SevenZipTests</Product>
<Copyright>Copyright © Joel Ahlgren 2021</Copyright>
<IntermediateOutputPath>..\Stage\obj\$(Configuration)\</IntermediateOutputPath>
<OutputPath>..\Stage\$(Configuration)\</OutputPath>
</PropertyGroup>
<PropertyGroup>
<SignAssembly>true</SignAssembly>
</PropertyGroup>
<PropertyGroup>
<AssemblyOriginatorKeyFile>SevenZipTests.snk</AssemblyOriginatorKeyFile>
<Configurations>Debug;Release;LiteDebug;LiteRelease</Configurations>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DefineConstants>SFX</DefineConstants>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DefineConstants>SFX</DefineConstants>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="NUnit.ConsoleRunner" Version="3.10.0" />
Expand Down
28 changes: 28 additions & 0 deletions SevenZip.Tests/SevenZipExtractorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,34 @@ public void ExtractArchiveWithLongPath()
}
}

[Test]
public void ReadArchivedFileNames()
{
using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z"))
{
var fileNames = extractor.ArchiveFileNames;
Assert.AreEqual(3, fileNames.Count);

Assert.AreEqual("file1.txt", fileNames[0]);
Assert.AreEqual("file2.txt", fileNames[1]);
Assert.AreEqual("file3.txt", fileNames[2]);
}
}

[Test]
public void ReadArchivedFileData()
{
using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z"))
{
var fileData = extractor.ArchiveFileData;
Assert.AreEqual(3, fileData.Count);

Assert.AreEqual("file1.txt", fileData[0].FileName);
Assert.IsFalse(fileData[0].Encrypted);
Assert.IsFalse(fileData[0].IsDirectory);
}
}

[Test, TestCaseSource(nameof(TestFiles))]
public void ExtractDifferentFormatsTest(TestFile file)
{
Expand Down
14 changes: 13 additions & 1 deletion SevenZip.sln
Original file line number Diff line number Diff line change
Expand Up @@ -10,24 +10,36 @@ EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{043464C6-413E-4D0F-8A43-B23F674B1804}"
ProjectSection(SolutionItems) = preProject
appveyor.yml = appveyor.yml
changelog.md = changelog.md
license = license
nuget.config = nuget.config
package.nuspec = package.nuspec
package.lite.nuspec = package.lite.nuspec
package.regular.nuspec = package.regular.nuspec
readme.md = readme.md
EndProjectSection
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
LiteDebug|Any CPU = LiteDebug|Any CPU
LiteRelease|Any CPU = LiteRelease|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.LiteDebug|Any CPU.ActiveCfg = LiteDebug|Any CPU
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.LiteDebug|Any CPU.Build.0 = LiteDebug|Any CPU
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.LiteRelease|Any CPU.ActiveCfg = LiteRelease|Any CPU
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.LiteRelease|Any CPU.Build.0 = LiteRelease|Any CPU
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Release|Any CPU.Build.0 = Release|Any CPU
{67192E62-C7FE-485F-BEC4-05734A943FAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{67192E62-C7FE-485F-BEC4-05734A943FAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{67192E62-C7FE-485F-BEC4-05734A943FAA}.LiteDebug|Any CPU.ActiveCfg = LiteDebug|Any CPU
{67192E62-C7FE-485F-BEC4-05734A943FAA}.LiteDebug|Any CPU.Build.0 = LiteDebug|Any CPU
{67192E62-C7FE-485F-BEC4-05734A943FAA}.LiteRelease|Any CPU.ActiveCfg = LiteRelease|Any CPU
{67192E62-C7FE-485F-BEC4-05734A943FAA}.LiteRelease|Any CPU.Build.0 = LiteRelease|Any CPU
{67192E62-C7FE-485F-BEC4-05734A943FAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{67192E62-C7FE-485F-BEC4-05734A943FAA}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
Expand Down
32 changes: 17 additions & 15 deletions SevenZip/ArchiveUpdateCallback.cs
Original file line number Diff line number Diff line change
Expand Up @@ -681,10 +681,10 @@ public void SetOperationResult(OperationResult operationResult)
AddException(new ExtractionFailedException("File is corrupted. Crc check has failed."));
break;
case OperationResult.DataError:
AddException(new ExtractionFailedException("File is corrupted. Data error has occured."));
AddException(new ExtractionFailedException("File is corrupted. Data error has occurred."));
break;
case OperationResult.UnsupportedMethod:
AddException(new ExtractionFailedException("Unsupported method error has occured."));
AddException(new ExtractionFailedException("Unsupported method error has occurred."));
break;
case OperationResult.Unavailable:
AddException(new ExtractionFailedException("File is unavailable."));
Expand All @@ -711,23 +711,25 @@ public void SetOperationResult(OperationResult operationResult)
}
if (_fileStream != null)
{

_fileStream.BytesRead -= IntEventArgsHandler;
//Specific Zip implementation - can not Dispose files for Zip.
if (_compressor.ArchiveFormat != OutArchiveFormat.Zip)
_fileStream.BytesRead -= IntEventArgsHandler;

//Specific Zip implementation - can not Dispose files for Zip.
if (_compressor.ArchiveFormat != OutArchiveFormat.Zip)
{
try
{
try
{
_fileStream.Dispose();
}
catch (ObjectDisposedException) {}
_fileStream.Dispose();
}
else
{
_wrappersToDispose.Add(_fileStream);
}
catch (ObjectDisposedException) {}
}
else
{
_wrappersToDispose.Add(_fileStream);
}

_fileStream = null;
}

OnFileCompressionFinished(EventArgs.Empty);
}

Expand Down
26 changes: 17 additions & 9 deletions SevenZip/COM.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
using System.Globalization;
using System.IO;
using System.Runtime.InteropServices;
#if NET45 || NETSTANDARD2_0
using System.Security.Permissions;
#endif
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;

#if UNMANAGED
Expand Down Expand Up @@ -120,11 +122,14 @@ public object Object
{
get
{
#if NET45 || NETSTANDARD2_0
var sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
sp.Demand();

#endif
switch (VarType)
{
case VarEnum.VT_BSTR:
return Marshal.PtrToStringBSTR(Value);
case VarEnum.VT_EMPTY:
return null;
case VarEnum.VT_FILETIME:
Expand All @@ -137,7 +142,8 @@ public object Object
return DateTime.MinValue;
}
default:
GCHandle propHandle = GCHandle.Alloc(this, GCHandleType.Pinned);
var propHandle = GCHandle.Alloc(this, GCHandleType.Pinned);

try
{
return Marshal.GetObjectForNativeVariant(propHandle.AddrOfPinnedObject());
Expand Down Expand Up @@ -173,7 +179,7 @@ public object Object
/// <returns>true if the specified System.Object is equal to the current PropVariant; otherwise, false.</returns>
public override bool Equals(object obj)
{
return (obj is PropVariant variant) && Equals(variant);
return obj is PropVariant variant && Equals(variant);
}

/// <summary>
Expand All @@ -187,10 +193,12 @@ private bool Equals(PropVariant afi)
{
return false;
}

if (VarType != VarEnum.VT_BSTR)
{
return afi.Int64Value == Int64Value;
}

return afi.Value == Value;
}

Expand Down Expand Up @@ -268,11 +276,11 @@ public enum OperationResult
/// </summary>
UnsupportedMethod,
/// <summary>
/// Data error has occured
/// Data error has occurred
/// </summary>
DataError,
/// <summary>
/// CrcError has occured
/// CrcError has occurred
/// </summary>
CrcError,
/// <summary>
Expand Down Expand Up @@ -577,7 +585,7 @@ internal static class PropIdToName
/// PropId string names
/// </summary>
public static readonly Dictionary<ItemPropId, string> PropIdNames =
#region Initialization
#region Initialization
new Dictionary<ItemPropId, string>(46)
{
{ItemPropId.Path, "Path"},
Expand Down Expand Up @@ -648,7 +656,7 @@ internal static class PropIdToName
{ItemPropId.FreeSpace, "Free Space"},
{ItemPropId.ClusterSize, "Cluster Size"}
};
#endregion
#endregion
}

/// <summary>
Expand Down Expand Up @@ -801,7 +809,7 @@ internal interface IArchiveUpdateCallback
/// Gets the archive item property data.
/// </summary>
/// <param name="index">Item index</param>
/// <param name="propId">Property identificator</param>
/// <param name="propId">Property identifier</param>
/// <param name="value">Property value</param>
/// <returns>Zero if Ok</returns>
[PreserveSig]
Expand Down Expand Up @@ -1132,4 +1140,4 @@ internal interface ISetProperties
int SetProperties(IntPtr names, IntPtr values, int numProperties);
}
#endif
}
}
Loading

0 comments on commit 1258e9b

Please sign in to comment.