【问题标题】:Obtain version information from prior installation从之前的安装中获取版本信息
【发布时间】:2016-04-26 14:31:44
【问题描述】:

运行“更新当前安装”选项,我如何从之前的安装中获取版本信息?我已经通过 API,我见过的最接近的是 public static interface ApplicationRegistry.ApplicationInfo

编辑
这就是我目前的做法。它有效,但不确定这是否是最可行的方法。

import com.install4j.api.ApplicationRegistry;

ApplicationRegistry.ApplicationInfo[] AppInfo = ApplicationRegistry.getApplicationInfoById(context.getApplicationId());

return AppInfo[0].getVersion();

【问题讨论】:

    标签: java install4j


    【解决方案1】:

    你可以使用

    static ApplicationRegistry.ApplicationInfo getApplicationInfoByDir(java.io.File dir)
    

    检查指定目录是否包含由 install4j 安装的应用程序并检索有关它的信息。

    这将返回一个 ApplicationInfo 而不是 ApplicationInfo[]。

    【讨论】:

      【解决方案2】:

      例如,以下脚本检查是否已安装相同版本:

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

      这可以在安装程序的“启动”节点中的“运行脚本”操作中使用。

      【讨论】:

        猜你喜欢
        • 2019-01-05
        • 1970-01-01
        • 2021-01-24
        • 2013-07-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多