问题
I am building a setup in install4j which will be run for each client of a marketing agency. There is one installer, but the user can run it more than once, specifying a different clientId value at the installation time. In the end, I would like to end up with a directory structure like this:
on Mac:
/Applications/MYPRODUCTNAME-clientID1/
/Applications/MYPRODUCTNAME-clientID2/
/Applications/MYPRODUCTNAME-clientID3/
on Windows:
/Program Files/MYPRODUCTNAME-clientID1/
/Program Files/MYPRODUCTNAME-clientID2/
/Program Files/MYPRODUCTNAME-clientID3/
Where the IDs are entered at installation time, in independent installer runs. The IDs are not known in advance - I can't build as many installers as there are IDs. Ideally, on Mac, I would also prefer to change the name of the launcher file, so that it can be easily discerned from the others in Spotlight search. I've been playing with Directory Resolver - no luck, especially on Mac which seams to produce a broken launcher on every attempt to change its directory structure.
Any help will be greatly appreciated!
回答1:
You can change the installation directory by calling
context.setInstallationDirectory(...);
in a "Run script" action or any code snippet in install4j.
Changing launcher names at runtime is not directly supported by install4j.
回答2:
I ended up doing something like this:
At activation of the Location window:
systemInstallPath = context.getVariable( "sys.programFilesDir" ); // if Windows
if( systemInstallPath == null || systemInstallPath.isEmpty() ) // assume Mac
systemInstallPath = "/Applications";
context.setInstallationDirectory( new File( systemInstallPath ) );
Then at activation of Installation window:
final Boolean confirmedUpdate = context.getBooleanVariable("sys.confirmedUpdateInstallation");
if( confirmedUpdate == null || !confirmedUpdate ) {
final File originalInstallDir = context.getInstallationDirectory();
final String clientId = ( String )context.getVariable( "clientId" );
final File clientInstallDir = new File( originalInstallDir, "MYPRODUCTNAME-" + clientId );
context.setInstallationDirectory( clientInstallDir );
}
That did the trick.
来源:https://stackoverflow.com/questions/12066525/customizing-installation-directory-in-install4j