2017-08-10 1 views

Répondre

0

Vous pouvez ajouter une action "Exécuter un script" au noeud "Démarrage" de votre programme d'installation pour valider la version déjà installée.

L'extrait de code suivant montre comment valider contre les versions plus récentes si elles sont des nombres entiers simples:

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

Merci! Les versions sont plus complexes telles que 10.6.5. De quels changements aurais-je besoin? J'obtiens une exception java.lang.NumberFormatException: telle quelle. –

+0

Ce n'est pas dans l'API, mais vous pouvez utiliser la méthode interne 'com.install4j.runtime.util.VersionCheck.checkCompatible (version1, version2)' qui retournera true si 'version1' est inférieur à' version2'. –