Skip to content

Commit

Permalink
Added documentation for JSON operations
Browse files Browse the repository at this point in the history
and slightly improved grammar and info on other commands

closes #39
  • Loading branch information
hhyyrylainen committed Dec 17, 2024
1 parent d9c3ebb commit 6b2db55
Showing 1 changed file with 71 additions and 2 deletions.
73 changes: 71 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,20 @@ Long form:
godotpcktool --pack Thrive.pck --action add --remove-prefix extracted --file extracted
```

The files are added with the specified paths on the command line, but
with the prefix removed. So for example if there was a file called
`extracted/example.png` and `extracted/subfolder/file.txt` and the
above command was used, those files would get added to the pck as
`res://example.png` and `res://subfolder/file.txt`.

After adding files it is recommended to use the listing command to
view the resulting data inside the pck to verify the expected actions
happened correctly. When a new file matches exactly the path name
inside the pck, it will replace that file.

To have more control over the resulting paths inside the pck, see the
section below on the JSON commands.

### Filters

Filters can be used to only act on a subset of files in a pck file, or
Expand Down Expand Up @@ -87,7 +101,7 @@ NOTE: if you use max size to compliment min size extraction, you
should subtract one from the size, otherwise you'll operate on the
same files twice.

However if you want to work on exactly some size files you can specify the same size twice:
However, if you want to work on exactly some size files you can specify the same size twice:
```sh
godotpcktool --min-size-filter 1 --max-size-filter 1
```
Expand Down Expand Up @@ -138,12 +152,54 @@ godotpcktool -i '\.po' -e 'zh'
If you need more complex filtering you can specify regular expressions with
`--include-override-filter` which makes any file matching any of those
regular expression be included in the operation, even if another filter
would cause the file to be excluded. For example you can use this to set
would cause the file to be excluded. For example, you can use this to set
file size limits and then override those for specific type:
```sh
godotpcktool --min-size-filter 1000 --include-override-filter '\.txt'
```

#### JSON bulk operations

To have more control over the resulting paths inside the pck file,
there is a JSON operation API provided.

To use it, you first need to create a JSON file (`commands.json` in
the example command but any name can be used) with the following
structure (as many files can be specified as required):
```json
[
{
"file": "/path/to/file",
"target": "overridden/path/file"
},
{
"file": "LICENSE",
"target": "example/path/LICENSE"
}
]
```

Then run the following command to use it (the JSON command can always
be specified when the add operation is used):
```sh
godotpcktool Thrive.pck -a a --command-file commands.json
```

This will read `/path/to/file` which can be an absolute or a relative
path, and save it within the pck as `res://overridden/path/file` and
also the `LICENSE` file as `res://example/path/LICENSE`. This way it
is possible to use absolute paths and specify whatever path the file
should end up as in the pck file for maximum control.

Note that the full path without the `res://` prefix needs to be in the
JSON `target` property for where the file inside the pck should end up
in; this mode doesn't support specifying just the folder so multiple
files with `target` being `pck/folder` will overwrite each other
rather than being placed inside `pck/folder`. So always specify full
paths like `pck/folder/README.txt` rather than `pck/folder/` when
specifying the JSON commands.


### Advanced Options

#### Specifying Engine Version
Expand All @@ -158,6 +214,19 @@ godotpcktool NewPack.pck -a a some_file.txt --set-godot-version 3.5.0
Note that this approach **does not** override the engine version number in existing .pck
files. This currently only applies to new .pck files.

#### Scripting

It is possible to use the JSON bulk API without creating a temporary file. This is done by specifying `-` as the file to add and then writing the JSON to the tool's stdin and then closing it.

```sh
godotpcktool NewPack.pck -a a -
```

When starting the above command, the tool will read all lines from stdin until it is closed. At that point the input JSON is
parsed. As stdin needs to be closed for the tool to continue this is not meant for interactive use, but only for scripting. See the above section about the JSON command files for a version usable on the command line.

See above for the format of the accepted JSON as it is the same as the JSON command file format.

### General info

In the long form multiple files may be included like this:
Expand Down

0 comments on commit 6b2db55

Please sign in to comment.