/**
  * Informs all listeners.
  *
  * @param listeners list with the listener objects
  * @param action identifier which callback should be called
  * @param param parameter for the call
  * @param handler the current progress handler
  */
 private void informListeners(
     List listeners, int action, Object param, AbstractUIProgressHandler handler) {
   // Iterate the action list.
   Iterator iter = listeners.iterator();
   UninstallerListener il = null;
   while (iter.hasNext()) {
     try {
       il = (UninstallerListener) iter.next();
       switch (action) {
         case UninstallerListener.BEFORE_DELETION:
           il.beforeDeletion((List) param, handler);
           break;
         case UninstallerListener.AFTER_DELETION:
           il.afterDeletion((List) param, handler);
           break;
         case UninstallerListener.BEFORE_DELETE:
           il.beforeDelete((File) param, handler);
           break;
         case UninstallerListener.AFTER_DELETE:
           il.afterDelete((File) param, handler);
           break;
       }
     } catch (Throwable e) { // Catch it to prevent for a block of uninstallation.
       handler.emitError(
           "Skipping custom action because exception caught during " + il.getClass().getName(),
           e.toString());
     }
   }
 }
Beispiel #2
0
 @Override
 public void afterDeletion(List arg0, AbstractUIProgressHandler arg1) throws Exception {
   int answer =
       arg1.askQuestion(
           "Remove configuration files?",
           "Do you want to remove the configuration files for Svarog?",
           AbstractUIHandler.CHOICES_YES_NO,
           AbstractUIHandler.ANSWER_NO);
   if (answer == AbstractUIHandler.ANSWER_YES) {
     answer =
         arg1.askQuestion(
             "Curren user or all?",
             "Do you want to remove configuration files only for the current user (YES) or for all users (NO)?",
             AbstractUIHandler.CHOICES_YES_NO_CANCEL,
             AbstractUIHandler.ANSWER_CANCEL);
     if (answer == AbstractUIHandler.ANSWER_YES) {
       removeCurrentUser();
     } else if (answer == AbstractUIHandler.ANSWER_NO) removeAllProfiles();
   }
 }
  /** The run method. */
  public void run() {
    try {
      // We get the list of uninstaller listeners
      List[] listeners = getListenerLists();
      // We get the list of the files to delete
      ArrayList executables = getExecutablesList();

      FileExecutor executor = new FileExecutor(executables);
      executor.executeFiles(ExecutableFile.UNINSTALL, this.handler);

      ArrayList files = getFilesList();
      int size = files.size();

      // Custem action listener stuff --- beforeDeletion ----
      informListeners(listeners[0], UninstallerListener.BEFORE_DELETION, files, handler);

      handler.startAction("destroy", size);

      // We destroy the files
      for (int i = 0; i < size; i++) {
        File file = (File) files.get(i);
        // Custem action listener stuff --- beforeDelete ----
        informListeners(listeners[1], UninstallerListener.BEFORE_DELETE, file, handler);

        file.delete();

        // Custem action listener stuff --- afterDelete ----
        informListeners(listeners[1], UninstallerListener.AFTER_DELETE, file, handler);

        handler.progress(i, file.getAbsolutePath());
      }

      // Custem action listener stuff --- afterDeletion ----
      informListeners(listeners[0], UninstallerListener.AFTER_DELETION, files, handler);

      // We make a complementary cleanup
      handler.progress(size, "[ cleanups ]");
      cleanup(new File(installPath));

      handler.stopAction();
    } catch (Exception err) {
      handler.stopAction();
      err.printStackTrace();
      handler.emitError("exception caught", err.toString());
    }
  }