Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project>

<PropertyGroup>
<Version>1.0.0-rc4</Version>
<Version>1.0.0-rc5</Version>
<TargetFramework>net9.0</TargetFramework>
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
Expand Down
28 changes: 16 additions & 12 deletions Pack3r.Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,9 @@ private static void PrintDetails(PackOptions options, ILogger<Program> 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)
Expand Down Expand Up @@ -164,39 +166,41 @@ private static void PrintDetails(PackOptions options, ILogger<Program> 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()}");
}

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

Expand All @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion Pack3r.Core/Global.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Pack3r;

internal static class Global
public static class Global
{
public const int MAX_QPATH = 64;

Expand Down
23 changes: 14 additions & 9 deletions Pack3r.Core/Logging/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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);
}
Expand All @@ -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(
Expand Down
6 changes: 6 additions & 0 deletions Pack3r.Core/Models/Resource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)";
}
}

9 changes: 3 additions & 6 deletions Pack3r.Core/Progress/IProgressMeter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ public void Report(int value)
Console.Out.Write('\r');
}

var foreground = Console.ForegroundColor;

Console.ForegroundColor = ConsoleColor.Gray;

if (value >= _max)
Expand All @@ -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(' ');
Expand All @@ -84,17 +82,16 @@ 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);
Console.Out.Write("ms)");

Console.ForegroundColor = ConsoleColor.Green;
Console.Out.Write("\r DONE ");
Console.ForegroundColor = foreground;
Console.WriteLine();

Console.ResetColor();
}
}
}
14 changes: 5 additions & 9 deletions Pack3r.Core/QPath.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,11 @@ namespace Pack3r;
public ReadOnlyMemory<char> Value { get; }
public ReadOnlySpan<char> 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)]
Expand All @@ -37,11 +33,11 @@ public QPath(ReadOnlyMemory<char> 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('/');
}
}

Expand All @@ -54,10 +50,10 @@ private QPath(ReadOnlyMemory<char> 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);

Expand Down
3 changes: 1 addition & 2 deletions Pack3r.Core/Services/AppLifetime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
3 changes: 2 additions & 1 deletion Pack3r.Tests/Models/QTypeTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down