X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;ds=sidebyside;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=e0f26499c9a52f82f0e03910b504af115055e92c;hb=4623504d164c0f3cf870f1b5c5707fb058657e71;hp=21d7a808aa050cdf5dfdd497fc3bf9ac4cce2cb2;hpb=e0f1723814bdfd94f75dd9ad11462124cdcb8a6c;p=Sone.git diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 21d7a80..e0f2649 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -17,6 +17,7 @@ package net.pterodactylus.sone.core; +import java.io.InputStream; import java.net.MalformedURLException; import java.util.ArrayList; import java.util.Collection; @@ -438,6 +439,26 @@ public class Core extends AbstractService { } /** + * Loads a Sone from an input stream. + * + * @param soneInputStream + * The input stream to load the Sone from + * @return The parsed Sone, or {@code null} if the Sone could not be parsed + */ + public Sone loadSone(InputStream soneInputStream) { + Sone parsedSone = soneDownloader.parseSone(soneInputStream); + if (parsedSone == null) { + return null; + } + if (parsedSone.getInsertUri() != null) { + addLocalSone(parsedSone); + } else { + addSone(parsedSone); + } + return parsedSone; + } + + /** * Loads and updates the given Sone. * * @param sone @@ -615,6 +636,7 @@ public class Core extends AbstractService { /** * Loads the configuration. */ + @SuppressWarnings("unchecked") private void loadConfiguration() { logger.entering(Core.class.getName(), "loadConfiguration()"); @@ -625,7 +647,20 @@ public class Core extends AbstractService { SoneInserter.setInsertionDelay(newValue); } - })).set(configuration.getIntValue("Option/InsertionDelay").getValue(null)); + })); + + options.addBooleanOption("ClearOnNextRestart", new DefaultOption(false)).set(configuration.getBooleanValue("Option/ClearOnNextRestart").getValue(null)); + options.addBooleanOption("ReallyClearOnNextRestart", new DefaultOption(false)).set(configuration.getBooleanValue("Option/ReallyClearOnNextRestart").getValue(null)); + + boolean clearConfiguration = options.getBooleanOption("ClearOnNextRestart").get() && options.getBooleanOption("ReallyClearOnNextRestart").get(); + options.getBooleanOption("ClearOnNextRestart").set(null); + options.getBooleanOption("ReallyClearOnNextRestart").set(null); + if (clearConfiguration) { + /* stop loading the configuration. */ + return; + } + + options.getIntegerOption("InsertionDelay").set(configuration.getIntValue("Option/InsertionDelay").getValue(null)); /* parse local Sones. */ logger.log(Level.INFO, "Loading Sones…"); @@ -772,6 +807,8 @@ public class Core extends AbstractService { try { /* store the options first. */ configuration.getIntValue("Option/InsertionDelay").setValue(options.getIntegerOption("InsertionDelay").getReal()); + configuration.getBooleanValue("Option/ClearOnNextRestart").setValue(options.getBooleanOption("ClearOnNextRestart").getReal()); + configuration.getBooleanValue("Option/ReallyClearOnNextRestart").setValue(options.getBooleanOption("ReallyClearOnNextRestart").getReal()); /* store all Sones. */ int soneId = 0;