mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
write StaticConfiguration constants in caps, remove file name parameter from Configuration constructor
This commit is contained in:
parent
b212b1a2ff
commit
2c649f2834
@ -101,7 +101,7 @@ public final class Minosoft {
|
|||||||
progress.countUp();
|
progress.countUp();
|
||||||
Log.info("Reading config file...");
|
Log.info("Reading config file...");
|
||||||
try {
|
try {
|
||||||
config = new Configuration(Config.configFileName);
|
config = new Configuration();
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.fatal("Failed to load config file!");
|
Log.fatal("Failed to load config file!");
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
|
@ -17,7 +17,6 @@ import com.google.common.collect.HashBiMap;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.GsonBuilder;
|
import com.google.gson.GsonBuilder;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import de.bixilon.minosoft.Config;
|
|
||||||
import de.bixilon.minosoft.gui.main.Server;
|
import de.bixilon.minosoft.gui.main.Server;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.util.Util;
|
import de.bixilon.minosoft.util.Util;
|
||||||
@ -33,20 +32,20 @@ public class Configuration {
|
|||||||
final JsonObject config;
|
final JsonObject config;
|
||||||
private final Object lock = new Object();
|
private final Object lock = new Object();
|
||||||
|
|
||||||
public Configuration(String filename) throws IOException {
|
public Configuration() throws IOException {
|
||||||
File file = new File(Config.homeDir + "config/" + filename);
|
File file = new File(StaticConfiguration.homeDir + "config/" + StaticConfiguration.CONFIG_FILENAME);
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
// no configuration file
|
// no configuration file
|
||||||
InputStream input = getClass().getResourceAsStream("/config/" + filename);
|
InputStream input = getClass().getResourceAsStream("/config/" + StaticConfiguration.CONFIG_FILENAME);
|
||||||
if (input == null) {
|
if (input == null) {
|
||||||
throw new FileNotFoundException(String.format("[Config] Missing default config: %s!", filename));
|
throw new FileNotFoundException(String.format("[Config] Missing default config: %s!", StaticConfiguration.CONFIG_FILENAME));
|
||||||
}
|
}
|
||||||
File folder = new File(Config.homeDir + "config/");
|
File folder = new File(StaticConfiguration.homeDir + "config/");
|
||||||
if (!folder.exists() && !folder.mkdirs()) {
|
if (!folder.exists() && !folder.mkdirs()) {
|
||||||
throw new IOException("[Config] Could not create config folder!");
|
throw new IOException("[Config] Could not create config folder!");
|
||||||
}
|
}
|
||||||
Files.copy(input, Paths.get(file.getAbsolutePath()));
|
Files.copy(input, Paths.get(file.getAbsolutePath()));
|
||||||
file = new File(Config.homeDir + "config/" + filename);
|
file = new File(StaticConfiguration.homeDir + "config/" + StaticConfiguration.CONFIG_FILENAME);
|
||||||
}
|
}
|
||||||
config = Util.readJsonFromFile(file.getAbsolutePath());
|
config = Util.readJsonFromFile(file.getAbsolutePath());
|
||||||
int configVersion = getInt(ConfigurationPaths.CONFIG_VERSION);
|
int configVersion = getInt(ConfigurationPaths.CONFIG_VERSION);
|
||||||
@ -68,7 +67,7 @@ public class Configuration {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
// write config to temp file, delete original config, rename temp file to original file to avoid conflicts if minosoft gets closed while saving the config
|
// write config to temp file, delete original config, rename temp file to original file to avoid conflicts if minosoft gets closed while saving the config
|
||||||
File tempFile = new File(Config.homeDir + "config/" + filename + ".tmp");
|
File tempFile = new File(StaticConfiguration.homeDir + "config/" + StaticConfiguration.CONFIG_FILENAME + ".tmp");
|
||||||
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
Gson gson = new GsonBuilder().setPrettyPrinting().create();
|
||||||
FileWriter writer;
|
FileWriter writer;
|
||||||
try {
|
try {
|
||||||
@ -91,7 +90,7 @@ public class Configuration {
|
|||||||
if (!tempFile.renameTo(finalFile)) {
|
if (!tempFile.renameTo(finalFile)) {
|
||||||
Log.fatal("An error occurred while saving the config file");
|
Log.fatal("An error occurred while saving the config file");
|
||||||
} else {
|
} else {
|
||||||
Log.verbose(String.format("Configuration saved to file %s", filename));
|
Log.verbose(String.format("Configuration saved to file %s", StaticConfiguration.CONFIG_FILENAME));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, "IO").start();
|
}, "IO").start();
|
||||||
|
@ -11,17 +11,17 @@
|
|||||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package de.bixilon.minosoft;
|
package de.bixilon.minosoft.config;
|
||||||
|
|
||||||
import de.bixilon.minosoft.util.OSUtil;
|
import de.bixilon.minosoft.util.OSUtil;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class Config {
|
public class StaticConfiguration {
|
||||||
public static final String configFileName = "config.json"; // Filename of minosoft's base configuration (located in AppData/Minosoft/config)
|
public static final String CONFIG_FILENAME = "config.json"; // Filename of minosoft's base configuration (located in AppData/Minosoft/config)
|
||||||
public static final boolean skipAuthentication = false; // disables all connections to mojang
|
public static final boolean SKIP_MOJANG_AUTHENTICATION = false; // disables all connections to mojang
|
||||||
public static final boolean colorLog = true; // the log should be colored with ANSI (does not affect base components)
|
public static final boolean COLORED_LOG = true; // the log should be colored with ANSI (does not affect base components)
|
||||||
public static final boolean logRelativeTime = false; // prefix all log messages with the relative start time in milliseconds instead of the formatted time
|
public static final boolean LOG_RELATIVE_TIME = false; // prefix all log messages with the relative start time in milliseconds instead of the formatted time
|
||||||
|
|
||||||
public static String homeDir;
|
public static String homeDir;
|
||||||
|
|
@ -18,9 +18,9 @@ import com.google.gson.JsonElement;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import com.google.gson.stream.JsonReader;
|
import com.google.gson.stream.JsonReader;
|
||||||
import de.bixilon.minosoft.Config;
|
|
||||||
import de.bixilon.minosoft.Minosoft;
|
import de.bixilon.minosoft.Minosoft;
|
||||||
import de.bixilon.minosoft.config.ConfigurationPaths;
|
import de.bixilon.minosoft.config.ConfigurationPaths;
|
||||||
|
import de.bixilon.minosoft.config.StaticConfiguration;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.logging.LogLevels;
|
import de.bixilon.minosoft.logging.LogLevels;
|
||||||
import de.bixilon.minosoft.util.CountUpAndDownLatch;
|
import de.bixilon.minosoft.util.CountUpAndDownLatch;
|
||||||
@ -241,6 +241,6 @@ public class AssetsManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static String getAssetDiskPath(String hash) {
|
private static String getAssetDiskPath(String hash) {
|
||||||
return Config.homeDir + String.format("assets/objects/%s/%s.gz", hash.substring(0, 2), hash);
|
return StaticConfiguration.homeDir + String.format("assets/objects/%s/%s.gz", hash.substring(0, 2), hash);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,9 +16,9 @@ package de.bixilon.minosoft.data.mappings.versions;
|
|||||||
import com.google.common.collect.HashBiMap;
|
import com.google.common.collect.HashBiMap;
|
||||||
import com.google.gson.JsonElement;
|
import com.google.gson.JsonElement;
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import de.bixilon.minosoft.Config;
|
|
||||||
import de.bixilon.minosoft.Minosoft;
|
import de.bixilon.minosoft.Minosoft;
|
||||||
import de.bixilon.minosoft.config.ConfigurationPaths;
|
import de.bixilon.minosoft.config.ConfigurationPaths;
|
||||||
|
import de.bixilon.minosoft.config.StaticConfiguration;
|
||||||
import de.bixilon.minosoft.data.Mappings;
|
import de.bixilon.minosoft.data.Mappings;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.protocol.protocol.ConnectionStates;
|
import de.bixilon.minosoft.protocol.protocol.ConnectionStates;
|
||||||
@ -128,7 +128,7 @@ public class Versions {
|
|||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
|
||||||
// check if mapping folder exist
|
// check if mapping folder exist
|
||||||
File mappingFolder = new File(Config.homeDir + "assets/mapping");
|
File mappingFolder = new File(StaticConfiguration.homeDir + "assets/mapping");
|
||||||
if (!mappingFolder.exists()) {
|
if (!mappingFolder.exists()) {
|
||||||
if (mappingFolder.mkdirs()) {
|
if (mappingFolder.mkdirs()) {
|
||||||
Log.verbose("Created mappings folder.");
|
Log.verbose("Created mappings folder.");
|
||||||
@ -138,7 +138,7 @@ public class Versions {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileName = Config.homeDir + String.format("assets/mapping/%s.tar.gz", version.getVersionName());
|
String fileName = StaticConfiguration.homeDir + String.format("assets/mapping/%s.tar.gz", version.getVersionName());
|
||||||
HashMap<String, JsonObject> files;
|
HashMap<String, JsonObject> files;
|
||||||
try {
|
try {
|
||||||
files = Util.readJsonTarGzFile(fileName);
|
files = Util.readJsonTarGzFile(fileName);
|
||||||
|
@ -13,7 +13,7 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.logging;
|
package de.bixilon.minosoft.logging;
|
||||||
|
|
||||||
import de.bixilon.minosoft.Config;
|
import de.bixilon.minosoft.config.StaticConfiguration;
|
||||||
import de.bixilon.minosoft.data.text.ChatColors;
|
import de.bixilon.minosoft.data.text.ChatColors;
|
||||||
import de.bixilon.minosoft.data.text.ChatFormattingCodes;
|
import de.bixilon.minosoft.data.text.ChatFormattingCodes;
|
||||||
import de.bixilon.minosoft.data.text.RGBColor;
|
import de.bixilon.minosoft.data.text.RGBColor;
|
||||||
@ -68,7 +68,7 @@ public class Log {
|
|||||||
}
|
}
|
||||||
StringBuilder builder = new StringBuilder();
|
StringBuilder builder = new StringBuilder();
|
||||||
builder.append("[");
|
builder.append("[");
|
||||||
if (Config.logRelativeTime) {
|
if (StaticConfiguration.LOG_RELATIVE_TIME) {
|
||||||
builder.append(System.currentTimeMillis() - startTime);
|
builder.append(System.currentTimeMillis() - startTime);
|
||||||
} else {
|
} else {
|
||||||
builder.append(timeFormat.format(System.currentTimeMillis()));
|
builder.append(timeFormat.format(System.currentTimeMillis()));
|
||||||
@ -79,7 +79,7 @@ public class Log {
|
|||||||
builder.append(level.name());
|
builder.append(level.name());
|
||||||
builder.append("] ");
|
builder.append("] ");
|
||||||
builder.append(prefix);
|
builder.append(prefix);
|
||||||
if (color != null && Config.colorLog) {
|
if (color != null && StaticConfiguration.COLORED_LOG) {
|
||||||
builder.append(ChatColors.getANSIColorByRGBColor(color));
|
builder.append(ChatColors.getANSIColorByRGBColor(color));
|
||||||
builder.append(message);
|
builder.append(message);
|
||||||
builder.append(ChatFormattingCodes.RESET.getANSI());
|
builder.append(ChatFormattingCodes.RESET.getANSI());
|
||||||
|
@ -13,8 +13,8 @@
|
|||||||
|
|
||||||
package de.bixilon.minosoft.modding.loading;
|
package de.bixilon.minosoft.modding.loading;
|
||||||
|
|
||||||
import de.bixilon.minosoft.Config;
|
|
||||||
import de.bixilon.minosoft.Minosoft;
|
import de.bixilon.minosoft.Minosoft;
|
||||||
|
import de.bixilon.minosoft.config.StaticConfiguration;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.modding.MinosoftMod;
|
import de.bixilon.minosoft.modding.MinosoftMod;
|
||||||
import de.bixilon.minosoft.util.CountUpAndDownLatch;
|
import de.bixilon.minosoft.util.CountUpAndDownLatch;
|
||||||
@ -38,7 +38,7 @@ public class ModLoader {
|
|||||||
// sort the list and prioritize
|
// sort the list and prioritize
|
||||||
// load all lists and dependencies async
|
// load all lists and dependencies async
|
||||||
HashSet<Callable<MinosoftMod>> callables = new HashSet<>();
|
HashSet<Callable<MinosoftMod>> callables = new HashSet<>();
|
||||||
File[] files = new File(Config.homeDir + "mods").listFiles();
|
File[] files = new File(StaticConfiguration.homeDir + "mods").listFiles();
|
||||||
if (files == null) {
|
if (files == null) {
|
||||||
// no mods to load
|
// no mods to load
|
||||||
return;
|
return;
|
||||||
|
@ -15,9 +15,9 @@ package de.bixilon.minosoft.util.mojang.api;
|
|||||||
|
|
||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonParser;
|
import com.google.gson.JsonParser;
|
||||||
import de.bixilon.minosoft.Config;
|
|
||||||
import de.bixilon.minosoft.Minosoft;
|
import de.bixilon.minosoft.Minosoft;
|
||||||
import de.bixilon.minosoft.config.ConfigurationPaths;
|
import de.bixilon.minosoft.config.ConfigurationPaths;
|
||||||
|
import de.bixilon.minosoft.config.StaticConfiguration;
|
||||||
import de.bixilon.minosoft.logging.Log;
|
import de.bixilon.minosoft.logging.Log;
|
||||||
import de.bixilon.minosoft.util.HTTP;
|
import de.bixilon.minosoft.util.HTTP;
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ public final class MojangAuthentication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static void joinServer(MojangAccount account, String serverId) {
|
public static void joinServer(MojangAccount account, String serverId) {
|
||||||
if (Config.skipAuthentication) {
|
if (StaticConfiguration.SKIP_MOJANG_AUTHENTICATION) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -85,7 +85,7 @@ public final class MojangAuthentication {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static String refresh(String clientToken, String accessToken) {
|
public static String refresh(String clientToken, String accessToken) {
|
||||||
if (Config.skipAuthentication) {
|
if (StaticConfiguration.SKIP_MOJANG_AUTHENTICATION) {
|
||||||
return clientToken;
|
return clientToken;
|
||||||
}
|
}
|
||||||
JsonObject payload = new JsonObject();
|
JsonObject payload = new JsonObject();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user