Interface InstallerContext
- All Superinterfaces:
Context
The context provided by the installer.
In addition to the methods in the
Context interface, this extended context offers methods that are specific
to the installer.-
Method Summary
Modifier and TypeMethodDescriptionReturns the current media file.Get the name of the current media file.voidinstallDirectory(File directory, UninstallMode uninstallMode) Creates a directory.booleaninstallFile(File sourceFile, File destFile) Installs a file.booleaninstallFile(File sourceFile, File destFile, FileOptions options) Installs a file.booleaninstallFile(File sourceFile, File destFile, FileOptions options, ProgressInterface progressInterface, int fromPercent, int toPercent) Installs a file.booleanReturns whether the installer is or will be updating an existing version of the same program.voidregisterUninstallFile(File file) Registers an arbitrary file for uninstallation.voidsetInstallationDirectory(File installationDirectory) Set the installation directory programmatically.Methods inherited from interface Context
addInstallerEventListener, addToClassPath, cancel, finish, getActionById, getActions, getActions, getAddOnApplicationId, getAllUsersDefaultInstallationDirectory, getApplicationId, getApplicationName, getBooleanVariable, getCompilerVariable, getContentDirectory, getDefaultInstallationDirectory, getDestinationFile, getDestinationFile, getDestinationFileInfo, getExternalFile, getExternalFile, getExtraCommandLineArguments, getFileSetById, getFileSetByName, getFileSets, getFirstAction, getFirstScreen, getId, getId, getInstallationComponentById, getInstallationComponents, getInstallationDirectory, getLanguageId, getLauncherById, getLaunchers, getMediaFileId, getMessage, getMessage, getProgressInterface, getResourceDirectory, getScreenById, getScreens, getScreens, getUserWritableDefaultInstallationDirectory, getVariable, getVariableNames, getVersion, getWizardContext, goBack, goBackInHistory, goBackInHistory, goForward, gotoScreen, gotoScreen, handleCriticalException, hasBeenElevated, initializeLazilyCreatedScreens, isArchive, isCancelling, isConsole, isErrorOccurred, isGui, isRebootRequired, isUnattended, registerHiddenVariable, registerResponseFileComment, registerResponseFileVariable, removeInstallerEventListener, runElevated, runScript, runUnelevated, runWithSuspendedActions, setErrorOccurred, setVariable, triggerReboot, unregisterResponseFileVariableModifier and TypeMethodDescriptionvoidAdd a listener to receive installer events.voidaddToClassPath(File file) Add a JAR file or a classpath directory root to the classpath of the installer application.voidcancel()Cancel the installer application without asking any questions.voidfinish(int exitCode) Quits the process in an ordered manner.getActionById(String id) Get a particular action with the specified ID.Action[]getActions(Screen screen) Get all registered actions for a specified screen.Action[]getActions(Class<? extends Action> actionClass, Screen screen) Get all registered actions for a specified screen and a given action class.Returns the add-on application id if this project generates add-on installers.Retrieves the default installation directory for all users.Returns the application id of this project.Returns the name of the application.booleangetBooleanVariable(String variableName) Convenience method to get an installer variable with a type ofjava.lang.Boolean.getCompilerVariable(String variableName) Gets the value of a compiler variable as it was defined for this media file at compile time.Retrieves the directory mapped to the "Installation directory" in the distribution tree.Retrieves the default installation directory configured in the install4j IDE and resolved as suitable for the current privilege level.getDestinationFile(File archiveFile) Get the location where the installer will install a file in the distribution tree.getDestinationFile(String archivePath) Same asgetDestinationFile, only with a path argument.getDestinationFileInfo(String archivePath) Analyze a path in the distribution tree.getExternalFile(ExternalFile externalFile, boolean installedLocation) Get the location of an external file that was packaged with the installer.getExternalFile(LocalizedExternalFile localizedExternalFile, boolean installedLocation) Get the location of a localized external file that was packaged with the installer.String[]Returns an array with the command line arguments that were not recognized by install4j.getFileSetById(String id) Returns the file set for a specified ID.getFileSetByName(String name) Returns one file set with the specified name.Returns all additional files sets contained in this installer.getFirstAction(Class<? extends Action> actionClass, Screen screen) Get the registered action for a specified screen and a given action class.getFirstScreen(Class<?> screenClass) Get the registered screen for a given screen class.Get the ID that the framework associates with an action.Get the ID that the framework associates with a screen.Returns the installation component for a specified ID.Returns all installation components for this installer.Retrieves the installation directory selected by the user, or the default installation directory if the user has not yet made a selection.Return the ISO code for the language that the installer is running with.Returns the launcher for a specified ID.Returns all launchers for this installer.Returns the ID of the media file that was used to create this installer.getMessage(String key) Get a message for a localization key.getMessage(String key, Object... arguments) Get a message for a localization key.Get the current progress interface.Retrieves the directory where the resource files are present that have been configured on the "Installer->Custom Code & Resources" tab.getScreenById(String id) Get a particular screen with the specified ID.Screen[]Get all registered screens.Screen[]getScreens(Class<?> screenClass) Get all registered screens for a given screen class.Retrieves the default installation directory in a user-writable directory.getVariable(String variableName) Get an installer variable.Get the names of all defined installer variables.Returns the version of the installer.Get the wizard context if the installer or uninstaller is running in GUI mode.voidgoBack(int numberOfScreens) Go backwards in the screen sequence.voidgoBackInHistory(int numberOfScreens) Go backwards in the screen history.voidgoBackInHistory(Screen targetScreen) Go backwards in the screen history to the target screen.voidgoForward(int numberOfScreens, boolean checkCondition, boolean executeActions) Go forward in the screen sequence.voidgotoScreen(Screen screen) Programmatically switch to another screen in the installer without checking the condition of the target screen or executing any actions.voidgotoScreen(Screen screen, boolean checkCondition, boolean executeActions) Programmatically switch to another screen in the installer.voidIf you encounter an exception in your code that cannot be handled, you can use this method to invoke the default exception handling of the install4j runtime.booleanReturns if the code is running in the elevated helper process started by the "Request privileges" action.voidInitialize all lazily created screens.booleanReturns whether the media set was an archive as opposed to an installer.booleanReturns whether the user has canceled the installation or not.booleanReturns whether the installer or uninstaller is running in console mode.booleanDetermine if an error has occurred for any of the previous actions.booleanisGui()Returns whether the installer or uninstaller is running in GUI mode.booleanReturns whether a reboot is required on Windows.booleanReturns whether the installer or uninstaller is running in unattended mode.voidregisterHiddenVariable(String variableName) Register a variable whose values should not be written to the installation log file.voidregisterResponseFileComment(String variableName, String comment) Register a comment for a variable that is written to the response file.voidregisterResponseFileVariable(String variableName) Register a variable that should be written to the response file when the installation is finished.voidRemove a listener added withaddInstallerEventListener.runElevated(RemoteCallable remoteCallable, boolean alwaysExecute) Execute a remoteCallable with full admin rights if possible.runScript(ScriptProperty scriptProperty, Bean bean, Object... parameters) Run a script.runUnelevated(RemoteCallable remoteCallable) Execute a remoteCallable with the rights of the original user that started the installer.voidrunWithSuspendedActions(Runnable runnable) Execute some code while any running actions are suspended.voidsetErrorOccurred(boolean errorOccurred) Clear or set the error flag that is described forisErrorOccurred.voidsetVariable(String variableName, Object value) Set an installer variable.voidtriggerReboot(boolean askUser) Triggers a reboot at the end of installation or uninstallation on Windows.voidunregisterResponseFileVariable(String variableName) Reverses the action ofContext.registerResponseFileVariable(String).
-
Method Details
-
setInstallationDirectory
Set the installation directory programmatically. Based on the configuration in the media wizard, there is a default installation directory. The "Installation directory" screen will suggest the location returned byContext.getInstallationDirectory()and subsequently callsetInstallationDirectorywith the user selection. To change the default installation directory, you could call this method from a "Run script" action that is added to the "Startup" screen.- Parameters:
installationDirectory- the new installation directory
-
isUpdateInstallation
boolean isUpdateInstallation()Returns whether the installer is or will be updating an existing version of the same program. This method returnstrueifApplicationRegistry.isUpdateDirectory(File)returnstruefor the currently set installation directory (Context.getInstallationDirectory()).- Returns:
trueorfalse.
-
getInstallerFile
File getInstallerFile()Returns the current media file. On macOS it returns the base directory of the installer app bundle.- Returns:
- the current media file. Returns
nullif you debug the installer, since there is no installer file in that case.
-
getMediaName
String getMediaName()Get the name of the current media file.- Returns:
- the original file name of the media file being installed without the file extension.
-
installFile
Installs a file. This is the same as callinginstallFile(File, File, FileOptions)withnew FileOptions(sourceFile.lastModified()). The uninstaller will uninstall a file that has been installed with this method. The overwrite mode will beOverwriteMode.ALWAYS_ASK_EXCEPT_FOR_UPDATEand the uninstaller modeUninstallMode.IF_CREATED.- Parameters:
sourceFile- the file to be installed.destFile- the destination file.- Returns:
- whether the installation was successful or not
- Throws:
UserCanceledException- if the user cancels the installation.
-
installFile
boolean installFile(File sourceFile, File destFile, FileOptions options) throws UserCanceledException Installs a file. This is the same as callinginstallFile(File, File, FileOptions, ProgressInterface, int, int)with aProgressInterfaceofnull. TheFileOptionsparameter determines the overwrite and uninstall modes.- Parameters:
sourceFile- the file to be installed.destFile- the destination file.options- the installation and uninstallation options.- Returns:
- whether the installation was successful or not
- Throws:
UserCanceledException- if the user cancels the installation.
-
installFile
boolean installFile(File sourceFile, File destFile, FileOptions options, ProgressInterface progressInterface, int fromPercent, int toPercent) throws UserCanceledException Installs a file. The method will try to copy the source file to the destination file. TheFileOptionsparameter determines the overwrite mode and the uninstall mode. With this method, the progress interface will be updated during the installation. Use this method if you install very large files.Note that the progress bar is only available if this method is called from an action and the action is associated with a screen that offers a progress interface with a progress bar, such as the "Installation" screen or the customizable "Display progress" screen.
- Parameters:
sourceFile- the file to be installed.destFile- the destination file.options- the installation and uninstallation options.progressInterface- the interface for displaying progress during the file installation. The current progress interface can be obtained fromContext.getProgressInterface().fromPercent- the start percentage value for the file installation. The progress interface will be advanced starting with this percentage value.toPercent- the end percentage value for the file installation. The progress interface will be advanced up to this percentage value.- Returns:
- whether the installation was successful or not
- Throws:
UserCanceledException- if the user cancels the installation.
-
installDirectory
Creates a directory. The directory will be deleted by the uninstaller if all its containing files and directories are also uninstalled and theUninstallModerequires an uninstallation. This method is only necessary if the directory will be empty and you do not know if the directory will contain files. If you install a known set of files, you can just use theinstallFile(...)methods without creating the directory first.- Parameters:
directory- the directory to be created. All parent directories will be created if necessary.uninstallMode- the behavior for uninstallation. It is recommended to useUninstallMode.IF_CREATEDby default.
-
registerUninstallFile
Registers an arbitrary file for uninstallation.- Parameters:
file- the file that should be removed when uninstalling the application.
-