Skip to content

Commit

Permalink
Extended simulation mode
Browse files Browse the repository at this point in the history
- Renamed Directory to Destination
- WIP manifest file
  • Loading branch information
Tony Bark committed Aug 31, 2023
1 parent 7354f15 commit fa0f252
Show file tree
Hide file tree
Showing 7 changed files with 129 additions and 35 deletions.
46 changes: 39 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,40 @@
# File created using '.gitignore Generator' for Visual Studio Code: https://bit.ly/vscode-gig
# Created by https://www.toptal.com/developers/gitignore/api/linux,macos,visualstudio,visualstudiocode,windows
# Edit at https://www.toptal.com/developers/gitignore?templates=linux,macos,visualstudio,visualstudiocode,windows
# Created by https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,visualstudio,macos,linux,archives
# Edit at https://www.toptal.com/developers/gitignore?templates=windows,visualstudiocode,visualstudio,macos,linux,archives

### Archives ###
# It's better to unpack these files and commit the raw source because
# git has its own built in compression methods.
*.7z
*.jar
*.rar
*.zip
*.gz
*.gzip
*.tgz
*.bzip
*.bzip2
*.bz2
*.xz
*.lzma
*.cab
*.xar

# Packing-only formats
*.iso
*.tar

# Package management formats
*.dmg
*.xpi
*.gem
*.egg
*.deb
*.rpm
*.msi
*.msm
*.msp
*.txz

### Linux ###
*~
Expand Down Expand Up @@ -86,11 +120,7 @@ ehthumbs_vista.db
$RECYCLE.BIN/

# Windows Installer files
*.cab
*.msi
*.msix
*.msm
*.msp

# Windows shortcuts
*.lnk
Expand Down Expand Up @@ -484,7 +514,9 @@ FodyWeavers.xsd
### VisualStudio Patch ###
# Additional files built by Visual Studio

# End of https://www.toptal.com/developers/gitignore/api/linux,macos,visualstudio,visualstudiocode,windows
# End of https://www.toptal.com/developers/gitignore/api/windows,visualstudiocode,visualstudio,macos,linux,archives

# Custom rules (everything added below won't be overriden by 'Generate .gitignore File' if you use 'Update' option)

*.s1pk
*.iff
20 changes: 15 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,34 @@ Sims1Pack, or ``s1pk``, is a custom ZIP-based s1pk format designed to enhance th

## SimGet


SimGet is a simple command-line package manager designed to work with the ``s1pk`` format. At this stage, it provides support for extracting files. Packaging will need to be performed manually for now. SimGet serves as a reference implementation for the format. Below are the basic usage instructions:

### Usage

To extract an ``s1pk`` file, use the following command:

