I added the method below to com.izforge.izpack.installer.GUIInstaller and did a bit of
testing on Windows (the only thing I have accessible at the moment). It uses the app
name so other installers can run simultaneously.
If there's no objection, I'll commit it.
private void checkLockFile() throws Exception {
String tempDir = System.getProperty("java.io.tmpdir");
String appName = this.installdata.info.getAppName();
String fileName = "iz-"appName".tmp";
Debug.trace("Making temp file: "+fileName);
Debug.trace("In temp directory: "+tempDir);
File file = new File(tempDir, fileName);
if (file.exists()) {
// Ask user if they want to proceed.
Debug.trace("Lock File Exists, asking user for permission to proceed.");
StringBuffer msg = new StringBuffer();
msg.append("The "appName" installer you are attempting to run seems to have a
copy already running. \n\n");
msg.append("This could be from a previous failed installation attempt or you
may have accidentally launched \n");
msg.append("the installer twice. The recommended action is to select 'No' below
and wait for the other copy \n");
msg.append("of the installer to start. If you are sure there is no other copy
of the installer running click \n");
msg.append("the 'Yes' button to allow this installer to run. \n\n");
msg.append("Are you sure you want to proceed with this installation?");
int status = JOptionPane.showConfirmDialog(null, msg.toString(), "Warning",
JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE);
if (status == JOptionPane.YES_OPTION) {
// Take control of the file so it gets deleted after this installer instance
exits.
Debug.trace("Setting temp file to delete on exit");
file.deleteOnExit();
} else {
// Leave the file as it is.
Debug.trace("Leaving temp file alone and exiting");
System.exit(1);
}
} else {
try {
// Create the new lock file
if (file.createNewFile()) {
Debug.trace("Temp file created");
file.deleteOnExit();
} else {
Debug.trace("Temp file could not be created");
Debug.trace("*** Multiple instances of installer will be allowed ***");
}
} catch (Exception e) {
Debug.trace("Temp file could not be created: "+e);
Debug.trace("*** Multiple instances of installer will be allowed ***");
}
}
}
An IZEP has been filled by Jeff: http://docs.codehaus.org/display/IZPACK/Proposal+-+Single+Instance