Improve lzma progress report

This commit is contained in:
VaDiM
2025-09-12 19:57:36 +03:00
parent 763f188afb
commit 6c3ff89dbf
4 changed files with 82 additions and 14 deletions

View File

@@ -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);
}
}
}

View File

@@ -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:

View File

@@ -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;
}
}
}

View File

@@ -118,6 +118,9 @@ namespace AssetStudioGUI
private GUILogger logger;
private TaskbarManager taskbar = TaskbarManager.Instance;
private System.Drawing.Font progressBarTextFont;
private Brush progressBarTextBrush;
private StringFormat progressBarTextFormat;
[DllImport("gdi32.dll")]
private static extern IntPtr AddFontMemResourceEx(IntPtr pbFont, uint cbFont, IntPtr pdv, [In] ref uint pcFonts);
@@ -157,7 +160,16 @@ namespace AssetStudioGUI
Logger.Default = logger;
writeLogToFileToolStripMenuItem.Checked = Properties.Settings.Default.useFileLogger;
progressBarTextFont = new System.Drawing.Font(FontFamily.GenericSansSerif, 8);
progressBarTextBrush = new SolidBrush(SystemColors.ControlText);
progressBarTextFormat = new StringFormat
{
Alignment = StringAlignment.Center,
LineAlignment = StringAlignment.Center,
};
Progress.Default = new Progress<int>(SetProgressBarValue);
Progress.SetInstance(index: 1, new Progress<int>(SetProgressBarStringValue));
Studio.StatusStripUpdate = StatusStripUpdate;
}
@@ -1530,6 +1542,33 @@ namespace AssetStudioGUI
}));
}
private void SetProgressBarStringValue(int value)
{
var str = $"Decompressing LZMA: {value}%";
if (InvokeRequired)
{
BeginInvoke(new Action(() =>
{
using (var graphics = progressBar1.CreateGraphics())
{
progressBar1.Refresh();
var rect = new Rectangle(0, 0, progressBar1.Width, progressBar1.Height);
graphics.DrawString(str, progressBarTextFont, progressBarTextBrush, rect, progressBarTextFormat);
}
}));
}
else
{
using (var graphics = progressBar1.CreateGraphics())
{
progressBar1.Refresh();
var rect = new Rectangle(0, 0, progressBar1.Width, progressBar1.Height);
graphics.DrawString(str, progressBarTextFont, progressBarTextBrush, rect, progressBarTextFormat);
}
}
}
private void StatusStripUpdate(string statusText)
{
if (InvokeRequired)