gpt4 book ai didi

java - 防止旧版本安装在新版本之上

转载 作者:太空宇宙 更新时间:2023-11-04 11:14:35 26 4
gpt4 key购买 nike

我想设置一些版本验证,以防止最终用户在新版本之上安装旧版本。前任。安装版本 3 后阻止安装版本 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;
}

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;
}

关于java - 防止旧版本安装在新版本之上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45619014/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com