Tries a new fix to remove the pesky FileNotFoundException caused by the server version container
Some checks failed
KnarCraft/Minecraft-Server-Launcher/pipeline/head There was a failure building this commit
Some checks failed
KnarCraft/Minecraft-Server-Launcher/pipeline/head There was a failure building this commit
This commit is contained in:
parent
8e626d8097
commit
c721aef2a6
@ -92,6 +92,11 @@ public class ServerVersionContainer implements java.io.Serializable {
|
||||
PrintWriter file;
|
||||
try {
|
||||
if (!saveFile.exists()) {
|
||||
if (!saveFile.getParentFile().exists()) {
|
||||
if (!saveFile.getParentFile().mkdirs()) {
|
||||
throw new FileNotFoundException("Unable to create folder for version file");
|
||||
}
|
||||
}
|
||||
if (!saveFile.createNewFile()) {
|
||||
throw new FileNotFoundException("Unable to create version file");
|
||||
}
|
||||
|
@ -1,5 +1,6 @@
|
||||
package net.knarcraft.minecraftserverlauncher.utility;
|
||||
|
||||
import net.knarcraft.minecraftserverlauncher.Main;
|
||||
import net.knarcraft.minecraftserverlauncher.userinterface.ServerLauncherGUI;
|
||||
|
||||
import java.io.*;
|
||||
@ -20,6 +21,33 @@ import java.util.Scanner;
|
||||
*/
|
||||
public final class CommonFunctions {
|
||||
|
||||
private static String filesDirectory = Main.getApplicationWorkDirectory() + File.separator + "files";
|
||||
|
||||
/**
|
||||
* Creates all folders necessary for tests and normal operation
|
||||
*
|
||||
* @throws FileNotFoundException <p>If unable to create a folder</p>
|
||||
*/
|
||||
public static void createAllFolders() throws FileNotFoundException {
|
||||
createFolder(new File(filesDirectory));
|
||||
createFolder(new File(filesDirectory + File.separator + "Jars"));
|
||||
createFolder(new File(filesDirectory + File.separator + "testjars"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a given folder
|
||||
*
|
||||
* @param folder <p>The folder to create</p>
|
||||
* @throws FileNotFoundException <p>If unable to create the folder</p>
|
||||
*/
|
||||
private static void createFolder(File folder) throws FileNotFoundException {
|
||||
if (!folder.exists()) {
|
||||
if (!folder.mkdirs()) {
|
||||
throw new FileNotFoundException("Cannot create necessary directory.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets a resource as an InputStream
|
||||
*
|
||||
|
@ -8,14 +8,21 @@ import org.junit.Test;
|
||||
import java.io.*;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
import static net.knarcraft.minecraftserverlauncher.utility.CommonFunctions.createAllFolders;
|
||||
|
||||
public class ServerVersionContainerTest {
|
||||
|
||||
private String versionFile = Main.getApplicationWorkDirectory() + File.separator + "files" + File.separator + "versions.csv";
|
||||
private final String filesDirectory = Main.getApplicationWorkDirectory() + File.separator + "files";
|
||||
private String versionFile = filesDirectory + File.separator + "versions.csv";
|
||||
private ServerVersionContainer serverVersionContainer;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
try {
|
||||
createAllFolders();
|
||||
} catch (FileNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
serverVersionContainer = ServerVersionContainer.getInstance();
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user