From 0021cf221e2bcfe07c9a66446abd5eda490e4da2 Mon Sep 17 00:00:00 2001 From: VaDiM Date: Sat, 11 Oct 2025 14:15:17 +0300 Subject: [PATCH] Some minor improvements --- AssetStudio/BundleFile.cs | 9 ++++++--- AssetStudio/ColorConsole.cs | 18 +++++++++++++----- AssetStudioCLI/Options/CLIOptions.cs | 2 +- AssetStudioCLI/Studio.cs | 7 ++----- 4 files changed, 22 insertions(+), 14 deletions(-) diff --git a/AssetStudio/BundleFile.cs b/AssetStudio/BundleFile.cs index 040bf80..9cdd2b1 100644 --- a/AssetStudio/BundleFile.cs +++ b/AssetStudio/BundleFile.cs @@ -438,14 +438,16 @@ namespace AssetStudio try { - foreach (var blockInfo in m_BlocksInfo) + for (var i = 0; i < m_BlocksInfo.Length; i++) { + var blockInfo = m_BlocksInfo[i]; var compressionType = (CompressionType)(blockInfo.flags & StorageBlockFlags.CompressionTypeMask); if (customBlockCompression != CompressionType.Auto && compressionType > 0) { compressionType = customBlockCompression; } + var debugMsg = $"[{i:D2}] Compression: {compressionType} | UncompressedSize: {blockInfo.uncompressedSize} | CompressedSize: {blockInfo.compressedSize} "; long numWrite; var errorMsg = string.Empty; @@ -468,7 +470,8 @@ namespace AssetStudio sharedCompressedBuff.AsSpan().Clear(); sharedUncompressedBuff.AsSpan().Clear(); - _ = reader.Read(sharedCompressedBuff, 0, compressedSize); + var read = reader.Read(sharedCompressedBuff, 0, compressedSize); + debugMsg += $"(read: {read.ToString().ColorIf(read != compressedSize, ColorConsole.BrightRed)})"; var compressedSpan = new ReadOnlySpan(sharedCompressedBuff, 0, compressedSize); var uncompressedSpan = new Span(sharedUncompressedBuff, 0, uncompressedSize); @@ -476,7 +479,6 @@ namespace AssetStudio if (numWrite == uncompressedSize) { blocksStream.Write(sharedUncompressedBuff, 0, uncompressedSize); - continue; } break; case CompressionType.Lzham: @@ -484,6 +486,7 @@ namespace AssetStudio default: throw new IOException($"Unknown block compression type: {compressionType}.\nYou may try to specify the compression type manually.\n"); } + Logger.Debug(debugMsg); if (numWrite != blockInfo.uncompressedSize) { diff --git a/AssetStudio/ColorConsole.cs b/AssetStudio/ColorConsole.cs index afad630..d8f2af7 100644 --- a/AssetStudio/ColorConsole.cs +++ b/AssetStudio/ColorConsole.cs @@ -10,9 +10,9 @@ namespace AssetStudio Black = "\u001b[30m", Red = "\u001b[31m", Green = "\u001b[32m", - Yellow = "\u001b[33m", //remapped to ~BrightWhite in Windows PowerShell 6 + Yellow = "\u001b[33m", //remapped to ~BrightWhite in Windows PowerShell 6 Blue = "\u001b[34m", - Magenta = "\u001b[35m", //remapped to ~Blue in Windows PowerShell 6 + Magenta = "\u001b[35m", //remapped to ~Blue in Windows PowerShell 6 Cyan = "\u001b[36m", White = "\u001b[37m", BrightBlack = "\u001b[30;1m", @@ -28,13 +28,22 @@ namespace AssetStudio public static string Color(this string str, string ansiColor) { if (!ColorConsoleHelper.isAnsiCodesSupported) - { return str; - } return $"{ansiColor}{str}{Reset}"; } + public static string ColorIf(this string str, bool isTrue, string ansiColor, string defaultAnsiColor = null) + { + if (isTrue) + return str.Color(ansiColor); + + if (defaultAnsiColor != null) + return str.Color(defaultAnsiColor); + + return str; + } + public static void AnsiCodesTest() { Console.WriteLine("ANSI escape codes test"); @@ -45,5 +54,4 @@ namespace AssetStudio Console.WriteLine("\u001b[34;1m E \u001b[35;1m F \u001b[36;1m G \u001b[37;1m H \u001b[0m"); } } - } diff --git a/AssetStudioCLI/Options/CLIOptions.cs b/AssetStudioCLI/Options/CLIOptions.cs index 8f94c2f..37cd044 100644 --- a/AssetStudioCLI/Options/CLIOptions.cs +++ b/AssetStudioCLI/Options/CLIOptions.cs @@ -1272,7 +1272,7 @@ namespace AssetStudioCLI.Options } catch (Exception ex) { - Console.WriteLine("Unknown Error.".Color(ColorConsole.Red)); + Console.WriteLine("Unknown Error.".Color(ColorConsole.BrightRed)); Console.WriteLine(ex); return; } diff --git a/AssetStudioCLI/Studio.cs b/AssetStudioCLI/Studio.cs index 762588f..9bb0a11 100644 --- a/AssetStudioCLI/Studio.cs +++ b/AssetStudioCLI/Studio.cs @@ -794,13 +794,10 @@ namespace AssetStudioCLI { Logger.Default.Log(LoggerEvent.Info, "Nothing exported.", ignoreLevel: true); } - else if (toExportCount > exportedCount) - { - Logger.Default.Log(LoggerEvent.Info, $"Finished exporting {exportedCount} asset(s) to \"{CLIOptions.o_outputFolder.Value.Color(Ansi.BrightYellow)}\".", ignoreLevel: true); - } else { - Logger.Default.Log(LoggerEvent.Info, $"Finished exporting {exportedCount} asset(s) to \"{CLIOptions.o_outputFolder.Value.Color(Ansi.BrightGreen)}\".", ignoreLevel: true); + var outPath = CLIOptions.o_outputFolder.Value.ColorIf(toExportCount > exportedCount, Ansi.BrightYellow, Ansi.BrightGreen); + Logger.Default.Log(LoggerEvent.Info, $"Finished exporting {exportedCount} asset(s) to \"{outPath}\".", ignoreLevel: true); } if (toExportCount > exportedCount)