Commit 9825c886 authored by matthias's avatar matthias

fix LoadConfigFile sequence, Save: create folder if necessary

new variable serverconfig
parent f90d4379
......@@ -86,10 +86,11 @@ public class LoadConfigFile {
in.close();
configParameters = new ServerConfig(
defaultPrefs.getInt("MAX_CYCLES", 100000),
defaultPrefs.getInt("MAX_START_INSTRUCTIONS_COUNT", 1000),
defaultPrefs.getInt("PORT", 123),
defaultPrefs.getInt("MAX_PLAYER_COUNT", 2),
defaultPrefs.getInt("MAX_CYCLES", 100000),
defaultPrefs.getInt("CORE_SIZE", 10000),
defaultPrefs.getInt("PORT", 123));
defaultPrefs.getInt("WAIT_TIME_MS", 100));
}
}
......@@ -3,6 +3,7 @@ package gone.lib.config;
import gone.lib.common.Language;
import gone.lib.common.RcStandard;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.prefs.BackingStoreException;
......@@ -40,6 +41,12 @@ public class SaveConfigFile {
*/
private void saveClientConfig(ClientConfig params, String userFilePath, String nodeName)
throws IllegalArgumentException, IOException {
File input = new File(userFilePath);
if (!input.exists()) {
input.getParentFile().mkdirs();
}
if (userFilePath.isEmpty()) {
throw new IllegalArgumentException("user file path should not be empty!");
}
......@@ -75,6 +82,12 @@ public class SaveConfigFile {
private void saveServerConfig(ServerConfig params, String userFilePath, String nodeName)
throws IOException {
File input = new File(userFilePath);
if (!input.exists()) {
input.getParentFile().mkdirs();
}
if (userFilePath.isEmpty()) {
throw new IllegalArgumentException("user file path should not be empty!");
}
......@@ -85,6 +98,7 @@ public class SaveConfigFile {
userPrefs.putInt("MAX_CYCLES", params.getCoreSize());
userPrefs.putInt("CORE_SIZE", params.getCoreSize());
userPrefs.putInt("PORT", params.getPort());
userPrefs.putInt("WAIT_TIME_MS", params.getWaitTimeMs());
FileOutputStream out = new FileOutputStream(userFilePath);
try {
......
......@@ -11,49 +11,58 @@ public class ServerConfig extends ConfigParameters {
private int port;
private int maxPlayersCount;
private int coreSize;
private int waitTimeMs;
/* constructor */
public ServerConfig(int maxCycles, int maxStartInstructions, int port, int maxPlayersCount,
int coreSize) {
int coreSize, int waitTimeMs) {
setMaxCycles(maxCycles);
setMaxStartInstructions(maxStartInstructions);
setPort(port);
setMaxPlayersCount(maxPlayersCount);
setCoreSize(coreSize);
setWaitTimeMs(waitTimeMs);
}
/* setter */
private void setMaxCycles(int maxCycles) {
public void setWaitTimeMs(int waitTimeMs) {
if (waitTimeMs <= 0) {
throw new IllegalArgumentException("wait time milliseconds must be > 0");
}
this.waitTimeMs = waitTimeMs;
}
public void setMaxCycles(int maxCycles) {
if (maxCycles <= 0) {
throw new IllegalArgumentException("max cycles must be > 0");
}
this.maxCycles = maxCycles;
}
private void setMaxStartInstructions(int maxStartInstructions) {
public void setMaxStartInstructions(int maxStartInstructions) {
if (maxStartInstructions <= 0 || maxStartInstructions > 2000) {
throw new IllegalArgumentException("maxStartInstructions must be > 0 && <= 2000");
}
this.maxStartInstructions = maxStartInstructions;
}
private void setPort(int port) {
public void setPort(int port) {
if (port < 0 || port > 65535) {
throw new IllegalArgumentException("port must be >= 0 && <= 65535");
}
this.port = port;
}
private void setMaxPlayersCount(int maxPlayersCount) {
public void setMaxPlayersCount(int maxPlayersCount) {
if (maxPlayersCount != 1 && maxPlayersCount != 2) {
throw new IllegalArgumentException("maxPlayersCount must be 1 or 2");
}
this.maxPlayersCount = maxPlayersCount;
}
private void setCoreSize(int coreSize) {
public void setCoreSize(int coreSize) {
if (coreSize <= 0) {
throw new IllegalArgumentException("max cycles must be > 0");
}
......@@ -62,6 +71,10 @@ public class ServerConfig extends ConfigParameters {
/* getter */
public int getWaitTimeMs() {
return waitTimeMs;
}
public int getMaxCycles() {
return maxCycles;
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment