2016-04-26 124 views
3

運行「更新當前安裝」選項,如何從先前的安裝中獲取版本信息?我已經通過API了,我見過的最接近的是public static interface ApplicationRegistry.ApplicationInfo從以前的安裝中獲取版本信息

編輯
這是我當前如何去了解它。它的工作原理,但我不確定這是否是最可行的方法。

import com.install4j.api.ApplicationRegistry; 

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

return AppInfo[0].getVersion(); 

回答

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

例如,這可以在安裝程序的「啓動」節點「運行腳本」的行動中。

2

如果指定的目錄包含install4j安裝的應用程序並檢索其信息您可以使用

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

檢查。

這將返回一個ApplicationInfo而不是ApplicationInfo []。