```shell
simget extract --file <file_path> --directory <directory_path>
```text
-d, --destination
-f, --file
-v, --verbose
-s, --simulate
--help Display this help screen.
--version Display version information.
```

- `<file_path>` should be replaced with the path to the s1pk file you want to extract.
- `<directory_path>` is the location where the contents of the ``s1pk`` file will be extracted to.
- In simulation mode, the destination doesn't need to be specified

### Platform Specifics

#### Windows

On Windows, SimGet defaults to the Complete Collection install directory for The Sims 1. This makes it convenient to work with mods and custom content in the Windows environment.
On Windows, SimGet defaults to the Complete Collection install directory for The Sims 1.

#### Other Platforms

Expand Down
30 changes: 30 additions & 0 deletions SimGet/Manifest.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// A custom ZIP-based format designed to enhance the Sims 1 modding experience.
// Copyright (C) 2023 Tony Bark
//
// This program is free software: you can redistribute it and/or modify it
// under the terms of the GNU General Public License as published by the Free
// Software Foundation, either version 3 of the License, or (at your option)
// any later version.
//
// This program is distributed in the hope that it will be useful, but WITHOUT
// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
// more details.
//
// You should have received a copy of the GNU General Public License along with
// this program. If not, see <http://www.gnu.org/licenses/>.
using System.Text.Json.Serialization;

namespace S1Util;

public record Manifest
{
[JsonPropertyName("version")]
public string Version { get; set; } = "1.0";

[JsonPropertyName("author")]
public string Author { get; set; } = Environment.UserName;

[JsonPropertyName("files")]
public string[] Files { get; set; } = new string[] { };
}
9 changes: 5 additions & 4 deletions SimGet/Options.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@ namespace S1Util;

public class Options
{
[Option('d', "dir")] public string Directory { get; set; } = string.Empty;
[Option('d', "destination")] public string Destination { get; set; } = string.Empty;
[Option('f', "file", Required = true)] public string File { get; set; } = string.Empty;
[Option('s', "simulate")] public bool Simulate { get; set; } = false;
[Option('v', "verbose")] public bool Verbose { get; set; } = false;
[Option('s', "simulate", HelpText = "Simulate the extraction or compression process.")] public bool Simulate { get; set; } = false;
}

[Verb("extract")]
[Verb("extract", HelpText = "Extract .s1pk archives.")]
public class Extract : Options { }

[Verb("compress")]
[Verb("compress", HelpText = "Compress .s1pk files.")]
public class Compress : Options { }
46 changes: 34 additions & 12 deletions SimGet/PackUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,30 +19,34 @@ namespace S1Util;

public class PackUtil
{
public PackUtil(string directory, string file)
public PackUtil(string destination, string file, bool simulate)
{
OutputPath = directory;
Destination = destination;
FilePath = file;
Simulate = simulate;
}

string OutputPath { get; set; } = string.Empty;
string Destination { get; set; } = string.Empty;
string FilePath { get; set; } = string.Empty;
bool Simulate { get; set; } = false;

void PathDetection()
void PathResolver()
{
var os = Environment.OSVersion;

if (os.Platform == PlatformID.Win32NT && OutputPath == string.Empty)
if (Simulate) Destination = Environment.CurrentDirectory;

if (os.Platform == PlatformID.Win32NT && Destination == string.Empty && !Simulate)
{
// TODO Presumed location. I haven't played the game in a while.
var progFiles = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86);
var gamePath = Path.Combine(progFiles, "The Sims Complete Collection", "Downloads");

OutputPath = gamePath;
Destination = gamePath;
}

// Check if game directory exists
if (!Directory.Exists(OutputPath))
if (!Directory.Exists(Destination) && !Simulate)
{
Console.WriteLine("Game not found.");
Environment.Exit(Environment.ExitCode);
Expand All @@ -65,27 +69,45 @@ void PathDetection()
}
}

public void Extract(bool simulate = false)
public void Extract()
{
PathDetection();
PathResolver();

// Extract the s1pk file
using var archive = ZipFile.OpenRead(FilePath);

foreach (ZipArchiveEntry entry in archive.Entries)
{
// Check if the entry has the .iff extension
if (entry.FullName.EndsWith(".iff", StringComparison.InvariantCultureIgnoreCase) && !simulate)
if (entry.FullName.EndsWith(".iff", StringComparison.InvariantCultureIgnoreCase))
{
// Build the full path for the extracted file
string extractFilePath = Path.Combine(OutputPath, entry.FullName);
var extractFilePath = Path.Combine(Destination, entry.FullName);

Console.WriteLine(extractFilePath);

// Extract the file
entry.ExtractToFile(extractFilePath, true);
if (!Simulate) entry.ExtractToFile(extractFilePath, true);
}
}

Console.WriteLine("Extraction completed successfully.");

}

public void Compress()
{
var files = Directory.GetFiles(Destination);
// using var archive = ZipFile.CreateFromDirectory()

foreach (var file in files)
{
if (file.EndsWith("iff", StringComparison.InvariantCultureIgnoreCase))
{

}
}

throw new NotImplementedException();
}
}
13 changes: 6 additions & 7 deletions SimGet/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,19 @@
Parser.Default.ParseArguments<Extract, Compress>(args)
.WithParsed<Extract>(opts =>
{
var dirPath = opts.Directory;
var dirPath = opts.Destination;
var zipPath = opts.File;
var unpack = new PackUtil(zipPath, dirPath);
unpack.Extract(opts.Simulate);
var unpack = new PackUtil(zipPath, dirPath, opts.Simulate);
unpack.Extract();
})
.WithParsed<Compress>(opts =>
{
var dirPath = opts.Directory;
var dirPath = opts.Destination;
var zipPath = opts.File;
var compress = new PackUtil(zipPath, dirPath);
throw new NotImplementedException();
var compress = new PackUtil(zipPath, dirPath, opts.Simulate);
compress.Compress();
});
Empty file removed docs/.gitkeep
Empty file.

0 comments on commit fa0f252

Please sign in to comment.