This commit is contained in:
parent
31f996632d
commit
d55afa26ea
2 changed files with 6 additions and 5 deletions
|
@ -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<VersionedResource> resources;
|
||||
private final Logger logger;
|
||||
private final File cacheFile;
|
||||
|
||||
private final Set<VersionedResource> availableUpdates = new HashSet<>();
|
||||
|
||||
UpdateChecker(Plugin plugin, Set<VersionedResource> 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);
|
||||
|
|
|
@ -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<SpigotResource> 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<ResourceVersion> installedVersions;
|
||||
try (FileInputStream inputStream = new FileInputStream(cacheFile)) {
|
||||
installedVersions = VersionCheckCache.loadAll(inputStream);
|
||||
|
|
Loading…
Reference in a new issue