X-Git-Url: https://git.pterodactylus.net/?p=Sone.git;a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FSoneDownloader.java;h=4da122637fad01582ebb9ef3c488e18cee384298;hp=8d0d1f29ffa715586c9ea7b4e742cdb6d996dd15;hb=0df5e91852f737d760c5a9f54c5667309fbadcc2;hpb=356a84e5ec2bb0936b7d1cdc635f7f051788da6a diff --git a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java index 8d0d1f2..4da1226 100644 --- a/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java +++ b/src/main/java/net/pterodactylus/sone/core/SoneDownloader.java @@ -26,7 +26,6 @@ import java.util.Set; import java.util.logging.Level; import java.util.logging.Logger; -import net.pterodactylus.sone.core.Core.Preferences; import net.pterodactylus.sone.core.Core.SoneStatus; import net.pterodactylus.sone.data.Album; import net.pterodactylus.sone.data.Client; @@ -122,13 +121,12 @@ public class SoneDownloader extends AbstractService { * The Sone to fetch */ public void fetchSone(Sone sone) { - fetchSone(sone, sone.getRequestUri()); + fetchSone(sone, sone.getRequestUri().sskForUSK()); } /** * Fetches the updated Sone. This method can be used to fetch a Sone from a - * specific URI (which happens when {@link Preferences#isSoneRescueMode() - * „Sone rescue mode“} is active). + * specific URI. * * @param sone * The Sone to fetch @@ -136,6 +134,23 @@ public class SoneDownloader extends AbstractService { * The URI to fetch the Sone from */ public void fetchSone(Sone sone, FreenetURI soneUri) { + fetchSone(sone, soneUri, false); + } + + /** + * Fetches the Sone from the given URI. + * + * @param sone + * The Sone to fetch + * @param soneUri + * The URI of the Sone to fetch + * @param fetchOnly + * {@code true} to only fetch and parse the Sone, {@code false} + * to {@link Core#updateSone(Sone) update} it in the core + * @return The downloaded Sone, or {@code null} if the Sone could not be + * downloaded + */ + public Sone fetchSone(Sone sone, FreenetURI soneUri, boolean fetchOnly) { logger.log(Level.FINE, "Starting fetch for Sone “%s” from %s…", new Object[] { sone, soneUri }); FreenetURI requestUri = soneUri.setMetaString(new String[] { "sone.xml" }); core.setSoneStatus(sone, SoneStatus.downloading); @@ -143,14 +158,17 @@ public class SoneDownloader extends AbstractService { Pair fetchResults = freenetInterface.fetchUri(requestUri); if (fetchResults == null) { /* TODO - mark Sone as bad. */ - return; + return null; } logger.log(Level.FINEST, "Got %d bytes back.", fetchResults.getRight().size()); Sone parsedSone = parseSone(sone, fetchResults.getRight(), fetchResults.getLeft()); if (parsedSone != null) { - addSone(parsedSone); - core.updateSone(parsedSone); + if (!fetchOnly) { + core.updateSone(parsedSone); + addSone(parsedSone); + } } + return parsedSone; } finally { core.setSoneStatus(sone, (sone.getTime() == 0) ? SoneStatus.unknown : SoneStatus.idle); }