2016-04-26 2 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; 
} 

Это может быть, например, использоваться в «Run сценария» действия в узле «Автозагрузка» программы установки.

2

Вы можете использовать

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

Проверяет указанный каталог содержит приложение, установленное install4j и извлекает информацию об этом.

Это вернет ApplicationInfo вместо ApplicationInfo [].