简体   繁体   English

在install4j中自定义安装目录

[英]customizing installation directory in install4j

I am building a setup in install4j which will be run for each client of a marketing agency. 我正在install4j中构建一个设置,它将为营销机构的每个客户运行。 There is one installer, but the user can run it more than once, specifying a different clientId value at the installation time. 有一个安装程序,但用户可以多次运行它,在安装时指定不同的clientId值。 In the end, I would like to end up with a directory structure like this: 最后,我想最终得到这样的目录结构:

on Mac: 在Mac上:

/Applications/MYPRODUCTNAME-clientID1/
/Applications/MYPRODUCTNAME-clientID2/
/Applications/MYPRODUCTNAME-clientID3/

on Windows: 在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. 在安装时输入ID的位置,在独立安装程序运行中。 The IDs are not known in advance - I can't build as many installers as there are IDs. 这些ID事先不知道 - 我无法构建与ID相同数量的安装程序。 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. 理想情况下,在Mac上,我还希望更改启动器文件的名称,以便可以轻松地从Spotlight搜索中的其他文件中识别它。 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. 我一直在使用目录解析器 - 没有运气,特别是在Mac上,每次尝试更改其目录结构时都会产生破碎的启动器。

Any help will be greatly appreciated! 任何帮助将不胜感激!

You can change the installation directory by calling 您可以通过调用更改安装目录

context.setInstallationDirectory(...);

in a "Run script" action or any code snippet in install4j. 在“运行脚本”操作或install4j中的任何代码段。

Changing launcher names at runtime is not directly supported by install4j. install4j不直接支持在运行时更改启动器名称。

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. 这就是诀窍。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM