Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion ParTool/Options/Extract.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// -------------------------------------------------------
// © Kaplas. Licensed under MIT. See LICENSE for details.
// © Kaplas, Samuel W. Stark (TheTurboTurnip). Licensed under MIT. See LICENSE for details.
// -------------------------------------------------------
namespace ParTool.Options
{
Expand Down Expand Up @@ -29,5 +29,11 @@ internal class Extract
/// </summary>
[Option('r', "recursive", Default = false, HelpText = "Extract nested PAR archives.")]
public bool Recursive { get; set; }

/// <summary>
/// Gets or sets a value used as a Regex filter for which files to extract.
/// </summary>
[Option("filter", Default = null, HelpText = "Only extract files that match this RegEx (directories will always be extracted)")]
public string FilterRegex { get; set; }
}
}
8 changes: 7 additions & 1 deletion ParTool/Options/List.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// -------------------------------------------------------
// © Kaplas. Licensed under MIT. See LICENSE for details.
// © Kaplas, Samuel W. Stark (TheTurboTurnip). Licensed under MIT. See LICENSE for details.
// -------------------------------------------------------
namespace ParTool.Options
{
Expand All @@ -23,5 +23,11 @@ internal class List
/// </summary>
[Option('r', "recursive", Default = false, HelpText = "List nested PAR archives.")]
public bool Recursive { get; set; }

/// <summary>
/// Gets or sets a value used as a Regex filter for which files to list.
/// </summary>
[Option("filter", Default = null, HelpText = "Only list files that match this RegEx")]
public string FilterRegex { get; set; }
}
}
17 changes: 14 additions & 3 deletions ParTool/Program.Extract.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// -------------------------------------------------------
// © Kaplas. Licensed under MIT. See LICENSE for details.
// © Kaplas, Samuel W. Stark (TheTurboTurnip). Licensed under MIT. See LICENSE for details.
// -------------------------------------------------------
namespace ParTool
{
using System;
using System.IO;
using System.Text.RegularExpressions;
using ParLibrary;
using ParLibrary.Converter;
using Yarhl.FileSystem;
Expand Down Expand Up @@ -39,6 +40,9 @@ private static void Extract(Options.Extract opts)

Directory.CreateDirectory(opts.OutputDirectory);

// If a FilterRegex was specified (i.e. is not null) then make a new Regex using it. Otherwise, set filterRegex to null.
var filterRegex = (opts.FilterRegex == null) ? null : new Regex(opts.FilterRegex);

var parameters = new ParArchiveReaderParameters
{
Recursive = opts.Recursive,
Expand All @@ -47,10 +51,10 @@ private static void Extract(Options.Extract opts)
using Node par = NodeFactory.FromFile(opts.ParArchivePath, Yarhl.IO.FileOpenMode.Read);
par.TransformWith<ParArchiveReader, ParArchiveReaderParameters>(parameters);

Extract(par, opts.OutputDirectory);
Extract(par, filterRegex, opts.OutputDirectory);
}

private static void Extract(Node parNode, string outputFolder)
private static void Extract(Node parNode, Regex filterRegex, string outputFolder)
{
foreach (Node node in Navigator.IterateNodes(parNode))
{
Expand All @@ -65,6 +69,13 @@ private static void Extract(Node parNode, string outputFolder)
continue;
}

// If the filterRegex exists, skip files that don't match it
if (filterRegex != null && !filterRegex.IsMatch(node.Path))
{
Console.WriteLine($"Skipping {node.Path}");
continue;
}

Console.Write($"Extracting {node.Path}... ");

if (file.IsCompressed)
Expand Down
12 changes: 11 additions & 1 deletion ParTool/Program.List.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
// -------------------------------------------------------
// © Kaplas. Licensed under MIT. See LICENSE for details.
// © Kaplas, Samuel W. Stark (TheTurboTurnip). Licensed under MIT. See LICENSE for details.
// -------------------------------------------------------
namespace ParTool
{
using System;
using System.IO;
using System.Text.RegularExpressions;
using ParLibrary;
using ParLibrary.Converter;
using Yarhl.FileSystem;
Expand All @@ -24,6 +25,9 @@ private static void List(Options.List opts)
return;
}

// If a FilterRegex was specified (i.e. is not null) then make a new Regex using it. Otherwise, set filterRegex to null.
var filterRegex = (opts.FilterRegex == null) ? null : new Regex(opts.FilterRegex);

var parameters = new ParArchiveReaderParameters
{
Recursive = opts.Recursive,
Expand All @@ -37,6 +41,12 @@ private static void List(Options.List opts)
var file = node.GetFormatAs<ParFile>();
if (file != null)
{
// If the filterRegex exists, skip files that don't match it
if (filterRegex != null && !filterRegex.IsMatch(node.Path))
{
continue;
}

var compression = file.IsCompressed ? "*" : string.Empty;
Console.WriteLine($"{node.Path}{compression}\t{file.DecompressedSize} bytes\t{file.FileDate:G}");
}
Expand Down
25 changes: 22 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,39 @@ It supports ***SLLZ*** compression (Including ***SLLZ V2*** used in Yakuza Kiwam
## Usage
- **List mode**

`ParTool.exe list <archive.par> [-r]`
`ParTool.exe list <archive.par> [-r] [--filter '<regex filter>']`

Reads a PAR archive and shows it contents.

`-r` parameter enables *recursive* mode and shows the contents of nested PAR archives.

`--filter` parameter filters output lines using a user-provided regular expression.

For example, `ParTool.exe list mesh.par -r --filter '\.gmd$'` will only list GMD files (files that end with the characters '.gmd').
See [https://regexr.com/7q33s] for an explanation of this regular expression, and [the .NET Regular Expression Quick Reference](https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference) for a complete guide to the syntax.

If using Powershell, use single quotes `'` to surround the expression to avoid variable expansion [(see the Powershell docs)](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.4#single-quoted-strings).
If using Command Prompt, use double quotes.

- **Extraction mode**

`ParTool.exe extract <archive.par> <output_directory> [-r]`
`ParTool.exe extract <archive.par> <output_directory> [-r] [--filter '<regex filter>']`

Extracts the PAR archive contents to the specified directory.

`-r` parameter enables *recursive* mode and extracts the contents of nested PAR archives.


`--filter` parameter filters extracted files using a user-provided regular expression.
Files that do not match the filter will not be extracted.
Directories are always extracted.
When combined with `-r`, files matching the filter inside nested PAR archives will be extracted.

For example, `ParTool.exe extract mesh.par -r --filter '\.gmd$'` will only extract GMD files (files that end with the characters '.gmd').
See [https://regexr.com/7q33s] for an explanation of this regular expression, and [the .NET Regular Expression Quick Reference](https://learn.microsoft.com/en-us/dotnet/standard/base-types/regular-expression-language-quick-reference) for a complete guide to the syntax.

If using Powershell, use single quotes `'` to surround the expression to avoid variable expansion [(see the Powershell docs)](https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_quoting_rules?view=powershell-7.4#single-quoted-strings).
If using Command Prompt, use double quotes.

- **Creation mode**

`ParTool.exe create <input_directory> <archive.par> [-c compression_mode] [--alternative-mode]`
Expand Down