diff --git a/source/net/filebot/Main.java b/source/net/filebot/Main.java index 46979f47..62519260 100644 --- a/source/net/filebot/Main.java +++ b/source/net/filebot/Main.java @@ -194,6 +194,9 @@ public class Main { HistorySpooler.getInstance().commit(); SupportDialog.maybeShow(); + // backup preferences on exit + Settings.store(ApplicationFolder.AppData.resolve("preferences.backup.xml")); + System.exit(0); })); diff --git a/source/net/filebot/Settings.java b/source/net/filebot/Settings.java index b734de3a..9f736f7c 100644 --- a/source/net/filebot/Settings.java +++ b/source/net/filebot/Settings.java @@ -2,6 +2,13 @@ package net.filebot; import static net.filebot.Logging.*; +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.OutputStream; import java.util.Locale; import java.util.ResourceBundle; import java.util.logging.Level; @@ -249,4 +256,20 @@ public final class Settings { } } + public static void store(File f) { + try (OutputStream out = new BufferedOutputStream(new FileOutputStream(f))) { + Preferences.userRoot().exportSubtree(out); + } catch (Exception e) { + debug.log(Level.SEVERE, e, e::toString); + } + } + + public static void restore(File f) { + try (InputStream in = new BufferedInputStream(new FileInputStream(f))) { + Preferences.importPreferences(in); + } catch (Exception e) { + debug.log(Level.SEVERE, e, e::toString); + } + } + }