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
{
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<byte>(sharedCompressedBuff, 0, compressedSize);
var uncompressedSpan = new Span<byte>(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)
{

View File

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

View File

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

View File

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