From 9d009bf1c85799b42ccb8c0950c157a6c5f0ebac Mon Sep 17 00:00:00 2001
From: jvergara <jvergara@localhost>
Date: Wed, 17 Oct 2007 13:06:57 +0000
Subject: [PATCH] Add some code in order the code of the setup to be able to be more reactive to the Cancel operation.  Now the user does not have to wait until the end of the download to stop the setup process nor to the end of the replication initialization.

---
 opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java |   52 ++++++++++++++++++++++++++++++++++++----------------
 1 files changed, 36 insertions(+), 16 deletions(-)

diff --git a/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java b/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java
index 6de3e2c..aa9e458 100644
--- a/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java
+++ b/opends/src/quicksetup/org/opends/quicksetup/installer/webstart/WebStartInstaller.java
@@ -105,6 +105,7 @@
     initMaps();
     PrintStream origErr = System.err;
     PrintStream origOut = System.out;
+    boolean downloadedBits = false;
     try
     {
       System.setErr(getApplicationErrorStream());
@@ -125,6 +126,7 @@
       createParentDirectoryIfRequired();
       extractZipFiles(in, getRatio(InstallProgressStep.EXTRACTING),
           getRatio(InstallProgressStep.CONFIGURING_SERVER));
+      downloadedBits = true;
 
       try
       {
@@ -212,7 +214,8 @@
     } catch (ApplicationException ex)
     {
       if (ReturnCode.CANCELLED.equals(ex.getType())) {
-        uninstall();
+        uninstall(downloadedBits);
+
         setCurrentProgressStep(InstallProgressStep.FINISHED_CANCELED);
         notifyListeners(null);
       } else {
@@ -515,29 +518,46 @@
 
   /**
    * Uninstall what has already been installed.
+   * @param downloadedBits whether the bits were downloaded or not.
    */
-  private void uninstall() {
-    notifyListeners(getTaskSeparator());
+  private void uninstall(boolean downloadedBits) {
+    if (downloadedBits)
+    {
+      notifyListeners(getTaskSeparator());
+      Installation installation = getInstallation();
+      FileManager fm = new FileManager(this);
 
-    Installation installation = getInstallation();
-    FileManager fm = new FileManager(this);
+      // Stop the server if necessary
+      if (installation.getStatus().isServerRunning()) {
+        try {
+          new ServerController(installation).stopServer(true);
+        } catch (ApplicationException e) {
+          LOG.log(Level.INFO, "error stopping server", e);
+        }
+      }
 
-    // Stop the server if necessary
-    if (installation.getStatus().isServerRunning()) {
+      uninstallServices();
+
       try {
-        new ServerController(installation).stopServer(true);
+        fm.deleteRecursively(installation.getRootDirectory(), null,
+            FileManager.DeletionPolicy.DELETE_ON_EXIT_IF_UNSUCCESSFUL);
       } catch (ApplicationException e) {
-        LOG.log(Level.INFO, "error stopping server", e);
+        LOG.log(Level.INFO, "error deleting files", e);
       }
     }
-
-    uninstallServices();
-
-    try {
-      fm.deleteRecursively(installation.getRootDirectory(), null,
+    else
+    {
+      File serverRoot = new File(getUserData().getServerLocation());
+      if (serverRoot.exists())
+      {
+        FileManager fm = new FileManager(this);
+        try {
+          fm.deleteRecursively(serverRoot, null,
               FileManager.DeletionPolicy.DELETE_ON_EXIT_IF_UNSUCCESSFUL);
-    } catch (ApplicationException e) {
-      LOG.log(Level.INFO, "error deleting files", e);
+        } catch (ApplicationException e) {
+          LOG.log(Level.INFO, "error deleting files", e);
+        }
+      }
     }
   }
 

--
Gitblit v1.10.0