summaryrefslogtreecommitdiff
path: root/pdf-over-gui/src/main/java
diff options
context:
space:
mode:
Diffstat (limited to 'pdf-over-gui/src/main/java')
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java40
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java31
-rw-r--r--pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java16
3 files changed, 77 insertions, 10 deletions
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java
index 8d2800e7..eda1e59f 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/config/ConfigurationManager.java
@@ -24,6 +24,8 @@ import java.util.Locale;
import java.util.Properties;
import at.asit.pdfover.commons.Profile;
+
+import org.apache.commons.io.FileUtils;
import org.eclipse.swt.graphics.Point;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -75,6 +77,44 @@ public class ConfigurationManager {
this.configurationOverlay = new ConfigurationDataInMemory();
}
+ static public void factoryResetPersistentConfig() {
+ // tell logback to close all file handles
+ ((ch.qos.logback.classic.LoggerContext)LoggerFactory.getILoggerFactory()).stop();
+
+ File configDirectory = new File(Constants.CONFIG_DIRECTORY);
+ File backupDirectory = new File(Constants.CONFIG_BACKUP_DIRECTORY);
+
+ // delete existing backup, if any
+ FileUtils.deleteQuietly(backupDirectory);
+
+ // attempt 1: try to move the old config directory to a backup location
+ try {
+ FileUtils.moveDirectory(
+ configDirectory,
+ backupDirectory
+ );
+ } catch (Exception e) {
+ System.out.println("Failed move config directory to backup location:");
+ e.printStackTrace();
+
+ // attempt 2: try to simply force delete the config directory
+ try {
+ FileUtils.forceDelete(configDirectory);
+ } catch (Exception e2) {
+ System.out.println("Failed to delete config directory:");
+ e2.printStackTrace();
+
+ // attempt 3: try to schedule the config directory for force deletion on JVM exit
+ try {
+ FileUtils.forceDeleteOnExit(configDirectory);
+ } catch (Exception e3) {
+ System.out.println("Failed to schedule config directory for deletion:");
+ e3.printStackTrace();
+ }
+ }
+ }
+ }
+
/* load from disk */
public void loadFromDisk() throws IOException {
if (loaded)
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java
index 74b38410..2aad12c9 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/ConfigurationUIState.java
@@ -20,11 +20,15 @@ import org.eclipse.swt.SWT;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import at.asit.pdfover.commons.Messages;
import at.asit.pdfover.gui.MainWindowBehavior;
import at.asit.pdfover.gui.MainWindow.Buttons;
import at.asit.pdfover.gui.composites.ConfigurationComposite;
+import at.asit.pdfover.gui.controls.ErrorDialog;
+import at.asit.pdfover.gui.controls.Dialog.BUTTONS;
import at.asit.pdfover.gui.workflow.StateMachine;
import at.asit.pdfover.gui.workflow.Status;
+import at.asit.pdfover.gui.workflow.config.ConfigurationManager;
/**
*
@@ -64,10 +68,29 @@ public class ConfigurationUIState extends State {
@Override
public void run() {
Status status = getStateMachine().status;
-
- ConfigurationComposite config = this.getConfigurationComposite();
-
- getStateMachine().display(config);
+
+ ConfigurationComposite config;
+ try {
+ config = this.getConfigurationComposite();
+ getStateMachine().display(config);
+ } catch (Exception e) {
+ log.error("Failed to initialize config UI", e);
+ ErrorDialog error = new ErrorDialog(
+ getStateMachine().getMainShell(),
+ Messages.getString("error.ConfigInitialization"),
+ BUTTONS.YES_NO
+ );
+
+ int selection = error.open();
+ if (selection == SWT.YES)
+ {
+ ConfigurationManager.factoryResetPersistentConfig();
+ getStateMachine().exit();
+ return;
+ }
+
+ throw e;
+ }
if(config.isUserDone())
{
diff --git a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java
index 1a3fd8b5..b6ea9c0b 100644
--- a/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java
+++ b/pdf-over-gui/src/main/java/at/asit/pdfover/gui/workflow/states/PrepareConfigurationState.java
@@ -348,15 +348,19 @@ public class PrepareConfigurationState extends State {
setNextState(new OpenState(stateMachine));
- } catch (InitializationException e) {
+ } catch (Exception e) {
log.error("Failed to initialize: ", e);
- ErrorDialog error = new ErrorDialog(getStateMachine()
- .getMainShell(),
- Messages.getString("error.Initialization"),
- BUTTONS.OK);
+ ErrorDialog error = new ErrorDialog(
+ getStateMachine().getMainShell(),
+ Messages.getString("error.Initialization"),
+ BUTTONS.YES_NO
+ );
// error.setException(e);
// setNextState(error);
- error.open();
+ int selection = error.open();
+ if (selection == SWT.YES)
+ ConfigurationManager.factoryResetPersistentConfig();
+
getStateMachine().exit();
}
}