Store user preferences to a XML file just in case system preferences subsystem (e.g. Windows Registry) has issues

This commit is contained in:
Reinhard Pointner 2018-03-17 19:43:06 +07:00
parent 818c2ffcb1
commit cc0c58070c
2 changed files with 26 additions and 0 deletions

View File

@ -194,6 +194,9 @@ public class Main {
HistorySpooler.getInstance().commit(); HistorySpooler.getInstance().commit();
SupportDialog.maybeShow(); SupportDialog.maybeShow();
// backup preferences on exit
Settings.store(ApplicationFolder.AppData.resolve("preferences.backup.xml"));
System.exit(0); System.exit(0);
})); }));

View File

@ -2,6 +2,13 @@ package net.filebot;
import static net.filebot.Logging.*; 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.Locale;
import java.util.ResourceBundle; import java.util.ResourceBundle;
import java.util.logging.Level; 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);
}
}
} }