2016-04-26 16 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を返します。一例として、

関連する問題