Serilog integration

This commit is contained in:
Tony Bark 2025-05-01 09:27:58 -04:00
parent 9af646b534
commit d7e477c4dd
6 changed files with 24 additions and 10 deletions

View file

@ -1,7 +1,7 @@
[Desktop Entry] [Desktop Entry]
Name=s2pk Name=Sims 2 Package Manager
Exec=s2pk Exec=s2pk
Icon=s2pk Icon=logo.svg
Type=Application Type=Application
Categories=Utility; Categories=Utility;
Terminal=true Terminal=true

View file

@ -1,2 +1,5 @@
global using S2PK; global using S2PK;
global using Tomlyn; global using Tomlyn;
global using Serilog;
global using Serilog.Sinks.Debug;
global using Serilog.Sinks.Console;

View file

@ -28,14 +28,14 @@ public static class PackageManager
if (!dir.Exists) if (!dir.Exists)
{ {
Console.Error.WriteLine("Source directory does not exist."); Log.Error("Source directory does not exist.");
return; return;
} }
var packageFiles = dir.GetFiles($"*{PackageExtension}", SearchOption.AllDirectories); var packageFiles = dir.GetFiles($"*{PackageExtension}", SearchOption.AllDirectories);
if (packageFiles.Length == 0) if (packageFiles.Length == 0)
{ {
Console.Error.WriteLine("No .package files found to pack."); Log.Error("No .package files found to pack.");
return; return;
} }
@ -75,7 +75,7 @@ public static class PackageManager
// Check if destination directory exists // Check if destination directory exists
if (!Directory.Exists(destination)) if (!Directory.Exists(destination))
{ {
Console.Error.WriteLine("Destination directory does not exist."); Log.Error("Destination directory does not exist.");
return; return;
} }
@ -85,21 +85,21 @@ public static class PackageManager
if (!file.Exists) if (!file.Exists)
{ {
Console.Error.WriteLine("Package file does not exist."); Log.Error("Package file does not exist.");
return; return;
} }
if (!file.FullName.Contains(extension)) if (!file.FullName.Contains(extension))
{ {
Console.Error.WriteLine("Package file is not a valid."); Log.Error("Package file is not a valid.");
return; return;
} }
// Check for extension mismatch // Check for extension mismatch
if (file.FullName.Contains(S3pkExtension) && !ts3) 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; return;
} }
@ -113,7 +113,7 @@ public static class PackageManager
// Sanitize path to prevent directory traversal // Sanitize path to prevent directory traversal
if (!fullPath.StartsWith(dir.FullName, StringComparison.OrdinalIgnoreCase)) if (!fullPath.StartsWith(dir.FullName, StringComparison.OrdinalIgnoreCase))
{ {
Console.Error.WriteLine($"Skipping unsafe path: {entry.FullName}"); Log.Error($"Skipping unsafe path: {entry.FullName}");
continue; continue;
} }

View file

@ -2,6 +2,14 @@ using System.CommandLine;
var rootCommand = new RootCommand("The Sims 2 .s2pk Package Manager"); 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<bool>( var sims3option = new Option<bool>(
aliases: ["--ts3"], aliases: ["--ts3"],
description: "Switch to The Sims 3 mode.", description: "Switch to The Sims 3 mode.",

View file

@ -26,7 +26,7 @@ While The Sims 2 runs well on Linux through Wine, especially with Lutris setups,
| ----- | ------------------------------------------- | ------ | | ----- | ------------------------------------------- | ------ |
| v0.1 | Core package manager | ✅ | | v0.1 | Core package manager | ✅ |
| v0.2 | Config file with default paths | ✅ | | 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 | 🔜 | | v0.x | Target .NET 10 | 🔜 |
| v1.0 | Stable "Release" version with documentation | 🔜 | | v1.0 | Stable "Release" version with documentation | 🔜 |

View file

@ -14,6 +14,9 @@
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<PackageReference Include="Serilog" Version="4.2.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="6.0.0" />
<PackageReference Include="Serilog.Sinks.Debug" Version="3.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" /> <PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Tomlyn" Version="0.19.0" /> <PackageReference Include="Tomlyn" Version="0.19.0" />
</ItemGroup> </ItemGroup>