expansionInstallCallback inside a for loop
-
I have a custom expansionInstallCallback that shows an Alert Window after successfully installing an Expansion to inform users they need to restart the plugin. It works fine for single installations, but when I put it inside a loop to Batch Install multiple Expansions, it shows the alert window every time.
Is there a neat way to only show the alert window on the last Expansion install? I'm currently trying to get some sort of counter that keeps track of the number of remaining expansions but haven't been successful with it.
function expansionInstallCallback(obj) { if(obj.Status == 2 && isDefined(obj.Expansion)) Engine.showMessageBox("Installation Complete", "Library installed successfully, please restart NEAT Player.", 0); } expHandler.setInstallCallback(expansionInstallCallback);
//Bulk Install Method var num_expansions_remaining = 0; inline function onButton_BulkInstallControl(component, value) { if (value) { Engine.showYesNoWindow("Bulk Install", "Please select the folder containing the .hr1 files.", function(response) { if (!response) return; FileSystem.browseForDirectory(FileSystem.Downloads, function(f) { if (f.isDirectory()) { hrList = FileSystem.findFiles(f, "*.hr1", 0); Engine.showYesNoWindow("Target Directory", "Please select the folder to install the samples to.", function(response) { if (!response) return; FileSystem.browseForDirectory(FileSystem.Downloads, function(dir) { if (dir.isDirectory()) { num_expansions_remaining = hrList.length; for (i=0; i<hrList.length; i++) { num_expansions_remaining = hrList.length - (i + 1); expHandler.installExpansionFromPackage(hrList[i], dir); } } }); }); } }); }); } };
Cheers :)
-
@iamlamprey Just have a flag called something like
installComplete
. Set it to false before your install loop, after a successful install set it to true. After all installs complete check the state of the flag, if it's true then you show the alert. -
Also I think this video will be helpful to you
-
@d-healey said in expansionInstallCallback inside a for loop:
after a successful install set it to true.
Yeh that was my first attempt before this counter method, but the expansion install callback is on a different thread so putting the message outside of the callback makes it display instantly after clicking the button.
Also I think this video will be helpful to you
I actually like nesting code, I know it's uglier but I generally hate having single-use methods outside of the place they're being used, my brain just likes that more for some reason. :)
-
Don't use
var
unless you have to. Usereg
for your counter.num_expansions_remaining = hrList.length;
Try to stick to one naming convention, either use_
or use camelCase (HISE uses camel case so I recommend using the same).You need to increase your counter in the expansion callback, once the install is complete. Then you check and see if the counter >= the number of hrs, if it is then you show your message.
-
@d-healey said in expansionInstallCallback inside a for loop:
Don't use
var
unless you have to. Usereg
for your counter.Yeh I'll probably have to start namespacing soon, was trying to avoid it but I'm all out of regs :)
Got it working (so far):
var num_expansions_to_install; var expansionInstallIndex = 1; function expansionInstallCallback(obj) { if(obj.Status == 2 && isDefined(obj.Expansion)) { if (expansionInstallIndex >= num_expansions_to_install) { expansionInstallIndex = 1; Engine.showMessageBox("Installation Complete", "Library installation successful, please restart NEAT Player.", 0); } else expansionInstallIndex++; } } //Single if (dir.isDirectory()) { num_expansions_to_install = 1; expansionInstallIndex = 1; expHandler.installExpansionFromPackage(nest.hr, dir); } //Batch if (dir.isDirectory()) { num_expansions_to_install = hrList.length; expansionInstallIndex = 1; for (i=0; i<hrList.length; i++) { expHandler.installExpansionFromPackage(hrList[i], dir); } }
It's a bit clunky but it does the job, cheers!