Files
sharpcompress/SharpCompress/Common/SevenZip/CStreamSwitch.cs
hodm b0c514d87c Extract Options And Total Sizes
Fixed TotalSize For 7z
added TotalUncompressSize Tested for 7z
this enables to show progress for the entire archive
Added 2 Extract Options: PreserveFileTime And PreserveAttributes.
Put All the Log Command under DEBUG Condition.
2015-07-26 23:36:28 +03:00

68 lines
1.8 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using SharpCompress.Compressor.LZMA;
namespace SharpCompress.Common.SevenZip
{
internal struct CStreamSwitch : IDisposable
{
private ArchiveReader _archive;
private bool _needRemove;
private bool _active;
public void Dispose()
{
if (_active)
{
_active = false;
#if DEBUG
Log.WriteLine("[end of switch]");
#endif
}
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();
#if DEBUG
Log.WriteLine("[switch to stream {0}]", dataIndex);
#endif
_archive = archive;
_archive.AddByteStream(dataVector[dataIndex], 0, dataVector[dataIndex].Length);
_needRemove = true;
_active = true;
}
else
{
#if DEBUG
Log.WriteLine("[inline data]");
#endif
}
}
}
}