All checks were successful
KnarCraft/Minecraft-Server-Launcher/pipeline/head This commit looks good
Drops the idea of using serializable Adds a new controller object which takes care of profiles and saving Moves profile independent settings to its own file Makes saving and loading from file a lot cleaner Fixes the bug preventing lastly used profile from loading Makes the profile object only do profile things Moves gui initialization to the controller object Updates vanilla version from 1.16.1 to 1.16.2 Moves backup to common functions
72 lines
2.6 KiB
Java
72 lines
2.6 KiB
Java
package net.knarcraft.minecraftserverlauncher.utility;
|
|
|
|
import net.knarcraft.minecraftserverlauncher.server.ServerTypeHandler;
|
|
import net.knarcraft.minecraftserverlauncher.server.servertypes.ServerType;
|
|
import net.knarcraft.minecraftserverlauncher.userinterface.GUI;
|
|
|
|
import javax.naming.ConfigurationException;
|
|
import java.io.File;
|
|
import java.io.FileNotFoundException;
|
|
import java.io.IOException;
|
|
|
|
/**
|
|
* This class handles all downloading of .jar files
|
|
*/
|
|
public final class JarDownloader {
|
|
|
|
private final String jarDirectory;
|
|
private final GUI gui;
|
|
|
|
/**
|
|
* Initializes a jar downloader
|
|
*
|
|
* @param gui <p>The GUI to use for displaying messages</p>
|
|
* @param jarDirectory <p>The directory to download jar files to</p>
|
|
*/
|
|
public JarDownloader(GUI gui, String jarDirectory) {
|
|
this.gui = gui;
|
|
this.jarDirectory = jarDirectory;
|
|
}
|
|
|
|
/**
|
|
* Downloads all jars to the program directory.
|
|
*
|
|
* @throws IOException On version file failure or folder creation failure
|
|
*/
|
|
public void downloadJars() throws IOException {
|
|
if (!new File(jarDirectory).exists() && !new File(jarDirectory).mkdirs()) {
|
|
gui.showError("Could not create the Jars folder. Please run the program with admin permissions, or move it to " +
|
|
"a writable directory.");
|
|
throw new FileNotFoundException("Unable to create jars folder");
|
|
}
|
|
try {
|
|
gui.setStatus("Downloading all jars...");
|
|
downloadAll();
|
|
gui.setStatus("Finished downloading jars");
|
|
} catch (FileNotFoundException | ConfigurationException e) {
|
|
gui.setStatus(e.getMessage());
|
|
throw new FileNotFoundException("One or more downloads failed: " + e.getMessage());
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Downloads jar files for all possible server versions
|
|
*
|
|
* @throws IOException <p>If a jar fails to download</p>
|
|
*/
|
|
private void downloadAll() throws IOException, ConfigurationException {
|
|
for (ServerType type : ServerTypeHandler.getServerTypes()) {
|
|
if (type.getName().equals("Custom")) {
|
|
continue;
|
|
}
|
|
for (String version : type.getVersions()) {
|
|
gui.setStatus("Downloading " + type.getName() + version + "...");
|
|
boolean success = type.downloadJar(jarDirectory, version);
|
|
if (!success) {
|
|
throw new FileNotFoundException("Unable to download the jar file for " + type.getName() + version);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|