mirror of
https://github.com/adamhathcock/sharpcompress.git
synced 2026-09-21 14:35:11 +00:00
Resharper code cleanup
This commit is contained in:
@@ -28,7 +28,7 @@ namespace SharpCompress.Archive
|
||||
{
|
||||
throw new ArgumentException("File does not exist: " + fileInfo.FullName);
|
||||
}
|
||||
options = (Options)FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
|
||||
options = (Options) FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
|
||||
lazyVolumes = new LazyReadOnlyCollection<TVolume>(LoadVolumes(fileInfo, options));
|
||||
lazyEntries = new LazyReadOnlyCollection<TEntry>(LoadEntries(Volumes));
|
||||
}
|
||||
@@ -40,7 +40,8 @@ namespace SharpCompress.Archive
|
||||
internal AbstractArchive(ArchiveType type, IEnumerable<Stream> streams, Options options)
|
||||
{
|
||||
this.Type = type;
|
||||
lazyVolumes = new LazyReadOnlyCollection<TVolume>(LoadVolumes(streams.Select<Stream, Stream>(CheckStreams), options));
|
||||
lazyVolumes =
|
||||
new LazyReadOnlyCollection<TVolume>(LoadVolumes(streams.Select<Stream, Stream>(CheckStreams), options));
|
||||
lazyEntries = new LazyReadOnlyCollection<TEntry>(LoadEntries(Volumes));
|
||||
}
|
||||
|
||||
@@ -141,10 +142,10 @@ namespace SharpCompress.Archive
|
||||
if (CompressedBytesRead != null)
|
||||
{
|
||||
CompressedBytesRead(this, new CompressedBytesReadEventArgs()
|
||||
{
|
||||
CurrentFilePartCompressedBytesRead = currentPartCompressedBytes,
|
||||
CompressedBytesRead = compressedReadBytes
|
||||
});
|
||||
{
|
||||
CurrentFilePartCompressedBytesRead = currentPartCompressedBytes,
|
||||
CompressedBytesRead = compressedReadBytes
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,11 +154,11 @@ namespace SharpCompress.Archive
|
||||
if (FilePartExtractionBegin != null)
|
||||
{
|
||||
FilePartExtractionBegin(this, new FilePartExtractionBeginEventArgs()
|
||||
{
|
||||
CompressedSize = compressedSize,
|
||||
Size = size,
|
||||
Name = name,
|
||||
});
|
||||
{
|
||||
CompressedSize = compressedSize,
|
||||
Size = size,
|
||||
Name = name,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -185,10 +186,7 @@ namespace SharpCompress.Archive
|
||||
/// </summary>
|
||||
public virtual bool IsSolid
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,68 +5,70 @@ namespace SharpCompress.Archive
|
||||
{
|
||||
public static class AbstractWritableArchiveExtensions
|
||||
{
|
||||
|
||||
public static void SaveTo<TEntry, TVolume>(this AbstractWritableArchive<TEntry, TVolume> writableArchive,
|
||||
Stream stream, CompressionType compressionType)
|
||||
where TEntry : IArchiveEntry
|
||||
where TVolume : IVolume
|
||||
{
|
||||
writableArchive.SaveTo(stream, new CompressionInfo { Type = compressionType });
|
||||
}
|
||||
#if !PORTABLE
|
||||
|
||||
public static void AddEntry<TEntry, TVolume>(this AbstractWritableArchive<TEntry, TVolume> writableArchive,
|
||||
string entryPath, string filePath)
|
||||
where TEntry : IArchiveEntry
|
||||
where TVolume : IVolume
|
||||
{
|
||||
var fileInfo = new FileInfo(filePath);
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
throw new FileNotFoundException("Could not AddEntry: " + filePath);
|
||||
}
|
||||
writableArchive.AddEntry(entryPath, new FileInfo(filePath).OpenRead(), true, fileInfo.Length, fileInfo.LastWriteTime);
|
||||
}
|
||||
|
||||
public static void SaveTo<TEntry, TVolume>(this AbstractWritableArchive<TEntry, TVolume> writableArchive,
|
||||
string filePath, CompressionType compressionType)
|
||||
Stream stream, CompressionType compressionType)
|
||||
where TEntry : IArchiveEntry
|
||||
where TVolume : IVolume
|
||||
{
|
||||
writableArchive.SaveTo(new FileInfo(filePath), new CompressionInfo { Type = compressionType });
|
||||
writableArchive.SaveTo(stream, new CompressionInfo {Type = compressionType});
|
||||
}
|
||||
|
||||
#if !PORTABLE
|
||||
|
||||
public static void AddEntry<TEntry, TVolume>(this AbstractWritableArchive<TEntry, TVolume> writableArchive,
|
||||
string entryPath, string filePath)
|
||||
where TEntry : IArchiveEntry
|
||||
where TVolume : IVolume
|
||||
{
|
||||
var fileInfo = new FileInfo(filePath);
|
||||
if (!fileInfo.Exists)
|
||||
{
|
||||
throw new FileNotFoundException("Could not AddEntry: " + filePath);
|
||||
}
|
||||
writableArchive.AddEntry(entryPath, new FileInfo(filePath).OpenRead(), true, fileInfo.Length,
|
||||
fileInfo.LastWriteTime);
|
||||
}
|
||||
|
||||
public static void SaveTo<TEntry, TVolume>(this AbstractWritableArchive<TEntry, TVolume> writableArchive,
|
||||
FileInfo fileInfo, CompressionType compressionType)
|
||||
string filePath, CompressionType compressionType)
|
||||
where TEntry : IArchiveEntry
|
||||
where TVolume : IVolume
|
||||
{
|
||||
writableArchive.SaveTo(new FileInfo(filePath), new CompressionInfo {Type = compressionType});
|
||||
}
|
||||
|
||||
public static void SaveTo<TEntry, TVolume>(this AbstractWritableArchive<TEntry, TVolume> writableArchive,
|
||||
FileInfo fileInfo, CompressionType compressionType)
|
||||
where TEntry : IArchiveEntry
|
||||
where TVolume : IVolume
|
||||
{
|
||||
using (var stream = fileInfo.Open(FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
writableArchive.SaveTo(stream, new CompressionInfo { Type = compressionType });
|
||||
writableArchive.SaveTo(stream, new CompressionInfo {Type = compressionType});
|
||||
}
|
||||
}
|
||||
|
||||
public static void SaveTo<TEntry, TVolume>(this AbstractWritableArchive<TEntry, TVolume> writableArchive,
|
||||
string filePath, CompressionInfo compressionInfo)
|
||||
where TEntry : IArchiveEntry
|
||||
where TVolume : IVolume
|
||||
string filePath, CompressionInfo compressionInfo)
|
||||
where TEntry : IArchiveEntry
|
||||
where TVolume : IVolume
|
||||
{
|
||||
writableArchive.SaveTo(new FileInfo(filePath), compressionInfo);
|
||||
writableArchive.SaveTo(new FileInfo(filePath), compressionInfo);
|
||||
}
|
||||
|
||||
public static void SaveTo<TEntry, TVolume>(this AbstractWritableArchive<TEntry, TVolume> writableArchive,
|
||||
FileInfo fileInfo, CompressionInfo compressionInfo)
|
||||
where TEntry : IArchiveEntry
|
||||
where TVolume : IVolume
|
||||
FileInfo fileInfo, CompressionInfo compressionInfo)
|
||||
where TEntry : IArchiveEntry
|
||||
where TVolume : IVolume
|
||||
{
|
||||
using (var stream = fileInfo.Open(FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
writableArchive.SaveTo(stream, compressionInfo);
|
||||
}
|
||||
using (var stream = fileInfo.Open(FileMode.Create, FileAccess.Write))
|
||||
{
|
||||
writableArchive.SaveTo(stream, compressionInfo);
|
||||
}
|
||||
}
|
||||
|
||||
public static void AddAllFromDirectory<TEntry, TVolume>(this AbstractWritableArchive<TEntry, TVolume> writableArchive,
|
||||
public static void AddAllFromDirectory<TEntry, TVolume>(
|
||||
this AbstractWritableArchive<TEntry, TVolume> writableArchive,
|
||||
string filePath, string searchPattern = "*.*", SearchOption searchOption = SearchOption.AllDirectories)
|
||||
where TEntry : IArchiveEntry
|
||||
where TVolume : IVolume
|
||||
@@ -78,10 +80,11 @@ namespace SharpCompress.Archive
|
||||
#endif
|
||||
|
||||
{
|
||||
var fileInfo = new FileInfo(path);
|
||||
writableArchive.AddEntry(path.Substring(filePath.Length), fileInfo.OpenRead(), true, fileInfo.Length, fileInfo.LastWriteTime);
|
||||
var fileInfo = new FileInfo(path);
|
||||
writableArchive.AddEntry(path.Substring(filePath.Length), fileInfo.OpenRead(), true, fileInfo.Length,
|
||||
fileInfo.LastWriteTime);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@ namespace SharpCompress.Archive
|
||||
anyNotWritable = true;
|
||||
}
|
||||
}
|
||||
|
||||
#if !PORTABLE
|
||||
internal AbstractWritableArchive(ArchiveType type, FileInfo fileInfo, Options options)
|
||||
: base(type, fileInfo, options)
|
||||
@@ -66,10 +67,7 @@ namespace SharpCompress.Archive
|
||||
|
||||
private IEnumerable<TEntry> OldEntries
|
||||
{
|
||||
get
|
||||
{
|
||||
return base.Entries.Where(x => !removedEntries.Contains(x));
|
||||
}
|
||||
get { return base.Entries.Where(x => !removedEntries.Contains(x)); }
|
||||
}
|
||||
|
||||
public void RemoveEntry(TEntry entry)
|
||||
@@ -83,7 +81,7 @@ namespace SharpCompress.Archive
|
||||
}
|
||||
|
||||
public void AddEntry(string filePath, Stream source,
|
||||
long size = 0, DateTime? modified = null)
|
||||
long size = 0, DateTime? modified = null)
|
||||
{
|
||||
CheckWritable();
|
||||
newEntries.Add(CreateEntry(filePath, source, size, modified, false));
|
||||
@@ -91,14 +89,14 @@ namespace SharpCompress.Archive
|
||||
}
|
||||
|
||||
public void AddEntry(string filePath, Stream source, bool closeStream,
|
||||
long size = 0, DateTime? modified = null)
|
||||
long size = 0, DateTime? modified = null)
|
||||
{
|
||||
CheckWritable();
|
||||
newEntries.Add(CreateEntry(filePath, source, size, modified, closeStream));
|
||||
RebuildModifiedCollection();
|
||||
CheckWritable();
|
||||
newEntries.Add(CreateEntry(filePath, source, size, modified, closeStream));
|
||||
RebuildModifiedCollection();
|
||||
}
|
||||
|
||||
#if !PORTABLE
|
||||
#if !PORTABLE
|
||||
public void AddEntry(string filePath, FileInfo fileInfo)
|
||||
{
|
||||
if (!fileInfo.Exists)
|
||||
@@ -107,15 +105,17 @@ namespace SharpCompress.Archive
|
||||
}
|
||||
AddEntry(filePath, fileInfo.OpenRead(), true, fileInfo.Length, fileInfo.LastWriteTime);
|
||||
}
|
||||
#endif
|
||||
#endif
|
||||
|
||||
public void SaveTo(Stream stream, CompressionInfo compressionType)
|
||||
{
|
||||
SaveTo(stream, compressionType, OldEntries, newEntries);
|
||||
}
|
||||
|
||||
protected abstract TEntry CreateEntry(string filePath, Stream source, long size, DateTime? modified, bool closeStream);
|
||||
protected abstract TEntry CreateEntry(string filePath, Stream source, long size, DateTime? modified,
|
||||
bool closeStream);
|
||||
|
||||
protected abstract void SaveTo(Stream stream, CompressionInfo compressionType,
|
||||
IEnumerable<TEntry> oldEntries, IEnumerable<TEntry> newEntries);
|
||||
IEnumerable<TEntry> oldEntries, IEnumerable<TEntry> newEntries);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ namespace SharpCompress.Archive
|
||||
/// Extract to specific directory, retaining filename
|
||||
/// </summary>
|
||||
public static void WriteToDirectory(string sourceArchive, string destinationDirectory,
|
||||
ExtractOptions options = ExtractOptions.Overwrite)
|
||||
ExtractOptions options = ExtractOptions.Overwrite)
|
||||
{
|
||||
using (IArchive archive = Open(sourceArchive))
|
||||
{
|
||||
@@ -165,4 +165,4 @@ namespace SharpCompress.Archive
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -161,7 +161,8 @@ namespace SharpCompress.Archive.GZip
|
||||
this.SaveTo(stream, CompressionType.GZip);
|
||||
}
|
||||
|
||||
protected override GZipArchiveEntry CreateEntry(string filePath, Stream source, long size, DateTime? modified, bool closeStream)
|
||||
protected override GZipArchiveEntry CreateEntry(string filePath, Stream source, long size, DateTime? modified,
|
||||
bool closeStream)
|
||||
{
|
||||
if (Entries.Any())
|
||||
{
|
||||
@@ -171,7 +172,8 @@ namespace SharpCompress.Archive.GZip
|
||||
}
|
||||
|
||||
protected override void SaveTo(Stream stream, CompressionInfo compressionInfo,
|
||||
IEnumerable<GZipArchiveEntry> oldEntries, IEnumerable<GZipArchiveEntry> newEntries)
|
||||
IEnumerable<GZipArchiveEntry> oldEntries,
|
||||
IEnumerable<GZipArchiveEntry> newEntries)
|
||||
{
|
||||
if (Entries.Count > 1)
|
||||
{
|
||||
@@ -180,7 +182,7 @@ namespace SharpCompress.Archive.GZip
|
||||
using (var writer = new GZipWriter(stream))
|
||||
{
|
||||
foreach (var entry in oldEntries.Concat(newEntries)
|
||||
.Where(x => !x.IsDirectory))
|
||||
.Where(x => !x.IsDirectory))
|
||||
{
|
||||
using (var entryStream = entry.OpenEntryStream())
|
||||
{
|
||||
@@ -208,4 +210,4 @@ namespace SharpCompress.Archive.GZip
|
||||
return GZipReader.Open(stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -33,12 +33,9 @@ namespace SharpCompress.Archive.GZip
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace SharpCompress.Archive.GZip
|
||||
private bool closeStream;
|
||||
|
||||
internal GZipWritableArchiveEntry(GZipArchive archive, Stream stream,
|
||||
string path, long size, DateTime? lastModified, bool closeStream)
|
||||
string path, long size, DateTime? lastModified, bool closeStream)
|
||||
: base(archive, null)
|
||||
{
|
||||
this.Stream = stream;
|
||||
@@ -29,14 +29,20 @@ namespace SharpCompress.Archive.GZip
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public override string FilePath { get { return path; } }
|
||||
public override string FilePath
|
||||
{
|
||||
get { return path; }
|
||||
}
|
||||
|
||||
public override long CompressedSize
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public override long Size { get { return size; } }
|
||||
public override long Size
|
||||
{
|
||||
get { return size; }
|
||||
}
|
||||
|
||||
public override DateTime? LastModifiedTime
|
||||
{
|
||||
@@ -87,10 +93,10 @@ namespace SharpCompress.Archive.GZip
|
||||
|
||||
internal override void Close()
|
||||
{
|
||||
if (closeStream)
|
||||
{
|
||||
Stream.Dispose();
|
||||
}
|
||||
if (closeStream)
|
||||
{
|
||||
Stream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,7 +10,7 @@ namespace SharpCompress.Archive
|
||||
/// Extract to specific directory, retaining filename
|
||||
/// </summary>
|
||||
public static void WriteToDirectory(this IArchive archive, string destinationDirectory,
|
||||
ExtractOptions options = ExtractOptions.Overwrite)
|
||||
ExtractOptions options = ExtractOptions.Overwrite)
|
||||
{
|
||||
foreach (IArchiveEntry entry in archive.Entries.Where(x => !x.IsDirectory))
|
||||
{
|
||||
@@ -19,4 +19,4 @@ namespace SharpCompress.Archive
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,18 +13,9 @@ namespace SharpCompress.Archive
|
||||
event EventHandler<CompressedBytesReadEventArgs> CompressedBytesRead;
|
||||
event EventHandler<FilePartExtractionBeginEventArgs> FilePartExtractionBegin;
|
||||
|
||||
IEnumerable<IArchiveEntry> Entries
|
||||
{
|
||||
get;
|
||||
}
|
||||
long TotalSize
|
||||
{
|
||||
get;
|
||||
}
|
||||
IEnumerable<IVolume> Volumes
|
||||
{
|
||||
get;
|
||||
}
|
||||
IEnumerable<IArchiveEntry> Entries { get; }
|
||||
long TotalSize { get; }
|
||||
IEnumerable<IVolume> Volumes { get; }
|
||||
|
||||
ArchiveType Type { get; }
|
||||
|
||||
@@ -40,14 +31,11 @@ namespace SharpCompress.Archive
|
||||
/// Archive is SOLID (this means the Archive saved bytes by reusing information which helps for archives containing many small files).
|
||||
/// Rar Archives can be SOLID while all 7Zip archives are considered SOLID.
|
||||
/// </summary>
|
||||
bool IsSolid
|
||||
{
|
||||
get;
|
||||
}
|
||||
bool IsSolid { get; }
|
||||
|
||||
/// <summary>
|
||||
/// This checks to see if all the known entries have IsComplete = true
|
||||
/// </summary>
|
||||
bool IsComplete { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,12 +1,12 @@
|
||||
using System.IO;
|
||||
using SharpCompress.Common;
|
||||
|
||||
#if THREEFIVE
|
||||
using SharpCompress.Common.Rar.Headers;
|
||||
#endif
|
||||
|
||||
namespace SharpCompress.Archive
|
||||
{
|
||||
|
||||
public static class IArchiveEntryExtensions
|
||||
{
|
||||
#if !PORTABLE
|
||||
@@ -14,7 +14,7 @@ namespace SharpCompress.Archive
|
||||
/// Extract to specific directory, retaining filename
|
||||
/// </summary>
|
||||
public static void WriteToDirectory(this IArchiveEntry entry, string destinationDirectory,
|
||||
ExtractOptions options = ExtractOptions.Overwrite)
|
||||
ExtractOptions options = ExtractOptions.Overwrite)
|
||||
{
|
||||
string destinationFileName = string.Empty;
|
||||
string file = Path.GetFileName(entry.FilePath);
|
||||
@@ -22,7 +22,6 @@ namespace SharpCompress.Archive
|
||||
|
||||
if (options.HasFlag(ExtractOptions.ExtractFullPath))
|
||||
{
|
||||
|
||||
string folder = Path.GetDirectoryName(entry.FilePath);
|
||||
string destdir = Path.Combine(destinationDirectory, folder);
|
||||
if (!Directory.Exists(destdir))
|
||||
@@ -42,7 +41,7 @@ namespace SharpCompress.Archive
|
||||
/// Extract to specific file
|
||||
/// </summary>
|
||||
public static void WriteToFile(this IArchiveEntry entry, string destinationFileName,
|
||||
ExtractOptions options = ExtractOptions.Overwrite)
|
||||
ExtractOptions options = ExtractOptions.Overwrite)
|
||||
{
|
||||
if (entry.IsDirectory)
|
||||
{
|
||||
@@ -58,9 +57,9 @@ namespace SharpCompress.Archive
|
||||
// using (Stream entryStream = entry.OpenEntryStream())
|
||||
{
|
||||
//entryStream.TransferTo(fs);
|
||||
entry.WriteTo(fs);
|
||||
entry.WriteTo(fs);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,4 +18,4 @@ namespace SharpCompress.Archive
|
||||
/// </summary>
|
||||
bool IsComplete { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,22 +24,14 @@ namespace SharpCompress.Archive.Rar
|
||||
//make sure we're closing streams with fileinfo
|
||||
if (options.HasFlag(Options.KeepStreamsOpen))
|
||||
{
|
||||
options = (Options)FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
|
||||
options = (Options) FlagUtility.SetFlag(options, Options.KeepStreamsOpen, false);
|
||||
}
|
||||
return options;
|
||||
}
|
||||
|
||||
internal ReadOnlyCollection<RarFilePart> FileParts
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal ReadOnlyCollection<RarFilePart> FileParts { get; private set; }
|
||||
|
||||
internal FileInfo FileInfo
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal FileInfo FileInfo { get; private set; }
|
||||
|
||||
internal override RarFilePart CreateFilePart(FileHeader fileHeader, MarkHeader markHeader)
|
||||
{
|
||||
@@ -53,10 +45,7 @@ namespace SharpCompress.Archive.Rar
|
||||
|
||||
public override FileInfo VolumeFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return FileInfo;
|
||||
}
|
||||
get { return FileInfo; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,11 +15,7 @@ namespace SharpCompress.Archive.Rar
|
||||
FileInfo = fi;
|
||||
}
|
||||
|
||||
internal FileInfo FileInfo
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal FileInfo FileInfo { get; private set; }
|
||||
|
||||
internal override Stream GetCompressedStream()
|
||||
{
|
||||
@@ -33,8 +29,8 @@ namespace SharpCompress.Archive.Rar
|
||||
get
|
||||
{
|
||||
return "Rar File: " + FileInfo.FullName
|
||||
+ " File Entry: " + FileHeader.FileName;
|
||||
+ " File Entry: " + FileHeader.FileName;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -28,4 +28,4 @@ namespace SharpCompress.Archive.Rar
|
||||
return archive.IsSolid;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,10 +18,7 @@ namespace SharpCompress.Archive.Rar
|
||||
|
||||
internal Unpack Unpack
|
||||
{
|
||||
get
|
||||
{
|
||||
return unpack;
|
||||
}
|
||||
get { return unpack; }
|
||||
}
|
||||
|
||||
#if !PORTABLE
|
||||
@@ -70,10 +67,7 @@ namespace SharpCompress.Archive.Rar
|
||||
|
||||
public override bool IsSolid
|
||||
{
|
||||
get
|
||||
{
|
||||
return Volumes.First().IsSolidArchive;
|
||||
}
|
||||
get { return Volumes.First().IsSolidArchive; }
|
||||
}
|
||||
|
||||
#region Creation
|
||||
@@ -196,7 +190,7 @@ namespace SharpCompress.Archive.Rar
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Enum.IsDefined(typeof(HeaderType), header.HeaderType);
|
||||
return Enum.IsDefined(typeof (HeaderType), header.HeaderType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
|
||||
@@ -23,26 +23,16 @@ namespace SharpCompress.Archive.Rar
|
||||
get { return CompressionType.Rar; }
|
||||
}
|
||||
|
||||
private RarArchive Archive
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
private RarArchive Archive { get; set; }
|
||||
|
||||
internal override IEnumerable<FilePart> Parts
|
||||
{
|
||||
get
|
||||
{
|
||||
return parts.Cast<FilePart>();
|
||||
}
|
||||
get { return parts.Cast<FilePart>(); }
|
||||
}
|
||||
|
||||
internal override FileHeader FileHeader
|
||||
{
|
||||
get
|
||||
{
|
||||
return parts.First().FileHeader;
|
||||
}
|
||||
get { return parts.First().FileHeader; }
|
||||
}
|
||||
|
||||
public override uint Crc
|
||||
@@ -51,8 +41,8 @@ namespace SharpCompress.Archive.Rar
|
||||
{
|
||||
CheckIncomplete();
|
||||
return parts.Select(fp => fp.FileHeader)
|
||||
.Where(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER))
|
||||
.Single().FileCRC;
|
||||
.Where(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER))
|
||||
.Single().FileCRC;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -71,10 +61,7 @@ namespace SharpCompress.Archive.Rar
|
||||
get
|
||||
{
|
||||
CheckIncomplete();
|
||||
return parts.Aggregate(0L, (total, fp) =>
|
||||
{
|
||||
return total + fp.FileHeader.CompressedSize;
|
||||
});
|
||||
return parts.Aggregate(0L, (total, fp) => { return total + fp.FileHeader.CompressedSize; });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -100,10 +87,7 @@ namespace SharpCompress.Archive.Rar
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
get
|
||||
{
|
||||
return parts.Select(fp => fp.FileHeader).Any(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER));
|
||||
}
|
||||
get { return parts.Select(fp => fp.FileHeader).Any(fh => !fh.FileFlags.HasFlag(FileFlags.SPLIT_AFTER)); }
|
||||
}
|
||||
|
||||
private void CheckIncomplete()
|
||||
|
||||
@@ -25,7 +25,7 @@ namespace SharpCompress.Archive.Rar
|
||||
{
|
||||
groupedParts.Add(fp);
|
||||
|
||||
if (!FlagUtility.HasFlag((long)fp.FileHeader.FileFlags, (long)FileFlags.SPLIT_AFTER))
|
||||
if (!FlagUtility.HasFlag((long) fp.FileHeader.FileFlags, (long) FileFlags.SPLIT_AFTER))
|
||||
{
|
||||
yield return groupedParts;
|
||||
groupedParts = new List<RarFilePart>();
|
||||
@@ -46,4 +46,4 @@ namespace SharpCompress.Archive.Rar
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -55,7 +55,7 @@ namespace SharpCompress.Archive.Rar
|
||||
return null;
|
||||
}
|
||||
bool oldNumbering = !ah.ArchiveHeaderFlags.HasFlag(ArchiveFlags.NEWNUMBERING)
|
||||
|| currentFilePart.MarkHeader.OldFormat;
|
||||
|| currentFilePart.MarkHeader.OldFormat;
|
||||
if (oldNumbering)
|
||||
{
|
||||
return FindNextFileWithOldNumbering(currentFilePart.FileInfo);
|
||||
@@ -73,7 +73,7 @@ namespace SharpCompress.Archive.Rar
|
||||
|
||||
StringBuilder buffer = new StringBuilder(currentFileInfo.FullName.Length);
|
||||
buffer.Append(currentFileInfo.FullName.Substring(0,
|
||||
currentFileInfo.FullName.Length - extension.Length));
|
||||
currentFileInfo.FullName.Length - extension.Length));
|
||||
if (string.Compare(extension, ".rar", StringComparison.InvariantCultureIgnoreCase) == 0)
|
||||
{
|
||||
buffer.Append(".r00");
|
||||
@@ -116,7 +116,8 @@ namespace SharpCompress.Archive.Rar
|
||||
buffer.Append(currentFileInfo.FullName, 0, startIndex);
|
||||
int num = 0;
|
||||
string numString = currentFileInfo.FullName.Substring(startIndex + 5,
|
||||
currentFileInfo.FullName.IndexOf('.', startIndex + 5) - startIndex - 5);
|
||||
currentFileInfo.FullName.IndexOf('.', startIndex + 5) -
|
||||
startIndex - 5);
|
||||
buffer.Append(".part");
|
||||
if (int.TryParse(numString, out num))
|
||||
{
|
||||
@@ -138,9 +139,9 @@ namespace SharpCompress.Archive.Rar
|
||||
private static void ThrowInvalidFileName(FileInfo fileInfo)
|
||||
{
|
||||
throw new ArgumentException("Filename invalid or next archive could not be found:"
|
||||
+ fileInfo.FullName);
|
||||
+ fileInfo.FullName);
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,11 +12,7 @@ namespace SharpCompress.Archive.Rar
|
||||
Stream = stream;
|
||||
}
|
||||
|
||||
internal Stream Stream
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal Stream Stream { get; private set; }
|
||||
|
||||
internal override Stream GetCompressedStream()
|
||||
{
|
||||
@@ -26,10 +22,7 @@ namespace SharpCompress.Archive.Rar
|
||||
|
||||
internal override string FilePartName
|
||||
{
|
||||
get
|
||||
{
|
||||
return "Unknown Stream - File Entry: " + base.FileHeader.FileName;
|
||||
}
|
||||
get { return "Unknown Stream - File Entry: " + base.FileHeader.FileName; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,4 +31,4 @@ namespace SharpCompress.Archive.Rar
|
||||
return new SeekableStreamFilePart(markHeader, fileHeader, Stream);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -74,6 +74,7 @@ namespace SharpCompress.Archive.SevenZip
|
||||
stream.CheckNotNull("stream");
|
||||
return new SevenZipArchive(stream, options);
|
||||
}
|
||||
|
||||
#if !PORTABLE
|
||||
internal SevenZipArchive(FileInfo fileInfo, Options options)
|
||||
: base(ArchiveType.SevenZip, fileInfo, options)
|
||||
@@ -133,10 +134,10 @@ namespace SharpCompress.Archive.SevenZip
|
||||
for (int i = 0; i < database.Files.Count; i++)
|
||||
{
|
||||
var file = database.Files[i];
|
||||
if (!file.IsDir)
|
||||
{
|
||||
yield return new SevenZipArchiveEntry(this, new SevenZipFilePart(stream, database, i, file));
|
||||
}
|
||||
if (!file.IsDir)
|
||||
{
|
||||
yield return new SevenZipArchiveEntry(this, new SevenZipFilePart(stream, database, i, file));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -163,12 +164,14 @@ namespace SharpCompress.Archive.SevenZip
|
||||
return false;
|
||||
}
|
||||
}
|
||||
private static readonly byte[] SIGNATURE = new byte[] { (byte)'7', (byte)'z', 0xBC, 0xAF, 0x27, 0x1C };
|
||||
|
||||
private static readonly byte[] SIGNATURE = new byte[] {(byte) '7', (byte) 'z', 0xBC, 0xAF, 0x27, 0x1C};
|
||||
|
||||
private static bool SignatureMatch(Stream stream)
|
||||
{
|
||||
BinaryReader reader = new BinaryReader(stream);
|
||||
byte[] signatureBytes = reader.ReadBytes(6);
|
||||
return signatureBytes.BinaryEquals(SIGNATURE);
|
||||
BinaryReader reader = new BinaryReader(stream);
|
||||
byte[] signatureBytes = reader.ReadBytes(6);
|
||||
return signatureBytes.BinaryEquals(SIGNATURE);
|
||||
}
|
||||
|
||||
protected override IReader CreateReaderForSolidExtraction()
|
||||
@@ -178,10 +181,7 @@ namespace SharpCompress.Archive.SevenZip
|
||||
|
||||
public override bool IsSolid
|
||||
{
|
||||
get
|
||||
{
|
||||
return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1;
|
||||
}
|
||||
get { return Entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder).Count() > 1; }
|
||||
}
|
||||
|
||||
private class SevenZipReader : AbstractReader<SevenZipEntry, SevenZipVolume>
|
||||
@@ -213,26 +213,26 @@ namespace SharpCompress.Archive.SevenZip
|
||||
}
|
||||
foreach (var group in entries.Where(x => !x.IsDirectory).GroupBy(x => x.FilePart.Folder))
|
||||
{
|
||||
currentFolder = group.Key;
|
||||
if (group.Key == null)
|
||||
{
|
||||
currentFolder = group.Key;
|
||||
if (group.Key == null)
|
||||
{
|
||||
currentStream = Stream.Null;
|
||||
}
|
||||
else
|
||||
{
|
||||
}
|
||||
else
|
||||
{
|
||||
currentStream = archive.database.GetFolderStream(stream, currentFolder, null);
|
||||
}
|
||||
foreach (var entry in group)
|
||||
{
|
||||
}
|
||||
foreach (var entry in group)
|
||||
{
|
||||
currentItem = entry.FilePart.Header;
|
||||
yield return entry;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override EntryStream GetEntryStream()
|
||||
{
|
||||
return new EntryStream(new ReadOnlySubStream(currentStream, currentItem.Size));
|
||||
return new EntryStream(new ReadOnlySubStream(currentStream, currentItem.Size));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,10 +30,7 @@ namespace SharpCompress.Archive.SevenZip
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -44,4 +41,4 @@ namespace SharpCompress.Archive.SevenZip
|
||||
get { return FilePart.Header.IsAnti; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -102,7 +102,7 @@ namespace SharpCompress.Archive.Tar
|
||||
{
|
||||
TarHeader tar = new TarHeader();
|
||||
tar.Read(new BinaryReader(stream));
|
||||
return tar.Name.Length > 0 && Enum.IsDefined(typeof(EntryType), tar.EntryType);
|
||||
return tar.Name.Length > 0 && Enum.IsDefined(typeof (EntryType), tar.EntryType);
|
||||
}
|
||||
catch
|
||||
{
|
||||
@@ -163,7 +163,8 @@ namespace SharpCompress.Archive.Tar
|
||||
{
|
||||
if (previousHeader != null)
|
||||
{
|
||||
var entry = new TarArchiveEntry(this, new TarFilePart(previousHeader, stream), CompressionType.None);
|
||||
var entry = new TarArchiveEntry(this, new TarFilePart(previousHeader, stream),
|
||||
CompressionType.None);
|
||||
var memoryStream = new MemoryStream();
|
||||
entry.WriteTo(memoryStream);
|
||||
memoryStream.Position = 0;
|
||||
@@ -183,19 +184,20 @@ namespace SharpCompress.Archive.Tar
|
||||
}
|
||||
|
||||
protected override TarArchiveEntry CreateEntry(string filePath, Stream source,
|
||||
long size, DateTime? modified, bool closeStream)
|
||||
long size, DateTime? modified, bool closeStream)
|
||||
{
|
||||
return new TarWritableArchiveEntry(this, source, CompressionType.Unknown, filePath, size, modified, closeStream);
|
||||
return new TarWritableArchiveEntry(this, source, CompressionType.Unknown, filePath, size, modified,
|
||||
closeStream);
|
||||
}
|
||||
|
||||
protected override void SaveTo(Stream stream, CompressionInfo compressionInfo,
|
||||
IEnumerable<TarArchiveEntry> oldEntries,
|
||||
IEnumerable<TarArchiveEntry> newEntries)
|
||||
IEnumerable<TarArchiveEntry> oldEntries,
|
||||
IEnumerable<TarArchiveEntry> newEntries)
|
||||
{
|
||||
using (var writer = new TarWriter(stream, compressionInfo))
|
||||
{
|
||||
foreach (var entry in oldEntries.Concat(newEntries)
|
||||
.Where(x => !x.IsDirectory))
|
||||
.Where(x => !x.IsDirectory))
|
||||
{
|
||||
using (var entryStream = entry.OpenEntryStream())
|
||||
{
|
||||
|
||||
@@ -8,6 +8,7 @@ namespace SharpCompress.Archive.Tar
|
||||
public class TarArchiveEntry : TarEntry, IArchiveEntry
|
||||
{
|
||||
private TarArchive archive;
|
||||
|
||||
internal TarArchiveEntry(TarArchive archive, TarFilePart part, CompressionType compressionType)
|
||||
: base(part, compressionType)
|
||||
{
|
||||
@@ -32,10 +33,7 @@ namespace SharpCompress.Archive.Tar
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace SharpCompress.Archive.Tar
|
||||
private bool closeStream;
|
||||
|
||||
internal TarWritableArchiveEntry(TarArchive archive, Stream stream, CompressionType compressionType,
|
||||
string path, long size, DateTime? lastModified, bool closeStream)
|
||||
string path, long size, DateTime? lastModified, bool closeStream)
|
||||
: base(archive, null, compressionType)
|
||||
{
|
||||
this.Stream = stream;
|
||||
@@ -29,14 +29,20 @@ namespace SharpCompress.Archive.Tar
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public override string FilePath { get { return path; } }
|
||||
public override string FilePath
|
||||
{
|
||||
get { return path; }
|
||||
}
|
||||
|
||||
public override long CompressedSize
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public override long Size { get { return size; } }
|
||||
public override long Size
|
||||
{
|
||||
get { return size; }
|
||||
}
|
||||
|
||||
public override DateTime? LastModifiedTime
|
||||
{
|
||||
@@ -87,10 +93,10 @@ namespace SharpCompress.Archive.Tar
|
||||
|
||||
internal override void Close()
|
||||
{
|
||||
if (closeStream)
|
||||
{
|
||||
Stream.Dispose();
|
||||
}
|
||||
if (closeStream)
|
||||
{
|
||||
Stream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -121,7 +121,7 @@ namespace SharpCompress.Archive.Zip
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return Enum.IsDefined(typeof(ZipHeaderType), header.ZipHeaderType);
|
||||
return Enum.IsDefined(typeof (ZipHeaderType), header.ZipHeaderType);
|
||||
}
|
||||
catch (CryptographicException)
|
||||
{
|
||||
@@ -187,7 +187,9 @@ namespace SharpCompress.Archive.Zip
|
||||
case ZipHeaderType.DirectoryEntry:
|
||||
{
|
||||
yield return new ZipArchiveEntry(this,
|
||||
new SeekableZipFilePart(headerFactory, h as DirectoryEntryHeader, stream));
|
||||
new SeekableZipFilePart(headerFactory,
|
||||
h as DirectoryEntryHeader,
|
||||
stream));
|
||||
}
|
||||
break;
|
||||
case ZipHeaderType.DirectoryEnd:
|
||||
@@ -202,15 +204,15 @@ namespace SharpCompress.Archive.Zip
|
||||
}
|
||||
|
||||
protected override void SaveTo(Stream stream, CompressionInfo compressionInfo,
|
||||
IEnumerable<ZipArchiveEntry> oldEntries,
|
||||
IEnumerable<ZipArchiveEntry> newEntries)
|
||||
IEnumerable<ZipArchiveEntry> oldEntries,
|
||||
IEnumerable<ZipArchiveEntry> newEntries)
|
||||
{
|
||||
using (var writer = new ZipWriter(stream, compressionInfo, string.Empty))
|
||||
{
|
||||
foreach (var entry in oldEntries.Concat(newEntries)
|
||||
.Where(x => !x.IsDirectory))
|
||||
.Where(x => !x.IsDirectory))
|
||||
{
|
||||
using(var entryStream = entry.OpenEntryStream())
|
||||
using (var entryStream = entry.OpenEntryStream())
|
||||
{
|
||||
writer.Write(entry.FilePath, entryStream, entry.LastModifiedTime, string.Empty);
|
||||
}
|
||||
@@ -218,7 +220,8 @@ namespace SharpCompress.Archive.Zip
|
||||
}
|
||||
}
|
||||
|
||||
protected override ZipArchiveEntry CreateEntry(string filePath, Stream source, long size, DateTime? modified, bool closeStream)
|
||||
protected override ZipArchiveEntry CreateEntry(string filePath, Stream source, long size, DateTime? modified,
|
||||
bool closeStream)
|
||||
{
|
||||
return new ZipWritableArchiveEntry(this, source, filePath, size, modified, closeStream);
|
||||
}
|
||||
|
||||
@@ -28,20 +28,14 @@ namespace SharpCompress.Archive.Zip
|
||||
|
||||
public bool IsComplete
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
public string Comment
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Parts.Single() as SeekableZipFilePart).Comment;
|
||||
}
|
||||
get { return (Parts.Single() as SeekableZipFilePart).Comment; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,7 +13,8 @@ namespace SharpCompress.Archive.Zip
|
||||
private DateTime? lastModified;
|
||||
private bool closeStream;
|
||||
|
||||
internal ZipWritableArchiveEntry(ZipArchive archive, Stream stream, string path, long size, DateTime? lastModified, bool closeStream)
|
||||
internal ZipWritableArchiveEntry(ZipArchive archive, Stream stream, string path, long size,
|
||||
DateTime? lastModified, bool closeStream)
|
||||
: base(archive, null)
|
||||
{
|
||||
this.Stream = stream;
|
||||
@@ -28,14 +29,20 @@ namespace SharpCompress.Archive.Zip
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public override string FilePath { get { return path; } }
|
||||
public override string FilePath
|
||||
{
|
||||
get { return path; }
|
||||
}
|
||||
|
||||
public override long CompressedSize
|
||||
{
|
||||
get { return 0; }
|
||||
}
|
||||
|
||||
public override long Size { get { return size; } }
|
||||
public override long Size
|
||||
{
|
||||
get { return size; }
|
||||
}
|
||||
|
||||
public override DateTime? LastModifiedTime
|
||||
{
|
||||
@@ -81,15 +88,15 @@ namespace SharpCompress.Archive.Zip
|
||||
|
||||
public override Stream OpenEntryStream()
|
||||
{
|
||||
return new NonDisposingStream(Stream);
|
||||
return new NonDisposingStream(Stream);
|
||||
}
|
||||
|
||||
internal override void Close()
|
||||
{
|
||||
if (closeStream)
|
||||
{
|
||||
Stream.Dispose();
|
||||
}
|
||||
if (closeStream)
|
||||
{
|
||||
Stream.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,9 +13,13 @@ using System.Runtime.CompilerServices;
|
||||
[assembly: AssemblyTitle("SharpCompress.3.5")]
|
||||
[assembly: AssemblyProduct("SharpCompress.3.5")]
|
||||
#else
|
||||
|
||||
[assembly: AssemblyTitle("SharpCompress")]
|
||||
[assembly: AssemblyProduct("SharpCompress")]
|
||||
[assembly: InternalsVisibleTo("SharpCompress.Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010005d6ae1b0f6875393da83c920a5b9408f5191aaf4e8b3c2c476ad2a11f5041ecae84ce9298bc4c203637e2fd3a80ad5378a9fa8da1363e98cea45c73969198a4b64510927c910001491cebbadf597b22448ad103b0a4007e339faf8fe8665dcdb70d65b27ac05b1977c0655fad06b372b820ecbdccf10a0f214fee0986dfeded")]
|
||||
#endif
|
||||
[assembly:
|
||||
InternalsVisibleTo(
|
||||
"SharpCompress.Test, PublicKey=002400000480000094000000060200000024000052534131000400000100010005d6ae1b0f6875393da83c920a5b9408f5191aaf4e8b3c2c476ad2a11f5041ecae84ce9298bc4c203637e2fd3a80ad5378a9fa8da1363e98cea45c73969198a4b64510927c910001491cebbadf597b22448ad103b0a4007e339faf8fe8665dcdb70d65b27ac05b1977c0655fad06b372b820ecbdccf10a0f214fee0986dfeded"
|
||||
)]
|
||||
#endif
|
||||
#endif
|
||||
#endif
|
||||
@@ -26,4 +26,4 @@ namespace SharpCompress.Common
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,4 @@ namespace SharpCompress.Common
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,4 +11,4 @@ namespace SharpCompress.Common
|
||||
|
||||
public T Item { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
namespace SharpCompress.Common
|
||||
namespace SharpCompress.Common
|
||||
{
|
||||
public enum ArchiveType
|
||||
{
|
||||
@@ -9,4 +8,4 @@ namespace SharpCompress.Common
|
||||
SevenZip,
|
||||
GZip,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,4 @@ namespace SharpCompress.Common
|
||||
/// </summary>
|
||||
public long CurrentFilePartCompressedBytesRead { get; internal set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,26 +2,29 @@
|
||||
|
||||
namespace SharpCompress.Common
|
||||
{
|
||||
/// <summary>
|
||||
/// Detailed compression properties when saving.
|
||||
/// </summary>
|
||||
public class CompressionInfo
|
||||
{
|
||||
public CompressionInfo()
|
||||
{
|
||||
DeflateCompressionLevel = CompressionLevel.Default;
|
||||
}
|
||||
/// <summary>
|
||||
/// Detailed compression properties when saving.
|
||||
/// </summary>
|
||||
public class CompressionInfo
|
||||
{
|
||||
public CompressionInfo()
|
||||
{
|
||||
DeflateCompressionLevel = CompressionLevel.Default;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The algorthm to use. Must be valid for the format type.
|
||||
/// </summary>
|
||||
public CompressionType Type { get; set; }
|
||||
/// <summary>
|
||||
/// The algorthm to use. Must be valid for the format type.
|
||||
/// </summary>
|
||||
public CompressionType Type { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// When CompressionType.Deflate is used, this property is referenced. Defaults to CompressionLevel.Default.
|
||||
/// </summary>
|
||||
public CompressionLevel DeflateCompressionLevel { get; set; }
|
||||
/// <summary>
|
||||
/// When CompressionType.Deflate is used, this property is referenced. Defaults to CompressionLevel.Default.
|
||||
/// </summary>
|
||||
public CompressionLevel DeflateCompressionLevel { get; set; }
|
||||
|
||||
public static implicit operator CompressionInfo(CompressionType compressionType) { return new CompressionInfo() { Type = compressionType }; }
|
||||
}
|
||||
}
|
||||
public static implicit operator CompressionInfo(CompressionType compressionType)
|
||||
{
|
||||
return new CompressionInfo() {Type = compressionType};
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
namespace SharpCompress.Common
|
||||
namespace SharpCompress.Common
|
||||
{
|
||||
public enum CompressionType
|
||||
{
|
||||
@@ -14,4 +13,4 @@ namespace SharpCompress.Common
|
||||
BCJ2,
|
||||
Unknown,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,4 +9,4 @@ namespace SharpCompress.Common
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,100 +10,61 @@ namespace SharpCompress.Common
|
||||
/// <summary>
|
||||
/// The File's 32 bit CRC Hash
|
||||
/// </summary>
|
||||
public abstract uint Crc
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract uint Crc { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The path of the file internal to the Rar Archive.
|
||||
/// </summary>
|
||||
public abstract string FilePath
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract string FilePath { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The compressed file size
|
||||
/// </summary>
|
||||
public abstract long CompressedSize
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract long CompressedSize { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The compression type
|
||||
/// </summary>
|
||||
public abstract CompressionType CompressionType
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract CompressionType CompressionType { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The uncompressed file size
|
||||
/// </summary>
|
||||
public abstract long Size
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract long Size { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The entry last modified time in the archive, if recorded
|
||||
/// </summary>
|
||||
public abstract DateTime? LastModifiedTime
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract DateTime? LastModifiedTime { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The entry create time in the archive, if recorded
|
||||
/// </summary>
|
||||
public abstract DateTime? CreatedTime
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract DateTime? CreatedTime { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The entry last accessed time in the archive, if recorded
|
||||
/// </summary>
|
||||
public abstract DateTime? LastAccessedTime
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract DateTime? LastAccessedTime { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The entry time whend archived, if recorded
|
||||
/// </summary>
|
||||
public abstract DateTime? ArchivedTime
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract DateTime? ArchivedTime { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Entry is password protected and encrypted and cannot be extracted.
|
||||
/// </summary>
|
||||
public abstract bool IsEncrypted
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract bool IsEncrypted { get; }
|
||||
|
||||
/// <summary>
|
||||
/// Entry is password protected and encrypted and cannot be extracted.
|
||||
/// </summary>
|
||||
public abstract bool IsDirectory
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract bool IsDirectory { get; }
|
||||
|
||||
public abstract bool IsSplit
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract bool IsSplit { get; }
|
||||
|
||||
internal abstract IEnumerable<FilePart> Parts
|
||||
{
|
||||
get;
|
||||
}
|
||||
internal abstract IEnumerable<FilePart> Parts { get; }
|
||||
|
||||
internal abstract void Close();
|
||||
}
|
||||
|
||||
@@ -29,7 +29,8 @@ namespace SharpCompress.Common
|
||||
{
|
||||
if (!completed)
|
||||
{
|
||||
throw new InvalidOperationException("EntryStream has not been fully consumed. Read the entire stream or use SkipEntry.");
|
||||
throw new InvalidOperationException(
|
||||
"EntryStream has not been fully consumed. Read the entire stream or use SkipEntry.");
|
||||
}
|
||||
base.Dispose(disposing);
|
||||
stream.Dispose();
|
||||
@@ -62,14 +63,8 @@ namespace SharpCompress.Common
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
get { throw new System.NotImplementedException(); }
|
||||
set { throw new System.NotImplementedException(); }
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
@@ -97,4 +92,4 @@ namespace SharpCompress.Common
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,13 +6,15 @@ namespace SharpCompress.Common
|
||||
public enum ExtractOptions
|
||||
{
|
||||
None,
|
||||
|
||||
/// <summary>
|
||||
/// overwrite target if it exists
|
||||
/// </summary>
|
||||
Overwrite,
|
||||
|
||||
/// <summary>
|
||||
/// extract with internal directory structure
|
||||
/// </summary>
|
||||
ExtractFullPath,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
using System;
|
||||
using System;
|
||||
|
||||
namespace SharpCompress.Common
|
||||
{
|
||||
@@ -9,9 +8,10 @@ namespace SharpCompress.Common
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public ExtractionException(string message, Exception inner)
|
||||
: base(message, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,12 +4,9 @@ namespace SharpCompress.Common
|
||||
{
|
||||
public abstract class FilePart
|
||||
{
|
||||
internal abstract string FilePartName
|
||||
{
|
||||
get;
|
||||
}
|
||||
internal abstract string FilePartName { get; }
|
||||
|
||||
internal abstract Stream GetCompressedStream();
|
||||
internal abstract Stream GetRawStream();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,14 +8,15 @@ namespace SharpCompress.Common
|
||||
/// File name for the part for the current entry
|
||||
/// </summary>
|
||||
public string Name { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Uncompressed size of the current entry in the part
|
||||
/// </summary>
|
||||
public long Size { get; internal set; }
|
||||
|
||||
/// <summary>
|
||||
/// Compressed size of the current entry in the part
|
||||
/// </summary>
|
||||
public long CompressedSize { get; internal set; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -50,12 +50,12 @@ namespace SharpCompress.Common
|
||||
}
|
||||
|
||||
#if PORTABLE
|
||||
/// <summary>
|
||||
/// Generically checks enums in a Windows Phone 7 enivronment
|
||||
/// </summary>
|
||||
/// <param name="enumVal"></param>
|
||||
/// <param name="flag"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// Generically checks enums in a Windows Phone 7 enivronment
|
||||
/// </summary>
|
||||
/// <param name="enumVal"></param>
|
||||
/// <param name="flag"></param>
|
||||
/// <returns></returns>
|
||||
public static bool HasFlag(this Enum enumVal, Enum flag)
|
||||
{
|
||||
if (enumVal.GetHashCode() > 0) //GetHashCode returns the enum value. But it's something very crazy if not set beforehand
|
||||
@@ -71,12 +71,12 @@ namespace SharpCompress.Common
|
||||
#endif
|
||||
|
||||
#if THREEFIVE
|
||||
/// <summary>
|
||||
/// Generically checks enums in a .NET 3.5
|
||||
/// </summary>
|
||||
/// <param name="enumVal"></param>
|
||||
/// <param name="flag"></param>
|
||||
/// <returns></returns>
|
||||
/// <summary>
|
||||
/// Generically checks enums in a .NET 3.5
|
||||
/// </summary>
|
||||
/// <param name="enumVal"></param>
|
||||
/// <param name="flag"></param>
|
||||
/// <returns></returns>
|
||||
public static bool HasFlag(this Enum enumVal, Enum flag)
|
||||
{
|
||||
return (Convert.ToInt32(enumVal) & Convert.ToInt32(flag)) == Convert.ToInt32(flag);
|
||||
@@ -145,4 +145,4 @@ namespace SharpCompress.Common
|
||||
return SetFlag(bitField.ToInt64(null), flag, @on);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -57,7 +57,7 @@ namespace SharpCompress.Common.GZip
|
||||
// read and discard extra field
|
||||
n = stream.Read(header, 0, 2); // 2-byte length field
|
||||
|
||||
Int16 extraLength = (Int16)(header[0] + header[1] * 256);
|
||||
Int16 extraLength = (Int16) (header[0] + header[1]*256);
|
||||
byte[] extra = new byte[extraLength];
|
||||
n = stream.Read(extra, 0, extra.Length);
|
||||
if (n != extraLength)
|
||||
@@ -100,4 +100,4 @@ namespace SharpCompress.Common.GZip
|
||||
return ArchiveEncoding.Default.GetString(a, 0, a.Length);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,27 +27,18 @@ namespace SharpCompress.Common.GZip
|
||||
/// </summary>
|
||||
public override FileInfo VolumeFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return fileInfo;
|
||||
}
|
||||
get { return fileInfo; }
|
||||
}
|
||||
#endif
|
||||
|
||||
public override bool IsFirstVolume
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMultiVolume
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,27 +27,18 @@ namespace SharpCompress.Common
|
||||
/// </summary>
|
||||
public override FileInfo VolumeFile
|
||||
{
|
||||
get
|
||||
{
|
||||
return fileInfo;
|
||||
}
|
||||
get { return fileInfo; }
|
||||
}
|
||||
#endif
|
||||
|
||||
public override bool IsFirstVolume
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool IsMultiVolume
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
get { return true; }
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,53 +4,17 @@ namespace SharpCompress.Common
|
||||
{
|
||||
public interface IEntry
|
||||
{
|
||||
CompressionType CompressionType
|
||||
{
|
||||
get;
|
||||
}
|
||||
DateTime? ArchivedTime
|
||||
{
|
||||
get;
|
||||
}
|
||||
long CompressedSize
|
||||
{
|
||||
get;
|
||||
}
|
||||
uint Crc
|
||||
{
|
||||
get;
|
||||
}
|
||||
DateTime? CreatedTime
|
||||
{
|
||||
get;
|
||||
}
|
||||
string FilePath
|
||||
{
|
||||
get;
|
||||
}
|
||||
bool IsDirectory
|
||||
{
|
||||
get;
|
||||
}
|
||||
bool IsEncrypted
|
||||
{
|
||||
get;
|
||||
}
|
||||
bool IsSplit
|
||||
{
|
||||
get;
|
||||
}
|
||||
DateTime? LastAccessedTime
|
||||
{
|
||||
get;
|
||||
}
|
||||
DateTime? LastModifiedTime
|
||||
{
|
||||
get;
|
||||
}
|
||||
long Size
|
||||
{
|
||||
get;
|
||||
}
|
||||
CompressionType CompressionType { get; }
|
||||
DateTime? ArchivedTime { get; }
|
||||
long CompressedSize { get; }
|
||||
uint Crc { get; }
|
||||
DateTime? CreatedTime { get; }
|
||||
string FilePath { get; }
|
||||
bool IsDirectory { get; }
|
||||
bool IsEncrypted { get; }
|
||||
bool IsSplit { get; }
|
||||
DateTime? LastAccessedTime { get; }
|
||||
DateTime? LastModifiedTime { get; }
|
||||
long Size { get; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,9 +1,8 @@
|
||||
|
||||
namespace SharpCompress.Common
|
||||
namespace SharpCompress.Common
|
||||
{
|
||||
internal interface IStreamListener
|
||||
{
|
||||
void FireFilePartExtractionBegin(string name, long size, long compressedSize);
|
||||
void FireCompressedBytesRead(long currentPartCompressedBytes, long compressedReadBytes);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
#if !PORTABLE
|
||||
using System.IO;
|
||||
|
||||
#endif
|
||||
|
||||
namespace SharpCompress.Common
|
||||
@@ -11,10 +12,7 @@ namespace SharpCompress.Common
|
||||
/// <summary>
|
||||
/// File that backs this volume, if it not stream based
|
||||
/// </summary>
|
||||
FileInfo VolumeFile
|
||||
{
|
||||
get;
|
||||
}
|
||||
FileInfo VolumeFile { get; }
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
namespace SharpCompress.Common
|
||||
namespace SharpCompress.Common
|
||||
{
|
||||
public class IncompleteArchiveException : ArchiveException
|
||||
{
|
||||
@@ -8,4 +7,4 @@ namespace SharpCompress.Common
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,4 +14,4 @@ namespace SharpCompress.Common
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,10 @@ namespace SharpCompress.Common
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public MultiVolumeExtractionException(string message, Exception inner)
|
||||
: base(message, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
namespace SharpCompress.Common
|
||||
namespace SharpCompress.Common
|
||||
{
|
||||
public class MultipartStreamRequiredException : ExtractionException
|
||||
{
|
||||
@@ -8,4 +7,4 @@ namespace SharpCompress.Common
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -9,13 +9,15 @@ namespace SharpCompress.Common
|
||||
/// No options specified
|
||||
/// </summary>
|
||||
None = 0,
|
||||
|
||||
/// <summary>
|
||||
/// SharpCompress will keep the supplied streams open
|
||||
/// </summary>
|
||||
KeepStreamsOpen = 1,
|
||||
|
||||
/// <summary>
|
||||
/// Look for RarArchive (Check for self-extracting archives or cases where RarArchive isn't at the start of the file)
|
||||
/// </summary>
|
||||
LookForHeader = 2,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,10 @@ namespace SharpCompress.Common
|
||||
: base(message)
|
||||
{
|
||||
}
|
||||
|
||||
public PasswordProtectedException(string message, Exception inner)
|
||||
: base(message, inner)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,22 +11,10 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
UserNameSize = reader.ReadInt16();
|
||||
}
|
||||
|
||||
internal int CreationTime
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal int CreationTime { get; private set; }
|
||||
|
||||
internal short ArcNameSize
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal short ArcNameSize { get; private set; }
|
||||
|
||||
internal short UserNameSize
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal short UserNameSize { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,28 +19,13 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
|
||||
internal ArchiveFlags ArchiveHeaderFlags
|
||||
{
|
||||
get
|
||||
{
|
||||
return (ArchiveFlags)base.Flags;
|
||||
}
|
||||
get { return (ArchiveFlags) base.Flags; }
|
||||
}
|
||||
|
||||
internal short HighPosAv
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal short HighPosAv { get; private set; }
|
||||
|
||||
internal int PosAv
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal int PosAv { get; private set; }
|
||||
|
||||
internal byte EncryptionVersion
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal byte EncryptionVersion { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,27 +12,11 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
CommCRC = reader.ReadInt16();
|
||||
}
|
||||
|
||||
internal short UnpSize
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal short UnpSize { get; private set; }
|
||||
|
||||
internal byte UnpVersion
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal byte UnpVersion { get; private set; }
|
||||
|
||||
internal byte UnpMethod
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal short CommCRC
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal byte UnpMethod { get; private set; }
|
||||
internal short CommCRC { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,22 +18,11 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
|
||||
internal EndArchiveFlags EndArchiveFlags
|
||||
{
|
||||
get
|
||||
{
|
||||
return (EndArchiveFlags)base.Flags;
|
||||
}
|
||||
get { return (EndArchiveFlags) base.Flags; }
|
||||
}
|
||||
|
||||
internal int? ArchiveCRC
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal int? ArchiveCRC { get; private set; }
|
||||
|
||||
internal short? VolumeNumber
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal short? VolumeNumber { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,7 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
{
|
||||
uint lowUncompressedSize = reader.ReadUInt32();
|
||||
|
||||
HostOS = (HostOS)(int)reader.ReadByte();
|
||||
HostOS = (HostOS) (int) reader.ReadByte();
|
||||
|
||||
FileCRC = reader.ReadUInt32();
|
||||
|
||||
@@ -39,16 +39,14 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
{
|
||||
if (lowUncompressedSize == 0xffffffff)
|
||||
{
|
||||
|
||||
lowUncompressedSize = 0xffffffff;
|
||||
highUncompressedkSize = int.MaxValue;
|
||||
}
|
||||
|
||||
}
|
||||
CompressedSize = UInt32To64(highCompressedSize, AdditionalSize);
|
||||
UncompressedSize = UInt32To64(highUncompressedkSize, lowUncompressedSize);
|
||||
|
||||
nameSize = nameSize > 4 * 1024 ? (short)(4 * 1024) : nameSize;
|
||||
nameSize = nameSize > 4*1024 ? (short) (4*1024) : nameSize;
|
||||
|
||||
byte[] fileNameBytes = reader.ReadBytes(nameSize);
|
||||
|
||||
@@ -60,7 +58,7 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
{
|
||||
int length = 0;
|
||||
while (length < fileNameBytes.Length
|
||||
&& fileNameBytes[length] != 0)
|
||||
&& fileNameBytes[length] != 0)
|
||||
{
|
||||
length++;
|
||||
}
|
||||
@@ -96,7 +94,7 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
if (NewSubHeaderType.SUBHEAD_TYPE_RR.Equals(fileNameBytes))
|
||||
{
|
||||
RecoverySectors = SubData[8] + (SubData[9] << 8)
|
||||
+ (SubData[10] << 16) + (SubData[11] << 24);
|
||||
+ (SubData[10] << 16) + (SubData[11] << 24);
|
||||
}
|
||||
}
|
||||
break;
|
||||
@@ -129,9 +127,10 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
return l + y;
|
||||
}
|
||||
|
||||
private static DateTime? ProcessExtendedTime(ushort extendedFlags, DateTime? time, MarkingBinaryReader reader, int i)
|
||||
private static DateTime? ProcessExtendedTime(ushort extendedFlags, DateTime? time, MarkingBinaryReader reader,
|
||||
int i)
|
||||
{
|
||||
uint rmode = (uint)extendedFlags >> (3 - i) * 4;
|
||||
uint rmode = (uint) extendedFlags >> (3 - i)*4;
|
||||
if ((rmode & 8) == 0)
|
||||
{
|
||||
return null;
|
||||
@@ -146,14 +145,14 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
time = time.Value.AddSeconds(1);
|
||||
}
|
||||
uint nanosecondHundreds = 0;
|
||||
int count = (int)rmode & 3;
|
||||
int count = (int) rmode & 3;
|
||||
for (int j = 0; j < count; j++)
|
||||
{
|
||||
byte b = reader.ReadByte();
|
||||
nanosecondHundreds |= (((uint)b) << ((j + 3 - count) * 8));
|
||||
nanosecondHundreds |= (((uint) b) << ((j + 3 - count)*8));
|
||||
}
|
||||
//10^-7 to 10^-3
|
||||
return time.Value.AddMilliseconds(nanosecondHundreds * Math.Pow(10, -4));
|
||||
return time.Value.AddMilliseconds(nanosecondHundreds*Math.Pow(10, -4));
|
||||
}
|
||||
|
||||
private static string ConvertPath(string path, HostOS os)
|
||||
@@ -185,117 +184,46 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
#endif
|
||||
}
|
||||
|
||||
internal long DataStartPosition
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
internal HostOS HostOS
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal long DataStartPosition { get; set; }
|
||||
internal HostOS HostOS { get; private set; }
|
||||
|
||||
internal uint FileCRC
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal uint FileCRC { get; private set; }
|
||||
|
||||
internal DateTime? FileLastModifiedTime
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal DateTime? FileLastModifiedTime { get; private set; }
|
||||
|
||||
internal DateTime? FileCreatedTime
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal DateTime? FileCreatedTime { get; private set; }
|
||||
|
||||
internal DateTime? FileLastAccessedTime
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal DateTime? FileLastAccessedTime { get; private set; }
|
||||
|
||||
internal DateTime? FileArchivedTime
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal DateTime? FileArchivedTime { get; private set; }
|
||||
|
||||
internal byte RarVersion
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal byte RarVersion { get; private set; }
|
||||
|
||||
internal byte PackingMethod
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal byte PackingMethod { get; private set; }
|
||||
|
||||
internal int FileAttributes
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal int FileAttributes { get; private set; }
|
||||
|
||||
internal FileFlags FileFlags
|
||||
{
|
||||
get
|
||||
{
|
||||
return (FileFlags)base.Flags;
|
||||
}
|
||||
get { return (FileFlags) base.Flags; }
|
||||
}
|
||||
|
||||
internal long CompressedSize
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal long UncompressedSize
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal long CompressedSize { get; private set; }
|
||||
internal long UncompressedSize { get; private set; }
|
||||
|
||||
internal string FileName
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal string FileName { get; private set; }
|
||||
|
||||
internal byte[] SubData
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal byte[] SubData { get; private set; }
|
||||
|
||||
internal int RecoverySectors
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal int RecoverySectors { get; private set; }
|
||||
|
||||
internal byte[] Salt
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal byte[] Salt { get; private set; }
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return FileName;
|
||||
}
|
||||
|
||||
public Stream PackedStream
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
public Stream PackedStream { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -31,21 +31,20 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
}
|
||||
switch (flags >> 6)
|
||||
{
|
||||
|
||||
case 0:
|
||||
buf.Append((char)(GetChar(name, encPos++)));
|
||||
buf.Append((char) (GetChar(name, encPos++)));
|
||||
++decPos;
|
||||
break;
|
||||
|
||||
case 1:
|
||||
buf.Append((char)(GetChar(name, encPos++) + (highByte << 8)));
|
||||
buf.Append((char) (GetChar(name, encPos++) + (highByte << 8)));
|
||||
++decPos;
|
||||
break;
|
||||
|
||||
case 2:
|
||||
low = GetChar(name, encPos);
|
||||
high = GetChar(name, encPos + 1);
|
||||
buf.Append((char)((high << 8) + low));
|
||||
buf.Append((char) ((high << 8) + low));
|
||||
++decPos;
|
||||
encPos += 2;
|
||||
break;
|
||||
@@ -58,14 +57,14 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
for (length = (length & 0x7f) + 2; length > 0 && decPos < name.Length; length--, decPos++)
|
||||
{
|
||||
low = (GetChar(name, decPos) + correction) & 0xff;
|
||||
buf.Append((char)((highByte << 8) + low));
|
||||
buf.Append((char) ((highByte << 8) + low));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for (length += 2; length > 0 && decPos < name.Length; length--, decPos++)
|
||||
{
|
||||
buf.Append((char)(GetChar(name, decPos)));
|
||||
buf.Append((char) (GetChar(name, decPos)));
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -82,4 +82,4 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
EARC_REVSPACE = 0x0004,
|
||||
EARC_VOLNUMBER = 0x0008,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -4,7 +4,6 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
{
|
||||
internal class MarkHeader : RarHeader
|
||||
{
|
||||
|
||||
protected override void ReadFromReader(MarkingBinaryReader reader)
|
||||
{
|
||||
}
|
||||
@@ -55,10 +54,6 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
return valid;
|
||||
}
|
||||
|
||||
internal bool OldFormat
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal bool OldFormat { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -27,7 +27,7 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
bytes = new byte[chars.Length];
|
||||
for (int i = 0; i < chars.Length; ++i)
|
||||
{
|
||||
bytes[i] = (byte)chars[i];
|
||||
bytes[i] = (byte) chars[i];
|
||||
}
|
||||
}
|
||||
|
||||
@@ -56,4 +56,4 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,7 +39,7 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
protected virtual void ReadFromReader(MarkingBinaryReader reader)
|
||||
{
|
||||
HeadCRC = reader.ReadInt16();
|
||||
HeaderType = (HeaderType)(int)(reader.ReadByte() & 0xff);
|
||||
HeaderType = (HeaderType) (int) (reader.ReadByte() & 0xff);
|
||||
Flags = reader.ReadInt16();
|
||||
HeaderSize = reader.ReadInt16();
|
||||
if (FlagUtility.HasFlag(Flags, LONG_BLOCK))
|
||||
@@ -58,7 +58,7 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
header.ReadFromReader(reader);
|
||||
header.ReadBytes += reader.CurrentReadByteCount;
|
||||
|
||||
int headerSizeDiff = header.HeaderSize - (int)header.ReadBytes;
|
||||
int headerSizeDiff = header.HeaderSize - (int) header.ReadBytes;
|
||||
|
||||
if (headerSizeDiff > 0)
|
||||
{
|
||||
@@ -75,46 +75,22 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
/// <summary>
|
||||
/// This is the number of bytes read when reading the header
|
||||
/// </summary>
|
||||
protected long ReadBytes
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
protected long ReadBytes { get; private set; }
|
||||
|
||||
protected short HeadCRC
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
protected short HeadCRC { get; private set; }
|
||||
|
||||
internal HeaderType HeaderType
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal HeaderType HeaderType { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// Untyped flags. These should be typed when Promoting to another header
|
||||
/// </summary>
|
||||
protected short Flags
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
protected short Flags { get; private set; }
|
||||
|
||||
protected short HeaderSize
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
protected short HeaderSize { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// This additional size of the header could be file data
|
||||
/// </summary>
|
||||
protected uint AdditionalSize
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
protected uint AdditionalSize { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,17 +15,9 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
Options = options;
|
||||
}
|
||||
|
||||
private Options Options
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
private Options Options { get; set; }
|
||||
|
||||
internal StreamingMode StreamingMode
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal StreamingMode StreamingMode { get; private set; }
|
||||
|
||||
internal IEnumerable<RarHeader> ReadHeaders(Stream stream)
|
||||
{
|
||||
@@ -197,4 +189,4 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,28 +12,12 @@ namespace SharpCompress.Common.Rar.Headers
|
||||
AVInfoCRC = reader.ReadInt32();
|
||||
}
|
||||
|
||||
internal int AVInfoCRC
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal int AVInfoCRC { get; private set; }
|
||||
|
||||
internal byte UnpackVersion
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal byte UnpackVersion { get; private set; }
|
||||
|
||||
internal byte Method
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal byte Method { get; private set; }
|
||||
|
||||
internal byte AVVersion
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal byte AVVersion { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,21 +14,13 @@ namespace SharpCompress.Common.Rar
|
||||
FileHeader = fh;
|
||||
}
|
||||
|
||||
internal MarkHeader MarkHeader
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal MarkHeader MarkHeader { get; private set; }
|
||||
|
||||
internal FileHeader FileHeader
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal FileHeader FileHeader { get; private set; }
|
||||
|
||||
internal override Stream GetRawStream()
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -22,10 +22,7 @@ namespace SharpCompress.Common.Rar
|
||||
|
||||
internal StreamingMode Mode
|
||||
{
|
||||
get
|
||||
{
|
||||
return headerFactory.StreamingMode;
|
||||
}
|
||||
get { return headerFactory.StreamingMode; }
|
||||
}
|
||||
|
||||
internal abstract IEnumerable<RarFilePart> ReadFileParts();
|
||||
@@ -60,11 +57,7 @@ namespace SharpCompress.Common.Rar
|
||||
}
|
||||
}
|
||||
|
||||
internal ArchiveHeader ArchiveHeader
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal ArchiveHeader ArchiveHeader { get; private set; }
|
||||
|
||||
private void EnsureArchiveHeaderLoaded()
|
||||
{
|
||||
@@ -118,4 +111,4 @@ namespace SharpCompress.Common.Rar
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -39,10 +39,10 @@ namespace SharpCompress.Common.SevenZip
|
||||
internal bool IsEmpty()
|
||||
{
|
||||
return PackSizes.Count == 0
|
||||
&& PackCRCs.Count == 0
|
||||
&& Folders.Count == 0
|
||||
&& NumUnpackStreamsVector.Count == 0
|
||||
&& Files.Count == 0;
|
||||
&& PackCRCs.Count == 0
|
||||
&& Folders.Count == 0
|
||||
&& NumUnpackStreamsVector.Count == 0
|
||||
&& Files.Count == 0;
|
||||
}
|
||||
|
||||
private void FillStartPos()
|
||||
@@ -158,4 +158,4 @@ namespace SharpCompress.Common.SevenZip
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -220,7 +220,11 @@ 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()));
|
||||
Log.WriteLine("MethodId: " +
|
||||
String.Join("",
|
||||
Enumerable.Range(0, idSize)
|
||||
.Select(x => longID[x].ToString("x2"))
|
||||
.ToArray()));
|
||||
if (idSize > 8)
|
||||
throw new NotSupportedException();
|
||||
ulong id = 0;
|
||||
@@ -232,7 +236,8 @@ namespace SharpCompress.Common.SevenZip
|
||||
{
|
||||
coder.NumInStreams = ReadNum();
|
||||
coder.NumOutStreams = ReadNum();
|
||||
Log.WriteLine("Complex Stream (In: " + coder.NumInStreams + " - Out: " + coder.NumOutStreams + ")");
|
||||
Log.WriteLine("Complex Stream (In: " + coder.NumInStreams + " - Out: " + coder.NumOutStreams +
|
||||
")");
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -246,7 +251,8 @@ 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()));
|
||||
Log.WriteLine("Settings: " +
|
||||
String.Join("", coder.Props.Select(bt => bt.ToString("x2")).ToArray()));
|
||||
}
|
||||
|
||||
if ((mainByte & 0x80) != 0)
|
||||
@@ -255,7 +261,10 @@ namespace SharpCompress.Common.SevenZip
|
||||
numInStreams += coder.NumInStreams;
|
||||
numOutStreams += coder.NumOutStreams;
|
||||
}
|
||||
finally { Log.PopIndent(); }
|
||||
finally
|
||||
{
|
||||
Log.PopIndent();
|
||||
}
|
||||
}
|
||||
|
||||
int numBindPairs = numOutStreams - 1;
|
||||
@@ -382,7 +391,10 @@ namespace SharpCompress.Common.SevenZip
|
||||
packCRCs.Add(null);
|
||||
}
|
||||
}
|
||||
finally { Log.PopIndent(); }
|
||||
finally
|
||||
{
|
||||
Log.PopIndent();
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadUnpackInfo(List<byte[]> dataVector, out List<CFolder> folders)
|
||||
@@ -445,10 +457,14 @@ namespace SharpCompress.Common.SevenZip
|
||||
SkipData();
|
||||
}
|
||||
}
|
||||
finally { Log.PopIndent(); }
|
||||
finally
|
||||
{
|
||||
Log.PopIndent();
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadSubStreamsInfo(List<CFolder> folders, out List<int> numUnpackStreamsInFolders, out List<long> unpackSizes, out List<uint?> digests)
|
||||
private void ReadSubStreamsInfo(List<CFolder> folders, out List<int> numUnpackStreamsInFolders,
|
||||
out List<long> unpackSizes, out List<uint?> digests)
|
||||
{
|
||||
Log.WriteLine("-- ReadSubStreamsInfo --");
|
||||
Log.PushIndent();
|
||||
@@ -571,18 +587,21 @@ namespace SharpCompress.Common.SevenZip
|
||||
type = ReadId();
|
||||
}
|
||||
}
|
||||
finally { Log.PopIndent(); }
|
||||
finally
|
||||
{
|
||||
Log.PopIndent();
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadStreamsInfo(
|
||||
List<byte[]> dataVector,
|
||||
out long dataOffset,
|
||||
out List<long> packSizes,
|
||||
out List<uint?> packCRCs,
|
||||
out List<CFolder> folders,
|
||||
out List<int> numUnpackStreamsInFolders,
|
||||
out List<long> unpackSizes,
|
||||
out List<uint?> digests)
|
||||
List<byte[]> dataVector,
|
||||
out long dataOffset,
|
||||
out List<long> packSizes,
|
||||
out List<uint?> packCRCs,
|
||||
out List<CFolder> folders,
|
||||
out List<int> numUnpackStreamsInFolders,
|
||||
out List<long> unpackSizes,
|
||||
out List<uint?> digests)
|
||||
{
|
||||
Log.WriteLine("-- ReadStreamsInfo --");
|
||||
Log.PushIndent();
|
||||
@@ -616,7 +635,10 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { Log.PopIndent(); }
|
||||
finally
|
||||
{
|
||||
Log.PopIndent();
|
||||
}
|
||||
}
|
||||
|
||||
private List<byte[]> ReadAndDecodePackedStreams(long baseOffset, IPasswordProvider pass)
|
||||
@@ -657,7 +679,8 @@ namespace SharpCompress.Common.SevenZip
|
||||
dataStartPos += packSize;
|
||||
}
|
||||
|
||||
var outStream = DecoderStreamHelper.CreateDecoderStream(_stream, oldDataStartPos, myPackSizes, folder, pass);
|
||||
var outStream = DecoderStreamHelper.CreateDecoderStream(_stream, oldDataStartPos, myPackSizes,
|
||||
folder, pass);
|
||||
|
||||
int unpackSize = checked((int)folder.GetUnpackSize());
|
||||
byte[] data = new byte[unpackSize];
|
||||
@@ -672,7 +695,10 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
return dataVector;
|
||||
}
|
||||
finally { Log.PopIndent(); }
|
||||
finally
|
||||
{
|
||||
Log.PopIndent();
|
||||
}
|
||||
}
|
||||
|
||||
private void ReadHeader(ArchiveDatabase db, IPasswordProvider getTextPassword)
|
||||
@@ -772,10 +798,13 @@ namespace SharpCompress.Common.SevenZip
|
||||
case BlockType.WinAttributes:
|
||||
Log.Write("WinAttributes:");
|
||||
ReadAttributeVector(dataVector, numFiles, delegate(int i, uint? attr)
|
||||
{
|
||||
db.Files[i].Attrib = attr;
|
||||
Log.Write(" " + (attr.HasValue ? attr.Value.ToString("x8") : "n/a"));
|
||||
});
|
||||
{
|
||||
db.Files[i].Attrib = attr;
|
||||
Log.Write(" " +
|
||||
(attr.HasValue
|
||||
? attr.Value.ToString("x8")
|
||||
: "n/a"));
|
||||
});
|
||||
Log.WriteLine();
|
||||
break;
|
||||
case BlockType.EmptyStream:
|
||||
@@ -816,37 +845,49 @@ namespace SharpCompress.Common.SevenZip
|
||||
case BlockType.StartPos:
|
||||
Log.Write("StartPos:");
|
||||
ReadNumberVector(dataVector, numFiles, delegate(int i, long? startPos)
|
||||
{
|
||||
db.Files[i].StartPos = startPos;
|
||||
Log.Write(" " + (startPos.HasValue ? startPos.Value.ToString() : "n/a"));
|
||||
});
|
||||
{
|
||||
db.Files[i].StartPos = startPos;
|
||||
Log.Write(" " +
|
||||
(startPos.HasValue
|
||||
? startPos.Value.ToString()
|
||||
: "n/a"));
|
||||
});
|
||||
Log.WriteLine();
|
||||
break;
|
||||
case BlockType.CTime:
|
||||
Log.Write("CTime:");
|
||||
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
|
||||
{
|
||||
db.Files[i].CTime = time;
|
||||
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
|
||||
});
|
||||
{
|
||||
db.Files[i].CTime = time;
|
||||
Log.Write(" " +
|
||||
(time.HasValue
|
||||
? time.Value.ToString()
|
||||
: "n/a"));
|
||||
});
|
||||
Log.WriteLine();
|
||||
break;
|
||||
case BlockType.ATime:
|
||||
Log.Write("ATime:");
|
||||
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
|
||||
{
|
||||
db.Files[i].ATime = time;
|
||||
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
|
||||
});
|
||||
{
|
||||
db.Files[i].ATime = time;
|
||||
Log.Write(" " +
|
||||
(time.HasValue
|
||||
? time.Value.ToString()
|
||||
: "n/a"));
|
||||
});
|
||||
Log.WriteLine();
|
||||
break;
|
||||
case BlockType.MTime:
|
||||
Log.Write("MTime:");
|
||||
ReadDateTimeVector(dataVector, numFiles, delegate(int i, DateTime? time)
|
||||
{
|
||||
db.Files[i].MTime = time;
|
||||
Log.Write(" " + (time.HasValue ? time.Value.ToString() : "n/a"));
|
||||
});
|
||||
{
|
||||
db.Files[i].MTime = time;
|
||||
Log.Write(" " +
|
||||
(time.HasValue
|
||||
? time.Value.ToString()
|
||||
: "n/a"));
|
||||
});
|
||||
Log.WriteLine();
|
||||
break;
|
||||
case BlockType.Dummy:
|
||||
@@ -890,7 +931,10 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
}
|
||||
}
|
||||
finally { Log.PopIndent(); }
|
||||
finally
|
||||
{
|
||||
Log.PopIndent();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
@@ -1016,6 +1060,7 @@ namespace SharpCompress.Common.SevenZip
|
||||
internal int FileIndex;
|
||||
internal int FolderIndex;
|
||||
internal List<bool> ExtractStatuses = new List<bool>();
|
||||
|
||||
internal CExtractFolderInfo(int fileIndex, int folderIndex)
|
||||
{
|
||||
FileIndex = fileIndex;
|
||||
@@ -1069,14 +1114,8 @@ namespace SharpCompress.Common.SevenZip
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
get { throw new NotImplementedException(); }
|
||||
set { throw new NotImplementedException(); }
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
@@ -1097,6 +1136,7 @@ namespace SharpCompress.Common.SevenZip
|
||||
private Stream _stream;
|
||||
private long _rem;
|
||||
private int _currentIndex;
|
||||
|
||||
private void ProcessEmptyFiles()
|
||||
{
|
||||
while (_currentIndex < _extractStatuses.Count && _db.Files[_startIndex + _currentIndex].Size == 0)
|
||||
@@ -1107,6 +1147,7 @@ namespace SharpCompress.Common.SevenZip
|
||||
_currentIndex++;
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenFile()
|
||||
{
|
||||
bool skip = !_extractStatuses[_currentIndex];
|
||||
@@ -1122,6 +1163,7 @@ namespace SharpCompress.Common.SevenZip
|
||||
_stream = new MemoryStream();
|
||||
_rem = _db.Files[index].Size;
|
||||
}
|
||||
|
||||
public override void Write(byte[] buffer, int offset, int count)
|
||||
{
|
||||
while (count != 0)
|
||||
@@ -1172,7 +1214,8 @@ namespace SharpCompress.Common.SevenZip
|
||||
for (int j = 0; j < folderInfo.PackStreams.Count; j++)
|
||||
packSizes.Add(_db.PackSizes[packStreamIndex + j]);
|
||||
|
||||
s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes.ToArray(), folderInfo, pw);
|
||||
s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes.ToArray(), folderInfo,
|
||||
pw);
|
||||
_cachedStreams.Add(folderIndex, s);
|
||||
}
|
||||
return s;
|
||||
@@ -1255,7 +1298,8 @@ namespace SharpCompress.Common.SevenZip
|
||||
|
||||
// TODO: If the decoding fails the last file may be extracted incompletely. Delete it?
|
||||
|
||||
Stream s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes.ToArray(), folderInfo, pw);
|
||||
Stream s = DecoderStreamHelper.CreateDecoderStream(_stream, folderStartPackPos, packSizes.ToArray(),
|
||||
folderInfo, pw);
|
||||
byte[] buffer = new byte[4 << 10];
|
||||
for (; ; )
|
||||
{
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
namespace SharpCompress.Common.SevenZip
|
||||
{
|
||||
internal class CBindPair
|
||||
{
|
||||
internal int InIndex;
|
||||
internal int OutIndex;
|
||||
}
|
||||
internal class CBindPair
|
||||
{
|
||||
internal int InIndex;
|
||||
internal int OutIndex;
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,10 @@
|
||||
namespace SharpCompress.Common.SevenZip
|
||||
{
|
||||
internal class CCoderInfo
|
||||
{
|
||||
internal CMethodId MethodId;
|
||||
internal byte[] Props;
|
||||
internal int NumInStreams;
|
||||
internal int NumOutStreams;
|
||||
}
|
||||
internal class CCoderInfo
|
||||
{
|
||||
internal CMethodId MethodId;
|
||||
internal byte[] Props;
|
||||
internal int NumInStreams;
|
||||
internal int NumOutStreams;
|
||||
}
|
||||
}
|
||||
@@ -11,8 +11,16 @@ namespace SharpCompress.Common.SevenZip
|
||||
|
||||
public bool HasStream { get; internal set; }
|
||||
public bool IsDir { get; internal set; }
|
||||
public bool CrcDefined { get { return Crc != null; } }
|
||||
public bool AttribDefined { get { return Attrib != null; } }
|
||||
|
||||
public bool CrcDefined
|
||||
{
|
||||
get { return Crc != null; }
|
||||
}
|
||||
|
||||
public bool AttribDefined
|
||||
{
|
||||
get { return Attrib != null; }
|
||||
}
|
||||
|
||||
public void SetAttrib(uint attrib)
|
||||
{
|
||||
|
||||
@@ -4,132 +4,136 @@ using SharpCompress.Compressor.LZMA;
|
||||
|
||||
namespace SharpCompress.Common.SevenZip
|
||||
{
|
||||
internal class CFolder
|
||||
{
|
||||
internal List<CCoderInfo> Coders = new List<CCoderInfo>();
|
||||
internal List<CBindPair> BindPairs = new List<CBindPair>();
|
||||
internal List<int> PackStreams = new List<int>();
|
||||
internal int FirstPackStreamId;
|
||||
internal List<long> UnpackSizes = new List<long>();
|
||||
internal uint? UnpackCRC;
|
||||
internal bool UnpackCRCDefined { get { return UnpackCRC != null; } }
|
||||
internal class CFolder
|
||||
{
|
||||
internal List<CCoderInfo> Coders = new List<CCoderInfo>();
|
||||
internal List<CBindPair> BindPairs = new List<CBindPair>();
|
||||
internal List<int> PackStreams = new List<int>();
|
||||
internal int FirstPackStreamId;
|
||||
internal List<long> UnpackSizes = new List<long>();
|
||||
internal uint? UnpackCRC;
|
||||
|
||||
public long GetUnpackSize()
|
||||
{
|
||||
if(UnpackSizes.Count == 0)
|
||||
return 0;
|
||||
internal bool UnpackCRCDefined
|
||||
{
|
||||
get { return UnpackCRC != null; }
|
||||
}
|
||||
|
||||
for(int i = UnpackSizes.Count - 1; i >= 0; i--)
|
||||
if(FindBindPairForOutStream(i) < 0)
|
||||
return UnpackSizes[i];
|
||||
public long GetUnpackSize()
|
||||
{
|
||||
if (UnpackSizes.Count == 0)
|
||||
return 0;
|
||||
|
||||
throw new Exception();
|
||||
}
|
||||
for (int i = UnpackSizes.Count - 1; i >= 0; i--)
|
||||
if (FindBindPairForOutStream(i) < 0)
|
||||
return UnpackSizes[i];
|
||||
|
||||
public int GetNumOutStreams()
|
||||
{
|
||||
int count = 0;
|
||||
for(int i = 0; i < Coders.Count; i++)
|
||||
count += Coders[i].NumOutStreams;
|
||||
throw new Exception();
|
||||
}
|
||||
|
||||
return count;
|
||||
}
|
||||
public int GetNumOutStreams()
|
||||
{
|
||||
int count = 0;
|
||||
for (int i = 0; i < Coders.Count; i++)
|
||||
count += Coders[i].NumOutStreams;
|
||||
|
||||
public int FindBindPairForInStream(int inStreamIndex)
|
||||
{
|
||||
for(int i = 0; i < BindPairs.Count; i++)
|
||||
if(BindPairs[i].InIndex == inStreamIndex)
|
||||
return i;
|
||||
return count;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
public int FindBindPairForInStream(int inStreamIndex)
|
||||
{
|
||||
for (int i = 0; i < BindPairs.Count; i++)
|
||||
if (BindPairs[i].InIndex == inStreamIndex)
|
||||
return i;
|
||||
|
||||
public int FindBindPairForOutStream(int outStreamIndex)
|
||||
{
|
||||
for(int i = 0; i < BindPairs.Count; i++)
|
||||
if(BindPairs[i].OutIndex == outStreamIndex)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
public int FindBindPairForOutStream(int outStreamIndex)
|
||||
{
|
||||
for (int i = 0; i < BindPairs.Count; i++)
|
||||
if (BindPairs[i].OutIndex == outStreamIndex)
|
||||
return i;
|
||||
|
||||
public int FindPackStreamArrayIndex(int inStreamIndex)
|
||||
{
|
||||
for(int i = 0; i < PackStreams.Count; i++)
|
||||
if(PackStreams[i] == inStreamIndex)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
public int FindPackStreamArrayIndex(int inStreamIndex)
|
||||
{
|
||||
for (int i = 0; i < PackStreams.Count; i++)
|
||||
if (PackStreams[i] == inStreamIndex)
|
||||
return i;
|
||||
|
||||
public bool IsEncrypted()
|
||||
{
|
||||
for(int i = Coders.Count - 1; i >= 0; i--)
|
||||
if(Coders[i].MethodId == CMethodId.kAES)
|
||||
return true;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
public bool IsEncrypted()
|
||||
{
|
||||
for (int i = Coders.Count - 1; i >= 0; i--)
|
||||
if (Coders[i].MethodId == CMethodId.kAES)
|
||||
return true;
|
||||
|
||||
public bool CheckStructure()
|
||||
{
|
||||
const int kNumCodersMax = 32; // don't change it
|
||||
const int kMaskSize = 32; // it must be >= kNumCodersMax
|
||||
const int kNumBindsMax = 32;
|
||||
|
||||
if(Coders.Count > kNumCodersMax || BindPairs.Count > kNumBindsMax)
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
var v = new BitVector(BindPairs.Count + PackStreams.Count);
|
||||
public bool CheckStructure()
|
||||
{
|
||||
const int kNumCodersMax = 32; // don't change it
|
||||
const int kMaskSize = 32; // it must be >= kNumCodersMax
|
||||
const int kNumBindsMax = 32;
|
||||
|
||||
for(int i = 0; i < BindPairs.Count; i++)
|
||||
if(v.GetAndSet(BindPairs[i].InIndex))
|
||||
return false;
|
||||
if (Coders.Count > kNumCodersMax || BindPairs.Count > kNumBindsMax)
|
||||
return false;
|
||||
|
||||
for(int i = 0; i < PackStreams.Count; i++)
|
||||
if(v.GetAndSet(PackStreams[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
{
|
||||
var v = new BitVector(UnpackSizes.Count);
|
||||
for(int i = 0; i < BindPairs.Count; i++)
|
||||
if(v.GetAndSet(BindPairs[i].OutIndex))
|
||||
return false;
|
||||
}
|
||||
|
||||
uint[] mask = new uint[kMaskSize];
|
||||
|
||||
{
|
||||
List<int> inStreamToCoder = new List<int>();
|
||||
List<int> outStreamToCoder = new List<int>();
|
||||
for(int i = 0; i < Coders.Count; i++)
|
||||
{
|
||||
CCoderInfo coder = Coders[i];
|
||||
for(int j = 0; j < coder.NumInStreams; j++)
|
||||
inStreamToCoder.Add(i);
|
||||
for(int j = 0; j < coder.NumOutStreams; j++)
|
||||
outStreamToCoder.Add(i);
|
||||
var v = new BitVector(BindPairs.Count + PackStreams.Count);
|
||||
|
||||
for (int i = 0; i < BindPairs.Count; i++)
|
||||
if (v.GetAndSet(BindPairs[i].InIndex))
|
||||
return false;
|
||||
|
||||
for (int i = 0; i < PackStreams.Count; i++)
|
||||
if (v.GetAndSet(PackStreams[i]))
|
||||
return false;
|
||||
}
|
||||
|
||||
for(int i = 0; i < BindPairs.Count; i++)
|
||||
{
|
||||
CBindPair bp = BindPairs[i];
|
||||
mask[inStreamToCoder[bp.InIndex]] |= (1u << outStreamToCoder[bp.OutIndex]);
|
||||
var v = new BitVector(UnpackSizes.Count);
|
||||
for (int i = 0; i < BindPairs.Count; i++)
|
||||
if (v.GetAndSet(BindPairs[i].OutIndex))
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for(int i = 0; i < kMaskSize; i++)
|
||||
for(int j = 0; j < kMaskSize; j++)
|
||||
if(((1u << j) & mask[i]) != 0)
|
||||
mask[i] |= mask[j];
|
||||
uint[] mask = new uint[kMaskSize];
|
||||
|
||||
for(int i = 0; i < kMaskSize; i++)
|
||||
if(((1u << i) & mask[i]) != 0)
|
||||
return false;
|
||||
{
|
||||
List<int> inStreamToCoder = new List<int>();
|
||||
List<int> outStreamToCoder = new List<int>();
|
||||
for (int i = 0; i < Coders.Count; i++)
|
||||
{
|
||||
CCoderInfo coder = Coders[i];
|
||||
for (int j = 0; j < coder.NumInStreams; j++)
|
||||
inStreamToCoder.Add(i);
|
||||
for (int j = 0; j < coder.NumOutStreams; j++)
|
||||
outStreamToCoder.Add(i);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
for (int i = 0; i < BindPairs.Count; i++)
|
||||
{
|
||||
CBindPair bp = BindPairs[i];
|
||||
mask[inStreamToCoder[bp.InIndex]] |= (1u << outStreamToCoder[bp.OutIndex]);
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < kMaskSize; i++)
|
||||
for (int j = 0; j < kMaskSize; j++)
|
||||
if (((1u << j) & mask[i]) != 0)
|
||||
mask[i] |= mask[j];
|
||||
|
||||
for (int i = 0; i < kMaskSize; i++)
|
||||
if (((1u << i) & mask[i]) != 0)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,7 @@
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
return obj is CMethodId && (CMethodId)obj == this;
|
||||
return obj is CMethodId && (CMethodId) obj == this;
|
||||
}
|
||||
|
||||
public bool Equals(CMethodId other)
|
||||
@@ -47,9 +47,9 @@
|
||||
public int GetLength()
|
||||
{
|
||||
int bytes = 0;
|
||||
for(ulong value = Id; value != 0; value >>= 8)
|
||||
for (ulong value = Id; value != 0; value >>= 8)
|
||||
bytes++;
|
||||
return bytes;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,58 +5,58 @@ using SharpCompress.Compressor.LZMA;
|
||||
|
||||
namespace SharpCompress.Common.SevenZip
|
||||
{
|
||||
internal struct CStreamSwitch: IDisposable
|
||||
{
|
||||
private ArchiveReader _archive;
|
||||
private bool _needRemove;
|
||||
private bool _active;
|
||||
internal struct CStreamSwitch : IDisposable
|
||||
{
|
||||
private ArchiveReader _archive;
|
||||
private bool _needRemove;
|
||||
private bool _active;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if(_active)
|
||||
{
|
||||
_active = false;
|
||||
Log.WriteLine("[end of switch]");
|
||||
}
|
||||
public void Dispose()
|
||||
{
|
||||
if (_active)
|
||||
{
|
||||
_active = false;
|
||||
Log.WriteLine("[end of switch]");
|
||||
}
|
||||
|
||||
if(_needRemove)
|
||||
{
|
||||
_needRemove = false;
|
||||
_archive.DeleteByteStream();
|
||||
}
|
||||
}
|
||||
if (_needRemove)
|
||||
{
|
||||
_needRemove = false;
|
||||
_archive.DeleteByteStream();
|
||||
}
|
||||
}
|
||||
|
||||
public void Set(ArchiveReader archive, byte[] dataVector)
|
||||
{
|
||||
Dispose();
|
||||
_archive = archive;
|
||||
_archive.AddByteStream(dataVector, 0, dataVector.Length);
|
||||
_needRemove = true;
|
||||
_active = true;
|
||||
}
|
||||
|
||||
public void Set(ArchiveReader archive, List<byte[]> dataVector)
|
||||
{
|
||||
Dispose();
|
||||
_active = true;
|
||||
|
||||
byte external = archive.ReadByte();
|
||||
if(external != 0)
|
||||
{
|
||||
int dataIndex = archive.ReadNum();
|
||||
if(dataIndex < 0 || dataIndex >= dataVector.Count)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
Log.WriteLine("[switch to stream {0}]", dataIndex);
|
||||
public void Set(ArchiveReader archive, byte[] dataVector)
|
||||
{
|
||||
Dispose();
|
||||
_archive = archive;
|
||||
_archive.AddByteStream(dataVector[dataIndex], 0, dataVector[dataIndex].Length);
|
||||
_archive.AddByteStream(dataVector, 0, dataVector.Length);
|
||||
_needRemove = true;
|
||||
_active = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.WriteLine("[inline data]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Set(ArchiveReader archive, List<byte[]> dataVector)
|
||||
{
|
||||
Dispose();
|
||||
_active = true;
|
||||
|
||||
byte external = archive.ReadByte();
|
||||
if (external != 0)
|
||||
{
|
||||
int dataIndex = archive.ReadNum();
|
||||
if (dataIndex < 0 || dataIndex >= dataVector.Count)
|
||||
throw new InvalidOperationException();
|
||||
|
||||
Log.WriteLine("[switch to stream {0}]", dataIndex);
|
||||
_archive = archive;
|
||||
_archive.AddByteStream(dataVector[dataIndex], 0, dataVector[dataIndex].Length);
|
||||
_needRemove = true;
|
||||
_active = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.WriteLine("[inline data]");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,164 +5,164 @@ using SharpCompress.Compressor.LZMA;
|
||||
|
||||
namespace SharpCompress.Common.SevenZip
|
||||
{
|
||||
internal class DataReader
|
||||
{
|
||||
#region Static Methods
|
||||
internal class DataReader
|
||||
{
|
||||
#region Static Methods
|
||||
|
||||
public static uint Get32(byte[] buffer, int offset)
|
||||
{
|
||||
return (uint)buffer[offset]
|
||||
+ ((uint)buffer[offset + 1] << 8)
|
||||
+ ((uint)buffer[offset + 2] << 16)
|
||||
+ ((uint)buffer[offset + 3] << 24);
|
||||
}
|
||||
public static uint Get32(byte[] buffer, int offset)
|
||||
{
|
||||
return (uint) buffer[offset]
|
||||
+ ((uint) buffer[offset + 1] << 8)
|
||||
+ ((uint) buffer[offset + 2] << 16)
|
||||
+ ((uint) buffer[offset + 3] << 24);
|
||||
}
|
||||
|
||||
public static ulong Get64(byte[] buffer, int offset)
|
||||
{
|
||||
return (ulong)buffer[offset]
|
||||
+ ((ulong)buffer[offset + 1] << 8)
|
||||
+ ((ulong)buffer[offset + 2] << 16)
|
||||
+ ((ulong)buffer[offset + 3] << 24)
|
||||
+ ((ulong)buffer[offset + 4] << 32)
|
||||
+ ((ulong)buffer[offset + 5] << 40)
|
||||
+ ((ulong)buffer[offset + 6] << 48)
|
||||
+ ((ulong)buffer[offset + 7] << 56);
|
||||
}
|
||||
public static ulong Get64(byte[] buffer, int offset)
|
||||
{
|
||||
return (ulong) buffer[offset]
|
||||
+ ((ulong) buffer[offset + 1] << 8)
|
||||
+ ((ulong) buffer[offset + 2] << 16)
|
||||
+ ((ulong) buffer[offset + 3] << 24)
|
||||
+ ((ulong) buffer[offset + 4] << 32)
|
||||
+ ((ulong) buffer[offset + 5] << 40)
|
||||
+ ((ulong) buffer[offset + 6] << 48)
|
||||
+ ((ulong) buffer[offset + 7] << 56);
|
||||
}
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Variables
|
||||
#region Variables
|
||||
|
||||
private byte[] _buffer;
|
||||
private int _origin;
|
||||
private int _offset;
|
||||
private int _ending;
|
||||
private byte[] _buffer;
|
||||
private int _origin;
|
||||
private int _offset;
|
||||
private int _ending;
|
||||
|
||||
#endregion
|
||||
#endregion
|
||||
|
||||
#region Public Methods
|
||||
#region Public Methods
|
||||
|
||||
public DataReader(byte[] buffer, int offset, int length)
|
||||
{
|
||||
_buffer = buffer;
|
||||
_origin = offset;
|
||||
_offset = offset;
|
||||
_ending = offset + length;
|
||||
}
|
||||
public DataReader(byte[] buffer, int offset, int length)
|
||||
{
|
||||
_buffer = buffer;
|
||||
_origin = offset;
|
||||
_offset = offset;
|
||||
_ending = offset + length;
|
||||
}
|
||||
|
||||
public int Offset
|
||||
{
|
||||
get { return _offset; }
|
||||
}
|
||||
public int Offset
|
||||
{
|
||||
get { return _offset; }
|
||||
}
|
||||
|
||||
public Byte ReadByte()
|
||||
{
|
||||
if(_offset >= _ending)
|
||||
throw new EndOfStreamException();
|
||||
public Byte ReadByte()
|
||||
{
|
||||
if (_offset >= _ending)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
return _buffer[_offset++];
|
||||
}
|
||||
return _buffer[_offset++];
|
||||
}
|
||||
|
||||
public void ReadBytes(byte[] buffer, int offset, int length)
|
||||
{
|
||||
if(length > _ending - _offset)
|
||||
throw new EndOfStreamException();
|
||||
public void ReadBytes(byte[] buffer, int offset, int length)
|
||||
{
|
||||
if (length > _ending - _offset)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
while(length-- > 0)
|
||||
buffer[offset++] = _buffer[_offset++];
|
||||
}
|
||||
while (length-- > 0)
|
||||
buffer[offset++] = _buffer[_offset++];
|
||||
}
|
||||
|
||||
public void SkipData(long size)
|
||||
{
|
||||
if(size > _ending - _offset)
|
||||
throw new EndOfStreamException();
|
||||
public void SkipData(long size)
|
||||
{
|
||||
if (size > _ending - _offset)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
_offset += (int)size;
|
||||
Log.WriteLine("SkipData {0}", size);
|
||||
}
|
||||
_offset += (int) size;
|
||||
Log.WriteLine("SkipData {0}", size);
|
||||
}
|
||||
|
||||
public void SkipData()
|
||||
{
|
||||
SkipData(checked((long)ReadNumber()));
|
||||
}
|
||||
public void SkipData()
|
||||
{
|
||||
SkipData(checked((long) ReadNumber()));
|
||||
}
|
||||
|
||||
public ulong ReadNumber()
|
||||
{
|
||||
if(_offset >= _ending)
|
||||
throw new EndOfStreamException();
|
||||
public ulong ReadNumber()
|
||||
{
|
||||
if (_offset >= _ending)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
byte firstByte = _buffer[_offset++];
|
||||
byte mask = 0x80;
|
||||
ulong value = 0;
|
||||
byte firstByte = _buffer[_offset++];
|
||||
byte mask = 0x80;
|
||||
ulong value = 0;
|
||||
|
||||
for(int i = 0; i < 8; i++)
|
||||
{
|
||||
if((firstByte & mask) == 0)
|
||||
for (int i = 0; i < 8; i++)
|
||||
{
|
||||
ulong highPart = firstByte & (mask - 1u);
|
||||
value += highPart << (i * 8);
|
||||
return value;
|
||||
if ((firstByte & mask) == 0)
|
||||
{
|
||||
ulong highPart = firstByte & (mask - 1u);
|
||||
value += highPart << (i*8);
|
||||
return value;
|
||||
}
|
||||
|
||||
if (_offset >= _ending)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
value |= (ulong) _buffer[_offset++] << (8*i);
|
||||
mask >>= 1;
|
||||
}
|
||||
|
||||
if(_offset >= _ending)
|
||||
throw new EndOfStreamException();
|
||||
return value;
|
||||
}
|
||||
|
||||
value |= (ulong)_buffer[_offset++] << (8 * i);
|
||||
mask >>= 1;
|
||||
}
|
||||
public int ReadNum()
|
||||
{
|
||||
ulong value = ReadNumber();
|
||||
if (value > Int32.MaxValue)
|
||||
throw new NotSupportedException();
|
||||
|
||||
return value;
|
||||
}
|
||||
return (int) value;
|
||||
}
|
||||
|
||||
public int ReadNum()
|
||||
{
|
||||
ulong value = ReadNumber();
|
||||
if(value > Int32.MaxValue)
|
||||
throw new NotSupportedException();
|
||||
public uint ReadUInt32()
|
||||
{
|
||||
if (_offset + 4 > _ending)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
return (int)value;
|
||||
}
|
||||
uint res = Get32(_buffer, _offset);
|
||||
_offset += 4;
|
||||
return res;
|
||||
}
|
||||
|
||||
public uint ReadUInt32()
|
||||
{
|
||||
if(_offset + 4 > _ending)
|
||||
throw new EndOfStreamException();
|
||||
public ulong ReadUInt64()
|
||||
{
|
||||
if (_offset + 8 > _ending)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
uint res = Get32(_buffer, _offset);
|
||||
_offset += 4;
|
||||
return res;
|
||||
}
|
||||
ulong res = Get64(_buffer, _offset);
|
||||
_offset += 8;
|
||||
return res;
|
||||
}
|
||||
|
||||
public ulong ReadUInt64()
|
||||
{
|
||||
if(_offset + 8 > _ending)
|
||||
throw new EndOfStreamException();
|
||||
public string ReadString()
|
||||
{
|
||||
int ending = _offset;
|
||||
|
||||
ulong res = Get64(_buffer, _offset);
|
||||
_offset += 8;
|
||||
return res;
|
||||
}
|
||||
for (;;)
|
||||
{
|
||||
if (ending + 2 > _ending)
|
||||
throw new EndOfStreamException();
|
||||
|
||||
public string ReadString()
|
||||
{
|
||||
int ending = _offset;
|
||||
if (_buffer[ending] == 0 && _buffer[ending + 1] == 0)
|
||||
break;
|
||||
|
||||
for(; ; )
|
||||
{
|
||||
if(ending + 2 > _ending)
|
||||
throw new EndOfStreamException();
|
||||
ending += 2;
|
||||
}
|
||||
|
||||
if(_buffer[ending] == 0 && _buffer[ending + 1] == 0)
|
||||
break;
|
||||
string str = Encoding.Unicode.GetString(_buffer, _offset, ending - _offset);
|
||||
_offset = ending + 2;
|
||||
return str;
|
||||
}
|
||||
|
||||
ending += 2;
|
||||
}
|
||||
|
||||
string str = Encoding.Unicode.GetString(_buffer, _offset, ending - _offset);
|
||||
_offset = ending + 2;
|
||||
return str;
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -14,10 +14,7 @@ namespace SharpCompress.Common.SevenZip
|
||||
|
||||
public override CompressionType CompressionType
|
||||
{
|
||||
get
|
||||
{
|
||||
return FilePart.CompressionType;
|
||||
}
|
||||
get { return FilePart.CompressionType; }
|
||||
}
|
||||
|
||||
public override uint Crc
|
||||
@@ -37,7 +34,7 @@ namespace SharpCompress.Common.SevenZip
|
||||
|
||||
public override long Size
|
||||
{
|
||||
get { return (long)FilePart.Header.Size; }
|
||||
get { return (long) FilePart.Header.Size; }
|
||||
}
|
||||
|
||||
public override DateTime? LastModifiedTime
|
||||
@@ -84,4 +81,4 @@ namespace SharpCompress.Common.SevenZip
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -73,15 +73,15 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
|
||||
//copied from DecoderRegistry
|
||||
const uint k_Copy = 0x0;
|
||||
const uint k_Delta = 3;
|
||||
const uint k_LZMA2 = 0x21;
|
||||
const uint k_LZMA = 0x030101;
|
||||
const uint k_PPMD = 0x030401;
|
||||
const uint k_BCJ = 0x03030103;
|
||||
const uint k_BCJ2 = 0x0303011B;
|
||||
const uint k_Deflate = 0x040108;
|
||||
const uint k_BZip2 = 0x040202;
|
||||
private const uint k_Copy = 0x0;
|
||||
private const uint k_Delta = 3;
|
||||
private const uint k_LZMA2 = 0x21;
|
||||
private const uint k_LZMA = 0x030101;
|
||||
private const uint k_PPMD = 0x030401;
|
||||
private const uint k_BCJ = 0x03030103;
|
||||
private const uint k_BCJ2 = 0x0303011B;
|
||||
private const uint k_Deflate = 0x040108;
|
||||
private const uint k_BZip2 = 0x040202;
|
||||
|
||||
internal CompressionType GetCompression()
|
||||
{
|
||||
@@ -106,4 +106,4 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,4 @@ namespace SharpCompress.Common.SevenZip
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,18 +10,19 @@ namespace SharpCompress.Common.Tar.Headers
|
||||
internal enum EntryType : byte
|
||||
{
|
||||
File = 0,
|
||||
OldFile = (byte)'0',
|
||||
HardLink = (byte)'1',
|
||||
SymLink = (byte)'2',
|
||||
CharDevice = (byte)'3',
|
||||
BlockDevice = (byte)'4',
|
||||
Directory = (byte)'5',
|
||||
Fifo = (byte)'6',
|
||||
LongLink = (byte)'K',
|
||||
LongName = (byte)'L',
|
||||
SparseFile = (byte)'S',
|
||||
VolumeHeader = (byte)'V',
|
||||
OldFile = (byte) '0',
|
||||
HardLink = (byte) '1',
|
||||
SymLink = (byte) '2',
|
||||
CharDevice = (byte) '3',
|
||||
BlockDevice = (byte) '4',
|
||||
Directory = (byte) '5',
|
||||
Fifo = (byte) '6',
|
||||
LongLink = (byte) 'K',
|
||||
LongName = (byte) 'L',
|
||||
SparseFile = (byte) 'S',
|
||||
VolumeHeader = (byte) 'V',
|
||||
}
|
||||
|
||||
internal class TarHeader
|
||||
{
|
||||
internal static readonly DateTime Epoch = new DateTime(1970, 1, 1, 0, 0, 0);
|
||||
@@ -55,10 +56,10 @@ namespace SharpCompress.Common.Tar.Headers
|
||||
WriteOctalBytes(0, buffer, 108, 8);
|
||||
WriteOctalBytes(0, buffer, 116, 8);
|
||||
WriteOctalBytes(Size, buffer, 124, 12);
|
||||
var time = (long)(LastModifiedTime - Epoch).TotalSeconds;
|
||||
var time = (long) (LastModifiedTime - Epoch).TotalSeconds;
|
||||
WriteOctalBytes(time, buffer, 136, 12);
|
||||
|
||||
buffer[156] = (byte)EntryType;
|
||||
buffer[156] = (byte) EntryType;
|
||||
|
||||
//Encoding.UTF8.GetBytes("magic").CopyTo(buffer, 257);
|
||||
if (Name.Length > 100)
|
||||
@@ -99,7 +100,7 @@ namespace SharpCompress.Common.Tar.Headers
|
||||
//Mode = ReadASCIIInt32Base8(buffer, 100, 7);
|
||||
//UserId = ReadASCIIInt32Base8(buffer, 108, 7);
|
||||
//GroupId = ReadASCIIInt32Base8(buffer, 116, 7);
|
||||
EntryType = (EntryType)buffer[156];
|
||||
EntryType = (EntryType) buffer[156];
|
||||
if ((buffer[124] & 0x80) == 0x80) // if size in binary
|
||||
{
|
||||
long sizeBigEndian = BitConverter.ToInt64(buffer, 0x80);
|
||||
@@ -141,7 +142,7 @@ namespace SharpCompress.Common.Tar.Headers
|
||||
|
||||
for (i = 0; i < length - 1 && i < name.Length; ++i)
|
||||
{
|
||||
buffer[offset + i] = (byte)name[i];
|
||||
buffer[offset + i] = (byte) name[i];
|
||||
}
|
||||
|
||||
for (; i < length; ++i)
|
||||
@@ -156,11 +157,11 @@ namespace SharpCompress.Common.Tar.Headers
|
||||
int shift = length - val.Length - 1;
|
||||
for (int i = 0; i < shift; i++)
|
||||
{
|
||||
buffer[offset + i] = (byte)' ';
|
||||
buffer[offset + i] = (byte) ' ';
|
||||
}
|
||||
for (int i = 0; i < val.Length; i++)
|
||||
{
|
||||
buffer[offset + i + shift] = (byte)val[i];
|
||||
buffer[offset + i + shift] = (byte) val[i];
|
||||
}
|
||||
buffer[offset + length] = 0;
|
||||
}
|
||||
@@ -226,8 +227,9 @@ namespace SharpCompress.Common.Tar.Headers
|
||||
}
|
||||
return headerChecksum;
|
||||
}
|
||||
|
||||
public long? DataStartPosition { get; set; }
|
||||
|
||||
public string Magic { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -82,7 +82,8 @@ namespace SharpCompress.Common.Tar
|
||||
get { return filePart.AsEnumerable<FilePart>(); }
|
||||
}
|
||||
|
||||
internal static IEnumerable<TarEntry> GetEntries(StreamingMode mode, Stream stream, CompressionType compressionType)
|
||||
internal static IEnumerable<TarEntry> GetEntries(StreamingMode mode, Stream stream,
|
||||
CompressionType compressionType)
|
||||
{
|
||||
foreach (TarHeader h in TarHeaderFactory.ReadHeader(mode, stream))
|
||||
{
|
||||
|
||||
@@ -13,6 +13,7 @@ namespace SharpCompress.Common.Tar
|
||||
this.seekableStream = seekableStream;
|
||||
this.Header = header;
|
||||
}
|
||||
|
||||
internal TarHeader Header { get; private set; }
|
||||
|
||||
internal override string FilePartName
|
||||
@@ -35,4 +36,4 @@ namespace SharpCompress.Common.Tar
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -50,7 +50,7 @@ namespace SharpCompress.Common.Tar
|
||||
|
||||
private static long PadTo512(long size)
|
||||
{
|
||||
int zeros = (int)(size % 512);
|
||||
int zeros = (int) (size%512);
|
||||
if (zeros == 0)
|
||||
{
|
||||
return size;
|
||||
@@ -58,4 +58,4 @@ namespace SharpCompress.Common.Tar
|
||||
return 512 - zeros + size;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,7 +16,7 @@ namespace SharpCompress.Common.Tar
|
||||
{
|
||||
if (disposing)
|
||||
{
|
||||
int skipBytes = this.amountRead % 512;
|
||||
int skipBytes = this.amountRead%512;
|
||||
if (skipBytes == 0)
|
||||
{
|
||||
return;
|
||||
@@ -31,40 +31,23 @@ namespace SharpCompress.Common.Tar
|
||||
}
|
||||
}
|
||||
|
||||
private long BytesLeftToRead
|
||||
{
|
||||
get;
|
||||
set;
|
||||
}
|
||||
private long BytesLeftToRead { get; set; }
|
||||
|
||||
public Stream Stream
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
public Stream Stream { get; private set; }
|
||||
|
||||
public override bool CanRead
|
||||
{
|
||||
get
|
||||
{
|
||||
return true;
|
||||
}
|
||||
get { return true; }
|
||||
}
|
||||
|
||||
public override bool CanSeek
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override bool CanWrite
|
||||
{
|
||||
get
|
||||
{
|
||||
return false;
|
||||
}
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public override void Flush()
|
||||
@@ -74,29 +57,20 @@ namespace SharpCompress.Common.Tar
|
||||
|
||||
public override long Length
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
get { throw new System.NotImplementedException(); }
|
||||
}
|
||||
|
||||
public override long Position
|
||||
{
|
||||
get
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
set
|
||||
{
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
get { throw new System.NotImplementedException(); }
|
||||
set { throw new System.NotImplementedException(); }
|
||||
}
|
||||
|
||||
public override int Read(byte[] buffer, int offset, int count)
|
||||
{
|
||||
if (this.BytesLeftToRead < count)
|
||||
{
|
||||
count = (int)this.BytesLeftToRead;
|
||||
count = (int) this.BytesLeftToRead;
|
||||
}
|
||||
int read = this.Stream.Read(buffer, offset, count);
|
||||
if (read > 0)
|
||||
@@ -122,4 +96,4 @@ namespace SharpCompress.Common.Tar
|
||||
throw new System.NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -16,4 +16,4 @@ namespace SharpCompress.Common.Tar
|
||||
}
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,10 +15,7 @@ namespace SharpCompress.Common
|
||||
|
||||
internal Stream Stream
|
||||
{
|
||||
get
|
||||
{
|
||||
return new NonDisposingStream(actualStream);
|
||||
}
|
||||
get { return new NonDisposingStream(actualStream); }
|
||||
}
|
||||
|
||||
internal Options Options { get; private set; }
|
||||
@@ -27,27 +24,19 @@ namespace SharpCompress.Common
|
||||
/// RarArchive is the first volume of a multi-part archive.
|
||||
/// Only Rar 3.0 format and higher
|
||||
/// </summary>
|
||||
public abstract bool IsFirstVolume
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract bool IsFirstVolume { get; }
|
||||
|
||||
/// <summary>
|
||||
/// RarArchive is part of a multi-part archive.
|
||||
/// </summary>
|
||||
public abstract bool IsMultiVolume
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract bool IsMultiVolume { get; }
|
||||
|
||||
#if !PORTABLE
|
||||
public abstract FileInfo VolumeFile
|
||||
{
|
||||
get;
|
||||
}
|
||||
public abstract FileInfo VolumeFile { get; }
|
||||
#endif
|
||||
|
||||
private bool disposed;
|
||||
|
||||
public void Dispose()
|
||||
{
|
||||
if (!Options.HasFlag(Options.KeepStreamsOpen) && !disposed)
|
||||
@@ -57,4 +46,4 @@ namespace SharpCompress.Common
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -49,4 +49,4 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
|
||||
public ushort TotalNumberOfEntries { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -13,8 +13,8 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
{
|
||||
Version = reader.ReadUInt16();
|
||||
VersionNeededToExtract = reader.ReadUInt16();
|
||||
Flags = (HeaderFlags)reader.ReadUInt16();
|
||||
CompressionMethod = (ZipCompressionMethod)reader.ReadUInt16();
|
||||
Flags = (HeaderFlags) reader.ReadUInt16();
|
||||
CompressionMethod = (ZipCompressionMethod) reader.ReadUInt16();
|
||||
LastModifiedTime = reader.ReadUInt16();
|
||||
LastModifiedDate = reader.ReadUInt16();
|
||||
Crc = reader.ReadUInt32();
|
||||
@@ -40,8 +40,8 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
{
|
||||
writer.Write(Version);
|
||||
writer.Write(VersionNeededToExtract);
|
||||
writer.Write((ushort)Flags);
|
||||
writer.Write((ushort)CompressionMethod);
|
||||
writer.Write((ushort) Flags);
|
||||
writer.Write((ushort) CompressionMethod);
|
||||
writer.Write(LastModifiedTime);
|
||||
writer.Write(LastModifiedDate);
|
||||
writer.Write(Crc);
|
||||
@@ -49,10 +49,10 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
writer.Write(UncompressedSize);
|
||||
|
||||
byte[] nameBytes = EncodeString(Name);
|
||||
writer.Write((ushort)nameBytes.Length);
|
||||
writer.Write((ushort) nameBytes.Length);
|
||||
//writer.Write((ushort)Extra.Length);
|
||||
writer.Write((ushort)0);
|
||||
writer.Write((ushort)Comment.Length);
|
||||
writer.Write((ushort) 0);
|
||||
writer.Write((ushort) Comment.Length);
|
||||
|
||||
writer.Write(DiskNumberStart);
|
||||
writer.Write(InternalFileAttributes);
|
||||
@@ -78,4 +78,4 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
|
||||
public string Comment { get; private set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,4 +12,4 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
EnhancedDeflate = 16,
|
||||
UTF8 = 2048
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
{
|
||||
WinZipAes = 0x9901,
|
||||
}
|
||||
|
||||
internal class ExtraData
|
||||
{
|
||||
internal ExtraDataType Type { get; set; }
|
||||
@@ -23,8 +24,8 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
internal override void Read(BinaryReader reader)
|
||||
{
|
||||
Version = reader.ReadUInt16();
|
||||
Flags = (HeaderFlags)reader.ReadUInt16();
|
||||
CompressionMethod = (ZipCompressionMethod)reader.ReadUInt16();
|
||||
Flags = (HeaderFlags) reader.ReadUInt16();
|
||||
CompressionMethod = (ZipCompressionMethod) reader.ReadUInt16();
|
||||
LastModifiedTime = reader.ReadUInt16();
|
||||
LastModifiedDate = reader.ReadUInt16();
|
||||
Crc = reader.ReadUInt32();
|
||||
@@ -41,8 +42,8 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
internal override void Write(BinaryWriter writer)
|
||||
{
|
||||
writer.Write(Version);
|
||||
writer.Write((ushort)Flags);
|
||||
writer.Write((ushort)CompressionMethod);
|
||||
writer.Write((ushort) Flags);
|
||||
writer.Write((ushort) CompressionMethod);
|
||||
writer.Write(LastModifiedTime);
|
||||
writer.Write(LastModifiedDate);
|
||||
writer.Write(Crc);
|
||||
@@ -51,8 +52,8 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
|
||||
byte[] nameBytes = EncodeString(Name);
|
||||
|
||||
writer.Write((ushort)nameBytes.Length);
|
||||
writer.Write((ushort)0);
|
||||
writer.Write((ushort) nameBytes.Length);
|
||||
writer.Write((ushort) 0);
|
||||
//if (Extra != null)
|
||||
//{
|
||||
// writer.Write(Extra);
|
||||
@@ -61,7 +62,5 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
}
|
||||
|
||||
internal ushort Version { get; private set; }
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -19,4 +19,4 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -66,10 +66,10 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
|
||||
protected void LoadExtra(byte[] extra)
|
||||
{
|
||||
for (int i = 0; i < extra.Length; )
|
||||
for (int i = 0; i < extra.Length;)
|
||||
{
|
||||
ExtraDataType type = (ExtraDataType)BitConverter.ToUInt16(extra, i);
|
||||
if (!Enum.IsDefined(typeof(ExtraDataType), type))
|
||||
ExtraDataType type = (ExtraDataType) BitConverter.ToUInt16(extra, i);
|
||||
if (!Enum.IsDefined(typeof (ExtraDataType), type))
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -77,14 +77,15 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
byte[] data = new byte[length];
|
||||
Buffer.BlockCopy(extra, i + 4, data, 0, length);
|
||||
Extra.Add(new ExtraData
|
||||
{
|
||||
Type = type,
|
||||
Length = length,
|
||||
DataBytes = data
|
||||
});
|
||||
{
|
||||
Type = type,
|
||||
Length = length,
|
||||
DataBytes = data
|
||||
});
|
||||
i += length + 4;
|
||||
}
|
||||
}
|
||||
|
||||
internal ZipFilePart Part { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -10,11 +10,7 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
HasData = true;
|
||||
}
|
||||
|
||||
internal ZipHeaderType ZipHeaderType
|
||||
{
|
||||
get;
|
||||
private set;
|
||||
}
|
||||
internal ZipHeaderType ZipHeaderType { get; private set; }
|
||||
|
||||
internal abstract void Read(BinaryReader reader);
|
||||
|
||||
@@ -22,4 +18,4 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
|
||||
internal bool HasData { get; set; }
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
|
||||
namespace SharpCompress.Common.Zip.Headers
|
||||
namespace SharpCompress.Common.Zip.Headers
|
||||
{
|
||||
internal enum ZipHeaderType
|
||||
{
|
||||
@@ -9,4 +8,4 @@ namespace SharpCompress.Common.Zip.Headers
|
||||
DirectoryEnd,
|
||||
Split,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,7 @@ namespace SharpCompress.Common.Zip
|
||||
internal class PkwareTraditionalEncryptionData
|
||||
{
|
||||
private static readonly CRC32 crc32 = new CRC32();
|
||||
private readonly UInt32[] _Keys = { 0x12345678, 0x23456789, 0x34567890 };
|
||||
private readonly UInt32[] _Keys = {0x12345678, 0x23456789, 0x34567890};
|
||||
|
||||
private PkwareTraditionalEncryptionData(string password)
|
||||
{
|
||||
@@ -19,22 +19,23 @@ namespace SharpCompress.Common.Zip
|
||||
{
|
||||
get
|
||||
{
|
||||
ushort t = (ushort)((ushort)(_Keys[2] & 0xFFFF) | 2);
|
||||
return (byte)((t * (t ^ 1)) >> 8);
|
||||
ushort t = (ushort) ((ushort) (_Keys[2] & 0xFFFF) | 2);
|
||||
return (byte) ((t*(t ^ 1)) >> 8);
|
||||
}
|
||||
}
|
||||
|
||||
public static PkwareTraditionalEncryptionData ForRead(string password, ZipFileEntry header, byte[] encryptionHeader)
|
||||
public static PkwareTraditionalEncryptionData ForRead(string password, ZipFileEntry header,
|
||||
byte[] encryptionHeader)
|
||||
{
|
||||
var encryptor = new PkwareTraditionalEncryptionData(password);
|
||||
byte[] plainTextHeader = encryptor.Decrypt(encryptionHeader, encryptionHeader.Length);
|
||||
if (plainTextHeader[11] != (byte)((header.Crc >> 24) & 0xff))
|
||||
if (plainTextHeader[11] != (byte) ((header.Crc >> 24) & 0xff))
|
||||
{
|
||||
if (!FlagUtility.HasFlag(header.Flags, HeaderFlags.UsePostDataDescriptor))
|
||||
{
|
||||
throw new CryptographicException("The password did not match.");
|
||||
}
|
||||
if (plainTextHeader[11] != (byte)((header.LastModifiedTime >> 8) & 0xff))
|
||||
if (plainTextHeader[11] != (byte) ((header.LastModifiedTime >> 8) & 0xff))
|
||||
{
|
||||
throw new CryptographicException("The password did not match.");
|
||||
}
|
||||
@@ -52,7 +53,7 @@ namespace SharpCompress.Common.Zip
|
||||
var plainText = new byte[length];
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
var C = (byte)(cipherText[i] ^ MagicByte);
|
||||
var C = (byte) (cipherText[i] ^ MagicByte);
|
||||
UpdateKeys(C);
|
||||
plainText[i] = C;
|
||||
}
|
||||
@@ -72,7 +73,7 @@ namespace SharpCompress.Common.Zip
|
||||
for (int i = 0; i < length; i++)
|
||||
{
|
||||
byte C = plainText[i];
|
||||
cipherText[i] = (byte)(plainText[i] ^ MagicByte);
|
||||
cipherText[i] = (byte) (plainText[i] ^ MagicByte);
|
||||
UpdateKeys(C);
|
||||
}
|
||||
return cipherText;
|
||||
@@ -98,10 +99,10 @@ namespace SharpCompress.Common.Zip
|
||||
|
||||
private void UpdateKeys(byte byteValue)
|
||||
{
|
||||
_Keys[0] = (UInt32)crc32.ComputeCrc32((int)_Keys[0], byteValue);
|
||||
_Keys[1] = _Keys[1] + (byte)_Keys[0];
|
||||
_Keys[1] = _Keys[1] * 0x08088405 + 1;
|
||||
_Keys[2] = (UInt32)crc32.ComputeCrc32((int)_Keys[2], (byte)(_Keys[1] >> 24));
|
||||
_Keys[0] = (UInt32) crc32.ComputeCrc32((int) _Keys[0], byteValue);
|
||||
_Keys[1] = _Keys[1] + (byte) _Keys[0];
|
||||
_Keys[1] = _Keys[1]*0x08088405 + 1;
|
||||
_Keys[2] = (UInt32) crc32.ComputeCrc32((int) _Keys[2], (byte) (_Keys[1] >> 24));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -26,10 +26,7 @@ namespace SharpCompress.Common.Zip
|
||||
|
||||
internal string Comment
|
||||
{
|
||||
get
|
||||
{
|
||||
return (Header as DirectoryEntryHeader).Comment;
|
||||
}
|
||||
get { return (Header as DirectoryEntryHeader).Comment; }
|
||||
}
|
||||
|
||||
private void LoadLocalHeader()
|
||||
@@ -45,4 +42,4 @@ namespace SharpCompress.Common.Zip
|
||||
return BaseStream;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -32,9 +32,10 @@ namespace SharpCompress.Common.Zip
|
||||
signature = reader.ReadUInt32();
|
||||
offset--;
|
||||
iterationCount++;
|
||||
if(iterationCount > MAX_ITERATIONS_FOR_DIRECTORY_HEADER)
|
||||
if (iterationCount > MAX_ITERATIONS_FOR_DIRECTORY_HEADER)
|
||||
{
|
||||
throw new ArchiveException("Could not find Zip file Directory at the end of the file. File may be corrupted.");
|
||||
throw new ArchiveException(
|
||||
"Could not find Zip file Directory at the end of the file. File may be corrupted.");
|
||||
}
|
||||
} while (signature != DIRECTORY_END_HEADER_BYTES);
|
||||
|
||||
@@ -73,4 +74,4 @@ namespace SharpCompress.Common.Zip
|
||||
return localEntryHeader;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user