2017-08-10 147 views

回答

0

您可以將「運行腳本」操作添加到安裝程序的「啓動」節點,以驗證已安裝的版本。

下面的代碼片段演示瞭如何驗證對較新版本,如果他們是簡單的整數:

// 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。 –

相關問題