Godot.Pck is a C# wrapper around Henri Hyyryläinen 's GodotPckTool. Providing a simple-to-use library for handling Godot 4 .pck files with C#.
Godot.Pck can be found on nuget.org as Pixel.Godot.Pck
We are open to any contribution deemed helpful to the project.
We lack macOS support and Godot 3 support!
Include the Godot.Pck namespace
Create a new pck file using the Package class's constructor with the PckMode.Create mode
Package(path, PckMode.Create)For example:
var myPck = Package("package.pck", PckMode.Create)If a file exists at path it will be overwritten, if it's a directory an error will be thrown.
If you already have a pck file you can use the Package class's constructor with the PckMode.Open mode
Package(path, PckMode.Open)For example:
var myPck = Package("package.pck", PckMode.Open)If the given file path does not exist an error will be thrown.
For adding files to the pck file you can use the AddFile functions
All of these functions return an AddError indicating the result of the function.
Package.AddFile(string filePath)Adds filePath to the root directory of the pck file
Package.AddFile(string filePath, string internalPath)Adds a filePath to internalPath in the pck file. Creates parent directories if needed.
Package.AddFile(Stream data, string internalPath)Adds a file from memory to internalPath in the pck file, as above it will create parent directories.
If you already have your pck laid out as a directory you use
Package.Pack(string dir, bool overwrite)This will create a pck file, writing all the contents of dir to the pck file's root
If overwrite is false, this will throw an error if the file was opened via PckMode.Open OR if you modified the pck file after creating it with PckMode.Create
Will throw an exception if dir does not exist.
This can be done with the GetFiles functions.
Package.GetFiles()This will return a string[] with the path of every file in the package
Package.GetFiles(string dir)This will return a string[] with the path of every file and directory in dir inside in the package.
Returned directories will always end with /
You can delete files using the DeleteFile function.
Package.DeleteFile(string filePath)This will delete the file in the pck, if the remaining directory is empty it will be deleted.
To extract the pck file into an empty directory you can use the Extract function.
Package.Extract(string dest)This will extract every file in the pck file into dest.
If dest does not exist; it will be created.