我使用install4j作为安装程序。我已经安装了我的应用程序,当我再次执行application_installer.exe来安装我的应用程序时,它会要求更新/创建新安装。但是如果已经安装了相同版本的应用程序,我想退出。我怎样才能在install4j安装程序中执行此操作?
答案 0 :(得分:1)
您可以使用以下脚本在安装程序的“启动”节点中添加“运行脚本”操作:
// 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;
}
这是代码编辑器代码库中的示例脚本。