HEMTT icon indicating copy to clipboard operation
HEMTT copied to clipboard

Feature Request - Customize addon naming scheme

Open DartRuffian opened this issue 1 year ago • 7 comments

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

DartRuffian avatar Jun 01 '24 00:06 DartRuffian

You can rename addons in a post-build hook. I can paste an example used in CUP later today.

jonpas avatar Jun 01 '24 02:06 jonpas

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.

DartRuffian avatar Jun 01 '24 02:06 DartRuffian

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);
        }
    }
}

jonpas avatar Jun 01 '24 18:06 jonpas

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!

DartRuffian avatar Jun 01 '24 18:06 DartRuffian

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.

DartRuffian avatar Jun 01 '24 19:06 DartRuffian

Can you include the project and the branch you are trying this on with the failing script? I can take a look sometime

BrettMayson avatar Jun 07 '24 23:06 BrettMayson

Our project's repo is private because a lot of our models are community donated. You should have gotten an invitation to the project

DartRuffian avatar Jun 08 '24 02:06 DartRuffian

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

BrettMayson avatar Mar 12 '25 02:03 BrettMayson

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

DartRuffian avatar Mar 12 '25 14:03 DartRuffian

It only runs before putting the files into the .zip, it won't run on build

BrettMayson avatar Mar 12 '25 21:03 BrettMayson

So that doesn't solve my use case, as they're not renamed in build at all

DartRuffian avatar Mar 13 '25 02:03 DartRuffian

.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");

BrettMayson avatar Mar 13 '25 02:03 BrettMayson

I didn't realize you could get the mode and call scripts in rhai, that's cool

That worked perfectly, thanks :thumbsup:

DartRuffian avatar Mar 14 '25 00:03 DartRuffian