diff --git a/Directory.Build.props b/Directory.Build.props index 191d860..f3231d7 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 1.0.0-rc4 + 1.0.0-rc5 net9.0 enable enable diff --git a/Pack3r.Console/Program.cs b/Pack3r.Console/Program.cs index 9ff7656..e552785 100644 --- a/Pack3r.Console/Program.cs +++ b/Pack3r.Console/Program.cs @@ -135,7 +135,9 @@ private static void PrintDetails(PackOptions options, ILogger appLogger { StringBuilder sb = new(); - sb.Append(options.DryRun ? "Running a dry run for map " : "Packing map "); + sb.AppendLine($"Packer v{Global.Version} https://github.com/ovska/Pack3r/"); + + sb.Append(options.DryRun ? "\tRunning a dry run for map " : "\tPacking map "); sb.Append(Path.GetFileNameWithoutExtension(options.MapFile.Name.AsSpan())); if (options.OnlySource) @@ -164,23 +166,26 @@ private static void PrintDetails(PackOptions options, ILogger appLogger sb.Append(" without creating a pk3"); } - sb.Append('.'); + sb.AppendLine("."); sb.Append( options.RequireAllAssets - ? " All assets are required." - : " Missing assets are ignored."); + ? "\tAll assets are required." + : "\tMissing assets are ignored."); - sb.Append(options.LoadPk3s ? " Pk3s in etmain are scanned." : " Pk3s in etmain are not scanned."); + sb.AppendLine(); + sb.Append(options.LoadPk3s ? "\tPk3s in etmain are scanned." : "\tPk3s in etmain are not scanned."); - sb.Append(" Logging verbosity is '"); + sb.Append("\tLogging verbosity is '"); sb.Append(options.LogLevel); sb.Append("'."); + sb.AppendLine(); - if (options.ModFolders is { Count : > 0 }) + if (options.ModFolders is { Count: > 0 }) { - sb.Append(" Mod folders are scanned: "); + sb.Append("\tMod folders are scanned: "); sb.AppendJoin(", ", options.ModFolders); + sb.AppendLine(); } appLogger.System($"{sb.ToString()}"); @@ -188,15 +193,14 @@ private static void PrintDetails(PackOptions options, ILogger appLogger private static bool PromptOverwrite(FileInfo pk3) { - var color = System.Console.ForegroundColor; System.Console.ForegroundColor = ConsoleColor.Red; System.Console.Write($"Output file already exists: "); - System.Console.ForegroundColor = color; + System.Console.ResetColor(); System.Console.WriteLine(pk3.FullName); System.Console.Write("Overwrite? "); System.Console.ForegroundColor = ConsoleColor.Cyan; System.Console.WriteLine("Y/N"); - System.Console.ForegroundColor = color; + System.Console.ResetColor(); return System.Console.ReadLine().AsSpan().Trim().EqualsF("y"); } @@ -212,7 +216,7 @@ private static bool PromptOverwrite(FileInfo pk3) return null; } - System.Console.WriteLine($"Pack3r {typeof(PackOptions).Assembly.GetName().Version?.ToString(3)}"); + System.Console.WriteLine($"Pack3r {Global.Version}"); System.Console.WriteLine("For more options, run Pack3r through the command line"); System.Console.WriteLine("Enter path to .map file:"); string? res = System.Console.ReadLine()?.Trim(); diff --git a/Pack3r.Core/Global.cs b/Pack3r.Core/Global.cs index b933992..b610aa9 100644 --- a/Pack3r.Core/Global.cs +++ b/Pack3r.Core/Global.cs @@ -5,7 +5,7 @@ namespace Pack3r; -internal static class Global +public static class Global { public const int MAX_QPATH = 64; diff --git a/Pack3r.Core/Logging/Logger.cs b/Pack3r.Core/Logging/Logger.cs index 7920a94..694054c 100644 --- a/Pack3r.Core/Logging/Logger.cs +++ b/Pack3r.Core/Logging/Logger.cs @@ -107,9 +107,6 @@ private void LogInternalNoLock(LogLevel level, string message, string? context) return; } - var defaultForeground = Console.ForegroundColor; - var defaultBackground = Console.BackgroundColor; - TextWriter output = Console.Out; GetPrefix( @@ -121,10 +118,14 @@ private void LogInternalNoLock(LogLevel level, string message, string? context) if (!prefix.IsEmpty) { - Console.BackgroundColor = backgroundColor ?? defaultBackground; - output.Write(' '); - Console.BackgroundColor = defaultBackground; + if (backgroundColor.HasValue) + { + Console.BackgroundColor = backgroundColor.Value; + } + + output.Write(' '); + Console.ResetColor(); Console.ForegroundColor = prefixColor; output.Write(prefix); } @@ -135,17 +136,21 @@ private void LogInternalNoLock(LogLevel level, string message, string? context) if (!string.IsNullOrEmpty(context)) { + Console.ResetColor(); Console.ForegroundColor = ConsoleColor.DarkGray; output.Write('['); output.Write(context); output.Write("] "); + Console.ResetColor(); } - Console.ForegroundColor = messageColor ?? defaultForeground; + if (messageColor.HasValue) + { + Console.ForegroundColor = messageColor.Value; + } output.Write(message); - output.Write(Environment.NewLine); - Console.ForegroundColor = defaultForeground; + Console.ResetColor(); } private static void GetPrefix( diff --git a/Pack3r.Core/Models/Resource.cs b/Pack3r.Core/Models/Resource.cs index 833da9c..aeb270d 100644 --- a/Pack3r.Core/Models/Resource.cs +++ b/Pack3r.Core/Models/Resource.cs @@ -69,5 +69,11 @@ private Resource(QString value, IResourceSource source) IsShader = true; Source = source; } + + public override string ToString() + { + if (!IsShader) return Value.ToString(); + return $"{Value} (shader)"; + } } diff --git a/Pack3r.Core/Progress/IProgressMeter.cs b/Pack3r.Core/Progress/IProgressMeter.cs index e691ac1..91f3bf1 100644 --- a/Pack3r.Core/Progress/IProgressMeter.cs +++ b/Pack3r.Core/Progress/IProgressMeter.cs @@ -53,8 +53,6 @@ public void Report(int value) Console.Out.Write('\r'); } - var foreground = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.Gray; if (value >= _max) @@ -66,7 +64,7 @@ public void Report(int value) Console.Out.Write([' ', ' ', ' ', ' ', ' ', ' ', Spin, ' ']); } - Console.ForegroundColor = foreground; + Console.ResetColor(); Console.Out.Write(_name); Console.Out.Write(' '); @@ -84,8 +82,6 @@ public void Dispose() { lock (Global.ConsoleLock) { - var foreground = Console.ForegroundColor; - Console.ForegroundColor = ConsoleColor.DarkGray; Console.Out.Write(" ("); Console.Out.Write((int)Stopwatch.GetElapsedTime(_timestamp).TotalMilliseconds); @@ -93,8 +89,9 @@ public void Dispose() Console.ForegroundColor = ConsoleColor.Green; Console.Out.Write("\r DONE "); - Console.ForegroundColor = foreground; Console.WriteLine(); + + Console.ResetColor(); } } } diff --git a/Pack3r.Core/QPath.cs b/Pack3r.Core/QPath.cs index ed93520..37f7443 100644 --- a/Pack3r.Core/QPath.cs +++ b/Pack3r.Core/QPath.cs @@ -19,15 +19,11 @@ namespace Pack3r; public ReadOnlyMemory Value { get; } public ReadOnlySpan Span => Value.Span; - public char this[int index] => Span[index]; - - public QPath this[Range range] => new(Value, range); - [MethodImpl(MethodImplOptions.AggressiveInlining)] public QPath(string path) { Global.EnsureQPathLength(path); - Value = path.Replace('\\', '/').AsMemory(); + Value = path.Replace('\\', '/').TrimStart('/').AsMemory(); } [MethodImpl(MethodImplOptions.AggressiveInlining)] @@ -37,11 +33,11 @@ public QPath(ReadOnlyMemory path) if (path.Span.Contains('\\')) { - Value = string.Create(path.Length, path, (dst, src) => src.Span.Replace(dst, '\\', '/')).AsMemory(); + Value = string.Create(path.Length, path, (dst, src) => src.Span.Replace(dst, '\\', '/')).AsMemory().TrimStart('/'); } else { - Value = path; + Value = path.TrimStart('/'); } } @@ -54,10 +50,10 @@ private QPath(ReadOnlyMemory value, Range range) [MethodImpl(MethodImplOptions.AggressiveInlining)] public int CompareTo(QPath other) => CultureInfo.InvariantCulture.CompareInfo.Compare(Value.Span, other.Value.Span); - + [MethodImpl(MethodImplOptions.AggressiveInlining)] public bool Equals(QPath other) => Value.Span.Equals(other.Value.Span, StringComparison.OrdinalIgnoreCase); - + [MethodImpl(MethodImplOptions.AggressiveInlining)] public override int GetHashCode() => CultureInfo.InvariantCulture.CompareInfo.GetHashCode(Value.Span, CompareOptions.OrdinalIgnoreCase); diff --git a/Pack3r.Core/Services/AppLifetime.cs b/Pack3r.Core/Services/AppLifetime.cs index 0421f11..1b1b4eb 100644 --- a/Pack3r.Core/Services/AppLifetime.cs +++ b/Pack3r.Core/Services/AppLifetime.cs @@ -38,10 +38,9 @@ public void HandleException(Exception? ex) { lock (Global.ConsoleLock) { - var old = Console.ForegroundColor; Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine("Operation canceled by user"); - Console.ForegroundColor = old; + Console.ResetColor(); } return; // don't drain log on cancellations } diff --git a/Pack3r.Tests/Models/QTypeTests.cs b/Pack3r.Tests/Models/QTypeTests.cs index c79e5a3..b35aba1 100644 --- a/Pack3r.Tests/Models/QTypeTests.cs +++ b/Pack3r.Tests/Models/QTypeTests.cs @@ -5,13 +5,14 @@ public static class QTypeTests [Theory] [InlineData("test", "test")] [InlineData("path/to/texture.jpg", "path/to/texture.jpg")] + [InlineData("/path/to/texture.jpg", "path/to/texture.jpg")] [InlineData(@"path\to\texture.jpg", "path/to/texture.jpg")] + [InlineData(@"\path\to\texture.jpg", "path/to/texture.jpg")] public static void QPath_Should_Normalize_Separators(string input, string expected) { Assert.Equal(expected, new QPath(input).ToString()); Assert.Equal(expected, new QPath(input.AsMemory()).ToString()); Assert.Equal(expected, new QPath(input.ToCharArray()).ToString()); - Assert.Equal(expected, new QPath(input)[Range.All].ToString()); } [Fact]