From d7e477c4ddc8589df3bb30023edb59ae3d2e5ef3 Mon Sep 17 00:00:00 2001 From: Tony Bark Date: Thu, 1 May 2025 09:27:58 -0400 Subject: [PATCH] Serilog integration --- AppDir/s2pk.desktop | 4 ++-- GlobalUsing.cs | 3 +++ PackageManger.cs | 14 +++++++------- Program.cs | 8 ++++++++ README.md | 2 +- S2PK.csproj | 3 +++ 6 files changed, 24 insertions(+), 10 deletions(-) diff --git a/AppDir/s2pk.desktop b/AppDir/s2pk.desktop index c92b910..caf5609 100644 --- a/AppDir/s2pk.desktop +++ b/AppDir/s2pk.desktop @@ -1,7 +1,7 @@ [Desktop Entry] -Name=s2pk +Name=Sims 2 Package Manager Exec=s2pk -Icon=s2pk +Icon=logo.svg Type=Application Categories=Utility; Terminal=true diff --git a/GlobalUsing.cs b/GlobalUsing.cs index 800695e..7ea0ebc 100644 --- a/GlobalUsing.cs +++ b/GlobalUsing.cs @@ -1,2 +1,5 @@ global using S2PK; global using Tomlyn; +global using Serilog; +global using Serilog.Sinks.Debug; +global using Serilog.Sinks.Console; diff --git a/PackageManger.cs b/PackageManger.cs index ace0601..6a6a9bf 100644 --- a/PackageManger.cs +++ b/PackageManger.cs @@ -28,14 +28,14 @@ public static class PackageManager if (!dir.Exists) { - Console.Error.WriteLine("Source directory does not exist."); + Log.Error("Source directory does not exist."); return; } var packageFiles = dir.GetFiles($"*{PackageExtension}", SearchOption.AllDirectories); if (packageFiles.Length == 0) { - Console.Error.WriteLine("No .package files found to pack."); + Log.Error("No .package files found to pack."); return; } @@ -75,7 +75,7 @@ public static class PackageManager // Check if destination directory exists if (!Directory.Exists(destination)) { - Console.Error.WriteLine("Destination directory does not exist."); + Log.Error("Destination directory does not exist."); return; } @@ -85,21 +85,21 @@ public static class PackageManager if (!file.Exists) { - Console.Error.WriteLine("Package file does not exist."); + Log.Error("Package file does not exist."); return; } if (!file.FullName.Contains(extension)) { - Console.Error.WriteLine("Package file is not a valid."); + Log.Error("Package file is not a valid."); return; } // Check for extension mismatch if (file.FullName.Contains(S3pkExtension) && !ts3) { - Console.Error.WriteLine("Package is for The Sims 3 but unpacking for The Sims 2."); + Log.Error("Package is for The Sims 3 but unpacking for The Sims 2."); return; } @@ -113,7 +113,7 @@ public static class PackageManager // Sanitize path to prevent directory traversal if (!fullPath.StartsWith(dir.FullName, StringComparison.OrdinalIgnoreCase)) { - Console.Error.WriteLine($"Skipping unsafe path: {entry.FullName}"); + Log.Error($"Skipping unsafe path: {entry.FullName}"); continue; } diff --git a/Program.cs b/Program.cs index 6ab3c17..b1d5114 100644 --- a/Program.cs +++ b/Program.cs @@ -2,6 +2,14 @@ using System.CommandLine; var rootCommand = new RootCommand("The Sims 2 .s2pk Package Manager"); +Log.Logger = new LoggerConfiguration() +#if DEBUG + .WriteTo.Debug() +#else + .WriteTo.Console(theme: AnsiConsoleTheme.Code) +#endif + .CreateLogger(); + var sims3option = new Option( aliases: ["--ts3"], description: "Switch to The Sims 3 mode.", diff --git a/README.md b/README.md index c062058..99dd98d 100644 --- a/README.md +++ b/README.md @@ -26,7 +26,7 @@ While The Sims 2 runs well on Linux through Wine, especially with Lutris setups, | ----- | ------------------------------------------- | ------ | | v0.1 | Core package manager | ✅ | | v0.2 | Config file with default paths | ✅ | -| v0.3 | Sims 3 support with `s3pk` extention | 🔜 | +| v0.3 | Sims 3 support with `s3pk` extension | 🔜 | | v0.x | Target .NET 10 | 🔜 | | v1.0 | Stable "Release" version with documentation | 🔜 | diff --git a/S2PK.csproj b/S2PK.csproj index bfe7c8e..54402e0 100644 --- a/S2PK.csproj +++ b/S2PK.csproj @@ -14,6 +14,9 @@ + + +