Comment and code additions

More comments are added.
More work on downloading server jars is done.
Server test added.
This commit is contained in:
Kristian Knarvik 2018-01-25 11:38:47 +01:00
parent b6685edc6f
commit 0c2c26e153
2 changed files with 14 additions and 6 deletions

View File

@ -127,6 +127,7 @@ public class Server {
throw new FileNotFoundException("Version file could not be downloaded.");
}
newestVersion = stringBetween(versionText, type.getSrcStart(), type.getSrcEnd());
System.out.println(newestVersion);
success = downloadFile(type.getDownloadURL() + newestVersion + type.getDownloadURLPart() + newestVersion + ".jar", filePath);
//TODO: Register the new version number, and only download if version mismatch or missing file.
if (!success) {
@ -208,6 +209,7 @@ public class Server {
* @return The wanted substring.
*/
private String stringBetween(String string, String start, String end) {
return string.substring(string.indexOf(start) + 1 + start.length(), string.indexOf(end));
int startPos = string.indexOf(start) + start.length();
return string.substring(startPos, string.indexOf(end, startPos));
}
}

View File

@ -1,7 +1,6 @@
import net.knarcraft.serverlauncher.server.*;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.*;
import java.util.ArrayList;
public class ServerTest {
@ -44,17 +43,24 @@ public class ServerTest {
if (server.isEnabled()) {
String path = server.getPath();
String type = server.getType();
try {
/* try {
server.downloadJar();
System.out.println("File downloaded.");
} catch (FileNotFoundException e) {
System.out.println("File was not found.");
return;
}
}*/
String ram = server.maxRam();
Runtime rt = Runtime.getRuntime();
try {
Process pr = rt.exec("java -Xmx" + ram + " -Xms512M -jar " + "\"" + path + "\\" + type + "\" nogui");
Process pr = rt.exec("java -Xmx" + ram + " -Xms512M -jar " + "\"" + path + "\\" + type + "\"", null, new File(server.getPath()));
String line;
BufferedReader in = new BufferedReader(
new InputStreamReader(pr.getInputStream()) );
while ((line = in.readLine()) != null) {
System.out.println(line);
}
in.close();
long pid = pr.pid();
server.updatePid(pid);
System.out.println("Success");