X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=27e8db86f41900d2b0cc3100ff79e8f9ab97d5b9;hp=053e04280b21a4a63039203a519a3b1a743a0603;hb=f4ea1e1b3526175e255831c975d6eea813589f25;hpb=3ff1cdf09693a28719246a9a98a8b908e8c848f7 diff --git a/src/main/java/net/pterodactylus/sone/core/Core.java b/src/main/java/net/pterodactylus/sone/core/Core.java index 053e042..27e8db8 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -34,6 +34,7 @@ import net.pterodactylus.sone.core.Options.OptionWatcher; import net.pterodactylus.sone.data.Client; import net.pterodactylus.sone.data.Post; import net.pterodactylus.sone.data.Profile; +import net.pterodactylus.sone.data.Profile.Field; import net.pterodactylus.sone.data.Reply; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.sone.freenet.wot.Identity; @@ -48,6 +49,7 @@ import net.pterodactylus.util.config.ConfigurationException; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.number.Numbers; import net.pterodactylus.util.validation.Validation; +import net.pterodactylus.util.version.Version; import freenet.keys.FreenetURI; /** @@ -55,7 +57,7 @@ import freenet.keys.FreenetURI; * * @author David ‘Bombe’ Roden */ -public class Core implements IdentityListener { +public class Core implements IdentityListener, UpdateListener { /** * Enumeration for the possible states of a {@link Sone}. @@ -101,6 +103,9 @@ public class Core implements IdentityListener { /** The Sone downloader. */ private final SoneDownloader soneDownloader; + /** The update checker. */ + private final UpdateChecker updateChecker; + /** Whether the core has been stopped. */ private volatile boolean stopped; @@ -168,6 +173,7 @@ public class Core implements IdentityListener { this.freenetInterface = freenetInterface; this.identityManager = identityManager; this.soneDownloader = new SoneDownloader(this, freenetInterface); + this.updateChecker = new UpdateChecker(freenetInterface); } // @@ -239,6 +245,15 @@ public class Core implements IdentityListener { } /** + * Returns the update checker. + * + * @return The update checker + */ + public UpdateChecker getUpdateChecker() { + return updateChecker; + } + + /** * Returns the status of the given Sone. * * @param sone @@ -930,7 +945,7 @@ public class Core implements IdentityListener { public void setTrust(Sone origin, Sone target, int trustValue) { Validation.begin().isNotNull("Trust Origin", origin).check().isInstanceOf("Trust Origin", origin.getIdentity(), OwnIdentity.class).isNotNull("Trust Target", target).isLessOrEqual("Trust Value", trustValue, 100).isGreaterOrEqual("Trust Value", trustValue, -100).check(); try { - ((OwnIdentity) origin.getIdentity()).setTrust(target.getIdentity(), trustValue, "Set from Sone Web Interface"); + ((OwnIdentity) origin.getIdentity()).setTrust(target.getIdentity(), trustValue, options.getStringOption("TrustComment").get()); } catch (WebOfTrustException wote1) { logger.log(Level.WARNING, "Could not set trust for Sone: " + target, wote1); } @@ -1138,6 +1153,17 @@ public class Core implements IdentityListener { profile.setBirthMonth(configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").getValue(null)); profile.setBirthYear(configuration.getIntValue(sonePrefix + "/Profile/BirthYear").getValue(null)); + /* load profile fields. */ + while (true) { + String fieldPrefix = sonePrefix + "/Profile/Fields/" + profile.getFields().size(); + String fieldName = configuration.getStringValue(fieldPrefix + "/Name").getValue(null); + if (fieldName == null) { + break; + } + String fieldValue = configuration.getStringValue(fieldPrefix + "/Value").getValue(""); + profile.addField(fieldName).setValue(fieldValue); + } + /* load posts. */ Set posts = new HashSet(); while (true) { @@ -1271,6 +1297,15 @@ public class Core implements IdentityListener { configuration.getIntValue(sonePrefix + "/Profile/BirthMonth").setValue(profile.getBirthMonth()); configuration.getIntValue(sonePrefix + "/Profile/BirthYear").setValue(profile.getBirthYear()); + /* save profile fields. */ + int fieldCounter = 0; + for (Field profileField : profile.getFields()) { + String fieldPrefix = sonePrefix + "/Profile/Fields/" + fieldCounter++; + configuration.getStringValue(fieldPrefix + "/Name").setValue(profileField.getName()); + configuration.getStringValue(fieldPrefix + "/Value").setValue(profileField.getValue()); + } + configuration.getStringValue(sonePrefix + "/Profile/Fields/" + fieldCounter + "/Name").setValue(null); + /* save posts. */ int postCounter = 0; for (Post post : sone.getPosts()) { @@ -1522,6 +1557,8 @@ public class Core implements IdentityListener { */ public void start() { loadConfiguration(); + updateChecker.addUpdateListener(this); + updateChecker.start(); } /** @@ -1533,6 +1570,8 @@ public class Core implements IdentityListener { soneInserter.stop(); } } + updateChecker.stop(); + updateChecker.removeUpdateListener(this); soneDownloader.stop(); saveConfiguration(); stopped = true; @@ -1552,9 +1591,11 @@ public class Core implements IdentityListener { /* store the options first. */ try { + configuration.getIntValue("Option/ConfigurationVersion").setValue(0); configuration.getIntValue("Option/InsertionDelay").setValue(options.getIntegerOption("InsertionDelay").getReal()); configuration.getIntValue("Option/PositiveTrust").setValue(options.getIntegerOption("PositiveTrust").getReal()); configuration.getIntValue("Option/NegativeTrust").setValue(options.getIntegerOption("NegativeTrust").getReal()); + configuration.getStringValue("Option/TrustComment").setValue(options.getStringOption("TrustComment").getReal()); configuration.getBooleanValue("Option/SoneRescueMode").setValue(options.getBooleanOption("SoneRescueMode").getReal()); configuration.getBooleanValue("Option/ClearOnNextRestart").setValue(options.getBooleanOption("ClearOnNextRestart").getReal()); configuration.getBooleanValue("Option/ReallyClearOnNextRestart").setValue(options.getBooleanOption("ReallyClearOnNextRestart").getReal()); @@ -1618,6 +1659,7 @@ public class Core implements IdentityListener { })); options.addIntegerOption("PositiveTrust", new DefaultOption(75)); options.addIntegerOption("NegativeTrust", new DefaultOption(-100)); + options.addStringOption("TrustComment", new DefaultOption("Set from Sone Web Interface")); options.addBooleanOption("SoneRescueMode", new DefaultOption(false)); options.addBooleanOption("ClearOnNextRestart", new DefaultOption(false)); options.addBooleanOption("ReallyClearOnNextRestart", new DefaultOption(false)); @@ -1636,6 +1678,7 @@ public class Core implements IdentityListener { options.getIntegerOption("InsertionDelay").set(configuration.getIntValue("Option/InsertionDelay").getValue(null)); options.getIntegerOption("PositiveTrust").set(configuration.getIntValue("Option/PositiveTrust").getValue(null)); options.getIntegerOption("NegativeTrust").set(configuration.getIntValue("Option/NegativeTrust").getValue(null)); + options.getStringOption("TrustComment").set(configuration.getStringValue("Option/TrustComment").getValue(null)); options.getBooleanOption("SoneRescueMode").set(configuration.getBooleanValue("Option/SoneRescueMode").getValue(null)); /* load known Sones. */ @@ -1753,4 +1796,16 @@ public class Core implements IdentityListener { trustedIdentities.get(ownIdentity).remove(identity); } + // + // INTERFACE UpdateListener + // + + /** + * {@inheritDoc} + */ + @Override + public void updateFound(Version version, long releaseTime) { + coreListenerManager.fireUpdateFound(version, releaseTime); + } + }