Pack
create a runnable package out of files and folders
Pack is a utility that allows you to pack a bunch of files and folders into one runnable file. When packing files you specify one file, the main program of the package, to be ran whenever the package is ran. The main program and any other programs ran within the execution of the package can then access the packed files as if those files were actually in the filesystem, even though those files are not. You can read, append to and overwrite the files inside the package through the main program just as you would normally do. The best part about Pack is that it should work with any and all already written programs. This is perfect if you have a multi-file program that you want to easily distribute for others to use.
First, you have to create a package. The package is created depending on certain variables. To start, a pack must have a main program, which is ran whenever the package is ran. Then, the package needs to know what files and folders it should contain. This list is called the 'include' list. Every file and folder inside the 'include' list will be included in the package, placed under their name. You can then tell the package that you want certain files to be read-only or maybe write-only. After setting those up the package is created. When the package is ran it first overwrites the fs API to emulate the packed files. The packed files are virtually placed in the 'root' directory, which by default is set to the directory the package is in. After overwriting the fs API the main program is ran. The main program and any other programs launched in the time of package execution will be able to read and write packed files just as if they were actually in the file system. After the main program stops, the package stops, restoring the original fs API and returning whatever the main program returned.
pack <main file> <destination file> [--pack-all | [[-i] folders/files/%self%[;(r|w|rw)]] [-e folders/files] [-p path;(r|w|rw)] [-r path] [--include-self]]
Usage explanation
main file - is a Lua program which is ran whenever you run the package. You do not need to add this file into the 'include' list.destination file - is the path of the resulting package.
main file and destination file are both required arguments. You can optionally specify these arguments:
–pack-all - if specified, this argument must be the third argument and will indicate to pack all the files and folders inside the current directory without any exceptions. No other arguments will be accepted after this argument.
[-i] folders/files/%self%[;(r|w|rw)] - if specified, this is the 'include' list of paths separated by either spaces ' ' or colons ':'. If one of the paths is %self% then Pack will also be included in the package. To change the permissions of a path group separated by colons ':' add a semicolon ';' at the end of a list and then either r - read-only, w - write-only or rw - read and write (default). The '-i' is optional if path list is the third argument.
-e folders/files - if specified, this is the 'exclude' list of paths separated by either spaces ' ' or colons ':'. By default, Pack is automatically inserted into this list.
-p path;(r|w|rw) - if specified, this is a list of resulting paths and their permissions separated by spaces ' ' or colons ':'.
-r path - if specified, changes the root directory of the resulting files. By default, the root directory is dynamically set whenever the resulting package is ran to the same directory the package is in.
–include-self - if specified, will include Pack in the resulting package.
If the 'include' list is not specified, the 'include' list will have all the files in the current directory, excluding Pack and external drives; if ran in the root directory the 'rom' folder and any connected 'disk' folders will be excluded.
Example usage
Any of these examples will pack the 'redirection' game inside the ROM together with its levels into a runnable package file located at '/red'. Assuming Pack was downloaded and saved as 'pack'.This example uses the file '/rom/programs/fun/advanced/redirection' as the main program and packs it together with the folder '/rom/programs/fun/advanced/levels/'.
> pack /rom/programs/fun/advanced/redirection red /rom/programs/fun/advanced/levels/
This example requires to first navigate to the '/rom/programs/fun/advanced/' folder and then continue from that. It uses the 'exclude' option to exclude unwanted files.
> cd /rom/programs/fun/advanced/
rom/programs/fun/advanced> /pack redirection /red -e paint redirection
In the above example the exclude list can also use colons to separate the files:
-e paint:redirection
This example changes the permissions of the 'levels' folder to read-only, so levels could not be edited, nor added.
> cd /rom/programs/fun/advanced/
rom/programs/fun/advanced> /pack redirection /red -i levels;r
This example makes all the existing levels read-only, but leaving the 'levels' folder editable so you could add more levels, but not overwrite existing ones.
> cd /rom/programs/fun/advanced/
rom/programs/fun/advanced> /pack redirection /red -include levels -p levels/*;r
Notes
- This program is licensed under the MIT license.
- The resulting package will pass all the arguments (it was passed) to the main program and return whatever the main program returns.
- Pack can also work with binary files.
- To overwrite files you simply put a file you want to overwrite in the place where your program expects the file to be. So, if I have a program which depends on the file '/settings.cfg' and I pack those files together I can then overwrite the 'settings.cfg' by simply creating a file with the same name and putting it in the root directory. This operation is seamless when overwriting/appending files through the package itself.
- You can use -include, -exclude, -perms (or -permissions) and -root instead of -i, -e, -p and -r.
- Type in 'pack ?' to get in-game help.
Changelog
[2015-07-23] 1.2:- added another switch: -p (-perms, -permissions) that lets changing inner file permissions.
- added ability to change the root folder of the packed files.
- added more checks, so errors are more clear.
- you can now use -include, -exclude, -perms (or -permissions) and -root instead of their short versions -i, -e, -p and -r.
- Added more comments in the resulting package for possible future additions - changes of the package files and permissions after it was created (just like .zip or .rar archives).
- fixed a bug when certain files were overwriting other file's permissions.
[2015-07-20] 1.1:
- added file permissions. You can no longer add files to packed read-only directories or overwrite packed read-only files. By default, all files and folders are readable and writable.
- added ability to use wildcards (*) in include and exclude paths.
- added more checks, so errors are more clear.
- will not pack the files if the main program has syntax errors.
- fixed a bug where you were able to overwrite files with folders and folders with files.
- Added more comments in the resulting package for possible future additions - changes of the package files and permissions after it was created (just like .zip folders).
[2015-07-19] 1.0.1:
- added more checks so the program wouldn't error as much.
[2015-07-19] 1.0:
- first public release.
Report any and all bugs by leaving a reply.
Feedback is greatly appreciated.
Enjoy the program!