Fallback to config for destination directory

- Install script
- Rewrote Why This Exists section
- Method documentation comments
This commit is contained in:
Tony Bark 2025-04-30 08:46:02 -04:00
parent 170a46b6bf
commit b23431cdb2
7 changed files with 99 additions and 10 deletions

18
Config.cs Normal file
View file

@ -0,0 +1,18 @@
namespace S2PK;
public class Config
{
public string Destination { get; set; } = string.Empty;
/// <summary>
/// Loads the configuration from the specified file path.
/// </summary>
/// <param name="path">The path to the configuration file.</param>
/// <returns>The loaded configuration.</returns>
public static Config Load(string path)
{
var file = File.ReadAllText(path);
var config = Toml.ToModel<Config>(file);
return config;
}
}

2
GlobalUsing.cs Normal file
View file

@ -0,0 +1,2 @@
global using S2PK;
global using Tomlyn;

View file

@ -1,4 +1,4 @@
namespace S2Pkg;
namespace S2PK;
using System.IO.Compression;
@ -7,6 +7,11 @@ public static class PackageManager
const string PackageExtension = ".package";
const string S2pkExtension = ".s2pk";
/// <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)
{
var dir = new DirectoryInfo(source);
@ -36,8 +41,19 @@ public static class PackageManager
Console.WriteLine($"Created {file.FullName} with {packageFiles.Length} files.");
}
public static void UnpackPackages(string package, string destination)
/// <summary>
/// Unpacks a package file into a destination directory.
/// </summary>
/// <param name="package">The path to the package file.</param>
/// <param name="destination">The destination directory. If not provided, the destination is read from the configuration file.</param>
public static void UnpackPackages(string package, string destination = "")
{
if (string.IsNullOrEmpty(destination))
{
var config = Config.Load("s2pk.toml"); // TODO: Config file should be in application directory
destination = config.Destination;
}
var file = new FileInfo(package);
var dir = new DirectoryInfo(destination);

View file

@ -1,4 +1,3 @@
using S2Pkg;
using System.CommandLine;
var rootCommand = new RootCommand("The Sims 2 .s2pk Package Manager");
@ -32,8 +31,7 @@ var packageOption = new Option<string>(
var destinationOption = new Option<string>(
aliases: ["--destination", "-d"],
description: "Destination directory (e.g., The Sims 2 Downloads folder)")
{ IsRequired = true };
description: "Destination directory (e.g., The Sims 2 Downloads folder)");
// Unpack command
var unpackCommand = new Command("unpack", "Unpacks a .s2pk archive to the Downloads folder")

View file

@ -2,19 +2,26 @@
S2PK, or Sims 2 Package Manager, aims to provide a simple cross-platform solution to package management.
## 💡 Why This Exists
## Why This Exists
S2PK was created to address the need for a reliable and efficient cross-platform package management system for The Sims 2 on Linux and macOS. Players on these platforms often face challenges in managing mods due to the lack of a unified solution that their Windows counterparts solved a long time ago.
While The Sims 2 runs well on Linux through Wine, especially with Lutris setups, and natively from macOS, only the Windows community had varies mod managers and installers compared to their cross-platform counterparts. Later installments addressed this dilemma, but TS2 never got that treatment.
``s2pk`` aims to fill this gap: a no-nonsense CLI utility for packaging, sharing, and managing mods across all platforms. Its small, clean, and plays nicely with scripts, backups, and version control. In theory, it would be possible to use it on legacy front ends.
## 🛣️ Project Roadmap
| Phase | Goal | Status |
| ----- | ------------------------------------------- | ------ |
| v0.1 | Core package manager | ✅ |
| v0.1 | Core package manager | ✅ |
| v0.2 | Config file with default destination | 🔜 |
| v0.x | Target .NET 10 | 🔜 |
| v1.0 | Stable "Release" version with documentation | 🔜 |
## 🎯 Stretch Goals
- [ ] Manifest validation
- [ ] ``s1pk`` soft fork
## 🧩 Tech Stack
- .NET 8.0
@ -22,7 +29,28 @@ S2PK was created to address the need for a reliable and efficient cross-platform
- System.CommandLine for CLI parsing (no external libraries)
- Pure backend logic (no UI planned)
## Example
## 📐 Design Principles
- Stay true to UNIX design philosophy
- Simple with no bloat or feature creep
- Portable and clean
## 🛠️ Installation
You can build yourself with ``make``, or use the installer script:
```shell
./install.sh ./dist/s2pk-linux/s2pkg
```
Make sure ``~/.local/bin`` is in your ``PATH``:
```shell
echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc
source ~/.bashrc
```
## 🗜️ Usage
```shell
s2pk pack -s ./mods -o output.s2pk

View file

@ -13,8 +13,8 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Nett" Version="0.15.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Tomlyn" Version="0.19.0" />
</ItemGroup>
</Project>

27
install.sh Normal file
View file

@ -0,0 +1,27 @@
#!/bin/bash
# Install s2pkg locally for current user (no sudo)
# Usage: ./install.sh ./dist/s2pkg-linux/s2pkg
set -e
SOURCE_BIN="$1"
INSTALL_DIR="$HOME/.local/bin"
TARGET="$INSTALL_DIR/s2pkg"
if [[ ! -x "$SOURCE_BIN" ]]; then
echo "❌ Error: Provide a valid built s2pkg binary as the first argument."
exit 1
fi
mkdir -p "$INSTALL_DIR"
cp "$SOURCE_BIN" "$TARGET"
chmod +x "$TARGET"
if [[ ":$PATH:" != *":$INSTALL_DIR:"* ]]; then
echo "⚠️ $INSTALL_DIR is not in your PATH. Consider adding this to your shell profile:"
echo " export PATH=\"\$HOME/.local/bin:\$PATH\""
else
echo "✅ Installed s2pkg to $TARGET"
echo "Run 's2pkg --help' to get started."
fi