X-Git-Url: https://git.pterodactylus.net/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Fnet%2Fpterodactylus%2Fsone%2Fcore%2FCore.java;h=4e3df64b5cc99bb5f51684eb1471cbb641630211;hb=eef0d7c1f6624cb4d94ebb56571486eb75324eef;hp=7f901846d8eccb6db5956777302d22ee23abfb5f;hpb=44c19966b15e377eb446aff94468d2e4457e89e5;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 7f90184..4e3df64 100644 --- a/src/main/java/net/pterodactylus/sone/core/Core.java +++ b/src/main/java/net/pterodactylus/sone/core/Core.java @@ -731,7 +731,6 @@ public class Core implements IdentityListener, UpdateListener { } /** - * * Returns the album with the given ID, creating a new album if no album * with the given ID can be found. * @@ -1435,6 +1434,31 @@ public class Core implements IdentityListener, UpdateListener { } configuration.getStringValue(sonePrefix + "/Friends/" + friendCounter + "/ID").setValue(null); + /* save albums. first, collect in a flat structure, top-level first. */ + List albums = new ArrayList(); + albums.addAll(sone.getAlbums()); + int lastAlbumIndex = 0; + while (lastAlbumIndex < albums.size()) { + int previousAlbumCount = albums.size(); + for (Album album : new ArrayList(albums.subList(lastAlbumIndex, albums.size()))) { + albums.addAll(album.getAlbums()); + } + lastAlbumIndex = previousAlbumCount; + } + + int albumCounter = 0; + for (Album album : albums) { + String albumPrefix = sonePrefix + "/Albums/" + albumCounter++; + configuration.getStringValue(albumPrefix + "/ID").setValue(album.getId()); + configuration.getStringValue(albumPrefix + "/Name").setValue(album.getName()); + configuration.getStringValue(albumPrefix + "/Description").setValue(album.getDescription()); + configuration.getStringValue(albumPrefix + "/Parent").setValue(album.getParent() == null ? null : album.getParent().getId()); + } + configuration.getStringValue(sonePrefix + "/Albums/" + albumCounter + "/ID").setValue(null); + + /* save options. */ + configuration.getBooleanValue(sonePrefix + "/Options/AutoFollow").setValue(sone.getOptions().getBooleanOption("AutoFollow").getReal()); + configuration.save(); logger.log(Level.INFO, "Sone %s saved.", sone); } catch (ConfigurationException ce1) { @@ -1711,8 +1735,9 @@ public class Core implements IdentityListener, UpdateListener { album.setSone(sone); if (parent != null) { parent.addAlbum(album); + } else { + sone.addAlbum(album); } - sone.addAlbum(album); return album; }