mirror of
https://github.com/tonytins/s2pk.git
synced 2025-05-19 07:23:17 -04:00
Unpacking now accounts for a lot more cases
This commit is contained in:
parent
b060f1de5e
commit
a773f267f7
2 changed files with 39 additions and 10 deletions
|
@ -8,16 +8,23 @@ public static class PackageManager
|
|||
const string S2pkExtension = ".s2pk";
|
||||
const string S3pkExtension = ".s3pk";
|
||||
|
||||
/// <summary>
|
||||
/// Returns the extension for the package file.
|
||||
/// </summary>
|
||||
/// <param name="ts3">Whether to use the Sims 3 extension.</param>
|
||||
/// <returns>The extension for the package file.</returns>
|
||||
static string ExtensionHandler(bool ts3 = false) => ts3 ? S3pkExtension : S2pkExtension;
|
||||
|
||||
/// <summary>
|
||||
/// Packs a directory into a package file.
|
||||
/// </summary>
|
||||
/// <param name="source">The source directory.</param>
|
||||
/// <param name="output">The output package file.</param>
|
||||
public static void PackPackages(string source, string output)
|
||||
/// <param name="package">The output package file.</param>
|
||||
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
|
|||
/// <param name="ts3">Whether to unpack for The Sims 3.</param>
|
||||
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);
|
||||
|
|
17
Program.cs
17
Program.cs
|
@ -2,6 +2,11 @@ using System.CommandLine;
|
|||
|
||||
var rootCommand = new RootCommand("The Sims 2 .s2pk Package Manager");
|
||||
|
||||
var sims3option = new Option<bool>(
|
||||
aliases: ["--ts3"],
|
||||
description: "Switch to The Sims 3 mode.",
|
||||
getDefaultValue: () => false);
|
||||
|
||||
var sourceOption = new Option<string>(
|
||||
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<string>(
|
||||
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);
|
||||
|
|
Loading…
Add table
Reference in a new issue