From d55afa26ead2a9e0b966cbdea975885287ea7f14 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Sun, 1 Dec 2024 14:50:28 +0100 Subject: [PATCH] Move updater cache to its own directory --- src/main/java/eu/m724/tweaks/updater/UpdateChecker.java | 5 +---- src/main/java/eu/m724/tweaks/updater/UpdaterManager.java | 6 +++++- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/main/java/eu/m724/tweaks/updater/UpdateChecker.java b/src/main/java/eu/m724/tweaks/updater/UpdateChecker.java index 02b07d5..10c023f 100644 --- a/src/main/java/eu/m724/tweaks/updater/UpdateChecker.java +++ b/src/main/java/eu/m724/tweaks/updater/UpdateChecker.java @@ -11,7 +11,6 @@ import eu.m724.tweaks.updater.cache.VersionedResource; import org.bukkit.plugin.Plugin; import org.bukkit.scheduler.BukkitRunnable; -import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.HashSet; @@ -24,14 +23,12 @@ import java.util.stream.Collectors; public class UpdateChecker extends BukkitRunnable { private final Set resources; private final Logger logger; - private final File cacheFile; private final Set availableUpdates = new HashSet<>(); UpdateChecker(Plugin plugin, Set resources) { this.logger = Logger.getLogger(plugin.getLogger().getName() + "." + getClass().getSimpleName()); this.resources = resources; // TODO make a copy? - this.cacheFile = new File(plugin.getDataFolder(), "version cache"); } private void checkAll() { @@ -82,7 +79,7 @@ public class UpdateChecker extends BukkitRunnable { public void run() { checkAll(); - try (FileOutputStream outputStream = new FileOutputStream(cacheFile)) { + try (FileOutputStream outputStream = new FileOutputStream(UpdaterManager.cacheFile)) { VersionCheckCache.writeAll(outputStream, resources.stream().map(VersionedResource::running).filter(Objects::nonNull).collect(Collectors.toSet())); } catch (IOException e) { throw new RuntimeException(e); diff --git a/src/main/java/eu/m724/tweaks/updater/UpdaterManager.java b/src/main/java/eu/m724/tweaks/updater/UpdaterManager.java index 449d4e1..e335ce2 100644 --- a/src/main/java/eu/m724/tweaks/updater/UpdaterManager.java +++ b/src/main/java/eu/m724/tweaks/updater/UpdaterManager.java @@ -20,18 +20,22 @@ import java.util.Set; import java.util.stream.Collectors; public class UpdaterManager { + static File cacheFile; + private final Plugin plugin; public UpdaterManager(Plugin plugin) { this.plugin = plugin; + cacheFile = new File(plugin.getDataFolder(), "cache/updater"); } public void init() throws IOException { // scan installed plugins Set resources = new PluginScanner(plugin).load(); + cacheFile.getParentFile().mkdirs(); // TODO move this somewhere else + // load installed versions from cache - File cacheFile = new File(plugin.getDataFolder(), "version cache"); Set installedVersions; try (FileInputStream inputStream = new FileInputStream(cacheFile)) { installedVersions = VersionCheckCache.loadAll(inputStream);