A
All checks were successful
/ deploy (push) Successful in 28s

This commit is contained in:
Minecon724 2024-12-22 11:57:39 +01:00
parent 6e55236a7d
commit a5d860cb35
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8

View file

@ -0,0 +1,50 @@
package eu.m724.autopeerer.common;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.nio.file.Files;
import java.util.Properties;
public class Configuration {
public final File directory = new File("config");
private final File configFile;
private final Properties properties = new Properties();
public Configuration(String profile) {
this.configFile = new File(directory, profile + ".properties");
}
public void load() throws IOException {
directory.mkdir();
if (!configFile.exists()) {
try (var is = getClass().getClassLoader().getResourceAsStream(configFile.getName())) {
Files.write(configFile.toPath(), is.readAllBytes());
properties.load(is);
}
}
try (var is = new FileInputStream(configFile)) {
properties.load(is);
}
}
public String getString(String property) {
return properties.getProperty(property);
}
public String getString(String property, String def) {
return properties.getProperty(property, def);
}
public int getInt(String property) {
return Integer.parseInt(getString(property));
}
public int getInt(String property, int def) {
return Integer.parseInt(getString(property, String.valueOf(def)));
}
}