Changes resource loading
Some checks failed
KnarCraft/Minecraft-Server-Launcher/master There was a failure building this commit
Some checks failed
KnarCraft/Minecraft-Server-Launcher/master There was a failure building this commit
Loads configuration and image files from resources folder Removes duplicate resources
This commit is contained in:
@ -16,6 +16,7 @@ import java.io.*;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.ArrayList;
|
||||
import java.util.NoSuchElementException;
|
||||
import java.util.Objects;
|
||||
import java.util.Scanner;
|
||||
import java.util.concurrent.Executors;
|
||||
@ -193,7 +194,7 @@ public class Profile {
|
||||
if (name == null) { //If a user cancels or crosses out window
|
||||
return;
|
||||
}
|
||||
if (name.equals("") && !name.contains("!") && !name.contains("?") && !name.contains(";")) {
|
||||
if (name.equals("") && !name.matches("^[!?;]+$")) {
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Profile name can't be blank.",
|
||||
@ -228,11 +229,7 @@ public class Profile {
|
||||
|
||||
public static void removeProfile(String name) {
|
||||
if (profiles.size() > 1) {
|
||||
for (int i = 0; i < profiles.size(); i++) {
|
||||
if (profiles.get(i).name.equals((name))) {
|
||||
profiles.remove(i);
|
||||
}
|
||||
}
|
||||
profiles.removeIf(profile -> profile.name.equals(name));
|
||||
}
|
||||
}
|
||||
|
||||
@ -376,7 +373,7 @@ public class Profile {
|
||||
throw new FileNotFoundException("Unable to save to the profiles file.");
|
||||
}
|
||||
}
|
||||
} catch (IOException e) {
|
||||
} catch (IOException | NullPointerException e) {
|
||||
if (gui != null) {
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
@ -434,18 +431,31 @@ public class Profile {
|
||||
JOptionPane.ERROR_MESSAGE
|
||||
);
|
||||
System.exit(1);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (profiles.size() == 0) {
|
||||
addProfile("Default");
|
||||
}
|
||||
} catch (FileNotFoundException e) {
|
||||
} catch (FileNotFoundException | NoSuchElementException e) {
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"A profiles file was not found. Default profile was created.",
|
||||
"Info",
|
||||
JOptionPane.INFORMATION_MESSAGE
|
||||
);
|
||||
gui = new GUI();
|
||||
try {
|
||||
gui = new GUI();
|
||||
} catch (FileNotFoundException ex) {
|
||||
JOptionPane.showMessageDialog(
|
||||
null,
|
||||
"Failed to load GUI messages. The GUI can't be shown.",
|
||||
"Info",
|
||||
JOptionPane.INFORMATION_MESSAGE
|
||||
);
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
}
|
||||
addProfile("Default");
|
||||
}
|
||||
gui.update();
|
||||
@ -549,7 +559,7 @@ public class Profile {
|
||||
String url = Objects.requireNonNull(type).getDownloadURL(), name = type.getName(), newestVersion;
|
||||
AdvancedServerType advType = type instanceof AdvancedServerType ? (AdvancedServerType) type : null;
|
||||
for (String version : type.getVersions()) {
|
||||
Boolean success;
|
||||
boolean success;
|
||||
printToGui("Downloading: " + name + version + ".jar");
|
||||
File file = new File(jarDir + type.getName() + version + ".jar");
|
||||
Path filePath = Paths.get(jarDir + type.getName() + version + ".jar");
|
||||
|
Reference in New Issue
Block a user