Feature Request - Customize addon naming scheme
Currently, HEMTT will always use a project's prefix for pbo names, and will result in prefix_addon.pbo. I have a different usecase where we want our main prefix to be used for pbo names instead, or to just add a new property for the pbo prefix specifically.
Our main prefix is an acronym for the group, and then each mod's prefix is the name of the mod. I.e. \ls\core\... is the file path for the core mod, \ls\battlefields\ for another mod, etc.
However, this would result in our pbo names being core_addon.pbo or battlefields_addon.pbo, which isn't ideal. Having someway to control the naming schemes for pbos would be great, that way we could format them to be ls_core_addon.pbo/ls_battlefields_addon.pbo or just ls_addon.pbo.
Some ideas:
-
usemainprefix = true: would use mainprefix instead of prefix -
pboprefix = "prefix": would be used for pbo names, or prefix if not defined
You can rename addons in a post-build hook. I can paste an example used in CUP later today.
You can rename addons in a post-build hook. I can paste an example used in CUP later today.
Could do that yeah, just thought a built in solution would be nice as well.
let addons = HEMTT_OUT.join("addons");
let prefix_len = HEMTT.project().prefix().len();
for pbo_path in addons.list() {
let rpbo = pbo_path.file_name();
// Weapons_CUP_Weapons_ACR.pbo => cup_weapons_acr.pbo
if rpbo.starts_with("Weapons_CUP_") {
rpbo.crop(prefix_len + 1);
rpbo.make_lower();
let rpbo_path = addons.join(rpbo);
if !pbo_path.move(rpbo_path) {
fatal("Failed to rename " + pbo_path + " to " + rpbo_path);
}
}
}
let addons = HEMTT_OUT.join("addons"); let prefix_len = HEMTT.project().prefix().len(); for pbo_path in addons.list() { let rpbo = pbo_path.file_name(); // Weapons_CUP_Weapons_ACR.pbo => cup_weapons_acr.pbo if rpbo.starts_with("Weapons_CUP_") { rpbo.crop(prefix_len + 1); rpbo.make_lower(); let rpbo_path = addons.join(rpbo); if !pbo_path.move(rpbo_path) { fatal("Failed to rename " + pbo_path + " to " + rpbo_path); } } }
Looks simple enough, thanks!
I tried it out on my project but it seems running the hook in post_build causes release to fail to find a file:
INFO Binarized 29 files
INFO Built 39 PBOs
INFO Running hook: post_build/01_rename_pbos.rhai
INFO Copied 5 files
ERROR IO Error: The system cannot find the file specified. (os error 2)
hemtt build works as expected. Running the script in post_release lets hemtt release work, but then pbos aren't renamed in build versions.
Can you include the project and the branch you are trying this on with the failing script? I can take a look sometime
Our project's repo is private because a lot of our models are community donated. You should have gotten an invitation to the project
Doing this in the post_build hook was causing the issue (it wasn't working in CUP either), this is why the archive hook was added. Move the script there and it'll run without issue
With some quick testing on 1.14.7, and it didn't seem like the hook was running at all when using hemtt build or hemtt release
It only runs before putting the files into the .zip, it won't run on build
So that doesn't solve my use case, as they're not renamed in build at all
.hemtt/hooks/post_build/01_rename_pbos.rhai
if HEMTT.mode() != "release" {
HEMTT.script("rename_pbos");
}
.hemtt/scripts/rename_pbos.rhai
if HEMTT.mode() == "script" {
fatal("rename_pbos can not be ran directly");
}
// put your rename script here
.hemtt/hooks/archive/01_rename_pbos.rhai
HEMTT.script("rename_pbos");
I didn't realize you could get the mode and call scripts in rhai, that's cool
That worked perfectly, thanks :thumbsup: