Install4j - 升级时如何获取当前版本

时间:2017-04-05 18:01:38

标签: java install4j

任何人都知道如何确定随install4j安装的应用程序的当前安装版本。 我们的想法是根据已安装的版本确定安装和控制的内容。

由于

1 个答案:

答案 0 :(得分:0)

您可以使用ApplicationRegistry API来实现此目的。这是一个示例代码片段,可用于"运行脚本" " Startup"如果已安装当前版本,则阻止安装的节点:

// The value returned by context.getInstallationDirectory() will be the
// last installation directory
// if the user has already installed the application
ApplicationRegistry.ApplicationInfo applicationInfo =
    ApplicationRegistry.getApplicationInfoByDir(context.getInstallationDirectory());

if (applicationInfo == null) {
  // The application has never been installed before
    return true;
}

// The version of this installer is contained in a system installer variable
String myVersion = (String)context.getVariable("sys.version");
if (applicationInfo.getVersion().equals(myVersion)) {
    // In that case the current version is already installed.
    Util.showErrorMessage("The current version is already installed in this directory");
    // By returning "false", the action will fail and the installer will quit.
    // Note that you have to set the "Failure strategy" property of your
    // "Run script" action to "Quit on error", otherwise the installer will continue.
    return false;
} else {
    return true;
}