diff --git a/PackageManger.cs b/PackageManger.cs
index f22dfdc..7f27084 100644
--- a/PackageManger.cs
+++ b/PackageManger.cs
@@ -8,16 +8,23 @@ public static class PackageManager
const string S2pkExtension = ".s2pk";
const string S3pkExtension = ".s3pk";
+ ///
+ /// Returns the extension for the package file.
+ ///
+ /// Whether to use the Sims 3 extension.
+ /// The extension for the package file.
+ static string ExtensionHandler(bool ts3 = false) => ts3 ? S3pkExtension : S2pkExtension;
+
///
/// Packs a directory into a package file.
///
/// The source directory.
- /// The output package file.
- public static void PackPackages(string source, string output)
+ /// The output package file.
+ public static void PackPackages(string source, string package, bool ts3 = false)
{
var dir = new DirectoryInfo(source);
- var file = new FileInfo(output);
- var extention = S2pkExtension;
+ var file = new FileInfo(package);
+ var extension = ExtensionHandler(ts3);
if (!dir.Exists)
{
@@ -51,6 +58,8 @@ public static class PackageManager
/// Whether to unpack for The Sims 3.
public static void UnpackPackages(string package, string destination = "", bool ts3 = false)
{
+ var extension = ExtensionHandler(ts3);
+
// If destination is not provided, read from configuration file
if (string.IsNullOrEmpty(destination))
{
@@ -63,6 +72,14 @@ public static class PackageManager
destination = config.Paths.Sims3;
}
+ // Check if destination directory exists
+ if (!Directory.Exists(destination))
+ {
+ Console.Error.WriteLine("Destination directory does not exist.");
+ return;
+ }
+
+
var file = new FileInfo(package);
var dir = new DirectoryInfo(destination);
@@ -72,6 +89,13 @@ public static class PackageManager
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.");
+ return;
+ }
+
dir.Create(); // Ensures directory exists
using var archive = ZipFile.OpenRead(file.FullName);
diff --git a/Program.cs b/Program.cs
index ba595e0..6ab3c17 100644
--- a/Program.cs
+++ b/Program.cs
@@ -2,6 +2,11 @@ using System.CommandLine;
var rootCommand = new RootCommand("The Sims 2 .s2pk Package Manager");
+var sims3option = new Option(
+ aliases: ["--ts3"],
+ description: "Switch to The Sims 3 mode.",
+ getDefaultValue: () => false);
+
var sourceOption = new Option(
aliases: ["--source", "-s"],
description: "Source directory containing .package files")
@@ -19,10 +24,10 @@ var packCommand = new Command("pack", "Packs .package files into a .s2pk archive
outputOption
};
-packCommand.SetHandler((source, output) =>
+packCommand.SetHandler((source, output, sims3) =>
{
- PackageManager.PackPackages(source, output);
-}, sourceOption, outputOption);
+ PackageManager.PackPackages(source, output, sims3);
+}, sourceOption, outputOption, sims3option);
var packageOption = new Option(
aliases: ["--package", "-p"],
@@ -40,10 +45,10 @@ var unpackCommand = new Command("unpack", "Unpacks a .s2pk archive to the Downlo
destinationOption
};
-unpackCommand.SetHandler((package, destination) =>
+unpackCommand.SetHandler((package, destination, sims3) =>
{
- PackageManager.UnpackPackages(package, destination);
-}, packageOption, destinationOption);
+ PackageManager.UnpackPackages(package, destination, sims3);
+}, packageOption, destinationOption, sims3option);
// Register commands
rootCommand.AddCommand(packCommand);