防止在较新版本上安装较旧版本
答
您可以将“运行脚本”操作添加到安装程序的“启动”节点,以验证已安装的版本。
下面的代码片段演示了如何验证对较新版本,如果他们是简单的整数:
// 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;
}
if (Integer.parseInt(applicationInfo.getVersion()) >
Integer.parseInt(context.getVersion())) {
Util.showErrorMessage("A more recent version has already been" +
" 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;
}
+0
谢谢!版本更复杂,例如10.6.5。我需要什么改变?我得到一个java.lang.NumberFormatException:原样。 –
+0
它不在API中,但可以使用内部方法'com.install4j.runtime.util.VersionCheck.checkCompatible(version1,version2)',如果'version1'低于'version2',它将返回true。 –
Install4j v5.1.15 –