IzPack

Single Instance

Details

  • Type: New Feature New Feature
  • Status: Closed Closed
  • Priority: Major Major
  • Resolution: Fixed
  • Affects Version/s: None
  • Fix Version/s: 4.0.0
  • Component/s: Installer
  • Labels:
    None
  • Number of attachments :
    0

Description

Provide a common way to detect a running instance, such as a lock file, and shut down the second instance with a warning message.

Activity

Hide
Julien Ponge added a comment -
Show
Julien Ponge added a comment - An IZEP has been filled by Jeff: http://docs.codehaus.org/display/IZPACK/Proposal+-+Single+Instance
Hide
Julien Ponge added a comment -

Assigned to Jeff with the initial target being v4.0.0.

Show
Julien Ponge added a comment - Assigned to Jeff with the initial target being v4.0.0.
Hide
Julien Ponge added a comment -

Jeff, do you have any news concerning this issue?

Thanks

Show
Julien Ponge added a comment - Jeff, do you have any news concerning this issue? Thanks
Hide
Jeff Gordon added a comment -

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.

  • Jeff

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 ***"); }
}
}

Show
Jeff Gordon added a comment - 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.
  • Jeff
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 ***"); } } }
Hide
Julien Ponge added a comment -

Good fix.

The only issue is that it is not internationalized, but in the same time this appears before any language choice has been made...

I haven't checked, but could you verify if the default option of the message box is the one that you suggest in the text?

Show
Julien Ponge added a comment - Good fix. The only issue is that it is not internationalized, but in the same time this appears before any language choice has been made... I haven't checked, but could you verify if the default option of the message box is the one that you suggest in the text?
Hide
Jeff Gordon added a comment -

I figured if I tried to localize it then I would need to localize all the surrounding methods and potentially introduce a new bug. Maybe a new issue should get created to provide earlier localization support. I'll change the type of option dialog to allow control of the initial selected item.

Show
Jeff Gordon added a comment - I figured if I tried to localize it then I would need to localize all the surrounding methods and potentially introduce a new bug. Maybe a new issue should get created to provide earlier localization support. I'll change the type of option dialog to allow control of the initial selected item.

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated:
    Resolved: