Some minor improvements

This commit is contained in:
VaDiM
2025-10-11 14:15:17 +03:00
parent c07dc59f51
commit 0021cf221e
4 changed files with 22 additions and 14 deletions

View File

@ -438,14 +438,16 @@ namespace AssetStudio
try 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); var compressionType = (CompressionType)(blockInfo.flags & StorageBlockFlags.CompressionTypeMask);
if (customBlockCompression != CompressionType.Auto && compressionType > 0) if (customBlockCompression != CompressionType.Auto && compressionType > 0)
{ {
compressionType = customBlockCompression; compressionType = customBlockCompression;
} }
var debugMsg = $"[{i:D2}] Compression: {compressionType} | UncompressedSize: {blockInfo.uncompressedSize} | CompressedSize: {blockInfo.compressedSize} ";
long numWrite; long numWrite;
var errorMsg = string.Empty; var errorMsg = string.Empty;
@ -468,7 +470,8 @@ namespace AssetStudio
sharedCompressedBuff.AsSpan().Clear(); sharedCompressedBuff.AsSpan().Clear();
sharedUncompressedBuff.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<byte>(sharedCompressedBuff, 0, compressedSize); var compressedSpan = new ReadOnlySpan<byte>(sharedCompressedBuff, 0, compressedSize);
var uncompressedSpan = new Span<byte>(sharedUncompressedBuff, 0, uncompressedSize); var uncompressedSpan = new Span<byte>(sharedUncompressedBuff, 0, uncompressedSize);
@ -476,7 +479,6 @@ namespace AssetStudio
if (numWrite == uncompressedSize) if (numWrite == uncompressedSize)
{ {
blocksStream.Write(sharedUncompressedBuff, 0, uncompressedSize); blocksStream.Write(sharedUncompressedBuff, 0, uncompressedSize);
continue;
} }
break; break;
case CompressionType.Lzham: case CompressionType.Lzham:
@ -484,6 +486,7 @@ namespace AssetStudio
default: default:
throw new IOException($"Unknown block compression type: {compressionType}.\nYou may try to specify the compression type manually.\n"); 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) if (numWrite != blockInfo.uncompressedSize)
{ {

View File

@ -10,9 +10,9 @@ namespace AssetStudio
Black = "\u001b[30m", Black = "\u001b[30m",
Red = "\u001b[31m", Red = "\u001b[31m",
Green = "\u001b[32m", 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", 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", Cyan = "\u001b[36m",
White = "\u001b[37m", White = "\u001b[37m",
BrightBlack = "\u001b[30;1m", BrightBlack = "\u001b[30;1m",
@ -28,13 +28,22 @@ namespace AssetStudio
public static string Color(this string str, string ansiColor) public static string Color(this string str, string ansiColor)
{ {
if (!ColorConsoleHelper.isAnsiCodesSupported) if (!ColorConsoleHelper.isAnsiCodesSupported)
{
return str; return str;
}
return $"{ansiColor}{str}{Reset}"; 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() public static void AnsiCodesTest()
{ {
Console.WriteLine("ANSI escape codes test"); 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"); Console.WriteLine("\u001b[34;1m E \u001b[35;1m F \u001b[36;1m G \u001b[37;1m H \u001b[0m");
} }
} }
} }

View File

@ -1272,7 +1272,7 @@ namespace AssetStudioCLI.Options
} }
catch (Exception ex) catch (Exception ex)
{ {
Console.WriteLine("Unknown Error.".Color(ColorConsole.Red)); Console.WriteLine("Unknown Error.".Color(ColorConsole.BrightRed));
Console.WriteLine(ex); Console.WriteLine(ex);
return; return;
} }

View File

@ -794,13 +794,10 @@ namespace AssetStudioCLI
{ {
Logger.Default.Log(LoggerEvent.Info, "Nothing exported.", ignoreLevel: true); 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 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) if (toExportCount > exportedCount)