From 6c3ff89dbf89af65bdbef9967faa0c41f89b4d10 Mon Sep 17 00:00:00 2001 From: VaDiM Date: Fri, 12 Sep 2025 19:57:36 +0300 Subject: [PATCH] Improve lzma progress report --- .../7zip/Compress/LZMA/LzmaDecoder.cs | 4 +- AssetStudio/BundleFile.cs | 1 - AssetStudio/Progress.cs | 52 +++++++++++++++---- AssetStudioGUI/AssetStudioGUIForm.cs | 39 ++++++++++++++ 4 files changed, 82 insertions(+), 14 deletions(-) diff --git a/AssetStudio/BundleCompression/SevenZipLzma/7zip/Compress/LZMA/LzmaDecoder.cs b/AssetStudio/BundleCompression/SevenZipLzma/7zip/Compress/LZMA/LzmaDecoder.cs index 504db61..a5f1e79 100644 --- a/AssetStudio/BundleCompression/SevenZipLzma/7zip/Compress/LZMA/LzmaDecoder.cs +++ b/AssetStudio/BundleCompression/SevenZipLzma/7zip/Compress/LZMA/LzmaDecoder.cs @@ -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); } } } diff --git a/AssetStudio/BundleFile.cs b/AssetStudio/BundleFile.cs index 6d82e7c..625bcc0 100644 --- a/AssetStudio/BundleFile.cs +++ b/AssetStudio/BundleFile.cs @@ -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: diff --git a/AssetStudio/Progress.cs b/AssetStudio/Progress.cs index 93db838..5392875 100644 --- a/AssetStudio/Progress.cs +++ b/AssetStudio/Progress.cs @@ -4,28 +4,58 @@ namespace AssetStudio { public static class Progress { - public static IProgress Default = new Progress(); - private static int preValue; + private static readonly int InstanceCount = 2; + private static readonly IProgress[] Instances; + private static readonly int[] PreValues; - public static void Reset() + static Progress() { - preValue = 0; - Default.Report(0); + Instances = new IProgress[InstanceCount]; + for (var i = 0; i < InstanceCount; i++) + { + Instances[i] = new Progress(); + } + + PreValues = new int[InstanceCount]; } - public static void Report(int current, int total) + public static int MaxCount => InstanceCount; + + public static IProgress 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 progress) + { + if (progress == null) + throw new ArgumentNullException(nameof(progress)); + if (index < 0 || index >= MaxCount) + throw new ArgumentOutOfRangeException(nameof(index)); + + Instances[index] = progress; + } } } diff --git a/AssetStudioGUI/AssetStudioGUIForm.cs b/AssetStudioGUI/AssetStudioGUIForm.cs index 17c8b5c..48dbd40 100644 --- a/AssetStudioGUI/AssetStudioGUIForm.cs +++ b/AssetStudioGUI/AssetStudioGUIForm.cs @@ -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(SetProgressBarValue); + Progress.SetInstance(index: 1, new Progress(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)