Improve lzma progress report
This commit is contained in:
@@ -249,7 +249,7 @@ namespace SevenZip.Compression.LZMA
|
||||
nowPos64++;
|
||||
}
|
||||
|
||||
Progress.Reset();
|
||||
Progress.Reset(index: 1);
|
||||
while (nowPos64 < outSize64)
|
||||
{
|
||||
// UInt64 next = Math.Min(nowPos64 + (1 << 18), outSize64);
|
||||
@@ -342,7 +342,7 @@ namespace SevenZip.Compression.LZMA
|
||||
m_OutWindow.CopyBlock(rep0, len);
|
||||
nowPos64 += len;
|
||||
|
||||
Progress.Report((int)(nowPos64 * 100f / outSize64), 100);
|
||||
Progress.Report((int)(nowPos64 * 100f / outSize64), 100, index: 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -458,7 +458,6 @@ namespace AssetStudio
|
||||
numWrite = blockInfo.compressedSize;
|
||||
break;
|
||||
case CompressionType.Lzma:
|
||||
Logger.Info("Decompressing LZMA stream...");
|
||||
numWrite = BundleDecompressionHelper.DecompressLzmaStream(reader.BaseStream, blocksStream, blockInfo.compressedSize, blockInfo.uncompressedSize, ref errorMsg);
|
||||
break;
|
||||
case CompressionType.Lz4:
|
||||
|
||||
@@ -4,28 +4,58 @@ namespace AssetStudio
|
||||
{
|
||||
public static class Progress
|
||||
{
|
||||
public static IProgress<int> Default = new Progress<int>();
|
||||
private static int preValue;
|
||||
private static readonly int InstanceCount = 2;
|
||||
private static readonly IProgress<int>[] Instances;
|
||||
private static readonly int[] PreValues;
|
||||
|
||||
public static void Reset()
|
||||
static Progress()
|
||||
{
|
||||
preValue = 0;
|
||||
Default.Report(0);
|
||||
Instances = new IProgress<int>[InstanceCount];
|
||||
for (var i = 0; i < InstanceCount; i++)
|
||||
{
|
||||
Instances[i] = new Progress<int>();
|
||||
}
|
||||
|
||||
PreValues = new int[InstanceCount];
|
||||
}
|
||||
|
||||
public static void Report(int current, int total)
|
||||
public static int MaxCount => InstanceCount;
|
||||
|
||||
public static IProgress<int> Default //alias
|
||||
{
|
||||
get => Instances[0];
|
||||
set => SetInstance(0, value);
|
||||
}
|
||||
|
||||
public static void Reset(int index = 0)
|
||||
{
|
||||
PreValues[index] = 0;
|
||||
Instances[index].Report(0);
|
||||
}
|
||||
|
||||
public static void Report(int current, int total, int index = 0)
|
||||
{
|
||||
var value = (int)(current * 100f / total);
|
||||
Report(value);
|
||||
_Report(value, index);
|
||||
}
|
||||
|
||||
private static void Report(int value)
|
||||
private static void _Report(int value, int index)
|
||||
{
|
||||
if (value > preValue)
|
||||
if (value > PreValues[index])
|
||||
{
|
||||
preValue = value;
|
||||
Default.Report(value);
|
||||
PreValues[index] = value;
|
||||
Instances[index].Report(value);
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetInstance(int index, IProgress<int> progress)
|
||||
{
|
||||
if (progress == null)
|
||||
throw new ArgumentNullException(nameof(progress));
|
||||
if (index < 0 || index >= MaxCount)
|
||||
throw new ArgumentOutOfRangeException(nameof(index));
|
||||
|
||||
Instances[index] = progress;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user