mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-02-07 13:44:36 +00:00
Compare commits
72 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ee5e3fbc1d | ||
|
|
d13b2ad073 | ||
|
|
e9a7efc371 | ||
|
|
9b8ddda191 | ||
|
|
1fc14e1075 | ||
|
|
b3a5204e74 | ||
|
|
0fab1ff976 | ||
|
|
a05b692fc3 | ||
|
|
ed7f140364 | ||
|
|
a4b594121e | ||
|
|
fe8da55c95 | ||
|
|
42c4eab4be | ||
|
|
2e8844c896 | ||
|
|
aed7ff003d | ||
|
|
681b28f654 | ||
|
|
0de64b1551 | ||
|
|
526df2404e | ||
|
|
f20274aac7 | ||
|
|
08b899fdac | ||
|
|
7b91b6e7c8 | ||
|
|
1661b7ec36 | ||
|
|
e5ab9dc883 | ||
|
|
25d22e33a7 | ||
|
|
8ceac9000c | ||
|
|
ecceec8e1a | ||
|
|
d5c88ebab3 | ||
|
|
0a2adbc205 | ||
|
|
3be7f9da37 | ||
|
|
3f2ca67416 | ||
|
|
21087323af | ||
|
|
05f92018c3 | ||
|
|
b8fc4a2415 | ||
|
|
a30872809d | ||
|
|
7abf2ed58b | ||
|
|
bec2662d23 | ||
|
|
dd35052de9 | ||
|
|
2a630e04b2 | ||
|
|
231b78e096 | ||
|
|
ce6e1d26f4 | ||
|
|
69a25cd142 | ||
|
|
cc2ad7d8d5 | ||
|
|
1aa0498e5d | ||
|
|
1ce5e15fd2 | ||
|
|
b40131736a | ||
|
|
c2b15b9c09 | ||
|
|
27a4f78712 | ||
|
|
2b5ee6e8cb | ||
|
|
cd8ea28576 | ||
|
|
b2b6934499 | ||
|
|
0f12a073af | ||
|
|
18bd810228 | ||
|
|
13bbb202c7 | ||
|
|
6e0f4ecbc9 | ||
|
|
9a638e7aa5 | ||
|
|
7a11dc4385 | ||
|
|
66816ce390 | ||
|
|
5d8bd7b69b | ||
|
|
0132c85ec7 | ||
|
|
9bf5df72a6 | ||
|
|
91fc241358 | ||
|
|
35a8b444b8 | ||
|
|
2e928e86fd | ||
|
|
6648f33c4e | ||
|
|
2a70ec8100 | ||
|
|
05e0d591a5 | ||
|
|
1d30a1b51d | ||
|
|
315c138c05 | ||
|
|
b0c514d87c | ||
|
|
8e5cb77af2 | ||
|
|
8faebc78d0 | ||
|
|
afff386622 | ||
|
|
9eb43156e8 |
@@ -2,11 +2,11 @@
|
||||
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
|
||||
<metadata>
|
||||
<id>sharpcompress</id>
|
||||
<version>0.11.0</version>
|
||||
<version>0.11.5</version>
|
||||
<title>SharpCompress - Pure C# Decompression/Compression</title>
|
||||
<authors>Adam Hathcock</authors>
|
||||
<owners>Adam Hathcock</owners>
|
||||
<licenseUrl>http://sharpcompress.codeplex.com/license</licenseUrl>
|
||||
<licenseUrl>https://github.com/adamhathcock/sharpcompress/blob/master/LICENSE.txt</licenseUrl>
|
||||
<projectUrl>https://github.com/adamhathcock/sharpcompress</projectUrl>
|
||||
<requireLicenseAcceptance>false</requireLicenseAcceptance>
|
||||
<description>SharpCompress is a compression library for .NET/Mono/Silverlight/WP7/WindowsStore that can unrar, decompress 7zip, zip/unzip, tar/untar bzip2/unbzip2 and gzip/ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip is implemented.</description>
|
||||
@@ -14,16 +14,11 @@
|
||||
<language>en-US</language>
|
||||
<tags>rar unrar zip unzip bzip2 gzip tar 7zip</tags>
|
||||
<dependencies>
|
||||
<group />
|
||||
<group targetFramework="net20">
|
||||
<dependency id="LinqBridge" version="1.3.0" />
|
||||
</group>
|
||||
</dependencies>
|
||||
</metadata>
|
||||
<files>
|
||||
<file src="..\bin\Full\SharpCompress.dll" target="lib\net40\SharpCompress.dll" />
|
||||
<file src="..\bin\WindowsStore\SharpCompress.dll" target="lib\netcore45\SharpCompress.dll" />
|
||||
<file src="..\bin\Portable\SharpCompress.dll" target="lib\portable-net4+sl5+wp8+win8\SharpCompress.dll" />
|
||||
<file src="..\bin\NET2\SharpCompress.dll" target="lib\net20\SharpCompress.dll" />
|
||||
</files>
|
||||
</package>
|
||||
25
README.md
25
README.md
@@ -1,8 +1,6 @@
|
||||
SharpCompress
|
||||
=============
|
||||
|
||||
Github mirror of http://sharpcompress.codeplex.com
|
||||
|
||||
SharpCompress is a compression library for .NET/Mono/Silverlight/WP7 that can unrar, un7zip, unzip, untar unbzip2 and ungzip with forward-only reading and file random access APIs. Write support for zip/tar/bzip2/gzip are implemented.
|
||||
|
||||
The major feature is support for non-seekable streams so large files can be processed on the fly (i.e. download stream).
|
||||
@@ -11,6 +9,8 @@ A Simple Request
|
||||
|
||||
Hi everyone. I hope you're using SharpCompress and finding it useful. Please give me feedback on what you'd like to see changed especially as far as usability goes. New feature suggestions are always welcome as well. I would also like to know what projects SharpCompress is being used in. I like seeing how it is used to give me ideas for future versions. Thanks!
|
||||
|
||||
Please do not email me directly to ask for help. If you think there is a real issue, please report it here.
|
||||
|
||||
Want to contribute?
|
||||
|
||||
I'm always looking for help or ideas. Please submit code or email with ideas. Unfortunately, just letting me know you'd like to help is not enough because I really have no overall plan of what needs to be done. I'll definitely accept code submissions and add you as a member of the project!
|
||||
@@ -21,6 +21,27 @@ TODOs (always lots):
|
||||
* Zip64
|
||||
* Multi-volume Zip support.
|
||||
|
||||
In-Progress:
|
||||
==============
|
||||
- RAR5 support
|
||||
- DNX/NET Core support
|
||||
- xproj targeting
|
||||
|
||||
Version 0.11.5:
|
||||
==============
|
||||
- Bug fix in Skip method
|
||||
|
||||
Version 0.11.4:
|
||||
==============
|
||||
- SharpCompress is now endian neutral (matters for Mono platforms)
|
||||
- Fix for Inflate (need to change implementation)
|
||||
- Fixes for RAR detection
|
||||
|
||||
Version 0.11.1:
|
||||
==============
|
||||
- Added Cancel on IReader
|
||||
- Removed .NET 2.0 support and LinqBridge dependency
|
||||
|
||||
Version 0.11:
|
||||
==============
|
||||
- Been over a year, contains mainly fixes from contributors!
|
||||
|
||||
@@ -125,6 +125,55 @@ namespace SharpCompress.Test
|
||||
|
||||
private long? entryTotal;
|
||||
private long partTotal;
|
||||
private long totalSize;
|
||||
|
||||
protected void ArchiveFileReadEx(string testArchive)
|
||||
{
|
||||
testArchive = Path.Combine(TEST_ARCHIVES_PATH, testArchive);
|
||||
ArchiveFileReadEx(testArchive.AsEnumerable());
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Demonstrate the TotalUncompressSize property, and the ExtractOptions.PreserveFileTime and ExtractOptions.PreserveAttributes extract options
|
||||
/// </summary>
|
||||
protected void ArchiveFileReadEx(IEnumerable<string> testArchives)
|
||||
{
|
||||
foreach (var path in testArchives)
|
||||
{
|
||||
ResetScratch();
|
||||
using (var archive = ArchiveFactory.Open(path))
|
||||
{
|
||||
this.totalSize = archive.TotalUncompressSize;
|
||||
archive.EntryExtractionBegin += Archive_EntryExtractionBeginEx;
|
||||
archive.EntryExtractionEnd += Archive_EntryExtractionEndEx;
|
||||
archive.CompressedBytesRead += Archive_CompressedBytesReadEx;
|
||||
|
||||
foreach (var entry in archive.Entries.Where(entry => !entry.IsDirectory))
|
||||
{
|
||||
entry.WriteToDirectory(SCRATCH_FILES_PATH,
|
||||
ExtractOptions.ExtractFullPath | ExtractOptions.Overwrite | ExtractOptions.PreserveFileTime | ExtractOptions.PreserveAttributes);
|
||||
}
|
||||
}
|
||||
VerifyFilesEx();
|
||||
}
|
||||
}
|
||||
|
||||
private void Archive_EntryExtractionEndEx(object sender, ArchiveExtractionEventArgs<IArchiveEntry> e)
|
||||
{
|
||||
this.partTotal += e.Item.Size;
|
||||
}
|
||||
|
||||
private void Archive_CompressedBytesReadEx(object sender, CompressedBytesReadEventArgs e)
|
||||
{
|
||||
string percentage = this.entryTotal.HasValue ? this.CreatePercentage(e.CompressedBytesRead, this.entryTotal.Value).ToString() : "-";
|
||||
string tortalPercentage = this.CreatePercentage(this.partTotal + e.CompressedBytesRead, this.totalSize).ToString();
|
||||
Console.WriteLine(@"Read Compressed File Progress: {0}% Total Progress {1}%", percentage, tortalPercentage);
|
||||
}
|
||||
|
||||
private void Archive_EntryExtractionBeginEx(object sender, ArchiveExtractionEventArgs<IArchiveEntry> e)
|
||||
{
|
||||
this.entryTotal = e.Item.Size;
|
||||
}
|
||||
|
||||
private int CreatePercentage(long n, long d)
|
||||
{
|
||||
|
||||
@@ -61,6 +61,11 @@ namespace SharpCompress.Test
|
||||
ArchiveFileRead("7Zip.BZip2.7z");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void SevenZipArchive_LZMA_Time_Attributes_PathRead()
|
||||
{
|
||||
ArchiveFileReadEx("7Zip.LZMA.7z");
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
[ExpectedException(typeof(IndexOutOfRangeException))]
|
||||
|
||||
@@ -145,5 +145,16 @@ namespace SharpCompress.Test
|
||||
}
|
||||
CompareArchivesByPath(modified, scratchPath);
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Tar_Containing_Rar_Archive()
|
||||
{
|
||||
string archiveFullPath = Path.Combine(TEST_ARCHIVES_PATH, "Tar.ContainsRar.tar");
|
||||
using (Stream stream = File.OpenRead(archiveFullPath))
|
||||
using (IArchive archive = ArchiveFactory.Open(stream))
|
||||
{
|
||||
Assert.IsTrue(archive.Type == ArchiveType.Tar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.IO;
|
||||
using Microsoft.VisualStudio.TestTools.UnitTesting;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Reader;
|
||||
using SharpCompress.Reader.Tar;
|
||||
|
||||
namespace SharpCompress.Test
|
||||
@@ -88,5 +89,16 @@ namespace SharpCompress.Test
|
||||
Assert.AreEqual(names.Count, 3);
|
||||
}
|
||||
}
|
||||
|
||||
[TestMethod]
|
||||
public void Tar_Containing_Rar_Reader()
|
||||
{
|
||||
string archiveFullPath = Path.Combine(TEST_ARCHIVES_PATH, "Tar.ContainsRar.tar");
|
||||
using (Stream stream = File.OpenRead(archiveFullPath))
|
||||
using (IReader reader = ReaderFactory.Open(stream))
|
||||
{
|
||||
Assert.IsTrue(reader.ArchiveType == ArchiveType.Tar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,6 +78,21 @@ namespace SharpCompress.Test
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the files also check modified time and attributes.
|
||||
/// </summary>
|
||||
public void VerifyFilesEx()
|
||||
{
|
||||
if (UseExtensionInsteadOfNameToVerify)
|
||||
{
|
||||
VerifyFilesByExtensionEx();
|
||||
}
|
||||
else
|
||||
{
|
||||
VerifyFilesByNameEx();
|
||||
}
|
||||
}
|
||||
|
||||
protected void VerifyFilesByName()
|
||||
{
|
||||
var extracted =
|
||||
@@ -97,6 +112,52 @@ namespace SharpCompress.Test
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the files by name also check modified time and attributes.
|
||||
/// </summary>
|
||||
protected void VerifyFilesByNameEx()
|
||||
{
|
||||
var extracted =
|
||||
Directory.EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories)
|
||||
.ToLookup(path => path.Substring(SCRATCH_FILES_PATH.Length));
|
||||
var original =
|
||||
Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories)
|
||||
.ToLookup(path => path.Substring(ORIGINAL_FILES_PATH.Length));
|
||||
|
||||
Assert.AreEqual(extracted.Count, original.Count);
|
||||
|
||||
foreach (var orig in original)
|
||||
{
|
||||
Assert.IsTrue(extracted.Contains(orig.Key));
|
||||
|
||||
CompareFilesByPath(orig.Single(), extracted[orig.Key].Single());
|
||||
CompareFilesByTimeAndAttribut(orig.Single(), extracted[orig.Key].Single());
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Verifies the files by extension also check modified time and attributes.
|
||||
/// </summary>
|
||||
protected void VerifyFilesByExtensionEx()
|
||||
{
|
||||
var extracted =
|
||||
Directory.EnumerateFiles(SCRATCH_FILES_PATH, "*.*", SearchOption.AllDirectories)
|
||||
.ToLookup(path => Path.GetExtension(path));
|
||||
var original =
|
||||
Directory.EnumerateFiles(ORIGINAL_FILES_PATH, "*.*", SearchOption.AllDirectories)
|
||||
.ToLookup(path => Path.GetExtension(path));
|
||||
|
||||
Assert.AreEqual(extracted.Count, original.Count);
|
||||
|
||||
foreach (var orig in original)
|
||||
{
|
||||
Assert.IsTrue(extracted.Contains(orig.Key));
|
||||
|
||||
CompareFilesByPath(orig.Single(), extracted[orig.Key].Single());
|
||||
CompareFilesByTimeAndAttribut(orig.Single(), extracted[orig.Key].Single());
|
||||
}
|
||||
}
|
||||
|
||||
protected bool UseExtensionInsteadOfNameToVerify { get; set; }
|
||||
|
||||
protected void VerifyFilesByExtension()
|
||||
@@ -137,6 +198,14 @@ namespace SharpCompress.Test
|
||||
}
|
||||
}
|
||||
|
||||
protected void CompareFilesByTimeAndAttribut(string file1, string file2)
|
||||
{
|
||||
FileInfo fi1 = new FileInfo(file1);
|
||||
FileInfo fi2 = new FileInfo(file2);
|
||||
Assert.AreNotEqual(fi1.LastWriteTime, fi2.LastWriteTime);
|
||||
Assert.AreEqual(fi1.Attributes, fi2.Attributes);
|
||||
}
|
||||
|
||||
protected void CompareArchivesByPath(string file1, string file2)
|
||||
{
|
||||
using (var archive1 = ReaderFactory.Open(File.OpenRead(file1), Options.None))
|
||||
|
||||
@@ -22,8 +22,6 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress.PortableTest"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress.Test.Portable", "SharpCompress.Test\SharpCompress.Test.Portable.csproj", "{E9C3C94B-FB27-4B4F-B225-57513C254D37}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress.NET2", "SharpCompress\SharpCompress.NET2.csproj", "{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}"
|
||||
EndProject
|
||||
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SharpCompress.Unsigned", "SharpCompress\SharpCompress.Unsigned.csproj", "{27D535CB-2FD3-4621-8C9A-46161FC77A5D}"
|
||||
EndProject
|
||||
Global
|
||||
@@ -56,10 +54,6 @@ Global
|
||||
{E9C3C94B-FB27-4B4F-B225-57513C254D37}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{E9C3C94B-FB27-4B4F-B225-57513C254D37}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{E9C3C94B-FB27-4B4F-B225-57513C254D37}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}.Release|Any CPU.Build.0 = Release|Any CPU
|
||||
{27D535CB-2FD3-4621-8C9A-46161FC77A5D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
|
||||
{27D535CB-2FD3-4621-8C9A-46161FC77A5D}.Debug|Any CPU.Build.0 = Debug|Any CPU
|
||||
{27D535CB-2FD3-4621-8C9A-46161FC77A5D}.Release|Any CPU.ActiveCfg = Release|Any CPU
|
||||
|
||||
@@ -84,7 +84,6 @@ namespace SharpCompress.Archive
|
||||
/// <summary>
|
||||
/// Returns an ReadOnlyCollection of all the RarArchiveEntries across the one or many parts of the RarArchive.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual ICollection<TEntry> Entries
|
||||
{
|
||||
get { return lazyEntries; }
|
||||
@@ -93,7 +92,6 @@ namespace SharpCompress.Archive
|
||||
/// <summary>
|
||||
/// Returns an ReadOnlyCollection of all the RarArchiveVolumes across the one or many parts of the RarArchive.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public ICollection<TVolume> Volumes
|
||||
{
|
||||
get { return lazyVolumes; }
|
||||
@@ -102,11 +100,19 @@ namespace SharpCompress.Archive
|
||||
/// <summary>
|
||||
/// The total size of the files compressed in the archive.
|
||||
/// </summary>
|
||||
public long TotalSize
|
||||
public virtual long TotalSize
|
||||
{
|
||||
get { return Entries.Aggregate(0L, (total, cf) => total + cf.CompressedSize); }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The total size of the files as uncompressed in the archive.
|
||||
/// </summary>
|
||||
public virtual long TotalUncompressSize
|
||||
{
|
||||
get { return Entries.Aggregate(0L, (total, cf) => total + cf.Size); }
|
||||
}
|
||||
|
||||
protected abstract IEnumerable<TVolume> LoadVolumes(IEnumerable<Stream> streams, Options options);
|
||||
protected abstract IEnumerable<TEntry> LoadEntries(IEnumerable<TVolume> volumes);
|
||||
|
||||
|
||||
@@ -31,12 +31,6 @@ namespace SharpCompress.Archive
|
||||
return ZipArchive.Open(stream, options, null);
|
||||
}
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
if (TarArchive.IsTarFile(stream))
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return TarArchive.Open(stream, options);
|
||||
}
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
if (SevenZipArchive.IsSevenZipFile(stream))
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
@@ -49,11 +43,17 @@ namespace SharpCompress.Archive
|
||||
return GZipArchive.Open(stream, options);
|
||||
}
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
if(RarArchive.IsRarFile(stream, Options.LookForHeader | Options.KeepStreamsOpen))
|
||||
if (RarArchive.IsRarFile(stream, options))
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return RarArchive.Open(stream, options);
|
||||
}
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
if (TarArchive.IsTarFile(stream))
|
||||
{
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
return TarArchive.Open(stream, options);
|
||||
}
|
||||
throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
|
||||
}
|
||||
|
||||
@@ -126,12 +126,6 @@ namespace SharpCompress.Archive
|
||||
return ZipArchive.Open(fileInfo, options, null);
|
||||
}
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
if (TarArchive.IsTarFile(stream))
|
||||
{
|
||||
stream.Dispose();
|
||||
return TarArchive.Open(fileInfo, options);
|
||||
}
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
if (SevenZipArchive.IsSevenZipFile(stream))
|
||||
{
|
||||
stream.Dispose();
|
||||
@@ -144,11 +138,17 @@ namespace SharpCompress.Archive
|
||||
return GZipArchive.Open(fileInfo, options);
|
||||
}
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
if(RarArchive.IsRarFile(stream, Options.LookForHeader | Options.KeepStreamsOpen))
|
||||
if (RarArchive.IsRarFile(stream, options))
|
||||
{
|
||||
stream.Dispose();
|
||||
return RarArchive.Open(fileInfo, options);
|
||||
}
|
||||
stream.Seek(0, SeekOrigin.Begin);
|
||||
if (TarArchive.IsTarFile(stream))
|
||||
{
|
||||
stream.Dispose();
|
||||
return TarArchive.Open(fileInfo, options);
|
||||
}
|
||||
throw new InvalidOperationException("Cannot determine compressed stream type. Supported Archive Formats: Zip, GZip, Tar, Rar, 7Zip");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,7 +14,6 @@ namespace SharpCompress.Archive
|
||||
event EventHandler<FilePartExtractionBeginEventArgs> FilePartExtractionBegin;
|
||||
|
||||
IEnumerable<IArchiveEntry> Entries { get; }
|
||||
long TotalSize { get; }
|
||||
IEnumerable<IVolume> Volumes { get; }
|
||||
|
||||
ArchiveType Type { get; }
|
||||
@@ -24,7 +23,6 @@ namespace SharpCompress.Archive
|
||||
/// This is primarily for SOLID Rar Archives or 7Zip Archives as they need to be
|
||||
/// extracted sequentially for the best performance.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
IReader ExtractAllEntries();
|
||||
|
||||
/// <summary>
|
||||
@@ -37,5 +35,15 @@ namespace SharpCompress.Archive
|
||||
/// This checks to see if all the known entries have IsComplete = true
|
||||
/// </summary>
|
||||
bool IsComplete { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The total size of the files compressed in the archive.
|
||||
/// </summary>
|
||||
long TotalSize { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The total size of the files as uncompressed in the archive.
|
||||
/// </summary>
|
||||
long TotalUncompressSize { get; }
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace SharpCompress.Archive
|
||||
{
|
||||
return;
|
||||
}
|
||||
using(entryStream)
|
||||
using (entryStream)
|
||||
using (Stream s = new ListeningStream(streamListener, entryStream))
|
||||
{
|
||||
s.TransferTo(streamToWriteTo);
|
||||
@@ -60,7 +60,10 @@ namespace SharpCompress.Archive
|
||||
{
|
||||
destinationFileName = Path.Combine(destinationDirectory, file);
|
||||
}
|
||||
entry.WriteToFile(destinationFileName, options);
|
||||
if (!entry.IsDirectory)
|
||||
{
|
||||
entry.WriteToFile(destinationFileName, options);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -69,10 +72,6 @@ namespace SharpCompress.Archive
|
||||
public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
|
||||
ExtractOptions options = ExtractOptions.Overwrite)
|
||||
{
|
||||
if (entry.IsDirectory)
|
||||
{
|
||||
return;
|
||||
}
|
||||
FileMode fm = FileMode.Create;
|
||||
|
||||
if (!options.HasFlag(ExtractOptions.Overwrite))
|
||||
@@ -83,6 +82,8 @@ namespace SharpCompress.Archive
|
||||
{
|
||||
entry.WriteTo(fs);
|
||||
}
|
||||
|
||||
entry.PreserveExtractionOptions(destinationFileName, options);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -60,7 +60,7 @@ namespace SharpCompress.Archive
|
||||
this IWritableArchive writableArchive,
|
||||
string filePath, string searchPattern = "*.*", SearchOption searchOption = SearchOption.AllDirectories)
|
||||
{
|
||||
#if NET2
|
||||
#if NET35
|
||||
foreach (var path in Directory.GetFiles(filePath, searchPattern, searchOption))
|
||||
#else
|
||||
foreach (var path in Directory.EnumerateFiles(filePath, searchPattern, searchOption))
|
||||
|
||||
@@ -6,12 +6,9 @@ namespace SharpCompress.Archive.Rar
|
||||
{
|
||||
internal class FileInfoRarFilePart : SeekableFilePart
|
||||
{
|
||||
private readonly FileInfoRarArchiveVolume volume;
|
||||
|
||||
internal FileInfoRarFilePart(FileInfoRarArchiveVolume volume, MarkHeader mh, FileHeader fh, FileInfo fi)
|
||||
: base(mh, fh, volume.Stream, volume.Password)
|
||||
{
|
||||
this.volume = volume;
|
||||
FileInfo = fi;
|
||||
}
|
||||
|
||||
|
||||
@@ -64,7 +64,7 @@ namespace SharpCompress.Archive.Rar
|
||||
{
|
||||
var stream = Volumes.First().Stream;
|
||||
stream.Position = 0;
|
||||
return RarReader.Open(stream);
|
||||
return RarReader.Open(stream, Password);
|
||||
}
|
||||
|
||||
public override bool IsSolid
|
||||
@@ -152,12 +152,8 @@ namespace SharpCompress.Archive.Rar
|
||||
try
|
||||
{
|
||||
var headerFactory = new RarHeaderFactory(StreamingMode.Seekable, options);
|
||||
RarHeader header = headerFactory.ReadHeaders(stream).FirstOrDefault();
|
||||
if (header == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Enum.IsDefined(typeof (HeaderType), header.HeaderType);
|
||||
var markHeader = headerFactory.ReadHeaders(stream).FirstOrDefault() as MarkHeader;
|
||||
return markHeader != null && markHeader.IsValid();
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
@@ -73,8 +74,11 @@ namespace SharpCompress.Archive.Rar
|
||||
|
||||
public Stream OpenEntryStream()
|
||||
{
|
||||
return new RarStream(archive.Unpack, FileHeader,
|
||||
new MultiVolumeReadOnlyStream(Parts.Cast<RarFilePart>(), archive));
|
||||
if (archive.IsSolid)
|
||||
{
|
||||
throw new InvalidOperationException("Use ExtractAllEntries to extract SOLID archives.");
|
||||
}
|
||||
return new RarStream(archive.Unpack, FileHeader, new MultiVolumeReadOnlyStream(Parts.Cast<RarFilePart>(), archive));
|
||||
}
|
||||
|
||||
public bool IsComplete
|
||||
|
||||
@@ -188,6 +188,15 @@ namespace SharpCompress.Archive.SevenZip
|
||||
get { return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1; }
|
||||
}
|
||||
|
||||
public override long TotalSize
|
||||
{
|
||||
get
|
||||
{
|
||||
int i = Entries.Count;
|
||||
return database.PackSizes.Aggregate(0L, (total, packSize) => total + packSize);
|
||||
}
|
||||
}
|
||||
|
||||
private class SevenZipReader : AbstractReader<SevenZipEntry, SevenZipVolume>
|
||||
{
|
||||
private readonly SevenZipArchive archive;
|
||||
@@ -236,7 +245,7 @@ namespace SharpCompress.Archive.SevenZip
|
||||
|
||||
protected override EntryStream GetEntryStream()
|
||||
{
|
||||
return new EntryStream(new ReadOnlySubStream(currentStream, currentItem.Size));
|
||||
return CreateEntryStream(new ReadOnlySubStream(currentStream, currentItem.Size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.IO;
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Common.SevenZip;
|
||||
|
||||
namespace SharpCompress.Archive.SevenZip
|
||||
|
||||
@@ -46,7 +46,7 @@ namespace SharpCompress.Common
|
||||
public abstract DateTime? LastAccessedTime { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The entry time whend archived, if recorded
|
||||
/// The entry time when archived, if recorded
|
||||
/// </summary>
|
||||
public abstract DateTime? ArchivedTime { get; }
|
||||
|
||||
@@ -70,7 +70,16 @@ namespace SharpCompress.Common
|
||||
|
||||
internal virtual void Close()
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Entry file attribute.
|
||||
/// </summary>
|
||||
public virtual int? Attrib
|
||||
{
|
||||
get { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,16 +1,19 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Reader;
|
||||
|
||||
namespace SharpCompress.Common
|
||||
{
|
||||
public class EntryStream : Stream
|
||||
{
|
||||
public IReader Reader { get; private set; }
|
||||
private Stream stream;
|
||||
private bool completed;
|
||||
private bool isDisposed;
|
||||
|
||||
internal EntryStream(Stream stream)
|
||||
internal EntryStream(IReader reader, Stream stream)
|
||||
{
|
||||
this.Reader = reader;
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
@@ -28,10 +31,9 @@ namespace SharpCompress.Common
|
||||
|
||||
protected override void Dispose(bool disposing)
|
||||
{
|
||||
if (!completed)
|
||||
if (!(completed || Reader.Cancelled))
|
||||
{
|
||||
throw new InvalidOperationException(
|
||||
"EntryStream has not been fully consumed. Read the entire stream or use SkipEntry.");
|
||||
SkipEntry();
|
||||
}
|
||||
if (isDisposed)
|
||||
{
|
||||
|
||||
@@ -5,16 +5,26 @@ namespace SharpCompress.Common
|
||||
[Flags]
|
||||
public enum ExtractOptions
|
||||
{
|
||||
None,
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// overwrite target if it exists
|
||||
/// </summary>
|
||||
Overwrite,
|
||||
Overwrite = 1 << 0,
|
||||
|
||||
/// <summary>
|
||||
/// extract with internal directory structure
|
||||
/// </summary>
|
||||
ExtractFullPath,
|
||||
ExtractFullPath = 1 << 1,
|
||||
|
||||
/// <summary>
|
||||
/// preserve file time
|
||||
/// </summary>
|
||||
PreserveFileTime = 1 << 2,
|
||||
|
||||
/// <summary>
|
||||
/// preserve windows file attributes
|
||||
/// </summary>
|
||||
PreserveAttributes = 1 << 3,
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using SharpCompress.Common.Tar.Headers;
|
||||
using SharpCompress.Compressor;
|
||||
using SharpCompress.Compressor.Deflate;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Common.GZip
|
||||
{
|
||||
@@ -50,7 +51,7 @@ namespace SharpCompress.Common.GZip
|
||||
if (header[0] != 0x1F || header[1] != 0x8B || header[2] != 8)
|
||||
throw new ZlibException("Bad GZIP header.");
|
||||
|
||||
Int32 timet = BitConverter.ToInt32(header, 4);
|
||||
Int32 timet = DataConverter.LittleEndian.GetInt32(header, 4);
|
||||
DateModified = TarHeader.Epoch.AddSeconds(timet);
|
||||
if ((header[3] & 0x04) == 0x04)
|
||||
{
|
||||
|
||||
@@ -4,10 +4,6 @@ namespace SharpCompress.Common.GZip
|
||||
{
|
||||
public class GZipVolume : Volume
|
||||
{
|
||||
#if !PORTABLE && !NETFX_CORE
|
||||
private readonly FileInfo fileInfo;
|
||||
#endif
|
||||
|
||||
public GZipVolume(Stream stream, Options options)
|
||||
: base(stream, options)
|
||||
{
|
||||
@@ -17,7 +13,6 @@ namespace SharpCompress.Common.GZip
|
||||
public GZipVolume(FileInfo fileInfo, Options options)
|
||||
: base(fileInfo.OpenRead(), options)
|
||||
{
|
||||
this.fileInfo = fileInfo;
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
48
SharpCompress/Common/IEntry.Extensions.cs
Normal file
48
SharpCompress/Common/IEntry.Extensions.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace SharpCompress.Common
|
||||
{
|
||||
internal static class IEntryExtensions
|
||||
{
|
||||
internal static void PreserveExtractionOptions(this IEntry entry, string destinationFileName,
|
||||
ExtractOptions options)
|
||||
{
|
||||
if (options.HasFlag(ExtractOptions.PreserveFileTime) || options.HasFlag(ExtractOptions.PreserveAttributes))
|
||||
{
|
||||
FileInfo nf = new FileInfo(destinationFileName);
|
||||
if (!nf.Exists)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// update file time to original packed time
|
||||
if (options.HasFlag(ExtractOptions.PreserveFileTime))
|
||||
{
|
||||
if (entry.CreatedTime.HasValue)
|
||||
{
|
||||
nf.CreationTime = entry.CreatedTime.Value;
|
||||
}
|
||||
|
||||
if (entry.LastModifiedTime.HasValue)
|
||||
{
|
||||
nf.LastWriteTime = entry.LastModifiedTime.Value;
|
||||
}
|
||||
|
||||
if (entry.LastAccessedTime.HasValue)
|
||||
{
|
||||
nf.LastAccessTime = entry.LastAccessedTime.Value;
|
||||
}
|
||||
}
|
||||
|
||||
if (options.HasFlag(ExtractOptions.PreserveAttributes))
|
||||
{
|
||||
if (entry.Attrib.HasValue)
|
||||
{
|
||||
nf.Attributes = (FileAttributes)System.Enum.ToObject(typeof(FileAttributes), entry.Attrib.Value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,5 +16,6 @@ namespace SharpCompress.Common
|
||||
DateTime? LastAccessedTime { get; }
|
||||
DateTime? LastModifiedTime { get; }
|
||||
long Size { get; }
|
||||
int? Attrib { get; }
|
||||
}
|
||||
}
|
||||
@@ -10,48 +10,15 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
|
||||
internal bool IsValid()
|
||||
{
|
||||
if (!(HeadCRC == 0x6152))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!(HeaderType == HeaderType.MarkHeader))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!(Flags == 0x1a21))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!(HeaderSize == BaseBlockSize))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
// Rar old signature: 52 45 7E 5E (not supported)
|
||||
|
||||
internal bool IsSignature()
|
||||
{
|
||||
bool valid = false;
|
||||
/*byte[] d = new byte[BaseBlock.BaseBlockSize];
|
||||
BinaryWriter writer = new BinaryWriter();
|
||||
writer.Write(HeadCRC);
|
||||
writer.Write((byte)HeaderType);
|
||||
writer.Write(flags);
|
||||
writer.Write(HeaderSize);
|
||||
writer.Flush
|
||||
|
||||
if (d[0] == 0x52) {
|
||||
if (d[1]==0x45 && d[2]==0x7e && d[3]==0x5e) {
|
||||
oldFormat=true;
|
||||
valid=true;
|
||||
}
|
||||
else if (d[1]==0x61 && d[2]==0x72 && d[3]==0x21 && d[4]==0x1a &&
|
||||
d[5]==0x07 && d[6]==0x00) {
|
||||
oldFormat=false;
|
||||
valid=true;
|
||||
}
|
||||
}*/
|
||||
return valid;
|
||||
// Rar4 signature: 52 61 72 21 1A 07 00
|
||||
return HeadCRC == 0x6152 &&
|
||||
HeaderType == HeaderType.MarkHeader &&
|
||||
Flags == 0x1A21 &&
|
||||
HeaderSize == 0x07;
|
||||
|
||||
// Rar5 signature: 52 61 72 21 1A 07 10 00 (not supported yet)
|
||||
}
|
||||
|
||||
internal bool OldFormat { get; private set; }
|
||||
|
||||
@@ -93,7 +93,7 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
{
|
||||
if (!Options.HasFlag(Options.KeepStreamsOpen))
|
||||
{
|
||||
#if NET2
|
||||
#if NET35
|
||||
reader.Close();
|
||||
#else
|
||||
reader.Dispose();
|
||||
|
||||
@@ -67,8 +67,9 @@ namespace SharpCompress.Common.SevenZip
|
||||
ulong id = _currentReader.ReadNumber();
|
||||
if (id > 25)
|
||||
return null;
|
||||
|
||||
#if DEBUG
|
||||
Log.WriteLine("ReadId: {0}", (BlockType)id);
|
||||
#endif
|
||||
return (BlockType)id;
|
||||
}
|
||||
|
||||
@@ -197,20 +198,25 @@ namespace SharpCompress.Common.SevenZip
|
||||
|
||||
private void GetNextFolderItem(CFolder folder)
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("-- GetNextFolderItem --");
|
||||
Log.PushIndent();
|
||||
#endif
|
||||
try
|
||||
{
|
||||
int numCoders = ReadNum();
|
||||
#if DEBUG
|
||||
Log.WriteLine("NumCoders: " + numCoders);
|
||||
|
||||
#endif
|
||||
folder.Coders = new List<CCoderInfo>(numCoders);
|
||||
int numInStreams = 0;
|
||||
int numOutStreams = 0;
|
||||
for (int i = 0; i < numCoders; i++)
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("-- Coder --");
|
||||
Log.PushIndent();
|
||||
#endif
|
||||
try
|
||||
{
|
||||
CCoderInfo coder = new CCoderInfo();
|
||||
@@ -220,11 +226,9 @@ namespace SharpCompress.Common.SevenZip
|
||||
int idSize = (mainByte & 0xF);
|
||||
byte[] longID = new byte[idSize];
|
||||
ReadBytes(longID, 0, idSize);
|
||||
Log.WriteLine("MethodId: " +
|
||||
String.Join("",
|
||||
Enumerable.Range(0, idSize)
|
||||
.Select(x => longID[x].ToString("x2"))
|
||||
.ToArray()));
|
||||
#if DEBUG
|
||||
Log.WriteLine("MethodId: " + String.Join("", Enumerable.Range(0, idSize).Select(x => longID[x].ToString("x2")).ToArray()));
|
||||
#endif
|
||||
if (idSize > 8)
|
||||
throw new NotSupportedException();
|
||||
ulong id = 0;
|
||||
@@ -236,12 +240,15 @@ namespace SharpCompress.Common.SevenZip
|
||||
{
|
||||
coder.NumInStreams = ReadNum();
|
||||
coder.NumOutStreams = ReadNum();
|
||||
Log.WriteLine("Complex Stream (In: " + coder.NumInStreams + " - Out: " + coder.NumOutStreams +
|
||||
")");
|
||||
#if DEBUG
|
||||
Log.WriteLine("Complex Stream (In: " + coder.NumInStreams + " - Out: " + coder.NumOutStreams + ")");
|
||||
#endif
|
||||
}
|
||||
else
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("Simple Stream (In: 1 - Out: 1)");
|
||||
#endif
|
||||
coder.NumInStreams = 1;
|
||||
coder.NumOutStreams = 1;
|
||||
}
|
||||
@@ -251,8 +258,9 @@ namespace SharpCompress.Common.SevenZip
|
||||
int propsSize = ReadNum();
|
||||
coder.Props = new byte[propsSize];
|
||||
ReadBytes(coder.Props, 0, propsSize);
|
||||
Log.WriteLine("Settings: " +
|
||||
String.Join("", coder.Props.Select(bt => bt.ToString("x2")).ToArray()));
|
||||
#if DEBUG
|
||||
Log.WriteLine("Settings: " + String.Join("", coder.Props.Select(bt => bt.ToString("x2")).ToArray()));
|
||||
#endif
|
||||
}
|
||||
|
||||
if ((mainByte & 0x80) != 0)
|
||||
@@ -263,23 +271,31 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if DEBUG
|
||||
Log.PopIndent();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
int numBindPairs = numOutStreams - 1;
|
||||
folder.BindPairs = new List<CBindPair>(numBindPairs);
|
||||
#if DEBUG
|
||||
Log.WriteLine("BindPairs: " + numBindPairs);
|
||||
Log.PushIndent();
|
||||
#endif
|
||||
for (int i = 0; i < numBindPairs; i++)
|
||||
{
|
||||
CBindPair bp = new CBindPair();
|
||||
bp.InIndex = ReadNum();
|
||||
bp.OutIndex = ReadNum();
|
||||
folder.BindPairs.Add(bp);
|
||||
#if DEBUG
|
||||
Log.WriteLine("#" + i + " - In: " + bp.InIndex + " - Out: " + bp.OutIndex);
|
||||
#endif
|
||||
}
|
||||
#if DEBUG
|
||||
Log.PopIndent();
|
||||
#endif
|
||||
|
||||
if (numInStreams < numBindPairs)
|
||||
throw new NotSupportedException();
|
||||
@@ -292,7 +308,9 @@ namespace SharpCompress.Common.SevenZip
|
||||
{
|
||||
if (folder.FindBindPairForInStream(i) < 0)
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("Single PackStream: #" + i);
|
||||
#endif
|
||||
folder.PackStreams.Add(i);
|
||||
break;
|
||||
}
|
||||
@@ -303,26 +321,36 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
else
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("Multiple PackStreams ...");
|
||||
Log.PushIndent();
|
||||
#endif
|
||||
for (int i = 0; i < numPackStreams; i++)
|
||||
{
|
||||
var num = ReadNum();
|
||||
#if DEBUG
|
||||
Log.WriteLine("#" + i + " - " + num);
|
||||
#endif
|
||||
folder.PackStreams.Add(num);
|
||||
}
|
||||
#if DEBUG
|
||||
Log.PopIndent();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if DEBUG
|
||||
Log.PopIndent();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private List<uint?> ReadHashDigests(int count)
|
||||
{
|
||||
#if DEBUG
|
||||
Log.Write("ReadHashDigests:");
|
||||
#endif
|
||||
|
||||
var defined = ReadOptionalBitVector(count);
|
||||
var digests = new List<uint?>(count);
|
||||
@@ -331,44 +359,62 @@ namespace SharpCompress.Common.SevenZip
|
||||
if (defined[i])
|
||||
{
|
||||
uint crc = ReadUInt32();
|
||||
#if DEBUG
|
||||
Log.Write(" " + crc.ToString("x8"));
|
||||
#endif
|
||||
digests.Add(crc);
|
||||
}
|
||||
else
|
||||
{
|
||||
#if DEBUG
|
||||
Log.Write(" ########");
|
||||
#endif
|
||||
digests.Add(null);
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
return digests;
|
||||
}
|
||||
|
||||
private void ReadPackInfo(out long dataOffset, out List<long> packSizes, out List<uint?> packCRCs)
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("-- ReadPackInfo --");
|
||||
Log.PushIndent();
|
||||
#endif
|
||||
try
|
||||
{
|
||||
packCRCs = null;
|
||||
|
||||
dataOffset = checked((long)ReadNumber());
|
||||
#if DEBUG
|
||||
Log.WriteLine("DataOffset: " + dataOffset);
|
||||
#endif
|
||||
|
||||
int numPackStreams = ReadNum();
|
||||
#if DEBUG
|
||||
Log.WriteLine("NumPackStreams: " + numPackStreams);
|
||||
#endif
|
||||
|
||||
WaitAttribute(BlockType.Size);
|
||||
packSizes = new List<long>(numPackStreams);
|
||||
#if DEBUG
|
||||
Log.Write("Sizes:");
|
||||
#endif
|
||||
for (int i = 0; i < numPackStreams; i++)
|
||||
{
|
||||
var size = checked((long)ReadNumber());
|
||||
#if DEBUG
|
||||
Log.Write(" " + size);
|
||||
#endif
|
||||
packSizes.Add(size);
|
||||
}
|
||||
#if DEBUG
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
|
||||
BlockType? type;
|
||||
for (; ; )
|
||||
@@ -393,19 +439,25 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if DEBUG
|
||||
Log.PopIndent();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadUnpackInfo(List<byte[]> dataVector, out List<CFolder> folders)
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("-- ReadUnpackInfo --");
|
||||
Log.PushIndent();
|
||||
#endif
|
||||
try
|
||||
{
|
||||
WaitAttribute(BlockType.Folder);
|
||||
int numFolders = ReadNum();
|
||||
#if DEBUG
|
||||
Log.WriteLine("NumFolders: {0}", numFolders);
|
||||
#endif
|
||||
|
||||
using (CStreamSwitch streamSwitch = new CStreamSwitch())
|
||||
{
|
||||
@@ -424,20 +476,27 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
|
||||
WaitAttribute(BlockType.CodersUnpackSize);
|
||||
|
||||
#if DEBUG
|
||||
Log.WriteLine("UnpackSizes:");
|
||||
#endif
|
||||
for (int i = 0; i < numFolders; i++)
|
||||
{
|
||||
CFolder folder = folders[i];
|
||||
#if DEBUG
|
||||
Log.Write(" #" + i + ":");
|
||||
#endif
|
||||
int numOutStreams = folder.GetNumOutStreams();
|
||||
for (int j = 0; j < numOutStreams; j++)
|
||||
{
|
||||
long size = checked((long)ReadNumber());
|
||||
#if DEBUG
|
||||
Log.Write(" " + size);
|
||||
#endif
|
||||
folder.UnpackSizes.Add(size);
|
||||
}
|
||||
#if DEBUG
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
}
|
||||
|
||||
for (; ; )
|
||||
@@ -459,15 +518,19 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if DEBUG
|
||||
Log.PopIndent();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadSubStreamsInfo(List<CFolder> folders, out List<int> numUnpackStreamsInFolders,
|
||||
out List<long> unpackSizes, out List<uint?> digests)
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("-- ReadSubStreamsInfo --");
|
||||
Log.PushIndent();
|
||||
#endif
|
||||
try
|
||||
{
|
||||
numUnpackStreamsInFolders = null;
|
||||
@@ -479,14 +542,20 @@ namespace SharpCompress.Common.SevenZip
|
||||
if (type == BlockType.NumUnpackStream)
|
||||
{
|
||||
numUnpackStreamsInFolders = new List<int>(folders.Count);
|
||||
#if DEBUG
|
||||
Log.Write("NumUnpackStreams:");
|
||||
#endif
|
||||
for (int i = 0; i < folders.Count; i++)
|
||||
{
|
||||
var num = ReadNum();
|
||||
#if DEBUG
|
||||
Log.Write(" " + num);
|
||||
#endif
|
||||
numUnpackStreamsInFolders.Add(num);
|
||||
}
|
||||
#if DEBUG
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
continue;
|
||||
}
|
||||
if (type == BlockType.CRC || type == BlockType.Size)
|
||||
@@ -511,21 +580,26 @@ namespace SharpCompress.Common.SevenZip
|
||||
int numSubstreams = numUnpackStreamsInFolders[i];
|
||||
if (numSubstreams == 0)
|
||||
continue;
|
||||
|
||||
#if DEBUG
|
||||
Log.Write("#{0} StreamSizes:", i);
|
||||
#endif
|
||||
long sum = 0;
|
||||
for (int j = 1; j < numSubstreams; j++)
|
||||
{
|
||||
if (type == BlockType.Size)
|
||||
{
|
||||
long size = checked((long)ReadNumber());
|
||||
#if DEBUG
|
||||
Log.Write(" " + size);
|
||||
#endif
|
||||
unpackSizes.Add(size);
|
||||
sum += size;
|
||||
}
|
||||
}
|
||||
unpackSizes.Add(folders[i].GetUnpackSize() - sum);
|
||||
#if DEBUG
|
||||
Log.WriteLine(" - rest: " + unpackSizes.Last());
|
||||
#endif
|
||||
}
|
||||
if (type == BlockType.Size)
|
||||
type = ReadId();
|
||||
@@ -589,7 +663,9 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if DEBUG
|
||||
Log.PopIndent();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -603,8 +679,10 @@ namespace SharpCompress.Common.SevenZip
|
||||
out List<long> unpackSizes,
|
||||
out List<uint?> digests)
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("-- ReadStreamsInfo --");
|
||||
Log.PushIndent();
|
||||
#endif
|
||||
try
|
||||
{
|
||||
dataOffset = long.MinValue;
|
||||
@@ -637,14 +715,18 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if DEBUG
|
||||
Log.PopIndent();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private List<byte[]> ReadAndDecodePackedStreams(long baseOffset, IPasswordProvider pass)
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("-- ReadAndDecodePackedStreams --");
|
||||
Log.PushIndent();
|
||||
#endif
|
||||
try
|
||||
{
|
||||
long dataStartPos;
|
||||
@@ -697,14 +779,18 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if DEBUG
|
||||
Log.PopIndent();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadHeader(ArchiveDatabase db, IPasswordProvider getTextPassword)
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("-- ReadHeader --");
|
||||
Log.PushIndent();
|
||||
#endif
|
||||
try
|
||||
{
|
||||
BlockType? type = ReadId();
|
||||
@@ -762,7 +848,9 @@ namespace SharpCompress.Common.SevenZip
|
||||
throw new InvalidOperationException();
|
||||
|
||||
int numFiles = ReadNum();
|
||||
#if DEBUG
|
||||
Log.WriteLine("NumFiles: " + numFiles);
|
||||
#endif
|
||||
db.Files = new List<CFileItem>(numFiles);
|
||||
for (int i = 0; i < numFiles; i++)
|
||||
db.Files.Add(new CFileItem());
|
||||
@@ -786,112 +874,147 @@ namespace SharpCompress.Common.SevenZip
|
||||
using (var streamSwitch = new CStreamSwitch())
|
||||
{
|
||||
streamSwitch.Set(this, dataVector);
|
||||
#if DEBUG
|
||||
Log.Write("FileNames:");
|
||||
#endif
|
||||
for (int i = 0; i < db.Files.Count; i++)
|
||||
{
|
||||
db.Files[i].Name = _currentReader.ReadString();
|
||||
#if DEBUG
|
||||
Log.Write(" " + db.Files[i].Name);
|
||||
#endif
|
||||
}
|
||||
#if DEBUG
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
case BlockType.WinAttributes:
|
||||
#if DEBUG
|
||||
Log.Write("WinAttributes:");
|
||||
#endif
|
||||
ReadAttributeVector(dataVector, numFiles, delegate(int i, uint? attr)
|
||||
{
|
||||
db.Files[i].Attrib = attr;
|
||||
Log.Write(" " +
|
||||
(attr.HasValue
|
||||
? attr.Value.ToString("x8")
|
||||
: "n/a"));
|
||||
#if DEBUG
|
||||
Log.Write(" " + (attr.HasValue ? attr.Value.ToString("x8") : "n/a"));
|
||||
#endif
|
||||
});
|
||||
#if DEBUG
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
break;
|
||||
case BlockType.EmptyStream:
|
||||
emptyStreamVector = ReadBitVector(numFiles);
|
||||
#if DEBUG
|
||||
|
||||
Log.Write("EmptyStream: ");
|
||||
#endif
|
||||
for (int i = 0; i < emptyStreamVector.Length; i++)
|
||||
{
|
||||
if (emptyStreamVector[i])
|
||||
{
|
||||
#if DEBUG
|
||||
Log.Write("x");
|
||||
#endif
|
||||
numEmptyStreams++;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if DEBUG
|
||||
Log.Write(".");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
#if DEBUG
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
|
||||
emptyFileVector = new BitVector(numEmptyStreams);
|
||||
antiFileVector = new BitVector(numEmptyStreams);
|
||||
break;
|
||||
case BlockType.EmptyFile:
|
||||
emptyFileVector = ReadBitVector(numEmptyStreams);
|
||||
#if DEBUG
|
||||
Log.Write("EmptyFile: ");
|
||||
for (int i = 0; i < numEmptyStreams; i++)
|
||||
Log.Write(emptyFileVector[i] ? "x" : ".");
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
break;
|
||||
case BlockType.Anti:
|
||||
antiFileVector = ReadBitVector(numEmptyStreams);
|
||||
#if DEBUG
|
||||
Log.Write("Anti: ");
|
||||
for (int i = 0; i < numEmptyStreams; i++)
|
||||
Log.Write(antiFileVector[i] ? "x" : ".");
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
break;
|
||||
case BlockType.StartPos:
|
||||
#if DEBUG
|
||||
Log.Write("StartPos:");
|
||||
#endif
|
||||
ReadNumberVector(dataVector, numFiles, delegate(int i, long? startPos)
|
||||
{
|
||||
db.Files[i].StartPos = startPos;
|
||||
Log.Write(" " +
|
||||
(startPos.HasValue
|
||||
? startPos.Value.ToString()
|
||||
: "n/a"));
|
||||
#if DEBUG
|
||||
Log.Write(" " + (startPos.HasValue ? startPos.Value.ToString() : "n/a"));
|
||||
#endif
|
||||
});
|
||||
#if DEBUG
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
break;
|
||||
case BlockType.CTime:
|
||||
#if DEBUG
|
||||
Log.Write("CTime:");
|
||||
#endif
|
||||
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
|
||||
{
|
||||
db.Files[i].CTime = time;
|
||||
Log.Write(" " +
|
||||
(time.HasValue
|
||||
? time.Value.ToString()
|
||||
: "n/a"));
|
||||
#if DEBUG
|
||||
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
|
||||
#endif
|
||||
});
|
||||
#if DEBUG
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
break;
|
||||
case BlockType.ATime:
|
||||
#if DEBUG
|
||||
Log.Write("ATime:");
|
||||
#endif
|
||||
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
|
||||
{
|
||||
db.Files[i].ATime = time;
|
||||
Log.Write(" " +
|
||||
(time.HasValue
|
||||
? time.Value.ToString()
|
||||
: "n/a"));
|
||||
#if DEBUG
|
||||
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
|
||||
#endif
|
||||
});
|
||||
#if DEBUG
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
break;
|
||||
case BlockType.MTime:
|
||||
#if DEBUG
|
||||
Log.Write("MTime:");
|
||||
#endif
|
||||
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
|
||||
{
|
||||
db.Files[i].MTime = time;
|
||||
Log.Write(" " +
|
||||
(time.HasValue
|
||||
? time.Value.ToString()
|
||||
: "n/a"));
|
||||
#if DEBUG
|
||||
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
|
||||
#endif
|
||||
});
|
||||
#if DEBUG
|
||||
Log.WriteLine();
|
||||
#endif
|
||||
break;
|
||||
case BlockType.Dummy:
|
||||
#if DEBUG
|
||||
Log.Write("Dummy: " + size);
|
||||
#endif
|
||||
for (long j = 0; j < size; j++)
|
||||
if (ReadByte() != 0)
|
||||
throw new InvalidOperationException();
|
||||
@@ -933,7 +1056,9 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
finally
|
||||
{
|
||||
#if DEBUG
|
||||
Log.PopIndent();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1073,14 +1198,12 @@ namespace SharpCompress.Common.SevenZip
|
||||
private class FolderUnpackStream : Stream
|
||||
{
|
||||
private ArchiveDatabase _db;
|
||||
private int _otherIndex;
|
||||
private int _startIndex;
|
||||
private List<bool> _extractStatuses;
|
||||
|
||||
public FolderUnpackStream(ArchiveDatabase db, int p, int startIndex, List<bool> list)
|
||||
{
|
||||
this._db = db;
|
||||
this._otherIndex = p;
|
||||
this._startIndex = startIndex;
|
||||
this._extractStatuses = list;
|
||||
}
|
||||
@@ -1150,13 +1273,10 @@ namespace SharpCompress.Common.SevenZip
|
||||
|
||||
private void OpenFile()
|
||||
{
|
||||
bool skip = !_extractStatuses[_currentIndex];
|
||||
int index = _startIndex + _currentIndex;
|
||||
int realIndex = _otherIndex + index;
|
||||
//string filename = @"D:\_testdump\" + _db.Files[index].Name;
|
||||
//Directory.CreateDirectory(Path.GetDirectoryName(filename));
|
||||
//_stream = new FileStream(filename, FileMode.Create, FileAccess.Write, FileShare.Delete);
|
||||
#if DEBUG
|
||||
Log.WriteLine(_db.Files[index].Name);
|
||||
#endif
|
||||
if (_db.Files[index].CrcDefined)
|
||||
_stream = new CrcCheckStream(_db.Files[index].Crc.Value);
|
||||
else
|
||||
|
||||
@@ -16,7 +16,9 @@ namespace SharpCompress.Common.SevenZip
|
||||
if (_active)
|
||||
{
|
||||
_active = false;
|
||||
#if DEBUG
|
||||
Log.WriteLine("[end of switch]");
|
||||
#endif
|
||||
}
|
||||
|
||||
if (_needRemove)
|
||||
@@ -47,7 +49,9 @@ namespace SharpCompress.Common.SevenZip
|
||||
if (dataIndex < 0 || dataIndex >= dataVector.Count)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
#if DEBUG
|
||||
Log.WriteLine("[switch to stream {0}]", dataIndex);
|
||||
#endif
|
||||
_archive = archive;
|
||||
_archive.AddByteStream(dataVector[dataIndex], 0, dataVector[dataIndex].Length);
|
||||
_needRemove = true;
|
||||
@@ -55,7 +59,9 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
else
|
||||
{
|
||||
#if DEBUG
|
||||
Log.WriteLine("[inline data]");
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ namespace SharpCompress.Common.SevenZip
|
||||
#region Variables
|
||||
|
||||
private byte[] _buffer;
|
||||
private int _origin;
|
||||
private int _offset;
|
||||
private int _ending;
|
||||
|
||||
@@ -45,7 +44,6 @@ namespace SharpCompress.Common.SevenZip
|
||||
public DataReader(byte[] buffer, int offset, int length)
|
||||
{
|
||||
_buffer = buffer;
|
||||
_origin = offset;
|
||||
_offset = offset;
|
||||
_ending = offset + length;
|
||||
}
|
||||
@@ -78,7 +76,9 @@ namespace SharpCompress.Common.SevenZip
|
||||
throw new EndOfStreamException();
|
||||
|
||||
_offset += (int) size;
|
||||
#if DEBUG
|
||||
Log.WriteLine("SkipData {0}", size);
|
||||
#endif
|
||||
}
|
||||
|
||||
public void SkipData()
|
||||
|
||||
@@ -72,6 +72,11 @@ namespace SharpCompress.Common.SevenZip
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override int? Attrib
|
||||
{
|
||||
get { return (int) FilePart.Header.Attrib; }
|
||||
}
|
||||
|
||||
internal override IEnumerable<FilePart> Parts
|
||||
{
|
||||
get { return FilePart.AsEnumerable<FilePart>(); }
|
||||
|
||||
@@ -4,6 +4,7 @@ using System.IO;
|
||||
using System.Net;
|
||||
#endif
|
||||
using System.Text;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Common.Tar.Headers
|
||||
{
|
||||
@@ -64,11 +65,7 @@ namespace SharpCompress.Common.Tar.Headers
|
||||
|
||||
if (Size >= 0x1FFFFFFFF)
|
||||
{
|
||||
#if PORTABLE || NETFX_CORE
|
||||
byte[] bytes = BitConverter.GetBytes(Utility.HostToNetworkOrder(Size));
|
||||
#else
|
||||
byte[] bytes = BitConverter.GetBytes(IPAddress.HostToNetworkOrder(Size));
|
||||
#endif
|
||||
byte[] bytes = DataConverter.BigEndian.GetBytes(Size);
|
||||
var bytes12 = new byte[12];
|
||||
bytes.CopyTo(bytes12, 12 - bytes.Length);
|
||||
bytes12[0] |= 0x80;
|
||||
@@ -119,12 +116,7 @@ namespace SharpCompress.Common.Tar.Headers
|
||||
EntryType = (EntryType) buffer[156];
|
||||
if ((buffer[124] & 0x80) == 0x80) // if size in binary
|
||||
{
|
||||
long sizeBigEndian = BitConverter.ToInt64(buffer, 0x80);
|
||||
#if PORTABLE || NETFX_CORE
|
||||
Size = Utility.NetworkToHostOrder(sizeBigEndian);
|
||||
#else
|
||||
Size = IPAddress.NetworkToHostOrder(sizeBigEndian);
|
||||
#endif
|
||||
Size = DataConverter.BigEndian.GetInt64(buffer, 0x80);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Common.Zip.Headers
|
||||
{
|
||||
@@ -68,13 +69,13 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
{
|
||||
for (int i = 0; i < extra.Length-4;)
|
||||
{
|
||||
ExtraDataType type = (ExtraDataType) BitConverter.ToUInt16(extra, i);
|
||||
ExtraDataType type = (ExtraDataType)DataConverter.LittleEndian.GetUInt16(extra, i);
|
||||
if (!Enum.IsDefined(typeof (ExtraDataType), type))
|
||||
{
|
||||
type = ExtraDataType.NotImplementedExtraData;
|
||||
}
|
||||
|
||||
ushort length = BitConverter.ToUInt16(extra, i + 2);
|
||||
ushort length = DataConverter.LittleEndian.GetUInt16(extra, i + 2);
|
||||
byte[] data = new byte[length];
|
||||
Buffer.BlockCopy(extra, i + 4, data, 0, length);
|
||||
Extra.Add(LocalEntryHeaderExtraFactory.Create(type,length,data));
|
||||
|
||||
@@ -8,7 +8,7 @@ namespace SharpCompress.Common.Zip
|
||||
{
|
||||
internal class SeekableZipHeaderFactory : ZipHeaderFactory
|
||||
{
|
||||
private const int MAX_ITERATIONS_FOR_DIRECTORY_HEADER = 1000;
|
||||
private const int MAX_ITERATIONS_FOR_DIRECTORY_HEADER = 4096;
|
||||
|
||||
internal SeekableZipHeaderFactory(string password)
|
||||
: base(StreamingMode.Seekable, password)
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using Org.BouncyCastle.Crypto;
|
||||
using Org.BouncyCastle.Crypto.Engines;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Common.Zip
|
||||
{
|
||||
@@ -113,7 +114,7 @@ namespace SharpCompress.Common.Zip
|
||||
: bytesRemaining;
|
||||
|
||||
// update the counter
|
||||
Array.Copy(BitConverter.GetBytes(nonce++), 0, counter, 0, 4);
|
||||
DataConverter.LittleEndian.PutBytes(counter, 0, nonce++);
|
||||
|
||||
// Determine if this is the final block
|
||||
if ((bytesToRead == bytesRemaining) && (totalBytesLeftToRead == 0))
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Security.Cryptography;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Common.Zip
|
||||
{
|
||||
@@ -117,7 +118,7 @@ namespace SharpCompress.Common.Zip
|
||||
: bytesRemaining;
|
||||
|
||||
// update the counter
|
||||
Array.Copy(BitConverter.GetBytes(nonce++), 0, counter, 0, 4);
|
||||
DataConverter.LittleEndian.PutBytes(counter, 0, nonce++);
|
||||
|
||||
// Determine if this is the final block
|
||||
if ((bytesToRead == bytesRemaining) && (totalBytesLeftToRead == 0))
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using SharpCompress.Converter;
|
||||
using SharpCompress.Crypto;
|
||||
|
||||
namespace SharpCompress.Common.Zip
|
||||
@@ -56,10 +57,10 @@ namespace SharpCompress.Common.Zip
|
||||
generatedVerifyValue = paramz.GetBytes(2);
|
||||
|
||||
|
||||
short verify = BitConverter.ToInt16(passwordVerifyValue, 0);
|
||||
short verify = DataConverter.LittleEndian.GetInt16(passwordVerifyValue, 0);
|
||||
if (password != null)
|
||||
{
|
||||
short generated = BitConverter.ToInt16(generatedVerifyValue, 0);
|
||||
short generated = DataConverter.LittleEndian.GetInt16(generatedVerifyValue, 0);
|
||||
if (verify != generated)
|
||||
throw new InvalidFormatException("bad password");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Common.Zip
|
||||
{
|
||||
@@ -54,10 +55,10 @@ namespace SharpCompress.Common.Zip
|
||||
IvBytes = rfc2898.GetBytes(KeySizeInBytes);
|
||||
generatedVerifyValue = rfc2898.GetBytes(2);
|
||||
|
||||
short verify = BitConverter.ToInt16(passwordVerifyValue, 0);
|
||||
short verify = DataConverter.LittleEndian.GetInt16(passwordVerifyValue, 0);
|
||||
if (password != null)
|
||||
{
|
||||
short generated = BitConverter.ToInt16(generatedVerifyValue, 0);
|
||||
short generated = DataConverter.LittleEndian.GetInt16(generatedVerifyValue, 0);
|
||||
if (verify != generated)
|
||||
throw new InvalidFormatException("bad password");
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ using SharpCompress.Compressor.BZip2;
|
||||
using SharpCompress.Compressor.Deflate;
|
||||
using SharpCompress.Compressor.LZMA;
|
||||
using SharpCompress.Compressor.PPMd;
|
||||
using SharpCompress.Converter;
|
||||
using SharpCompress.IO;
|
||||
|
||||
namespace SharpCompress.Common.Zip
|
||||
@@ -108,19 +109,19 @@ namespace SharpCompress.Common.Zip
|
||||
{
|
||||
throw new InvalidFormatException("Winzip data length is not 7.");
|
||||
}
|
||||
ushort method = BitConverter.ToUInt16(data.DataBytes, 0);
|
||||
ushort method = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 0);
|
||||
|
||||
if (method != 0x01 && method != 0x02)
|
||||
{
|
||||
throw new InvalidFormatException("Unexpected vendor version number for WinZip AES metadata");
|
||||
}
|
||||
|
||||
ushort vendorId = BitConverter.ToUInt16(data.DataBytes, 2);
|
||||
ushort vendorId = DataConverter.LittleEndian.GetUInt16(data.DataBytes, 2);
|
||||
if (vendorId != 0x4541)
|
||||
{
|
||||
throw new InvalidFormatException("Unexpected vendor ID for WinZip AES metadata");
|
||||
}
|
||||
Header.CompressionMethod = (ZipCompressionMethod)BitConverter.ToUInt16(data.DataBytes, 5);
|
||||
Header.CompressionMethod = (ZipCompressionMethod)DataConverter.LittleEndian.GetUInt16(data.DataBytes, 5);
|
||||
return CreateDecompressionStream(stream);
|
||||
}
|
||||
default:
|
||||
|
||||
@@ -670,6 +670,7 @@ namespace SharpCompress.Compressor.Deflate
|
||||
send_bits((tree[c2] & 0xffff), (tree[c2 + 1] & 0xffff));
|
||||
}
|
||||
|
||||
#pragma warning disable 675 // workaround for Visual Studio 2015 compiler bug: https://github.com/dotnet/roslyn/issues/4027
|
||||
internal void send_bits(int value, int length)
|
||||
{
|
||||
int len = length;
|
||||
@@ -680,7 +681,7 @@ namespace SharpCompress.Compressor.Deflate
|
||||
//int val = value;
|
||||
// bi_buf |= (val << bi_valid);
|
||||
|
||||
bi_buf |= (short) ((value << bi_valid) & 0xffff);
|
||||
bi_buf |= (short)((value << bi_valid) & 0xffff);
|
||||
//put_short(bi_buf);
|
||||
pending[pendingCount++] = (byte) bi_buf;
|
||||
pending[pendingCount++] = (byte) (bi_buf >> 8);
|
||||
@@ -692,11 +693,12 @@ namespace SharpCompress.Compressor.Deflate
|
||||
else
|
||||
{
|
||||
// bi_buf |= (value) << bi_valid;
|
||||
bi_buf |= (short) ((value << bi_valid) & 0xffff);
|
||||
bi_buf |= (short)((value << bi_valid) & 0xffff);
|
||||
bi_valid += len;
|
||||
}
|
||||
}
|
||||
}
|
||||
#pragma warning restore 675
|
||||
|
||||
// Send one empty static block to give enough lookahead for inflate.
|
||||
// This takes 10 bits, of which 7 may remain in the bit buffer.
|
||||
|
||||
@@ -30,6 +30,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Compressor.Deflate
|
||||
{
|
||||
@@ -417,7 +418,7 @@ namespace SharpCompress.Compressor.Deflate
|
||||
LastModified = DateTime.Now;
|
||||
TimeSpan delta = LastModified.Value - UnixEpoch;
|
||||
var timet = (Int32) delta.TotalSeconds;
|
||||
Array.Copy(BitConverter.GetBytes(timet), 0, header, i, 4);
|
||||
DataConverter.LittleEndian.PutBytes(header, i, timet);
|
||||
i += 4;
|
||||
|
||||
// xflg
|
||||
|
||||
@@ -895,6 +895,11 @@ namespace SharpCompress.Compressor.Deflate
|
||||
r = ZlibConstants.Z_OK;
|
||||
else
|
||||
{
|
||||
// Handling missing trailing bit(s)
|
||||
var tmp_tindex = (tree_index + (b & InternalInflateConstants.InflateMask[k]))*3;
|
||||
if (k >= tree[tmp_tindex + 1])
|
||||
break;
|
||||
|
||||
blocks.bitb = b;
|
||||
blocks.bitk = k;
|
||||
z.AvailableBytesIn = n;
|
||||
@@ -998,6 +1003,11 @@ namespace SharpCompress.Compressor.Deflate
|
||||
r = ZlibConstants.Z_OK;
|
||||
else
|
||||
{
|
||||
// Handling missing trailing bit(s)
|
||||
var tmp_tindex = (tree_index + (b & InternalInflateConstants.InflateMask[k]))*3;
|
||||
if (k >= tree[tmp_tindex + 1])
|
||||
break;
|
||||
|
||||
blocks.bitb = b;
|
||||
blocks.bitk = k;
|
||||
z.AvailableBytesIn = n;
|
||||
|
||||
@@ -27,6 +27,7 @@
|
||||
using System;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Common.Tar.Headers;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Compressor.Deflate
|
||||
{
|
||||
@@ -221,9 +222,9 @@ namespace SharpCompress.Compressor.Deflate
|
||||
{
|
||||
// Emit the GZIP trailer: CRC32 and size mod 2^32
|
||||
int c1 = crc.Crc32Result;
|
||||
_stream.Write(BitConverter.GetBytes(c1), 0, 4);
|
||||
_stream.Write(DataConverter.LittleEndian.GetBytes(c1), 0, 4);
|
||||
int c2 = (Int32)(crc.TotalBytesRead & 0x00000000FFFFFFFF);
|
||||
_stream.Write(BitConverter.GetBytes(c2), 0, 4);
|
||||
_stream.Write(DataConverter.LittleEndian.GetBytes(c2), 0, 4);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -267,9 +268,9 @@ namespace SharpCompress.Compressor.Deflate
|
||||
}
|
||||
|
||||
|
||||
Int32 crc32_expected = BitConverter.ToInt32(trailer, 0);
|
||||
Int32 crc32_expected = DataConverter.LittleEndian.GetInt32(trailer, 0);
|
||||
Int32 crc32_actual = crc.Crc32Result;
|
||||
Int32 isize_expected = BitConverter.ToInt32(trailer, 4);
|
||||
Int32 isize_expected = DataConverter.LittleEndian.GetInt32(trailer, 4);
|
||||
Int32 isize_actual = (Int32)(_z.TotalBytesOut & 0x00000000FFFFFFFF);
|
||||
|
||||
if (crc32_actual != crc32_expected)
|
||||
@@ -405,7 +406,7 @@ namespace SharpCompress.Compressor.Deflate
|
||||
if (header[0] != 0x1F || header[1] != 0x8B || header[2] != 8)
|
||||
throw new ZlibException("Bad GZIP header.");
|
||||
|
||||
Int32 timet = BitConverter.ToInt32(header, 4);
|
||||
Int32 timet = DataConverter.LittleEndian.GetInt32(header, 4);
|
||||
_GzipMtime = TarHeader.Epoch.AddSeconds(timet);
|
||||
totalBytesRead += n;
|
||||
if ((header[3] & 0x04) == 0x04)
|
||||
|
||||
@@ -99,7 +99,6 @@ namespace SharpCompress.Compressor.LZMA
|
||||
private RangeDecoder mRangeDecoder;
|
||||
private StatusDecoder[] mStatusDecoder;
|
||||
private long mWritten;
|
||||
private long mLimit;
|
||||
private IEnumerator<byte> mIter;
|
||||
private bool mFinished;
|
||||
private bool isDisposed;
|
||||
@@ -112,7 +111,6 @@ namespace SharpCompress.Compressor.LZMA
|
||||
if (streams.Length != 4)
|
||||
throw new NotSupportedException();
|
||||
|
||||
mLimit = limit;
|
||||
mMainStream = streams[0];
|
||||
mCallStream = streams[1];
|
||||
mJumpStream = streams[2];
|
||||
|
||||
@@ -79,33 +79,5 @@ namespace SharpCompress.Compressor.LZMA
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
#if !PORTABLE && !NETFX_CORE
|
||||
public static unsafe uint Update(uint crc, byte* buffer, int length)
|
||||
{
|
||||
while (length > 0 && ((int) buffer & 3) != 0)
|
||||
{
|
||||
crc = Update(crc, *buffer);
|
||||
buffer++;
|
||||
length--;
|
||||
}
|
||||
|
||||
while (length >= 4)
|
||||
{
|
||||
crc = Update(crc, *(uint*) buffer);
|
||||
buffer += 4;
|
||||
length -= 4;
|
||||
}
|
||||
|
||||
while (length > 0)
|
||||
{
|
||||
crc = Update(crc, *buffer);
|
||||
length--;
|
||||
}
|
||||
|
||||
return crc;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using SharpCompress.Compressor.LZMA.LZ;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Compressor.LZMA
|
||||
{
|
||||
@@ -56,7 +57,7 @@ namespace SharpCompress.Compressor.LZMA
|
||||
|
||||
if (!isLZMA2)
|
||||
{
|
||||
dictionarySize = BitConverter.ToInt32(properties, 1);
|
||||
dictionarySize = DataConverter.LittleEndian.GetInt32(properties, 1);
|
||||
outWindow.Create(dictionarySize);
|
||||
if (presetDictionary != null)
|
||||
outWindow.Train(presetDictionary);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
@@ -19,9 +20,9 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal int SummFreq
|
||||
{
|
||||
get { return Utility.readShortLittleEndian(Memory, Address) & 0xffff; }
|
||||
get { return DataConverter.LittleEndian.GetInt16(Memory, Address) & 0xffff; }
|
||||
|
||||
set { Utility.WriteLittleEndian(Memory, Address, (short) value); }
|
||||
set { DataConverter.LittleEndian.PutBytes(Memory, Address, (short)value); }
|
||||
}
|
||||
|
||||
internal FreqData Initialize(byte[] mem)
|
||||
@@ -31,12 +32,14 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal void IncrementSummFreq(int dSummFreq)
|
||||
{
|
||||
Utility.incShortLittleEndian(Memory, Address, (short) dSummFreq);
|
||||
short summFreq = DataConverter.LittleEndian.GetInt16(Memory, Address);
|
||||
summFreq += (short)dSummFreq;
|
||||
DataConverter.LittleEndian.PutBytes(Memory, Address, summFreq);
|
||||
}
|
||||
|
||||
internal int GetStats()
|
||||
{
|
||||
return Utility.readIntLittleEndian(Memory, Address + 2);
|
||||
return DataConverter.LittleEndian.GetInt32(Memory, Address + 2);
|
||||
}
|
||||
|
||||
internal virtual void SetStats(State state)
|
||||
@@ -46,7 +49,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal void SetStats(int state)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address + 2, state);
|
||||
DataConverter.LittleEndian.PutBytes(Memory, Address + 2, state);
|
||||
}
|
||||
|
||||
public override System.String ToString()
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
@@ -21,7 +22,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
if (Memory != null)
|
||||
{
|
||||
numStats = Utility.readShortLittleEndian(Memory, Address) & 0xffff;
|
||||
numStats = DataConverter.LittleEndian.GetInt16(Memory, Address) & 0xffff;
|
||||
}
|
||||
return numStats;
|
||||
}
|
||||
@@ -31,7 +32,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
this.numStats = value & 0xffff;
|
||||
if (Memory != null)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address, (short) value);
|
||||
DataConverter.LittleEndian.PutBytes(Memory, Address, (short) value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,7 +104,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
if (Memory != null)
|
||||
{
|
||||
suffix = Utility.readIntLittleEndian(Memory, Address + 8);
|
||||
suffix = DataConverter.LittleEndian.GetInt32(Memory, Address + 8);
|
||||
}
|
||||
return suffix;
|
||||
}
|
||||
@@ -118,7 +119,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
this.suffix = suffix;
|
||||
if (Memory != null)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address + 8, suffix);
|
||||
DataConverter.LittleEndian.PutBytes(Memory, Address + 8, suffix);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
internal class RarMemBlock : Pointer
|
||||
@@ -19,7 +21,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
if (Memory != null)
|
||||
{
|
||||
stamp = Utility.readShortLittleEndian(Memory, Address) & 0xffff;
|
||||
stamp = DataConverter.LittleEndian.GetInt16(Memory, Address) & 0xffff;
|
||||
}
|
||||
return stamp;
|
||||
}
|
||||
@@ -29,7 +31,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
this.stamp = value;
|
||||
if (Memory != null)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address, (short) value);
|
||||
DataConverter.LittleEndian.PutBytes(Memory, Address, (short)value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -60,7 +62,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
if (Memory != null)
|
||||
{
|
||||
next = Utility.readIntLittleEndian(Memory, Address + 4);
|
||||
next = DataConverter.LittleEndian.GetInt32(Memory, Address + 4);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
@@ -75,7 +77,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
this.next = next;
|
||||
if (Memory != null)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address + 4, next);
|
||||
DataConverter.LittleEndian.PutBytes(Memory, Address + 4, next);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +85,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
if (Memory != null)
|
||||
{
|
||||
NU = Utility.readShortLittleEndian(Memory, Address + 2) & 0xffff;
|
||||
NU = DataConverter.LittleEndian.GetInt16(Memory, Address + 2) & 0xffff;
|
||||
}
|
||||
return NU;
|
||||
}
|
||||
@@ -93,7 +95,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
NU = nu & 0xffff;
|
||||
if (Memory != null)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address + 2, (short) nu);
|
||||
DataConverter.LittleEndian.PutBytes(Memory, Address + 2, (short)nu);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +103,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
if (Memory != null)
|
||||
{
|
||||
prev = Utility.readIntLittleEndian(Memory, Address + 8);
|
||||
prev = DataConverter.LittleEndian.GetInt32(Memory, Address + 8);
|
||||
}
|
||||
return prev;
|
||||
}
|
||||
@@ -116,7 +118,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
this.prev = prev;
|
||||
if (Memory != null)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address + 8, prev);
|
||||
DataConverter.LittleEndian.PutBytes(Memory, Address + 8, prev);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Text;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
@@ -17,7 +18,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
if (Memory != null)
|
||||
{
|
||||
next = Utility.readIntLittleEndian(Memory, Address);
|
||||
next = DataConverter.LittleEndian.GetInt32(Memory, Address);
|
||||
}
|
||||
return next;
|
||||
}
|
||||
@@ -32,7 +33,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
this.next = next;
|
||||
if (Memory != null)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address, next);
|
||||
DataConverter.LittleEndian.PutBytes(Memory, Address, next);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Text;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd.H
|
||||
{
|
||||
@@ -38,7 +39,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal int GetSuccessor()
|
||||
{
|
||||
return Utility.readIntLittleEndian(Memory, Address + 2);
|
||||
return DataConverter.LittleEndian.GetInt32(Memory, Address + 2);
|
||||
}
|
||||
|
||||
internal void SetSuccessor(PPMContext successor)
|
||||
@@ -48,7 +49,7 @@ namespace SharpCompress.Compressor.PPMd.H
|
||||
|
||||
internal void SetSuccessor(int successor)
|
||||
{
|
||||
Utility.WriteLittleEndian(Memory, Address + 2, successor);
|
||||
DataConverter.LittleEndian.PutBytes(Memory, Address + 2, successor);
|
||||
}
|
||||
|
||||
internal void SetValues(StateRef state)
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Compressor.PPMd
|
||||
{
|
||||
@@ -39,7 +40,7 @@ namespace SharpCompress.Compressor.PPMd
|
||||
{
|
||||
if (properties.Length == 2)
|
||||
{
|
||||
ushort props = BitConverter.ToUInt16(properties, 0);
|
||||
ushort props = DataConverter.LittleEndian.GetUInt16(properties, 0);
|
||||
AllocatorSize = (((props >> 4) & 0xff) + 1) << 20;
|
||||
ModelOrder = (props & 0x0f) + 1;
|
||||
ModelRestorationMethod = (I1.ModelRestorationMethod) (props >> 12);
|
||||
@@ -47,7 +48,7 @@ namespace SharpCompress.Compressor.PPMd
|
||||
else if (properties.Length == 5)
|
||||
{
|
||||
Version = PpmdVersion.H7z;
|
||||
AllocatorSize = BitConverter.ToInt32(properties, 1);
|
||||
AllocatorSize = DataConverter.LittleEndian.GetInt32(properties, 1);
|
||||
ModelOrder = properties[0];
|
||||
}
|
||||
}
|
||||
@@ -72,7 +73,7 @@ namespace SharpCompress.Compressor.PPMd
|
||||
get
|
||||
{
|
||||
return
|
||||
BitConverter.GetBytes(
|
||||
DataConverter.LittleEndian.GetBytes(
|
||||
(ushort)
|
||||
((ModelOrder - 1) + (((AllocatorSize >> 20) - 1) << 4) + ((ushort) ModelRestorationMethod << 12)));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Compressor.Rar.VM
|
||||
{
|
||||
@@ -77,11 +78,12 @@ namespace SharpCompress.Compressor.Rar.VM
|
||||
{
|
||||
if (IsVMMem(mem))
|
||||
{
|
||||
return Utility.readIntLittleEndian(mem, offset);
|
||||
return DataConverter.LittleEndian.GetInt32(mem, offset);
|
||||
}
|
||||
else
|
||||
{
|
||||
return Utility.readIntBigEndian(mem, offset);
|
||||
return DataConverter.BigEndian.GetInt32(mem, offset);
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -103,19 +105,11 @@ namespace SharpCompress.Compressor.Rar.VM
|
||||
{
|
||||
if (IsVMMem(mem))
|
||||
{
|
||||
Utility.WriteLittleEndian(mem, offset, value);
|
||||
// Mem[offset + 0] = (byte) value;
|
||||
// Mem[offset + 1] = (byte) (value >>> 8);
|
||||
// Mem[offset + 2] = (byte) (value >>> 16);
|
||||
// Mem[offset + 3] = (byte) (value >>> 24);
|
||||
DataConverter.LittleEndian.PutBytes(mem, offset, value);
|
||||
}
|
||||
else
|
||||
{
|
||||
Utility.writeIntBigEndian(mem, offset, value);
|
||||
// Mem[offset + 3] = (byte) value;
|
||||
// Mem[offset + 2] = (byte) (value >>> 8);
|
||||
// Mem[offset + 1] = (byte) (value >>> 16);
|
||||
// Mem[offset + 0] = (byte) (value >>> 24);
|
||||
DataConverter.BigEndian.PutBytes(mem, offset, value);
|
||||
}
|
||||
}
|
||||
// #define SET_VALUE(ByteMode,Addr,Value) SetValue(ByteMode,(uint
|
||||
@@ -136,12 +130,12 @@ namespace SharpCompress.Compressor.Rar.VM
|
||||
if (cmdOp.Type == VMOpType.VM_OPREGMEM)
|
||||
{
|
||||
int pos = (cmdOp.Offset + cmdOp.Base) & VM_MEMMASK;
|
||||
ret = Utility.readIntLittleEndian(Mem, pos);
|
||||
ret = DataConverter.LittleEndian.GetInt32(Mem, pos);
|
||||
}
|
||||
else
|
||||
{
|
||||
int pos = cmdOp.Offset;
|
||||
ret = Utility.readIntLittleEndian(Mem, pos);
|
||||
ret = DataConverter.LittleEndian.GetInt32(Mem, pos);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
237
SharpCompress/Converter/DataConverter.Portable.cs
Normal file
237
SharpCompress/Converter/DataConverter.Portable.cs
Normal file
@@ -0,0 +1,237 @@
|
||||
using System;
|
||||
|
||||
namespace SharpCompress.Converter
|
||||
{
|
||||
// This is a portable version of Mono's DataConverter class with just the small subset of functionality
|
||||
// needed by SharpCompress. Portable in this case means that it contains no unsafe code.
|
||||
//
|
||||
// This class simply wraps BitConverter and reverses byte arrays when endianess doesn't match the host's.
|
||||
//
|
||||
// Everything public in this class must match signatures in Mono's DataConverter.
|
||||
|
||||
abstract class DataConverter
|
||||
{
|
||||
static readonly DataConverter copyConverter = new CopyConverter();
|
||||
static readonly DataConverter swapConverter = new SwapConverter();
|
||||
|
||||
static readonly bool isLittleEndian = BitConverter.IsLittleEndian;
|
||||
|
||||
public static DataConverter LittleEndian
|
||||
{
|
||||
get { return isLittleEndian ? copyConverter : swapConverter; }
|
||||
}
|
||||
|
||||
public static DataConverter BigEndian
|
||||
{
|
||||
get { return isLittleEndian ? swapConverter : copyConverter; }
|
||||
}
|
||||
|
||||
public abstract Int16 GetInt16(byte[] data, int index);
|
||||
public abstract UInt16 GetUInt16(byte[] data, int index);
|
||||
public abstract Int32 GetInt32(byte[] data, int index);
|
||||
public abstract UInt32 GetUInt32(byte[] data, int index);
|
||||
public abstract Int64 GetInt64(byte[] data, int index);
|
||||
public abstract UInt64 GetUInt64(byte[] data, int index);
|
||||
|
||||
public abstract byte[] GetBytes(Int16 value);
|
||||
public abstract byte[] GetBytes(UInt16 value);
|
||||
public abstract byte[] GetBytes(Int32 value);
|
||||
public abstract byte[] GetBytes(UInt32 value);
|
||||
public abstract byte[] GetBytes(Int64 value);
|
||||
public abstract byte[] GetBytes(UInt64 value);
|
||||
|
||||
public void PutBytes(byte[] data, int index, Int16 value)
|
||||
{
|
||||
byte[] temp = GetBytes(value);
|
||||
Array.Copy(temp, 0, data, index, 2);
|
||||
}
|
||||
|
||||
public void PutBytes(byte[] data, int index, UInt16 value)
|
||||
{
|
||||
byte[] temp = GetBytes(value);
|
||||
Array.Copy(temp, 0, data, index, 2);
|
||||
}
|
||||
|
||||
public void PutBytes(byte[] data, int index, Int32 value)
|
||||
{
|
||||
byte[] temp = GetBytes(value);
|
||||
Array.Copy(temp, 0, data, index, 4);
|
||||
}
|
||||
|
||||
public void PutBytes(byte[] data, int index, UInt32 value)
|
||||
{
|
||||
byte[] temp = GetBytes(value);
|
||||
Array.Copy(temp, 0, data, index, 4);
|
||||
}
|
||||
|
||||
public void PutBytes(byte[] data, int index, Int64 value)
|
||||
{
|
||||
byte[] temp = GetBytes(value);
|
||||
Array.Copy(temp, 0, data, index, 8);
|
||||
}
|
||||
|
||||
public void PutBytes(byte[] data, int index, UInt64 value)
|
||||
{
|
||||
byte[] temp = GetBytes(value);
|
||||
Array.Copy(temp, 0, data, index, 8);
|
||||
}
|
||||
|
||||
// CopyConverter wraps BitConverter making all conversions host endian
|
||||
class CopyConverter : DataConverter
|
||||
{
|
||||
public override Int16 GetInt16(byte[] data, int index)
|
||||
{
|
||||
return BitConverter.ToInt16(data, index);
|
||||
}
|
||||
|
||||
public override UInt16 GetUInt16(byte[] data, int index)
|
||||
{
|
||||
return BitConverter.ToUInt16(data, index);
|
||||
}
|
||||
|
||||
public override Int32 GetInt32(byte[] data, int index)
|
||||
{
|
||||
return BitConverter.ToInt32(data, index);
|
||||
}
|
||||
|
||||
public override UInt32 GetUInt32(byte[] data, int index)
|
||||
{
|
||||
return BitConverter.ToUInt32(data, index);
|
||||
}
|
||||
|
||||
public override Int64 GetInt64(byte[] data, int index)
|
||||
{
|
||||
return BitConverter.ToInt64(data, index);
|
||||
}
|
||||
|
||||
public override UInt64 GetUInt64(byte[] data, int index)
|
||||
{
|
||||
return BitConverter.ToUInt64(data, index);
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(Int16 value)
|
||||
{
|
||||
return BitConverter.GetBytes(value);
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(UInt16 value)
|
||||
{
|
||||
return BitConverter.GetBytes(value);
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(Int32 value)
|
||||
{
|
||||
return BitConverter.GetBytes(value);
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(UInt32 value)
|
||||
{
|
||||
return BitConverter.GetBytes(value);
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(Int64 value)
|
||||
{
|
||||
return BitConverter.GetBytes(value);
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(UInt64 value)
|
||||
{
|
||||
return BitConverter.GetBytes(value);
|
||||
}
|
||||
}
|
||||
|
||||
// SwapConverter wraps and reverses BitConverter making all conversions the opposite of host endian
|
||||
class SwapConverter : DataConverter
|
||||
{
|
||||
public override Int16 GetInt16(byte[] data, int index)
|
||||
{
|
||||
byte[] temp = new byte[2];
|
||||
Array.Copy(data, index, temp, 0, 2);
|
||||
Array.Reverse(temp);
|
||||
return BitConverter.ToInt16(temp, 0);
|
||||
}
|
||||
|
||||
public override UInt16 GetUInt16(byte[] data, int index)
|
||||
{
|
||||
byte[] temp = new byte[2];
|
||||
Array.Copy(data, index, temp, 0, 2);
|
||||
Array.Reverse(temp);
|
||||
return BitConverter.ToUInt16(temp, 0);
|
||||
}
|
||||
|
||||
public override Int32 GetInt32(byte[] data, int index)
|
||||
{
|
||||
byte[] temp = new byte[4];
|
||||
Array.Copy(data, index, temp, 0, 4);
|
||||
Array.Reverse(temp);
|
||||
return BitConverter.ToInt32(temp, 0);
|
||||
}
|
||||
|
||||
public override UInt32 GetUInt32(byte[] data, int index)
|
||||
{
|
||||
byte[] temp = new byte[4];
|
||||
Array.Copy(data, index, temp, 0, 4);
|
||||
Array.Reverse(temp);
|
||||
return BitConverter.ToUInt32(temp, 0);
|
||||
}
|
||||
|
||||
public override Int64 GetInt64(byte[] data, int index)
|
||||
{
|
||||
byte[] temp = new byte[8];
|
||||
Array.Copy(data, index, temp, 0, 8);
|
||||
Array.Reverse(temp);
|
||||
return BitConverter.ToInt64(temp, 0);
|
||||
}
|
||||
|
||||
public override UInt64 GetUInt64(byte[] data, int index)
|
||||
{
|
||||
byte[] temp = new byte[8];
|
||||
Array.Copy(data, index, temp, 0, 8);
|
||||
Array.Reverse(temp);
|
||||
return BitConverter.ToUInt64(temp, 0);
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(Int16 value)
|
||||
{
|
||||
byte[] ret = BitConverter.GetBytes(value);
|
||||
Array.Reverse(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(UInt16 value)
|
||||
{
|
||||
byte[] ret = BitConverter.GetBytes(value);
|
||||
Array.Reverse(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(Int32 value)
|
||||
{
|
||||
byte[] ret = BitConverter.GetBytes(value);
|
||||
Array.Reverse(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(UInt32 value)
|
||||
{
|
||||
byte[] ret = BitConverter.GetBytes(value);
|
||||
Array.Reverse(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(Int64 value)
|
||||
{
|
||||
byte[] ret = BitConverter.GetBytes(value);
|
||||
Array.Reverse(ret);
|
||||
return ret;
|
||||
}
|
||||
|
||||
public override byte[] GetBytes(UInt64 value)
|
||||
{
|
||||
byte[] ret = BitConverter.GetBytes(value);
|
||||
Array.Reverse(ret);
|
||||
return ret;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
1849
SharpCompress/Converter/DataConverter.cs
Normal file
1849
SharpCompress/Converter/DataConverter.cs
Normal file
File diff suppressed because it is too large
Load Diff
@@ -3,6 +3,7 @@ using Org.BouncyCastle.Crypto;
|
||||
using Org.BouncyCastle.Crypto.Digests;
|
||||
using Org.BouncyCastle.Crypto.Macs;
|
||||
using Org.BouncyCastle.Crypto.Parameters;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Crypto
|
||||
{
|
||||
@@ -68,7 +69,7 @@ namespace SharpCompress.Crypto
|
||||
|
||||
private byte[] Hash()
|
||||
{
|
||||
byte[] array = UIntToOctet(block);
|
||||
byte[] array = DataConverter.BigEndian.GetBytes(block);
|
||||
ICipherParameters param = new KeyParameter(password);
|
||||
|
||||
hMac.Init(param);
|
||||
@@ -96,24 +97,6 @@ namespace SharpCompress.Crypto
|
||||
block += 1u;
|
||||
return array3;
|
||||
}
|
||||
|
||||
internal static byte[] UIntToOctet(uint i)
|
||||
{
|
||||
byte[] bytes = BitConverter.GetBytes(i);
|
||||
byte[] result = new[]
|
||||
{
|
||||
bytes[3],
|
||||
bytes[2],
|
||||
bytes[1],
|
||||
bytes[0]
|
||||
};
|
||||
if (!BitConverter.IsLittleEndian)
|
||||
{
|
||||
return bytes;
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System;
|
||||
#if NET35
|
||||
using System;
|
||||
|
||||
namespace SharpCompress
|
||||
{
|
||||
@@ -12,4 +13,5 @@ namespace SharpCompress
|
||||
return (value & flagVal) == flagVal;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.IO
|
||||
{
|
||||
@@ -36,7 +37,7 @@ namespace SharpCompress.IO
|
||||
|
||||
public override bool ReadBoolean()
|
||||
{
|
||||
return BitConverter.ToBoolean(ReadBytes(1), 0);
|
||||
return ReadBytes(1).Single() != 0;
|
||||
}
|
||||
|
||||
public override byte ReadByte()
|
||||
@@ -68,39 +69,28 @@ namespace SharpCompress.IO
|
||||
#if !PORTABLE
|
||||
public override decimal ReadDecimal()
|
||||
{
|
||||
return ByteArrayToDecimal(ReadBytes(16), 0);
|
||||
}
|
||||
|
||||
private decimal ByteArrayToDecimal(byte[] src, int offset)
|
||||
{
|
||||
//http://stackoverflow.com/a/16984356/385387
|
||||
var i1 = BitConverter.ToInt32(src, offset);
|
||||
var i2 = BitConverter.ToInt32(src, offset + 4);
|
||||
var i3 = BitConverter.ToInt32(src, offset + 8);
|
||||
var i4 = BitConverter.ToInt32(src, offset + 12);
|
||||
|
||||
return new decimal(new[] { i1, i2, i3, i4 });
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
#endif
|
||||
|
||||
public override double ReadDouble()
|
||||
{
|
||||
return BitConverter.ToDouble(ReadBytes(8), 0);
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override short ReadInt16()
|
||||
{
|
||||
return BitConverter.ToInt16(ReadBytes(2), 0);
|
||||
return DataConverter.LittleEndian.GetInt16(ReadBytes(2), 0);
|
||||
}
|
||||
|
||||
public override int ReadInt32()
|
||||
{
|
||||
return BitConverter.ToInt32(ReadBytes(4), 0);
|
||||
return DataConverter.LittleEndian.GetInt32(ReadBytes(4), 0);
|
||||
}
|
||||
|
||||
public override long ReadInt64()
|
||||
{
|
||||
return BitConverter.ToInt64(ReadBytes(8), 0);
|
||||
return DataConverter.LittleEndian.GetInt64(ReadBytes(8), 0);
|
||||
}
|
||||
|
||||
public override sbyte ReadSByte()
|
||||
@@ -110,7 +100,7 @@ namespace SharpCompress.IO
|
||||
|
||||
public override float ReadSingle()
|
||||
{
|
||||
return BitConverter.ToSingle(ReadBytes(4), 0);
|
||||
throw new NotSupportedException();
|
||||
}
|
||||
|
||||
public override string ReadString()
|
||||
@@ -120,17 +110,17 @@ namespace SharpCompress.IO
|
||||
|
||||
public override ushort ReadUInt16()
|
||||
{
|
||||
return BitConverter.ToUInt16(ReadBytes(2), 0);
|
||||
return DataConverter.LittleEndian.GetUInt16(ReadBytes(2), 0);
|
||||
}
|
||||
|
||||
public override uint ReadUInt32()
|
||||
{
|
||||
return BitConverter.ToUInt32(ReadBytes(4), 0);
|
||||
return DataConverter.LittleEndian.GetUInt32(ReadBytes(4), 0);
|
||||
}
|
||||
|
||||
public override ulong ReadUInt64()
|
||||
{
|
||||
return BitConverter.ToUInt64(ReadBytes(8), 0);
|
||||
return DataConverter.LittleEndian.GetUInt64(ReadBytes(8), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -67,12 +67,32 @@ namespace SharpCompress.Reader
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
public bool Cancelled { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Indicates that the remaining entries are not required.
|
||||
/// On dispose of an EntryStream, the stream will not skip to the end of the entry.
|
||||
/// An attempt to move to the next entry will throw an exception, as the compressed stream is not positioned at an entry boundary.
|
||||
/// </summary>
|
||||
public void Cancel()
|
||||
{
|
||||
if (!completed)
|
||||
{
|
||||
Cancelled = true;
|
||||
}
|
||||
}
|
||||
|
||||
public bool MoveToNextEntry()
|
||||
{
|
||||
if (completed)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (Cancelled)
|
||||
{
|
||||
throw new InvalidOperationException("Reader has been cancelled.");
|
||||
}
|
||||
if (entriesForCurrentReadStream == null)
|
||||
{
|
||||
return LoadStreamForReading(RequestInitialStream());
|
||||
@@ -197,9 +217,17 @@ namespace SharpCompress.Reader
|
||||
return stream;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Retains a reference to the entry stream, so we can check whether it completed later.
|
||||
/// </summary>
|
||||
protected EntryStream CreateEntryStream(Stream decompressed)
|
||||
{
|
||||
return new EntryStream(this, decompressed);
|
||||
}
|
||||
|
||||
protected virtual EntryStream GetEntryStream()
|
||||
{
|
||||
return new EntryStream(Entry.Parts.First().GetCompressedStream());
|
||||
return CreateEntryStream(Entry.Parts.First().GetCompressedStream());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -89,6 +89,7 @@ namespace SharpCompress.Reader
|
||||
// s.TransferTo(fs);
|
||||
//}
|
||||
}
|
||||
reader.Entry.PreserveExtractionOptions(destinationFileName, options);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
@@ -22,6 +22,9 @@ namespace SharpCompress.Reader
|
||||
/// <param name="writableStream"></param>
|
||||
void WriteEntryTo(Stream writableStream);
|
||||
|
||||
bool Cancelled { get; }
|
||||
void Cancel();
|
||||
|
||||
/// <summary>
|
||||
/// Moves to the next entry by reading more data from the underlying stream. This skips if data has not been read.
|
||||
/// </summary>
|
||||
|
||||
@@ -73,7 +73,7 @@ namespace SharpCompress.Reader.Rar
|
||||
|
||||
protected override EntryStream GetEntryStream()
|
||||
{
|
||||
return new EntryStream(new RarStream(pack, Entry.FileHeader,
|
||||
return CreateEntryStream(new RarStream(pack, Entry.FileHeader,
|
||||
new MultiVolumeReadOnlyStream(
|
||||
CreateFilePartEnumerableForCurrentEntry().Cast<RarFilePart>(), this)));
|
||||
}
|
||||
|
||||
@@ -61,12 +61,6 @@ namespace SharpCompress.Reader
|
||||
}
|
||||
}
|
||||
|
||||
rewindableStream.Rewind(false);
|
||||
if (TarArchive.IsTarFile(rewindableStream))
|
||||
{
|
||||
rewindableStream.Rewind(true);
|
||||
return TarReader.Open(rewindableStream, options);
|
||||
}
|
||||
rewindableStream.Rewind(false);
|
||||
if (RarArchive.IsRarFile(rewindableStream, options))
|
||||
{
|
||||
@@ -74,6 +68,12 @@ namespace SharpCompress.Reader
|
||||
return RarReader.Open(rewindableStream, options);
|
||||
}
|
||||
|
||||
rewindableStream.Rewind(false);
|
||||
if (TarArchive.IsTarFile(rewindableStream))
|
||||
{
|
||||
rewindableStream.Rewind(true);
|
||||
return TarReader.Open(rewindableStream, options);
|
||||
}
|
||||
throw new InvalidOperationException("Cannot determine compressed stream type. Supported Reader Formats: Zip, GZip, BZip2, Tar, Rar");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,394 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003" ToolsVersion="4.0">
|
||||
<PropertyGroup>
|
||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||
<ProductVersion>9.0.30729</ProductVersion>
|
||||
<SchemaVersion>2.0</SchemaVersion>
|
||||
<ProjectGuid>{9A6F69DC-258D-4EB4-859E-09EFC7A14A3F}</ProjectGuid>
|
||||
<OutputType>Library</OutputType>
|
||||
<AppDesignerFolder>Properties</AppDesignerFolder>
|
||||
<RootNamespace>SharpCompress</RootNamespace>
|
||||
<AssemblyName>SharpCompress</AssemblyName>
|
||||
<TargetFrameworkVersion>v2.0</TargetFrameworkVersion>
|
||||
<FileAlignment>512</FileAlignment>
|
||||
<StartupObject>
|
||||
</StartupObject>
|
||||
<FileUpgradeFlags>
|
||||
</FileUpgradeFlags>
|
||||
<OldToolsVersion>3.5</OldToolsVersion>
|
||||
<UpgradeBackupLocation />
|
||||
<PublishUrl>publish\</PublishUrl>
|
||||
<Install>true</Install>
|
||||
<InstallFrom>Disk</InstallFrom>
|
||||
<UpdateEnabled>false</UpdateEnabled>
|
||||
<UpdateMode>Foreground</UpdateMode>
|
||||
<UpdateInterval>7</UpdateInterval>
|
||||
<UpdateIntervalUnits>Days</UpdateIntervalUnits>
|
||||
<UpdatePeriodically>false</UpdatePeriodically>
|
||||
<UpdateRequired>false</UpdateRequired>
|
||||
<MapFileExtensions>true</MapFileExtensions>
|
||||
<ApplicationRevision>0</ApplicationRevision>
|
||||
<ApplicationVersion>1.0.0.%2a</ApplicationVersion>
|
||||
<IsWebBootstrapper>false</IsWebBootstrapper>
|
||||
<UseApplicationTrust>false</UseApplicationTrust>
|
||||
<BootstrapperEnabled>true</BootstrapperEnabled>
|
||||
<BaseIntermediateOutputPath>obj\LinqBridge\</BaseIntermediateOutputPath>
|
||||
<SccProjectName>
|
||||
</SccProjectName>
|
||||
<SccLocalPath>
|
||||
</SccLocalPath>
|
||||
<SccAuxPath>
|
||||
</SccAuxPath>
|
||||
<SccProvider>
|
||||
</SccProvider>
|
||||
<SolutionDir Condition="$(SolutionDir) == '' Or $(SolutionDir) == '*Undefined*'">..\..\sharpcompress\</SolutionDir>
|
||||
<RestorePackages>true</RestorePackages>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||
<DebugSymbols>true</DebugSymbols>
|
||||
<DebugType>full</DebugType>
|
||||
<Optimize>false</Optimize>
|
||||
<OutputPath>..\bin\NET2\</OutputPath>
|
||||
<DefineConstants>TRACE;DEBUG;DISABLE_TRACE;NET2</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<NoWarn>1591</NoWarn>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\NET2\</OutputPath>
|
||||
<DefineConstants>TRACE;NET2</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
<CodeAnalysisRuleSet>AllRules.ruleset</CodeAnalysisRuleSet>
|
||||
<DocumentationFile>
|
||||
</DocumentationFile>
|
||||
<NoWarn>1591</NoWarn>
|
||||
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<SignAssembly>true</SignAssembly>
|
||||
</PropertyGroup>
|
||||
<PropertyGroup>
|
||||
<AssemblyOriginatorKeyFile>SharpCompress.pfx</AssemblyOriginatorKeyFile>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="LinqBridge">
|
||||
<HintPath>..\packages\LinqBridge.1.3.0\lib\net20\LinqBridge.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Archive\IWritableArchive.cs" />
|
||||
<Compile Include="Archive\IWritableArchive.Extensions.cs" />
|
||||
<Compile Include="Archive\IWritableArchiveEntry.cs" />
|
||||
<Compile Include="Archive\Rar\FileInfoRarFilePart.cs" />
|
||||
<Compile Include="Common\ArchiveEncoding.cs" />
|
||||
<Compile Include="Archive\AbstractWritableArchive.cs" />
|
||||
<Compile Include="Archive\AbstractArchive.cs" />
|
||||
<Compile Include="Archive\ArchiveFactory.cs" />
|
||||
<Compile Include="Archive\GZip\GZipWritableArchiveEntry.cs" />
|
||||
<Compile Include="Archive\IArchive.Extensions.cs" />
|
||||
<Compile Include="Archive\GZip\GZipArchive.cs" />
|
||||
<Compile Include="Archive\GZip\GZipArchiveEntry.cs" />
|
||||
<Compile Include="Archive\IArchiveEntry.cs" />
|
||||
<Compile Include="Archive\Rar\RarArchiveEntryFactory.cs" />
|
||||
<Compile Include="Archive\IArchive.cs" />
|
||||
<Compile Include="Archive\Rar\StreamRarArchiveVolume.cs" />
|
||||
<Compile Include="Archive\SevenZip\SevenZipArchive.cs" />
|
||||
<Compile Include="Archive\SevenZip\SevenZipArchiveEntry.cs" />
|
||||
<Compile Include="Archive\Tar\TarArchive.cs" />
|
||||
<Compile Include="Archive\Tar\TarArchiveEntry.cs" />
|
||||
<Compile Include="Archive\Tar\TarWritableArchiveEntry.cs" />
|
||||
<Compile Include="Archive\Zip\ZipWritableArchiveEntry.cs" />
|
||||
<Compile Include="Archive\Zip\ZipArchive.cs" />
|
||||
<Compile Include="Archive\Zip\ZipArchiveEntry.cs" />
|
||||
<Compile Include="Common\ArchiveException.cs" />
|
||||
<Compile Include="Common\ArchiveExtractionEventArgs.cs" />
|
||||
<Compile Include="Common\CompressedBytesReadEventArgs.cs" />
|
||||
<Compile Include="Common\CompressionInfo.cs" />
|
||||
<Compile Include="Common\CompressionType.cs" />
|
||||
<Compile Include="Common\FilePartExtractionBeginEventArgs.cs" />
|
||||
<Compile Include="Archive\IArchiveExtractionListener.cs" />
|
||||
<Compile Include="Common\IncompleteArchiveException.cs" />
|
||||
<Compile Include="Common\MultiVolumeExtractionException.cs" />
|
||||
<Compile Include="Common\PasswordProtectedException.cs" />
|
||||
<Compile Include="Common\CryptographicException.cs" />
|
||||
<Compile Include="Common\FlagUtility.cs" />
|
||||
<Compile Include="Common\GZip\GZipEntry.cs" />
|
||||
<Compile Include="Common\GZip\GZipFilePart.cs" />
|
||||
<Compile Include="Common\GZip\GZipVolume.cs" />
|
||||
<Compile Include="Common\ExtractOptions.cs" />
|
||||
<Compile Include="Common\FilePart.cs" />
|
||||
<Compile Include="Common\Entry.cs" />
|
||||
<Compile Include="Common\IEntry.cs" />
|
||||
<Compile Include="Common\IVolume.cs" />
|
||||
<Compile Include="Common\Rar\RarCryptoWrapper.cs" />
|
||||
<Compile Include="Common\Rar\RarRijndael.cs" />
|
||||
<Compile Include="Common\ReaderExtractionEventArgs.cs" />
|
||||
<Compile Include="Common\SevenZip\CBindPair.cs" />
|
||||
<Compile Include="Common\SevenZip\CCoderInfo.cs" />
|
||||
<Compile Include="Common\SevenZip\CFileItem.cs" />
|
||||
<Compile Include="Common\SevenZip\CFolder.cs" />
|
||||
<Compile Include="Common\SevenZip\CStreamSwitch.cs" />
|
||||
<Compile Include="Common\SevenZip\DataReader.cs" />
|
||||
<Compile Include="Common\SevenZip\SevenZipEntry.cs" />
|
||||
<Compile Include="Common\SevenZip\SevenZipFilePart.cs" />
|
||||
<Compile Include="Common\SevenZip\SevenZipVolume.cs" />
|
||||
<Compile Include="Common\Tar\Headers\TarHeader.cs" />
|
||||
<Compile Include="Common\Tar\TarReadOnlySubStream.cs" />
|
||||
<Compile Include="Common\Tar\TarVolume.cs" />
|
||||
<Compile Include="Common\Tar\TarEntry.cs" />
|
||||
<Compile Include="Common\Tar\TarFilePart.cs" />
|
||||
<Compile Include="Common\Tar\TarHeaderFactory.cs" />
|
||||
<Compile Include="Common\Zip\Headers\HeaderFlags.cs" />
|
||||
<Compile Include="Common\Zip\Headers\IgnoreHeader.cs" />
|
||||
<Compile Include="Common\Zip\Headers\LocalEntryHeaderExtraFactory.cs" />
|
||||
<Compile Include="Common\Zip\Headers\SplitHeader.cs" />
|
||||
<Compile Include="Common\Zip\Headers\ZipFileEntry.cs" />
|
||||
<Compile Include="Common\Zip\Headers\ZipHeaderType.cs" />
|
||||
<Compile Include="Common\Zip\SeekableZipFilePart.cs" />
|
||||
<Compile Include="Common\Zip\SeekableZipHeaderFactory.cs" />
|
||||
<Compile Include="Common\Zip\StreamingZipFilePart.cs" />
|
||||
<Compile Include="Common\Zip\StreamingZipHeaderFactory.cs" />
|
||||
<Compile Include="Common\Zip\WinzipAesCryptoStream.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Common\Zip\WinzipAesEncryptionData.cs" />
|
||||
<Compile Include="Common\Zip\WinzipAesKeySize.cs" />
|
||||
<Compile Include="Common\Zip\ZipVolume.cs" />
|
||||
<Compile Include="Compressor\BZip2\BZip2Constants.cs" />
|
||||
<Compile Include="Compressor\BZip2\BZip2Stream.cs" />
|
||||
<Compile Include="Compressor\BZip2\CBZip2InputStream.cs" />
|
||||
<Compile Include="Compressor\BZip2\CBZip2OutputStream.cs" />
|
||||
<Compile Include="Compressor\BZip2\CRC.cs" />
|
||||
<Compile Include="Compressor\CompressionMode.cs" />
|
||||
<Compile Include="Compressor\Deflate\FlushType.cs" />
|
||||
<Compile Include="Common\Zip\PkwareTraditionalCryptoStream.cs" />
|
||||
<Compile Include="Common\Zip\PkwareTraditionalEncryptionData.cs" />
|
||||
<Compile Include="Compressor\Deflate\GZipStream.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Compressor\Filters\BCJ2Filter.cs" />
|
||||
<Compile Include="Compressor\Filters\BCJFilter.cs" />
|
||||
<Compile Include="Compressor\Filters\Filter.cs" />
|
||||
<Compile Include="Compressor\LZMA\BitVector.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Compressor\LZMA\LZ\CRC.cs" />
|
||||
<Compile Include="Compressor\LZMA\CRC.cs" />
|
||||
<Compile Include="Common\SevenZip\ArchiveDatabase.cs" />
|
||||
<Compile Include="Common\SevenZip\ArchiveReader.cs" />
|
||||
<Compile Include="Common\SevenZip\CMethodId.cs" />
|
||||
<Compile Include="Compressor\LZMA\AesDecoderStream.cs" />
|
||||
<Compile Include="Compressor\LZMA\Bcj2DecoderStream.cs" />
|
||||
<Compile Include="Compressor\LZMA\DecoderStream.cs" />
|
||||
<Compile Include="Compressor\LZMA\Registry.cs" />
|
||||
<Compile Include="Compressor\LZMA\ICoder.cs" />
|
||||
<Compile Include="Compressor\LZMA\Log.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Compressor\LZMA\LzmaBase.cs" />
|
||||
<Compile Include="Compressor\LZMA\LzmaDecoder.cs" />
|
||||
<Compile Include="Compressor\LZMA\LzmaEncoder.cs" />
|
||||
<Compile Include="Compressor\LZMA\LzmaEncoderProperties.cs" />
|
||||
<Compile Include="Compressor\LZMA\LzmaStream.cs" />
|
||||
<Compile Include="Compressor\LZMA\LZ\LzBinTree.cs" />
|
||||
<Compile Include="Compressor\LZMA\LZ\LzInWindow.cs" />
|
||||
<Compile Include="Compressor\LZMA\LZ\LzOutWindow.cs" />
|
||||
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoder.cs" />
|
||||
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBit.cs" />
|
||||
<Compile Include="Compressor\LZMA\RangeCoder\RangeCoderBitTree.cs" />
|
||||
<Compile Include="Compressor\LZMA\Utilites\CrcBuilderStream.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Compressor\LZMA\Utilites\CrcCheckStream.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Compressor\LZMA\Utilites\IPasswordProvider.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Compressor\LZMA\Utilites\Utils.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="Compressor\PPMd\H\FreqData.cs" />
|
||||
<Compile Include="Compressor\PPMd\H\ModelPPM.cs" />
|
||||
<Compile Include="Compressor\PPMd\H\Pointer.cs" />
|
||||
<Compile Include="Compressor\PPMd\H\PPMContext.cs" />
|
||||
<Compile Include="Compressor\PPMd\H\RangeCoder.cs" />
|
||||
<Compile Include="Compressor\PPMd\H\RarMemBlock.cs" />
|
||||
<Compile Include="Compressor\PPMd\H\RarNode.cs" />
|
||||
<Compile Include="Compressor\PPMd\H\SEE2Context.cs" />
|
||||
<Compile Include="Compressor\PPMd\H\State.cs" />
|
||||
<Compile Include="Compressor\PPMd\H\StateRef.cs" />
|
||||
<Compile Include="Compressor\PPMd\H\SubAllocator.cs" />
|
||||
<Compile Include="Compressor\PPMd\I1\Allocator.cs" />
|
||||
<Compile Include="Compressor\PPMd\I1\Coder.cs" />
|
||||
<Compile Include="Compressor\PPMd\I1\MemoryNode.cs" />
|
||||
<Compile Include="Compressor\PPMd\I1\Model.cs" />
|
||||
<Compile Include="Compressor\PPMd\I1\ModelRestorationMethod.cs" />
|
||||
<Compile Include="Compressor\PPMd\I1\Pointer.cs" />
|
||||
<Compile Include="Compressor\PPMd\I1\PpmContext.cs" />
|
||||
<Compile Include="Compressor\PPMd\I1\PpmState.cs" />
|
||||
<Compile Include="Compressor\PPMd\I1\See2Context.cs" />
|
||||
<Compile Include="Compressor\PPMd\PpmdProperties.cs" />
|
||||
<Compile Include="Compressor\PPMd\PpmdStream.cs" />
|
||||
<Compile Include="Compressor\Rar\RarStream.cs" />
|
||||
<Compile Include="EnumExtensions.cs" />
|
||||
<Compile Include="IO\CountingWritableSubStream.cs" />
|
||||
<Compile Include="Common\EntryStream.cs">
|
||||
<SubType>Code</SubType>
|
||||
</Compile>
|
||||
<Compile Include="IO\ListeningStream.cs" />
|
||||
<Compile Include="IO\NonDisposingStream.cs" />
|
||||
<Compile Include="Common\Rar\RarCryptoBinaryReader.cs" />
|
||||
<Compile Include="IO\RewindableStream.cs" />
|
||||
<Compile Include="Reader\GZip\GZipReader.cs" />
|
||||
<Compile Include="Reader\IReaderExtractionListener.cs" />
|
||||
<Compile Include="Reader\ReaderFactory.cs" />
|
||||
<Compile Include="Reader\AbstractReader.cs" />
|
||||
<Compile Include="Common\Volume.cs" />
|
||||
<Compile Include="Compressor\Deflate\CRC32.cs" />
|
||||
<Compile Include="Compressor\Deflate\DeflateManager.cs" />
|
||||
<Compile Include="Compressor\Deflate\DeflateStream.cs" />
|
||||
<Compile Include="Compressor\Deflate\Inflate.cs" />
|
||||
<Compile Include="Compressor\Deflate\InfTree.cs" />
|
||||
<Compile Include="Compressor\Deflate\Tree.cs" />
|
||||
<Compile Include="Compressor\Deflate\Zlib.cs" />
|
||||
<Compile Include="Compressor\Deflate\ZlibBaseStream.cs" />
|
||||
<Compile Include="Compressor\Deflate\ZlibCodec.cs" />
|
||||
<Compile Include="Compressor\Deflate\ZlibConstants.cs" />
|
||||
<Compile Include="Compressor\Deflate\ZlibStream.cs" />
|
||||
<Compile Include="Common\Rar\Headers\FileNameDecoder.cs" />
|
||||
<Compile Include="Common\InvalidFormatException.cs" />
|
||||
<Compile Include="IO\ReadOnlySubStream.cs" />
|
||||
<Compile Include="IO\StreamingMode.cs" />
|
||||
<Compile Include="Common\IExtractionListener.cs" />
|
||||
<Compile Include="Common\MultipartStreamRequiredException.cs" />
|
||||
<Compile Include="LazyReadOnlyCollection.cs" />
|
||||
<Compile Include="Archive\Rar\RarArchive.Extensions.cs" />
|
||||
<Compile Include="Archive\IArchiveEntry.Extensions.cs" />
|
||||
<Compile Include="Archive\Rar\RarArchiveEntry.cs" />
|
||||
<Compile Include="Common\ExtractionException.cs" />
|
||||
<Compile Include="Common\Rar\RarEntry.cs" />
|
||||
<Compile Include="Common\Options.cs" />
|
||||
<Compile Include="Reader\IReader.cs" />
|
||||
<Compile Include="Reader\Rar\MultiVolumeRarReader.cs" />
|
||||
<Compile Include="Reader\Rar\RarReader.cs" />
|
||||
<Compile Include="Reader\IReader.Extensions.cs" />
|
||||
<Compile Include="Reader\Rar\RarReaderEntry.cs" />
|
||||
<Compile Include="Archive\Rar\SeekableFilePart.cs" />
|
||||
<Compile Include="Reader\Rar\SingleVolumeRarReader.cs" />
|
||||
<Compile Include="Common\ArchiveType.cs" />
|
||||
<Compile Include="Reader\Tar\TarReader.cs" />
|
||||
<Compile Include="ReadOnlyCollection.cs" />
|
||||
<Compile Include="VersionInfo.cs" />
|
||||
<Compile Include="Archive\Rar\FileInfoRarArchiveVolume.cs" />
|
||||
<Compile Include="Common\Rar\RarFilePart.cs" />
|
||||
<Compile Include="Common\Rar\Headers\AVHeader.cs" />
|
||||
<Compile Include="Common\Rar\Headers\CommentHeader.cs" />
|
||||
<Compile Include="Common\Rar\Headers\EndArchiveHeader.cs" />
|
||||
<Compile Include="Common\Rar\Headers\SignHeader.cs" />
|
||||
<Compile Include="Common\Rar\RarVolume.cs" />
|
||||
<Compile Include="Compressor\Rar\UnpackUtility.cs" />
|
||||
<Compile Include="Archive\Rar\RarArchive.cs" />
|
||||
<Compile Include="Compressor\Rar\MultiVolumeReadOnlyStream.cs" />
|
||||
<Compile Include="Compressor\Rar\RarCRC.cs" />
|
||||
<Compile Include="Common\Rar\Headers\FileHeader.cs" />
|
||||
<Compile Include="Common\Rar\Headers\ArchiveHeader.cs" />
|
||||
<Compile Include="Common\Rar\Headers\RarHeader.cs" />
|
||||
<Compile Include="IO\MarkingBinaryReader.cs" />
|
||||
<Compile Include="Common\Rar\Headers\NewSubHeader.cs" />
|
||||
<Compile Include="Common\Rar\Headers\ProtectHeader.cs" />
|
||||
<Compile Include="AssemblyInfo.cs" />
|
||||
<Compile Include="Common\Rar\Headers\RarHeaderFactory.cs" />
|
||||
<Compile Include="Common\Rar\Headers\Flags.cs" />
|
||||
<Compile Include="Compressor\Rar\Decode\AudioVariables.cs" />
|
||||
<Compile Include="Compressor\Rar\Decode\BitDecode.cs" />
|
||||
<Compile Include="Compressor\Rar\Decode\CodeType.cs" />
|
||||
<Compile Include="Compressor\Rar\Decode\Compress.cs" />
|
||||
<Compile Include="Compressor\Rar\Decode\Decode.cs" />
|
||||
<Compile Include="Compressor\Rar\Decode\DistDecode.cs" />
|
||||
<Compile Include="Compressor\Rar\Decode\FilterType.cs" />
|
||||
<Compile Include="Compressor\Rar\Decode\LitDecode.cs" />
|
||||
<Compile Include="Compressor\Rar\Decode\LowDistDecode.cs" />
|
||||
<Compile Include="Compressor\Rar\Decode\MultDecode.cs" />
|
||||
<Compile Include="Compressor\Rar\Decode\RepDecode.cs" />
|
||||
<Compile Include="Compressor\Rar\PPM\BlockTypes.cs" />
|
||||
<Compile Include="Compressor\Rar\Unpack.cs" />
|
||||
<Compile Include="Compressor\Rar\Unpack15.cs" />
|
||||
<Compile Include="Compressor\Rar\Unpack20.cs" />
|
||||
<Compile Include="Compressor\Rar\UnpackFilter.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\BitInput.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\RarVM.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMCmdFlags.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMCommands.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMFlags.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMOpType.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMPreparedCommand.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMPreparedOperand.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMPreparedProgram.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMStandardFilters.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMStandardFilterSignature.cs" />
|
||||
<Compile Include="Utility.cs" />
|
||||
<Compile Include="Common\Rar\Headers\MarkHeader.cs" />
|
||||
<Compile Include="Archive\Rar\RarArchiveVolumeFactory.cs" />
|
||||
<Compile Include="Reader\Rar\NonSeekableStreamFilePart.cs" />
|
||||
<Compile Include="Reader\Rar\RarReaderVolume.cs" />
|
||||
<Compile Include="Common\Zip\ZipCompressionMethod.cs" />
|
||||
<Compile Include="Common\Zip\Headers\DirectoryEndHeader.cs" />
|
||||
<Compile Include="Common\Zip\Headers\DirectoryEntryHeader.cs" />
|
||||
<Compile Include="Common\Zip\Headers\LocalEntryHeader.cs" />
|
||||
<Compile Include="Common\Zip\ZipFilePart.cs" />
|
||||
<Compile Include="Common\Zip\Headers\ZipHeader.cs" />
|
||||
<Compile Include="Common\Zip\ZipHeaderFactory.cs" />
|
||||
<Compile Include="Reader\Zip\ZipReader.cs" />
|
||||
<Compile Include="Common\Zip\ZipEntry.cs" />
|
||||
<Compile Include="Writer\AbstractWriter.cs" />
|
||||
<Compile Include="Writer\GZip\GZipWriter.cs" />
|
||||
<Compile Include="Writer\IWriter.Extensions.cs" />
|
||||
<Compile Include="Writer\IWriter.cs" />
|
||||
<Compile Include="Writer\Tar\TarWriter.cs" />
|
||||
<Compile Include="Writer\WriterFactory.cs" />
|
||||
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
|
||||
<Compile Include="Writer\Zip\ZipWriter.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Client.3.5">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1 Client Profile</ProductName>
|
||||
<Install>false</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Net.Framework.3.5.SP1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>.NET Framework 3.5 SP1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
<BootstrapperPackage Include="Microsoft.Windows.Installer.3.1">
|
||||
<Visible>False</Visible>
|
||||
<ProductName>Windows Installer 3.1</ProductName>
|
||||
<Install>true</Install>
|
||||
</BootstrapperPackage>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
<None Include="SharpCompress.pfx" />
|
||||
</ItemGroup>
|
||||
<ItemGroup />
|
||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
<Target Name="BeforeBuild">
|
||||
</Target>
|
||||
<Target Name="AfterBuild">
|
||||
</Target>
|
||||
-->
|
||||
</Project>
|
||||
@@ -270,6 +270,7 @@
|
||||
<Compile Include="Compressor\Rar\VM\VMPreparedProgram.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMStandardFilters.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMStandardFilterSignature.cs" />
|
||||
<Compile Include="Converter\DataConverter.Portable.cs" />
|
||||
<Compile Include="Crypto\BufferedBlockCipher.cs" />
|
||||
<Compile Include="Crypto\BufferedCipherBase.cs" />
|
||||
<Compile Include="Crypto\CryptoException.cs" />
|
||||
@@ -287,6 +288,7 @@
|
||||
<Compile Include="Crypto\PBKDF2.cs" />
|
||||
<Compile Include="Crypto\RijndaelEngine.cs" />
|
||||
<Compile Include="Crypto\Sha1Digest.cs" />
|
||||
<Compile Include="EnumExtensions.cs" />
|
||||
<Compile Include="IO\CountingWritableSubStream.cs" />
|
||||
<Compile Include="IO\ListeningStream.cs" />
|
||||
<Compile Include="IO\MarkingBinaryReader.cs" />
|
||||
@@ -321,6 +323,7 @@
|
||||
<Compile Include="Writer\Tar\TarWriter.cs" />
|
||||
<Compile Include="Writer\WriterFactory.cs" />
|
||||
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
|
||||
<Compile Include="Writer\Zip\ZipCompressionInfo.cs" />
|
||||
<Compile Include="Writer\Zip\ZipWriter.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -63,7 +63,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DefineConstants>TRACE;UNSIGNED</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
@@ -129,6 +129,7 @@
|
||||
<Compile Include="Common\FilePart.cs" />
|
||||
<Compile Include="Common\Entry.cs" />
|
||||
<Compile Include="Common\IEntry.cs" />
|
||||
<Compile Include="Common\IEntry.Extensions.cs" />
|
||||
<Compile Include="Common\IVolume.cs" />
|
||||
<Compile Include="Common\Rar\RarCryptoWrapper.cs" />
|
||||
<Compile Include="Common\Rar\RarRijndael.Portable.cs" />
|
||||
@@ -239,6 +240,7 @@
|
||||
<Compile Include="Compressor\PPMd\PpmdProperties.cs" />
|
||||
<Compile Include="Compressor\PPMd\PpmdStream.cs" />
|
||||
<Compile Include="Compressor\Rar\RarStream.cs" />
|
||||
<Compile Include="Converter\DataConverter.Portable.cs" />
|
||||
<Compile Include="Crypto\BigInteger.cs" />
|
||||
<Compile Include="Crypto\BufferedBlockCipher.cs" />
|
||||
<Compile Include="Crypto\BufferedCipherBase.cs" />
|
||||
@@ -256,6 +258,7 @@
|
||||
<Compile Include="Crypto\PBKDF2.cs" />
|
||||
<Compile Include="Crypto\RijndaelEngine.cs" />
|
||||
<Compile Include="Crypto\Sha1Digest.cs" />
|
||||
<Compile Include="EnumExtensions.cs" />
|
||||
<Compile Include="IO\CountingWritableSubStream.cs" />
|
||||
<Compile Include="Common\EntryStream.cs">
|
||||
<SubType>Code</SubType>
|
||||
@@ -371,6 +374,7 @@
|
||||
<Compile Include="Writer\Tar\TarWriter.cs" />
|
||||
<Compile Include="Writer\WriterFactory.cs" />
|
||||
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
|
||||
<Compile Include="Writer\Zip\ZipCompressionInfo.cs" />
|
||||
<Compile Include="Writer\Zip\ZipWriter.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -65,7 +65,7 @@
|
||||
<DebugType>pdbonly</DebugType>
|
||||
<Optimize>true</Optimize>
|
||||
<OutputPath>..\bin\</OutputPath>
|
||||
<DefineConstants>TRACE</DefineConstants>
|
||||
<DefineConstants>TRACE;UNSIGNED</DefineConstants>
|
||||
<ErrorReport>prompt</ErrorReport>
|
||||
<WarningLevel>4</WarningLevel>
|
||||
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
|
||||
@@ -131,6 +131,7 @@
|
||||
<Compile Include="Common\FilePart.cs" />
|
||||
<Compile Include="Common\Entry.cs" />
|
||||
<Compile Include="Common\IEntry.cs" />
|
||||
<Compile Include="Common\IEntry.Extensions.cs" />
|
||||
<Compile Include="Common\IVolume.cs" />
|
||||
<Compile Include="Common\Rar\RarCryptoWrapper.cs" />
|
||||
<Compile Include="Common\Rar\RarRijndael.cs" />
|
||||
@@ -243,6 +244,8 @@
|
||||
<Compile Include="Compressor\PPMd\PpmdProperties.cs" />
|
||||
<Compile Include="Compressor\PPMd\PpmdStream.cs" />
|
||||
<Compile Include="Compressor\Rar\RarStream.cs" />
|
||||
<Compile Include="EnumExtensions.cs" />
|
||||
<Compile Include="Converter\DataConverter.cs" />
|
||||
<Compile Include="IO\CountingWritableSubStream.cs" />
|
||||
<Compile Include="Common\EntryStream.cs">
|
||||
<SubType>Code</SubType>
|
||||
@@ -359,6 +362,7 @@
|
||||
<Compile Include="Writer\Tar\TarWriter.cs" />
|
||||
<Compile Include="Writer\WriterFactory.cs" />
|
||||
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
|
||||
<Compile Include="Writer\Zip\ZipCompressionInfo.cs" />
|
||||
<Compile Include="Writer\Zip\ZipWriter.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -256,6 +256,7 @@
|
||||
<Compile Include="Compressor\Rar\VM\VMPreparedProgram.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMStandardFilters.cs" />
|
||||
<Compile Include="Compressor\Rar\VM\VMStandardFilterSignature.cs" />
|
||||
<Compile Include="Converter\DataConverter.Portable.cs" />
|
||||
<Compile Include="Crypto\BigInteger.cs" />
|
||||
<Compile Include="Crypto\BufferedBlockCipher.cs" />
|
||||
<Compile Include="Crypto\BufferedCipherBase.cs" />
|
||||
@@ -273,6 +274,7 @@
|
||||
<Compile Include="Crypto\RijndaelEngine.cs" />
|
||||
<Compile Include="Crypto\Pack.cs" />
|
||||
<Compile Include="Crypto\Sha1Digest.cs" />
|
||||
<Compile Include="EnumExtensions.cs" />
|
||||
<Compile Include="IO\AppendingStream.cs" />
|
||||
<Compile Include="IO\CountingWritableSubStream.cs" />
|
||||
<Compile Include="IO\ListeningStream.cs" />
|
||||
@@ -306,6 +308,7 @@
|
||||
<Compile Include="Writer\Tar\TarWriter.cs" />
|
||||
<Compile Include="Writer\WriterFactory.cs" />
|
||||
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
|
||||
<Compile Include="Writer\Zip\ZipCompressionInfo.cs" />
|
||||
<Compile Include="Writer\Zip\ZipWriter.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -131,6 +131,7 @@
|
||||
<Compile Include="Common\FilePart.cs" />
|
||||
<Compile Include="Common\Entry.cs" />
|
||||
<Compile Include="Common\IEntry.cs" />
|
||||
<Compile Include="Common\IEntry.Extensions.cs" />
|
||||
<Compile Include="Common\IVolume.cs" />
|
||||
<Compile Include="Common\Rar\RarCryptoWrapper.cs" />
|
||||
<Compile Include="Common\Rar\RarRijndael.cs" />
|
||||
@@ -242,7 +243,9 @@
|
||||
<Compile Include="Compressor\PPMd\I1\See2Context.cs" />
|
||||
<Compile Include="Compressor\PPMd\PpmdProperties.cs" />
|
||||
<Compile Include="Compressor\PPMd\PpmdStream.cs" />
|
||||
<Compile Include="Compressor\Rar\RarStream.cs" />
|
||||
<Compile Include="Compressor\Rar\RarStream.cs" />
|
||||
<Compile Include="EnumExtensions.cs" />
|
||||
<Compile Include="Converter\DataConverter.cs" />
|
||||
<Compile Include="IO\CountingWritableSubStream.cs" />
|
||||
<Compile Include="Common\EntryStream.cs">
|
||||
<SubType>Code</SubType>
|
||||
@@ -359,6 +362,7 @@
|
||||
<Compile Include="Writer\Tar\TarWriter.cs" />
|
||||
<Compile Include="Writer\WriterFactory.cs" />
|
||||
<Compile Include="Writer\Zip\ZipCentralDirectoryEntry.cs" />
|
||||
<Compile Include="Writer\Zip\ZipCompressionInfo.cs" />
|
||||
<Compile Include="Writer\Zip\ZipWriter.cs" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
|
||||
@@ -2,9 +2,6 @@ using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using SharpCompress.Archive;
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.IO;
|
||||
|
||||
namespace SharpCompress
|
||||
{
|
||||
@@ -29,17 +26,6 @@ namespace SharpCompress
|
||||
return (number >> bits) + (2 << ~bits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an unsigned bitwise right shift with the specified number
|
||||
/// </summary>
|
||||
/// <param name="number">Number to operate on</param>
|
||||
/// <param name="bits">Ammount of bits to shift</param>
|
||||
/// <returns>The resulting number from the shift operation</returns>
|
||||
public static int URShift(int number, long bits)
|
||||
{
|
||||
return URShift(number, (int)bits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an unsigned bitwise right shift with the specified number
|
||||
/// </summary>
|
||||
@@ -54,17 +40,6 @@ namespace SharpCompress
|
||||
return (number >> bits) + (2L << ~bits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Performs an unsigned bitwise right shift with the specified number
|
||||
/// </summary>
|
||||
/// <param name="number">Number to operate on</param>
|
||||
/// <param name="bits">Ammount of bits to shift</param>
|
||||
/// <returns>The resulting number from the shift operation</returns>
|
||||
public static long URShift(long number, long bits)
|
||||
{
|
||||
return URShift(number, (int)bits);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Fills the array with an specific value from an specific index to an specific index.
|
||||
/// </summary>
|
||||
@@ -120,151 +95,6 @@ namespace SharpCompress
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary> Read a int value from the byte array at the given position (Big Endian)
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="array">the array to read from
|
||||
/// </param>
|
||||
/// <param name="pos">the offset
|
||||
/// </param>
|
||||
/// <returns> the value
|
||||
/// </returns>
|
||||
public static int readIntBigEndian(byte[] array, int pos)
|
||||
{
|
||||
int temp = 0;
|
||||
temp |= array[pos] & 0xff;
|
||||
temp <<= 8;
|
||||
temp |= array[pos + 1] & 0xff;
|
||||
temp <<= 8;
|
||||
temp |= array[pos + 2] & 0xff;
|
||||
temp <<= 8;
|
||||
temp |= array[pos + 3] & 0xff;
|
||||
return temp;
|
||||
}
|
||||
|
||||
/// <summary> Read a short value from the byte array at the given position (little
|
||||
/// Endian)
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="array">the array to read from
|
||||
/// </param>
|
||||
/// <param name="pos">the offset
|
||||
/// </param>
|
||||
/// <returns> the value
|
||||
/// </returns>
|
||||
public static short readShortLittleEndian(byte[] array, int pos)
|
||||
{
|
||||
return BitConverter.ToInt16(array, pos);
|
||||
}
|
||||
|
||||
/// <summary> Read an int value from the byte array at the given position (little
|
||||
/// Endian)
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="array">the array to read from
|
||||
/// </param>
|
||||
/// <param name="pos">the offset
|
||||
/// </param>
|
||||
/// <returns> the value
|
||||
/// </returns>
|
||||
public static int readIntLittleEndian(byte[] array, int pos)
|
||||
{
|
||||
return BitConverter.ToInt32(array, pos);
|
||||
}
|
||||
|
||||
/// <summary> Write an int value into the byte array at the given position (Big endian)
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="array">the array
|
||||
/// </param>
|
||||
/// <param name="pos">the offset
|
||||
/// </param>
|
||||
/// <param name="value">the value to write
|
||||
/// </param>
|
||||
public static void writeIntBigEndian(byte[] array, int pos, int value)
|
||||
{
|
||||
array[pos] = (byte)((Utility.URShift(value, 24)) & 0xff);
|
||||
array[pos + 1] = (byte)((Utility.URShift(value, 16)) & 0xff);
|
||||
array[pos + 2] = (byte)((Utility.URShift(value, 8)) & 0xff);
|
||||
array[pos + 3] = (byte)((value) & 0xff);
|
||||
}
|
||||
|
||||
/// <summary> Write a short value into the byte array at the given position (little
|
||||
/// endian)
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="array">the array
|
||||
/// </param>
|
||||
/// <param name="pos">the offset
|
||||
/// </param>
|
||||
/// <param name="value">the value to write
|
||||
/// </param>
|
||||
#if PORTABLE || NETFX_CORE
|
||||
public static void WriteLittleEndian(byte[] array, int pos, short value)
|
||||
{
|
||||
byte[] newBytes = BitConverter.GetBytes(value);
|
||||
Array.Copy(newBytes, 0, array, pos, newBytes.Length);
|
||||
}
|
||||
#else
|
||||
public static unsafe void WriteLittleEndian(byte[] array, int pos, short value)
|
||||
{
|
||||
fixed (byte* numRef = &(array[pos]))
|
||||
{
|
||||
*((short*)numRef) = value;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/// <summary> Increment a short value at the specified position by the specified amount
|
||||
/// (little endian).
|
||||
/// </summary>
|
||||
public static void incShortLittleEndian(byte[] array, int pos, short incrementValue)
|
||||
{
|
||||
short existingValue = BitConverter.ToInt16(array, pos);
|
||||
existingValue += incrementValue;
|
||||
WriteLittleEndian(array, pos, existingValue);
|
||||
//int c = Utility.URShift(((array[pos] & 0xff) + (dv & 0xff)), 8);
|
||||
//array[pos] = (byte)(array[pos] + (dv & 0xff));
|
||||
//if ((c > 0) || ((dv & 0xff00) != 0))
|
||||
//{
|
||||
// array[pos + 1] = (byte)(array[pos + 1] + ((Utility.URShift(dv, 8)) & 0xff) + c);
|
||||
//}
|
||||
}
|
||||
|
||||
/// <summary> Write an int value into the byte array at the given position (little
|
||||
/// endian)
|
||||
///
|
||||
/// </summary>
|
||||
/// <param name="array">the array
|
||||
/// </param>
|
||||
/// <param name="pos">the offset
|
||||
/// </param>
|
||||
/// <param name="value">the value to write
|
||||
/// </param>
|
||||
#if PORTABLE || NETFX_CORE
|
||||
public static void WriteLittleEndian(byte[] array, int pos, int value)
|
||||
{
|
||||
byte[] newBytes = BitConverter.GetBytes(value);
|
||||
Array.Copy(newBytes, 0, array, pos, newBytes.Length);
|
||||
}
|
||||
#else
|
||||
public static unsafe void WriteLittleEndian(byte[] array, int pos, int value)
|
||||
{
|
||||
fixed (byte* numRef = &(array[pos]))
|
||||
{
|
||||
*((int*)numRef) = value;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
public static void Initialize<T>(this T[] array, Func<T> func)
|
||||
{
|
||||
for (int i = 0; i < array.Length; i++)
|
||||
{
|
||||
array[i] = func();
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddRange<T>(this ICollection<T> destination, IEnumerable<T> source)
|
||||
{
|
||||
foreach (T item in source)
|
||||
@@ -316,7 +146,7 @@ namespace SharpCompress
|
||||
readCount = (int)advanceAmount;
|
||||
}
|
||||
read = source.Read(buffer, 0, readCount);
|
||||
if (read < 0)
|
||||
if (read <= 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
@@ -336,18 +166,6 @@ namespace SharpCompress
|
||||
} while (source.Read(buffer, 0, buffer.Length) == buffer.Length);
|
||||
}
|
||||
|
||||
|
||||
public static byte[] UInt32ToBigEndianBytes(uint x)
|
||||
{
|
||||
return new byte[]
|
||||
{
|
||||
(byte) ((x >> 24) & 0xff),
|
||||
(byte) ((x >> 16) & 0xff),
|
||||
(byte) ((x >> 8) & 0xff),
|
||||
(byte) (x & 0xff)
|
||||
};
|
||||
}
|
||||
|
||||
public static DateTime DosDateToDateTime(UInt16 iDate, UInt16 iTime)
|
||||
{
|
||||
int year = iDate / 512 + 1980;
|
||||
@@ -462,33 +280,6 @@ namespace SharpCompress
|
||||
{
|
||||
Array.Copy(array, 0, destination, index, array.Length);
|
||||
}
|
||||
|
||||
public static long HostToNetworkOrder(long host)
|
||||
{
|
||||
return (int)((long)HostToNetworkOrder((int)host)
|
||||
& unchecked((long)(unchecked((ulong)-1))) << 32
|
||||
| ((long)HostToNetworkOrder((int)((int)host >> 32)) & unchecked((long)(unchecked((ulong)-1)))));
|
||||
}
|
||||
public static int HostToNetworkOrder(int host)
|
||||
{
|
||||
return (int)((int)(HostToNetworkOrder((short)host) & -1) << 16 | (HostToNetworkOrder((short)(host >> 16)) & -1));
|
||||
}
|
||||
public static short HostToNetworkOrder(short host)
|
||||
{
|
||||
return (short)((int)(host & 255) << 8 | ((int)host >> 8 & 255));
|
||||
}
|
||||
public static long NetworkToHostOrder(long network)
|
||||
{
|
||||
return HostToNetworkOrder(network);
|
||||
}
|
||||
public static int NetworkToHostOrder(int network)
|
||||
{
|
||||
return HostToNetworkOrder(network);
|
||||
}
|
||||
public static short NetworkToHostOrder(short network)
|
||||
{
|
||||
return HostToNetworkOrder(network);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
@@ -11,5 +11,5 @@ using System.Runtime.InteropServices;
|
||||
[assembly: AssemblyCopyright("Copyright © Adam Hathcock")]
|
||||
[assembly: AssemblyTrademark("")]
|
||||
[assembly: AssemblyCulture("")]
|
||||
[assembly: AssemblyVersion("0.10.3.0")]
|
||||
[assembly: AssemblyFileVersion("0.10.3.0")]
|
||||
[assembly: AssemblyVersion("0.11.3.0")]
|
||||
[assembly: AssemblyFileVersion("0.11.3.0")]
|
||||
@@ -35,7 +35,7 @@ namespace SharpCompress.Writer
|
||||
{
|
||||
throw new ArgumentException("Directory does not exist: " + directory);
|
||||
}
|
||||
#if NET2
|
||||
#if NET35
|
||||
foreach (var file in Directory.GetFiles(directory, searchPattern, option))
|
||||
#else
|
||||
foreach (var file in Directory.EnumerateFiles(directory, searchPattern, option))
|
||||
|
||||
@@ -3,6 +3,7 @@ using System.IO;
|
||||
using System.Text;
|
||||
using SharpCompress.Common.Zip;
|
||||
using SharpCompress.Common.Zip.Headers;
|
||||
using SharpCompress.Converter;
|
||||
|
||||
namespace SharpCompress.Writer.Zip
|
||||
{
|
||||
@@ -32,23 +33,23 @@ namespace SharpCompress.Writer.Zip
|
||||
flags |= HeaderFlags.Bit1; // eos marker
|
||||
}
|
||||
}
|
||||
outputStream.Write(BitConverter.GetBytes((ushort) flags), 0, 2);
|
||||
outputStream.Write(BitConverter.GetBytes((ushort) compression), 0, 2); // zipping method
|
||||
outputStream.Write(BitConverter.GetBytes(ModificationTime.DateTimeToDosTime()), 0, 4);
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) flags), 0, 2);
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) compression), 0, 2); // zipping method
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes(ModificationTime.DateTimeToDosTime()), 0, 4);
|
||||
// zipping date and time
|
||||
outputStream.Write(BitConverter.GetBytes(Crc), 0, 4); // file CRC
|
||||
outputStream.Write(BitConverter.GetBytes(Compressed), 0, 4); // compressed file size
|
||||
outputStream.Write(BitConverter.GetBytes(Decompressed), 0, 4); // uncompressed file size
|
||||
outputStream.Write(BitConverter.GetBytes((ushort) encodedFilename.Length), 0, 2); // Filename in zip
|
||||
outputStream.Write(BitConverter.GetBytes((ushort) 0), 0, 2); // extra length
|
||||
outputStream.Write(BitConverter.GetBytes((ushort) encodedComment.Length), 0, 2);
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes(Crc), 0, 4); // file CRC
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes(Compressed), 0, 4); // compressed file size
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes(Decompressed), 0, 4); // uncompressed file size
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) encodedFilename.Length), 0, 2); // Filename in zip
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0), 0, 2); // extra length
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) encodedComment.Length), 0, 2);
|
||||
|
||||
outputStream.Write(BitConverter.GetBytes((ushort) 0), 0, 2); // disk=0
|
||||
outputStream.Write(BitConverter.GetBytes((ushort) 0), 0, 2); // file type: binary
|
||||
outputStream.Write(BitConverter.GetBytes((ushort) 0), 0, 2); // Internal file attributes
|
||||
outputStream.Write(BitConverter.GetBytes((ushort) 0x8100), 0, 2);
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0), 0, 2); // disk=0
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0), 0, 2); // file type: binary
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0), 0, 2); // Internal file attributes
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0x8100), 0, 2);
|
||||
// External file attributes (normal/readable)
|
||||
outputStream.Write(BitConverter.GetBytes(HeaderOffset), 0, 4); // Offset of header
|
||||
outputStream.Write(DataConverter.LittleEndian.GetBytes(HeaderOffset), 0, 4); // Offset of header
|
||||
|
||||
outputStream.Write(encodedFilename, 0, encodedFilename.Length);
|
||||
outputStream.Write(encodedComment, 0, encodedComment.Length);
|
||||
|
||||
47
SharpCompress/Writer/Zip/ZipCompressionInfo.cs
Normal file
47
SharpCompress/Writer/Zip/ZipCompressionInfo.cs
Normal file
@@ -0,0 +1,47 @@
|
||||
using SharpCompress.Common;
|
||||
using SharpCompress.Common.Zip;
|
||||
using SharpCompress.Compressor.Deflate;
|
||||
|
||||
namespace SharpCompress.Writer.Zip
|
||||
{
|
||||
internal class ZipCompressionInfo
|
||||
{
|
||||
internal CompressionLevel DeflateCompressionLevel { get; private set; }
|
||||
internal ZipCompressionMethod Compression { get; private set; }
|
||||
|
||||
public ZipCompressionInfo(CompressionInfo compressionInfo)
|
||||
{
|
||||
switch (compressionInfo.Type)
|
||||
{
|
||||
case CompressionType.None:
|
||||
{
|
||||
this.Compression = ZipCompressionMethod.None;
|
||||
}
|
||||
break;
|
||||
case CompressionType.Deflate:
|
||||
{
|
||||
this.DeflateCompressionLevel = compressionInfo.DeflateCompressionLevel;
|
||||
this.Compression = ZipCompressionMethod.Deflate;
|
||||
}
|
||||
break;
|
||||
case CompressionType.BZip2:
|
||||
{
|
||||
this.Compression = ZipCompressionMethod.BZip2;
|
||||
}
|
||||
break;
|
||||
case CompressionType.LZMA:
|
||||
{
|
||||
this.Compression = ZipCompressionMethod.LZMA;
|
||||
}
|
||||
break;
|
||||
case CompressionType.PPMd:
|
||||
{
|
||||
this.Compression = ZipCompressionMethod.PPMd;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new InvalidFormatException("Invalid compression method: " + compressionInfo.Type);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,6 +10,7 @@ using SharpCompress.Compressor.BZip2;
|
||||
using SharpCompress.Compressor.Deflate;
|
||||
using SharpCompress.Compressor.LZMA;
|
||||
using SharpCompress.Compressor.PPMd;
|
||||
using SharpCompress.Converter;
|
||||
using SharpCompress.IO;
|
||||
using DeflateStream = SharpCompress.Compressor.Deflate.DeflateStream;
|
||||
|
||||
@@ -17,52 +18,18 @@ namespace SharpCompress.Writer.Zip
|
||||
{
|
||||
public class ZipWriter : AbstractWriter
|
||||
{
|
||||
private readonly ZipCompressionMethod compression;
|
||||
private readonly CompressionLevel deflateCompressionLevel;
|
||||
|
||||
private readonly ZipCompressionInfo zipCompressionInfo;
|
||||
private readonly PpmdProperties ppmdProperties = new PpmdProperties(); // Caching properties to speed up PPMd
|
||||
private readonly List<ZipCentralDirectoryEntry> entries = new List<ZipCentralDirectoryEntry>();
|
||||
private readonly string zipComment;
|
||||
private long streamPosition;
|
||||
|
||||
private readonly PpmdProperties ppmdProperties; // Caching properties to speed up PPMd.
|
||||
|
||||
public ZipWriter(Stream destination, CompressionInfo compressionInfo, string zipComment)
|
||||
: base(ArchiveType.Zip)
|
||||
{
|
||||
this.zipComment = zipComment ?? string.Empty;
|
||||
|
||||
switch (compressionInfo.Type)
|
||||
{
|
||||
case CompressionType.None:
|
||||
{
|
||||
compression = ZipCompressionMethod.None;
|
||||
}
|
||||
break;
|
||||
case CompressionType.Deflate:
|
||||
{
|
||||
compression = ZipCompressionMethod.Deflate;
|
||||
deflateCompressionLevel = compressionInfo.DeflateCompressionLevel;
|
||||
}
|
||||
break;
|
||||
case CompressionType.BZip2:
|
||||
{
|
||||
compression = ZipCompressionMethod.BZip2;
|
||||
}
|
||||
break;
|
||||
case CompressionType.LZMA:
|
||||
{
|
||||
compression = ZipCompressionMethod.LZMA;
|
||||
}
|
||||
break;
|
||||
case CompressionType.PPMd:
|
||||
{
|
||||
ppmdProperties = new PpmdProperties();
|
||||
compression = ZipCompressionMethod.PPMd;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
throw new InvalidFormatException("Invalid compression method: " + compressionInfo.Type);
|
||||
}
|
||||
this.zipCompressionInfo = new ZipCompressionInfo(compressionInfo);
|
||||
InitalizeStream(destination, false);
|
||||
}
|
||||
|
||||
@@ -73,7 +40,7 @@ namespace SharpCompress.Writer.Zip
|
||||
uint size = 0;
|
||||
foreach (ZipCentralDirectoryEntry entry in entries)
|
||||
{
|
||||
size += entry.Write(OutputStream, compression);
|
||||
size += entry.Write(OutputStream, zipCompressionInfo.Compression);
|
||||
}
|
||||
WriteEndRecord(size);
|
||||
}
|
||||
@@ -85,15 +52,15 @@ namespace SharpCompress.Writer.Zip
|
||||
Write(entryPath, source, modificationTime, null);
|
||||
}
|
||||
|
||||
public void Write(string entryPath, Stream source, DateTime? modificationTime, string comment)
|
||||
public void Write(string entryPath, Stream source, DateTime? modificationTime, string comment, CompressionInfo compressionInfo = null)
|
||||
{
|
||||
using (Stream output = WriteToStream(entryPath, modificationTime, comment))
|
||||
using (Stream output = WriteToStream(entryPath, modificationTime, comment, compressionInfo))
|
||||
{
|
||||
source.TransferTo(output);
|
||||
}
|
||||
}
|
||||
|
||||
public Stream WriteToStream(string entryPath, DateTime? modificationTime, string comment)
|
||||
public Stream WriteToStream(string entryPath, DateTime? modificationTime, string comment, CompressionInfo compressionInfo = null)
|
||||
{
|
||||
entryPath = NormalizeFilename(entryPath);
|
||||
modificationTime = modificationTime ?? DateTime.Now;
|
||||
@@ -105,9 +72,10 @@ namespace SharpCompress.Writer.Zip
|
||||
ModificationTime = modificationTime,
|
||||
HeaderOffset = (uint) streamPosition,
|
||||
};
|
||||
var headersize = (uint) WriteHeader(entryPath, modificationTime);
|
||||
|
||||
var headersize = (uint)WriteHeader(entryPath, modificationTime, compressionInfo);
|
||||
streamPosition += headersize;
|
||||
return new ZipWritingStream(this, OutputStream, entry);
|
||||
return new ZipWritingStream(this, OutputStream, entry, compressionInfo);
|
||||
}
|
||||
|
||||
private string NormalizeFilename(string filename)
|
||||
@@ -121,29 +89,37 @@ namespace SharpCompress.Writer.Zip
|
||||
return filename.Trim('/');
|
||||
}
|
||||
|
||||
private int WriteHeader(string filename, DateTime? modificationTime)
|
||||
private int WriteHeader(string filename, DateTime? modificationTime, CompressionInfo compressionInfo = null)
|
||||
{
|
||||
var explicitZipCompressionInfo = compressionInfo != null ? new ZipCompressionInfo(compressionInfo) : this.zipCompressionInfo;
|
||||
byte[] encodedFilename = ArchiveEncoding.Default.GetBytes(filename);
|
||||
|
||||
OutputStream.Write(BitConverter.GetBytes(ZipHeaderFactory.ENTRY_HEADER_BYTES), 0, 4);
|
||||
OutputStream.Write(new byte[] {63, 0}, 0, 2); //version
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes(ZipHeaderFactory.ENTRY_HEADER_BYTES), 0, 4);
|
||||
if (explicitZipCompressionInfo.Compression == ZipCompressionMethod.Deflate)
|
||||
{
|
||||
OutputStream.Write(new byte[] {20, 0}, 0, 2); //older version which is more compatible
|
||||
}
|
||||
else
|
||||
{
|
||||
OutputStream.Write(new byte[] {63, 0}, 0, 2); //version says we used PPMd or LZMA
|
||||
}
|
||||
HeaderFlags flags = ArchiveEncoding.Default == Encoding.UTF8 ? HeaderFlags.UTF8 : (HeaderFlags)0;
|
||||
if (!OutputStream.CanSeek)
|
||||
{
|
||||
flags |= HeaderFlags.UsePostDataDescriptor;
|
||||
if (compression == ZipCompressionMethod.LZMA)
|
||||
if (explicitZipCompressionInfo.Compression == ZipCompressionMethod.LZMA)
|
||||
{
|
||||
flags |= HeaderFlags.Bit1; // eos marker
|
||||
}
|
||||
}
|
||||
OutputStream.Write(BitConverter.GetBytes((ushort) flags), 0, 2);
|
||||
OutputStream.Write(BitConverter.GetBytes((ushort) compression), 0, 2); // zipping method
|
||||
OutputStream.Write(BitConverter.GetBytes(modificationTime.DateTimeToDosTime()), 0, 4);
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) flags), 0, 2);
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort)explicitZipCompressionInfo.Compression), 0, 2); // zipping method
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes(modificationTime.DateTimeToDosTime()), 0, 4);
|
||||
// zipping date and time
|
||||
OutputStream.Write(new byte[] {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, 0, 12);
|
||||
// unused CRC, un/compressed size, updated later
|
||||
OutputStream.Write(BitConverter.GetBytes((ushort) encodedFilename.Length), 0, 2); // filename length
|
||||
OutputStream.Write(BitConverter.GetBytes((ushort) 0), 0, 2); // extra length
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) encodedFilename.Length), 0, 2); // filename length
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) 0), 0, 2); // extra length
|
||||
OutputStream.Write(encodedFilename, 0, encodedFilename.Length);
|
||||
|
||||
return 6 + 2 + 2 + 4 + 12 + 2 + 2 + encodedFilename.Length;
|
||||
@@ -151,9 +127,9 @@ namespace SharpCompress.Writer.Zip
|
||||
|
||||
private void WriteFooter(uint crc, uint compressed, uint uncompressed)
|
||||
{
|
||||
OutputStream.Write(BitConverter.GetBytes(crc), 0, 4);
|
||||
OutputStream.Write(BitConverter.GetBytes(compressed), 0, 4);
|
||||
OutputStream.Write(BitConverter.GetBytes(uncompressed), 0, 4);
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes(crc), 0, 4);
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes(compressed), 0, 4);
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes(uncompressed), 0, 4);
|
||||
}
|
||||
|
||||
private void WriteEndRecord(uint size)
|
||||
@@ -161,11 +137,11 @@ namespace SharpCompress.Writer.Zip
|
||||
byte[] encodedComment = ArchiveEncoding.Default.GetBytes(zipComment);
|
||||
|
||||
OutputStream.Write(new byte[] {80, 75, 5, 6, 0, 0, 0, 0}, 0, 8);
|
||||
OutputStream.Write(BitConverter.GetBytes((ushort) entries.Count), 0, 2);
|
||||
OutputStream.Write(BitConverter.GetBytes((ushort) entries.Count), 0, 2);
|
||||
OutputStream.Write(BitConverter.GetBytes(size), 0, 4);
|
||||
OutputStream.Write(BitConverter.GetBytes((uint) streamPosition), 0, 4);
|
||||
OutputStream.Write(BitConverter.GetBytes((ushort) encodedComment.Length), 0, 2);
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) entries.Count), 0, 2);
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) entries.Count), 0, 2);
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes(size), 0, 4);
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes((uint) streamPosition), 0, 4);
|
||||
OutputStream.Write(DataConverter.LittleEndian.GetBytes((ushort) encodedComment.Length), 0, 2);
|
||||
OutputStream.Write(encodedComment, 0, encodedComment.Length);
|
||||
}
|
||||
|
||||
@@ -178,16 +154,18 @@ namespace SharpCompress.Writer.Zip
|
||||
private readonly Stream originalStream;
|
||||
private readonly Stream writeStream;
|
||||
private readonly ZipWriter writer;
|
||||
private readonly ZipCompressionInfo compressionInfo;
|
||||
private CountingWritableSubStream counting;
|
||||
private uint decompressed;
|
||||
|
||||
internal ZipWritingStream(ZipWriter writer, Stream originalStream, ZipCentralDirectoryEntry entry)
|
||||
internal ZipWritingStream(ZipWriter writer, Stream originalStream, ZipCentralDirectoryEntry entry, CompressionInfo compressionInfo)
|
||||
{
|
||||
this.writer = writer;
|
||||
this.originalStream = originalStream;
|
||||
writeStream = GetWriteStream(originalStream);
|
||||
this.writer = writer;
|
||||
this.entry = entry;
|
||||
this.compressionInfo = compressionInfo == null ? writer.zipCompressionInfo : new ZipCompressionInfo(compressionInfo);
|
||||
writeStream = GetWriteStream(originalStream);
|
||||
}
|
||||
|
||||
public override bool CanRead
|
||||
@@ -220,7 +198,7 @@ namespace SharpCompress.Writer.Zip
|
||||
{
|
||||
counting = new CountingWritableSubStream(writeStream);
|
||||
Stream output = counting;
|
||||
switch (writer.compression)
|
||||
switch (compressionInfo.Compression)
|
||||
{
|
||||
case ZipCompressionMethod.None:
|
||||
{
|
||||
@@ -228,7 +206,7 @@ namespace SharpCompress.Writer.Zip
|
||||
}
|
||||
case ZipCompressionMethod.Deflate:
|
||||
{
|
||||
return new DeflateStream(counting, CompressionMode.Compress, writer.deflateCompressionLevel,
|
||||
return new DeflateStream(counting, CompressionMode.Compress, compressionInfo.DeflateCompressionLevel,
|
||||
true);
|
||||
}
|
||||
case ZipCompressionMethod.BZip2:
|
||||
@@ -254,7 +232,7 @@ namespace SharpCompress.Writer.Zip
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new NotSupportedException("CompressionMethod: " + writer.compression);
|
||||
throw new NotSupportedException("CompressionMethod: " + compressionInfo.Compression);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -279,7 +257,7 @@ namespace SharpCompress.Writer.Zip
|
||||
}
|
||||
else
|
||||
{
|
||||
originalStream.Write(BitConverter.GetBytes(ZipHeaderFactory.POST_DATA_DESCRIPTOR), 0, 4);
|
||||
originalStream.Write(DataConverter.LittleEndian.GetBytes(ZipHeaderFactory.POST_DATA_DESCRIPTOR), 0, 4);
|
||||
writer.WriteFooter(entry.Crc, counting.Count, decompressed);
|
||||
writer.streamPosition += entry.Compressed + 16;
|
||||
}
|
||||
|
||||
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="LinqBridge" version="1.3.0" targetFramework="net20" />
|
||||
</packages>
|
||||
@@ -128,5 +128,7 @@
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=StaticReadonly/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=TypeParameters/@EntryIndexedValue"><Policy Inspect="True" Prefix="T" Suffix="" Style="AaBb" /></s:String>
|
||||
<s:String x:Key="/Default/CodeStyle/Naming/VBNaming/PredefinedNamingRules/=TypesAndNamespaces/@EntryIndexedValue"><Policy Inspect="True" Prefix="" Suffix="" Style="AaBb" /></s:String>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EAddAccessorOwnerDeclarationBracesMigration/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateThisQualifierSettings/@EntryIndexedValue">True</s:Boolean>
|
||||
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002EJavaScript_002ECodeStyle_002ESettingsUpgrade_002EJsCodeFormatterSettingsUpgrader/@EntryIndexedValue">True</s:Boolean></wpf:ResourceDictionary>
|
||||
BIN
TestArchives/Archives/Tar.ContainsRar.tar
Normal file
BIN
TestArchives/Archives/Tar.ContainsRar.tar
Normal file
Binary file not shown.
@@ -1,4 +0,0 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<repositories>
|
||||
<repository path="..\SharpCompress\packages.config" />
|
||||
</repositories>
|
||||
Reference in New Issue
Block a user