Skip to content

Commit 1258e9b

Browse files
authored
Merge pull request squid-box#138 from squid-box/dev
Release 1.5.0
2 parents 76ddf5d + 028053f commit 1258e9b

19 files changed

+591
-347
lines changed

SevenZip.Tests/MiscellaneousTests.cs

+7-5
Original file line numberDiff line numberDiff line change
@@ -15,20 +15,21 @@ public class MiscellaneousTests : TestBase
1515
[Test]
1616
public void SerializationTest()
1717
{
18-
var ex = new ArgumentException("blahblah");
19-
var bf = new BinaryFormatter();
18+
var argumentException = new ArgumentException("blahblah");
19+
var binaryFormatter = new BinaryFormatter();
2020

2121
using (var ms = new MemoryStream())
2222
{
2323
using (var fileStream = File.Create(TemporaryFile))
2424
{
25-
bf.Serialize(ms, ex);
26-
SevenZipCompressor cmpr = new SevenZipCompressor();
27-
cmpr.CompressStream(ms, fileStream);
25+
binaryFormatter.Serialize(ms, argumentException);
26+
var compressor = new SevenZipCompressor();
27+
compressor.CompressStream(ms, fileStream);
2828
}
2929
}
3030
}
3131

32+
#if SFX
3233
[Test]
3334
public void CreateSfxArchiveTest([Values]SfxModule sfxModule)
3435
{
@@ -59,6 +60,7 @@ public void CreateSfxArchiveTest([Values]SfxModule sfxModule)
5960
process?.Kill();
6061
});
6162
}
63+
#endif
6264

6365
[Test]
6466
public void LzmaEncodeDecodeTest()

SevenZip.Tests/SevenZip.Tests.csproj

+11-7
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,21 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22
<PropertyGroup>
3-
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>
3+
<TargetFrameworks>net45</TargetFrameworks>
44
<AssemblyTitle>SevenZip.Tests</AssemblyTitle>
5-
<Product>SevenZipzTests</Product>
6-
<Copyright>Copyright © 2018</Copyright>
5+
<Product>SevenZipTests</Product>
6+
<Copyright>Copyright © Joel Ahlgren 2021</Copyright>
77
<IntermediateOutputPath>..\Stage\obj\$(Configuration)\</IntermediateOutputPath>
88
<OutputPath>..\Stage\$(Configuration)\</OutputPath>
9-
</PropertyGroup>
10-
<PropertyGroup>
119
<SignAssembly>true</SignAssembly>
12-
</PropertyGroup>
13-
<PropertyGroup>
1410
<AssemblyOriginatorKeyFile>SevenZipTests.snk</AssemblyOriginatorKeyFile>
11+
<Configurations>Debug;Release;LiteDebug;LiteRelease</Configurations>
12+
</PropertyGroup>
13+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
14+
<DefineConstants>SFX</DefineConstants>
15+
</PropertyGroup>
16+
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
17+
<DefineConstants>SFX</DefineConstants>
18+
<DebugSymbols>true</DebugSymbols>
1519
</PropertyGroup>
1620
<ItemGroup>
1721
<PackageReference Include="NUnit.ConsoleRunner" Version="3.10.0" />

SevenZip.Tests/SevenZipExtractorTests.cs

+28
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,34 @@ public void ExtractArchiveWithLongPath()
198198
}
199199
}
200200

