public class Installer extends Object
Modifier and Type | Class and Description |
---|---|
protected class |
Installer.copyProgress |
static class |
Installer.FileList |
static class |
Installer.InstalledFilesState |
static class |
Installer.SavedFiles |
static class |
Installer.UndeletedFilesException
Throw this during deleteProgramFiles() to indicate some files were not deleted.
|
static class |
Installer.UninstallInfo |
Modifier and Type | Field and Description |
---|---|
int |
action |
static int |
ACTION_INSTALL |
static int |
ACTION_MIGRATE |
static int |
ACTION_UNINSTALL |
InstallerConfig |
config |
protected Installer.copyProgress |
copiedProgress |
protected String |
dataDirectory |
static int |
ERROR_CANNOT_CREATE_DATA_DIRECTORY |
static int |
ERROR_CANNOT_CREATE_PROGRAM_DIRECTORY |
static int |
ERROR_UNEXPECTED_EXCEPTION |
protected ByteArrayOutputStream |
extraFiles |
static int |
FATAL_ERROR_BAD_CUSTOM_INSTALLER_CLASS |
static int |
FATAL_ERROR_BAD_INSTALLED_CONFIG |
static int |
FATAL_ERROR_BAD_INSTALLER_CONFIG |
static int |
FATAL_ERROR_CANNOT_LOCATE_VALID_VM |
static int |
FATAL_ERROR_NEED_ADMIN_RIGHTS |
static int |
FATAL_ERROR_NOT_WINDOWS |
static int |
FATAL_ERROR_UNSPECIFIED |
protected String |
installDirectory |
static String |
InstallFilesZipName |
boolean |
installingForAllUsers |
boolean |
silentInstall |
protected Windows.WindowsDirectories |
winDirs |
protected ZipOutputStream |
writingFiles |
Constructor and Description |
---|
Installer() |
Modifier and Type | Method and Description |
---|---|
protected OutputStream |
addExtraFileToCopy(boolean isDataFile,
String pathInDir) |
protected void |
addRegistryValue(int root,
String pathToValue,
String valueName,
int value) |
protected void |
addRegistryValue(int root,
String pathToValue,
String valueName,
String value) |
protected void |
addShortcut(String pathToExe,
String parameters,
String name,
String description,
boolean onDesktop) |
protected void |
addShortcutsToRemove(InstalledConfig installed,
Installer.FileList filesToDelete) |
protected String |
changePrefix(String name,
String prefix,
String changeTo) |
protected void |
copyAcross(File destinationDir,
InputStream data,
String destName,
boolean isData,
Installer.copyProgress progress) |
protected Map |
copyFiles(File installDir,
File dataDir,
InstalledConfig ic)
Copy across the files in the zip file.
|
protected boolean |
deleteDataFiles(Installer.InstalledFilesState installedDataFiles,
InstalledConfig ic)
This is called before any uninstallation is done to handle the deletion of the installed data files.
|
protected boolean |
deleteKey(IRegistryKey rk) |
protected boolean |
deleteProgramFiles(Installer.InstalledFilesState installedProgramFiles,
InstalledConfig ic)
This is called to delete program files.
|
protected void |
deleteRegisteredKeys(InstalledConfig installed) |
protected void |
displayFatalError(boolean isInstall,
int fatalError)
Display a fatal error that causes the install/uninstall to exit.
|
InstalledConfig |
doInstall(File installDir,
File dataDir,
InstalledConfig ic)
This should copy across the files, setup the program group and shortcuts.
|
protected boolean |
dontDeleteKey(String fullPath) |
protected void |
doRegistryKeys(Map installedFiles,
Map variables,
InstalledConfig ic) |
protected static String |
doVariableSubstitutions(String fullString,
char variableBlockChar,
Map vars) |
protected void |
excludeFromCopy(String nameInZip)
This excludes files in the original file list from being copied by the default copyFiles() method,
but it will not exclude extra files.
|
protected String |
fixWritableRegistryPath(String rootKey,
String pathInRoot,
boolean installingForAllUsers)
Alter the rootKey if necessary and merge with pathInRoot to form the final full path name to the registry key to
write.
|
protected String |
getAllUsersDataDirectory()
If this returns null then no data directory is created for the application.
|
protected String |
getApplicationFileName() |
protected String |
getApplicationTitle() |
protected String |
getApplicationVersion() |
protected File |
getDataDirectory()
Return the installation data files directory.
|
protected String |
getDesktopDirectory() |
protected ZipInputStream |
getOriginalFilesToCopy() |
protected File |
getProgramDirectory()
Return the installation program files directory.
|
protected String |
getProgramInstallDirectory() |
protected Installer.FileList |
getShortcutsAndExtraFilesToRemove(InstalledConfig installed)
If this return null the uninstall will be aborted.
|
protected String |
getStartMenuProgramsDirectory() |
int |
getUserChoice(boolean isUninstall,
String promptText,
String[] options,
String afterOptionsText,
InstallerConfig ic)
Ask for a user choice.
|
int |
getUserChoice(boolean isUninstall,
String promptText,
String[] options,
String afterOptionsText,
InstallerConfig ic,
int defaultValue)
Ask for a user choice.
|
int |
install(InstallerConfig config) |
protected boolean |
installError(boolean isInstall,
Exception e,
int error,
boolean canRetry)
Display a possibly recoverable error during installation.
|
protected String |
installErrorToMessage(boolean isInstall,
int error) |
protected boolean |
isADataFile(String nameInZip) |
protected boolean |
isAProgramFile(String nameInZip) |
static void |
main(String[] args) |
protected void |
makeShortcut(String shortcutSpecification,
File dest,
Map ht)
Make a shortcut to a file that was installed.
|
protected void |
makeShortcuts(Map installedFiles) |
InstalledConfig |
preInstall(File installDir,
File dataDir,
InstalledConfig ic)
This can be used to modify the installation before the standard "doInstall()" method is called.
|
protected int |
promptToSpecifyUser(InstallerConfig config)
This should prompt the user to specify the user for the install.
|
protected int |
runConfigInstallForm(InstallerConfig config)
This should return 0 if there is no configuration of the installation allowed meaning no Form was shown,
or -1 if the configuration was aborted or 1 if a configuration form is actually shown.
|
protected void |
runPostInstallForm(InstallerConfig config)
This is called after installation has completed successfully.
|
protected void |
runPostUninstallForm(InstalledConfig installed,
boolean allFilesDeleted) |
protected boolean |
runPreInstallForm(InstallerConfig config)
This is called before any installation is done.
|
protected int |
runStartForm(InstallerConfig config)
This is executed at the start of installation after it has been decided if the installation is for all users
or for the current user only.
|
protected int |
runUninstallStartForm(InstalledConfig installed)
This should return -1 if the uninstallation was aborted.
|
protected String[] |
splitShortcut(String shortcutSpecification)
Given a short cut in the form: "
|
int |
uninstall(InstalledConfig installed) |
protected void |
userCancelled(boolean isInstall) |
public boolean silentInstall
public boolean installingForAllUsers
public static final int ACTION_INSTALL
public static final int ACTION_UNINSTALL
public static final int ACTION_MIGRATE
public int action
public InstallerConfig config
protected Windows.WindowsDirectories winDirs
protected String installDirectory
protected String dataDirectory
public static final int ERROR_UNEXPECTED_EXCEPTION
public static final int ERROR_CANNOT_CREATE_PROGRAM_DIRECTORY
public static final int ERROR_CANNOT_CREATE_DATA_DIRECTORY
protected ByteArrayOutputStream extraFiles
protected ZipOutputStream writingFiles
protected Installer.copyProgress copiedProgress
public static final String InstallFilesZipName
public static final int FATAL_ERROR_UNSPECIFIED
public static final int FATAL_ERROR_CANNOT_LOCATE_VALID_VM
public static final int FATAL_ERROR_NEED_ADMIN_RIGHTS
public static final int FATAL_ERROR_BAD_INSTALLER_CONFIG
public static final int FATAL_ERROR_BAD_INSTALLED_CONFIG
public static final int FATAL_ERROR_BAD_CUSTOM_INSTALLER_CLASS
public static final int FATAL_ERROR_NOT_WINDOWS
protected String getApplicationTitle()
protected String getApplicationFileName()
protected String getApplicationVersion()
protected String getProgramInstallDirectory()
protected String getAllUsersDataDirectory()
protected String getDesktopDirectory()
protected String getStartMenuProgramsDirectory()
protected String installErrorToMessage(boolean isInstall, int error)
protected void userCancelled(boolean isInstall)
protected boolean installError(boolean isInstall, Exception e, int error, boolean canRetry)
isInstall
- true during an installation, false during program removal.e
- the cause of the error.error
- the error type.canRetry
- true if recovery is possible.protected int runUninstallStartForm(InstalledConfig installed)
protected boolean runPreInstallForm(InstallerConfig config)
config
- the InstallerConfig for the isntallation.protected int runStartForm(InstallerConfig config)
protected int runConfigInstallForm(InstallerConfig config)
When this is run the fields "installDirectory" and "dataDirectory" will be setup with the initial values and when it is complete it should hold the new values if any. If it returns 1, meaning a Form was shown, then this may be called again if the user selected information results in an invalid configuration.
protected void runPostInstallForm(InstallerConfig config)
config
- the InstallerConfig.protected void copyAcross(File destinationDir, InputStream data, String destName, boolean isData, Installer.copyProgress progress) throws IOException, StoppedException
IOException
StoppedException
protected boolean isADataFile(String nameInZip)
protected boolean isAProgramFile(String nameInZip)
protected void excludeFromCopy(String nameInZip)
nameInZip
- the name of the file.protected OutputStream addExtraFileToCopy(boolean isDataFile, String pathInDir) throws IOException
IOException
protected ZipInputStream getOriginalFilesToCopy() throws IOException
IOException
protected Map copyFiles(File installDir, File dataDir, InstalledConfig ic) throws IOException, StoppedException
installDir
- the program files installation directory.dataDir
- the program data directory.IOException
StoppedException
protected String[] splitShortcut(String shortcutSpecification)
shortcutSpecification
- a name of the formprotected void makeShortcut(String shortcutSpecification, File dest, Map ht) throws IOException
nm
- a name of the form "dest
- the destination directory for the shortcut.ht
- a mapping from the file name (without a path) to the File representing the file name as installed on the computer.IOException
protected void addShortcutsToRemove(InstalledConfig installed, Installer.FileList filesToDelete)
protected void makeShortcuts(Map installedFiles) throws StoppedException, IOException
StoppedException
IOException
protected void addShortcut(String pathToExe, String parameters, String name, String description, boolean onDesktop)
protected static String doVariableSubstitutions(String fullString, char variableBlockChar, Map vars)
protected String fixWritableRegistryPath(String rootKey, String pathInRoot, boolean installingForAllUsers)
rootKey
- pathInRoot
- installingForAllUsers
- protected void doRegistryKeys(Map installedFiles, Map variables, InstalledConfig ic) throws StoppedException, IOException
StoppedException
IOException
protected void addRegistryValue(int root, String pathToValue, String valueName, String value)
protected void addRegistryValue(int root, String pathToValue, String valueName, int value)
protected boolean deleteKey(IRegistryKey rk)
protected boolean dontDeleteKey(String fullPath)
protected void deleteRegisteredKeys(InstalledConfig installed)
protected File getProgramDirectory()
protected File getDataDirectory()
public InstalledConfig preInstall(File installDir, File dataDir, InstalledConfig ic) throws Exception
installDir
- the installation directory.dataDir
- the data directory.ic
- an already setup InstalledConfig. The "installerConfig" field holds the installerConfig object
being used for the installation. This can be modified to add/remove files or registry keys as necessary.Exception
public InstalledConfig doInstall(File installDir, File dataDir, InstalledConfig ic) throws Exception
installDir
- the installation directory.dataDir
- the data directory.ic
- an already setup InstalledConfig.Exception
protected void runPostUninstallForm(InstalledConfig installed, boolean allFilesDeleted)
public int getUserChoice(boolean isUninstall, String promptText, String[] options, String afterOptionsText, InstallerConfig ic)
isUninstall
- true if an uninstall is in progress, false if not.promptText
- the text to display before the choices.options
- the options for the user to select one of.afterOptionsText
- the text to display after the choices - this may be null.ic
- the InstallerConfig for the application.public int getUserChoice(boolean isUninstall, String promptText, String[] options, String afterOptionsText, InstallerConfig ic, int defaultValue)
isUninstall
- true if an uninstall is in progress, false if not.promptText
- the text to display before the choices.options
- the options for the user to select one of.afterOptionsText
- the text to display after the choices - this may be null.ic
- the InstallerConfig for the application.defaultValue
- the index of the default value, or -1 for no default.protected boolean deleteDataFiles(Installer.InstalledFilesState installedDataFiles, InstalledConfig ic)
installedDataFiles
- an InstalledFilesState representing the state of possibly modified files in the data directory.
You can handle any user prompting or you can simply call installedDataFiles.handleDataFiles() to handle the default behavior.
Or you can call removeFiles() explicitly to remove the files.protected boolean deleteProgramFiles(Installer.InstalledFilesState installedProgramFiles, InstalledConfig ic) throws Installer.UndeletedFilesException, IOException
installedProgramFiles
- ic
- Installer.UndeletedFilesException
IOException
protected Installer.FileList getShortcutsAndExtraFilesToRemove(InstalledConfig installed)
installed
- the InstalledConfig.protected int promptToSpecifyUser(InstallerConfig config)
config
- the InstallerConfig for the application.public int uninstall(InstalledConfig installed)
public int install(InstallerConfig config)
protected void displayFatalError(boolean isInstall, int fatalError)
isInstall
- true during installation, false during uninstallation.fatalError
- one of the FATAL_ERROR_XXX values.public static void main(String[] args)