201+
[Test]
202+
public void ReadArchivedFileNames()
203+
{
204+
using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z"))
205+
{
206+
var fileNames = extractor.ArchiveFileNames;
207+
Assert.AreEqual(3, fileNames.Count);
208+
209+
Assert.AreEqual("file1.txt", fileNames[0]);
210+
Assert.AreEqual("file2.txt", fileNames[1]);
211+
Assert.AreEqual("file3.txt", fileNames[2]);
212+
}
213+
}
214+
215+
[Test]
216+
public void ReadArchivedFileData()
217+
{
218+
using (var extractor = new SevenZipExtractor(@"TestData\multiple_files.7z"))
219+
{
220+
var fileData = extractor.ArchiveFileData;
221+
Assert.AreEqual(3, fileData.Count);
222+
223+
Assert.AreEqual("file1.txt", fileData[0].FileName);
224+
Assert.IsFalse(fileData[0].Encrypted);
225+
Assert.IsFalse(fileData[0].IsDirectory);
226+
}
227+
}
228+
201229
[Test, TestCaseSource(nameof(TestFiles))]
202230
public void ExtractDifferentFormatsTest(TestFile file)
203231
{

SevenZip.sln

+13-1
Original file line numberDiff line numberDiff line change
@@ -10,24 +10,36 @@ EndProject
1010
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{043464C6-413E-4D0F-8A43-B23F674B1804}"
1111
ProjectSection(SolutionItems) = preProject
1212
appveyor.yml = appveyor.yml
13+
changelog.md = changelog.md
1314
license = license
1415
nuget.config = nuget.config
15-
package.nuspec = package.nuspec
16+
package.lite.nuspec = package.lite.nuspec
17+
package.regular.nuspec = package.regular.nuspec
1618
readme.md = readme.md
1719
EndProjectSection
1820
EndProject
1921
Global
2022
GlobalSection(SolutionConfigurationPlatforms) = preSolution
2123
Debug|Any CPU = Debug|Any CPU
24+
LiteDebug|Any CPU = LiteDebug|Any CPU
25+
LiteRelease|Any CPU = LiteRelease|Any CPU
2226
Release|Any CPU = Release|Any CPU
2327
EndGlobalSection
2428
GlobalSection(ProjectConfigurationPlatforms) = postSolution
2529
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
2630
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Debug|Any CPU.Build.0 = Debug|Any CPU
31+
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.LiteDebug|Any CPU.ActiveCfg = LiteDebug|Any CPU
32+
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.LiteDebug|Any CPU.Build.0 = LiteDebug|Any CPU
33+
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.LiteRelease|Any CPU.ActiveCfg = LiteRelease|Any CPU
34+
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.LiteRelease|Any CPU.Build.0 = LiteRelease|Any CPU
2735
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Release|Any CPU.ActiveCfg = Release|Any CPU
2836
{4960DD14-3431-47EC-B9D9-9D2730A98DC3}.Release|Any CPU.Build.0 = Release|Any CPU
2937
{67192E62-C7FE-485F-BEC4-05734A943FAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
3038
{67192E62-C7FE-485F-BEC4-05734A943FAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{67192E62-C7FE-485F-BEC4-05734A943FAA}.LiteDebug|Any CPU.ActiveCfg = LiteDebug|Any CPU
40+
{67192E62-C7FE-485F-BEC4-05734A943FAA}.LiteDebug|Any CPU.Build.0 = LiteDebug|Any CPU
41+
{67192E62-C7FE-485F-BEC4-05734A943FAA}.LiteRelease|Any CPU.ActiveCfg = LiteRelease|Any CPU
42+
{67192E62-C7FE-485F-BEC4-05734A943FAA}.LiteRelease|Any CPU.Build.0 = LiteRelease|Any CPU
3143
{67192E62-C7FE-485F-BEC4-05734A943FAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
3244
{67192E62-C7FE-485F-BEC4-05734A943FAA}.Release|Any CPU.Build.0 = Release|Any CPU
3345
EndGlobalSection

SevenZip/ArchiveUpdateCallback.cs

+17-15
Original file line numberDiff line numberDiff line change
@@ -681,10 +681,10 @@ public void SetOperationResult(OperationResult operationResult)
681681
AddException(new ExtractionFailedException("File is corrupted. Crc check has failed."));
682682
break;
683683
case OperationResult.DataError:
684-
AddException(new ExtractionFailedException("File is corrupted. Data error has occured."));
684+
AddException(new ExtractionFailedException("File is corrupted. Data error has occurred."));
685685
break;
686686
case OperationResult.UnsupportedMethod:
687-
AddException(new ExtractionFailedException("Unsupported method error has occured."));
687+
AddException(new ExtractionFailedException("Unsupported method error has occurred."));
688688
break;
689689
case OperationResult.Unavailable:
690690
AddException(new ExtractionFailedException("File is unavailable."));
@@ -711,23 +711,25 @@ public void SetOperationResult(OperationResult operationResult)
711711
}
712712
if (_fileStream != null)
713713
{
714-
715-
_fileStream.BytesRead -= IntEventArgsHandler;
716-
//Specific Zip implementation - can not Dispose files for Zip.
717-
if (_compressor.ArchiveFormat != OutArchiveFormat.Zip)
714+
_fileStream.BytesRead -= IntEventArgsHandler;
715+
716+
//Specific Zip implementation - can not Dispose files for Zip.
717+
if (_compressor.ArchiveFormat != OutArchiveFormat.Zip)
718+
{
719+
try
718720
{
719-
try
720-
{
721-
_fileStream.Dispose();
722-
}
723-
catch (ObjectDisposedException) {}
721+
_fileStream.Dispose();
724722
}
725-
else
726-
{
727-
_wrappersToDispose.Add(_fileStream);
728-
}
723+
catch (ObjectDisposedException) {}
724+
}
725+
else
726+
{
727+
_wrappersToDispose.Add(_fileStream);
728+
}
729+
729730
_fileStream = null;
730731
}
732+
731733
OnFileCompressionFinished(EventArgs.Empty);
732734
}
733735

SevenZip/COM.cs

+17-9
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
using System.Globalization;
66
using System.IO;
77
using System.Runtime.InteropServices;
8+
#if NET45 || NETSTANDARD2_0
89
using System.Security.Permissions;
10+
#endif
911
using FILETIME = System.Runtime.InteropServices.ComTypes.FILETIME;
1012

1113
#if UNMANAGED
@@ -120,11 +122,14 @@ public object Object
120122
{
121123
get
122124
{
125+
#if NET45 || NETSTANDARD2_0
123126
var sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
124127
sp.Demand();
125-
128+
#endif
126129
switch (VarType)
127130
{
131+
case VarEnum.VT_BSTR:
132+
return Marshal.PtrToStringBSTR(Value);
128133
case VarEnum.VT_EMPTY:
129134
return null;
130135
case VarEnum.VT_FILETIME:
@@ -137,7 +142,8 @@ public object Object
137142
return DateTime.MinValue;
138143
}
139144
default:
140-
GCHandle propHandle = GCHandle.Alloc(this, GCHandleType.Pinned);
145+
var propHandle = GCHandle.Alloc(this, GCHandleType.Pinned);
146+
141147
try
142148
{
143149
return Marshal.GetObjectForNativeVariant(propHandle.AddrOfPinnedObject());
@@ -173,7 +179,7 @@ public object Object
173179
/// <returns>true if the specified System.Object is equal to the current PropVariant; otherwise, false.</returns>
174180
public override bool Equals(object obj)
175181
{
176-
return (obj is PropVariant variant) && Equals(variant);
182+
return obj is PropVariant variant && Equals(variant);
177183
}
178184

179185
/// <summary>
@@ -187,10 +193,12 @@ private bool Equals(PropVariant afi)
187193
{
188194
return false;
189195
}
196+
190197
if (VarType != VarEnum.VT_BSTR)
191198
{
192199
return afi.Int64Value == Int64Value;
193200
}
201+
194202
return afi.Value == Value;
195203
}
196204

@@ -268,11 +276,11 @@ public enum OperationResult
268276
/// </summary>
269277
UnsupportedMethod,
270278
/// <summary>
271-
/// Data error has occured
279+
/// Data error has occurred
272280
/// </summary>
273281
DataError,
274282
/// <summary>
275-
/// CrcError has occured
283+
/// CrcError has occurred
276284
/// </summary>
277285
CrcError,
278286
/// <summary>
@@ -577,7 +585,7 @@ internal static class PropIdToName
577585
/// PropId string names
578586
/// </summary>
579587
public static readonly Dictionary<ItemPropId, string> PropIdNames =
580-
#region Initialization
588+
#region Initialization
581589
new Dictionary<ItemPropId, string>(46)
582590
{
583591
{ItemPropId.Path, "Path"},
@@ -648,7 +656,7 @@ internal static class PropIdToName
648656
{ItemPropId.FreeSpace, "Free Space"},
649657
{ItemPropId.ClusterSize, "Cluster Size"}
650658
};
651-
#endregion
659+
#endregion
652660
}
653661

654662
/// <summary>
@@ -801,7 +809,7 @@ int GetUpdateItemInfo(
801809
/// Gets the archive item property data.
802810
/// </summary>
803811
/// <param name="index">Item index</param>
804-
/// <param name="propId">Property identificator</param>
812+
/// <param name="propId">Property identifier</param>
805813
/// <param name="value">Property value</param>
806814
/// <returns>Zero if Ok</returns>
807815
[PreserveSig]
@@ -1132,4 +1140,4 @@ internal interface ISetProperties
11321140
int SetProperties(IntPtr names, IntPtr values, int numProperties);
11331141
}
11341142
#endif
1135-
}
1143+
}

0 commit comments

Comments
 (0)