fixed logging, scrollpane just gets too big
This commit is contained in:
parent
6405861558
commit
e57a3d6864
2 changed files with 33 additions and 32 deletions
|
@ -89,7 +89,7 @@ task pack(type: io.github.fvarrui.javapackager.gradle.PackageTask, dependsOn: bu
|
||||||
organizationUrl = "https://brysonsteck.xyz"
|
organizationUrl = "https://brysonsteck.xyz"
|
||||||
organizationEmail = "me@brysonsteck.xyz"
|
organizationEmail = "me@brysonsteck.xyz"
|
||||||
url = "https://codeberg.org/brysonsteck/ServerCraft"
|
url = "https://codeberg.org/brysonsteck/ServerCraft"
|
||||||
additionalModules = [ "jdk.crypto.ec" ]
|
additionalModules = [ "java.management", "jdk.crypto.ec" ]
|
||||||
|
|
||||||
linuxConfig {
|
linuxConfig {
|
||||||
pngFile = file('src/main/resources/icon.png')
|
pngFile = file('src/main/resources/icon.png')
|
||||||
|
|
|
@ -137,8 +137,11 @@ class PrimaryController {
|
||||||
private var showingConsole = false
|
private var showingConsole = false
|
||||||
|
|
||||||
private fun log(str: String) {
|
private fun log(str: String) {
|
||||||
console.text = console.text + str + "\n"
|
if (console.text.length > 100000) {
|
||||||
println(str)
|
console.text = console.text.drop(str.length + 10)
|
||||||
|
}
|
||||||
|
console.text = console.text + str
|
||||||
|
print(str)
|
||||||
}
|
}
|
||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
|
@ -441,21 +444,21 @@ class PrimaryController {
|
||||||
withContext(Dispatchers.JavaFx){
|
withContext(Dispatchers.JavaFx){
|
||||||
statusBar.text = "Downloading ${it.key}..."
|
statusBar.text = "Downloading ${it.key}..."
|
||||||
progressBar.progress = ProgressBar.INDETERMINATE_PROGRESS
|
progressBar.progress = ProgressBar.INDETERMINATE_PROGRESS
|
||||||
log("Downloading ${it.key} from ${it.value}")
|
log("Downloading ${it.key} from ${it.value}\n")
|
||||||
}
|
}
|
||||||
val download = Download(URL(it.value), destinations[it.key]!!)
|
val download = Download(URL(it.value), destinations[it.key]!!)
|
||||||
download.start()
|
download.start()
|
||||||
while (download.status == Download.Status.DOWNLOADING) {
|
while (download.status == Download.Status.DOWNLOADING) {
|
||||||
var prog = (download.downloaded.toDouble() / download.contentLength.toDouble())
|
var prog = (download.downloaded.toDouble() / download.contentLength.toDouble())
|
||||||
// for whatever reason I need to print something to the screen in order for it to update the progress bar
|
// for whatever reason I need to print something to the screen in order for it to update the progress bar
|
||||||
withContext(Dispatchers.JavaFx) {log("Progress: ${prog * 100}%")}
|
withContext(Dispatchers.JavaFx) {log("Progress: ${prog * 100}%\n")}
|
||||||
if (prog >= 0.01) {
|
if (prog >= 0.01) {
|
||||||
withContext(Dispatchers.JavaFx) {progressBar.progress = prog}
|
withContext(Dispatchers.JavaFx) {progressBar.progress = prog}
|
||||||
}
|
}
|
||||||
if (!building) download.status = Download.Status.CANCELLED
|
if (!building) download.status = Download.Status.CANCELLED
|
||||||
Thread.sleep(300)
|
Thread.sleep(300)
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.JavaFx) {log("Download of ${it.key} complete with status: ${download.status}")}
|
withContext(Dispatchers.JavaFx) {log("Download of ${it.key} complete with status: ${download.status}\n")}
|
||||||
}
|
}
|
||||||
|
|
||||||
// extract java archive
|
// extract java archive
|
||||||
|
@ -463,7 +466,7 @@ class PrimaryController {
|
||||||
withContext(Dispatchers.JavaFx) {
|
withContext(Dispatchers.JavaFx) {
|
||||||
progressBar.progress = ProgressBar.INDETERMINATE_PROGRESS
|
progressBar.progress = ProgressBar.INDETERMINATE_PROGRESS
|
||||||
statusBar.text = "Extracting Java archive..."
|
statusBar.text = "Extracting Java archive..."
|
||||||
log("Extracting Java archive to ${directory + "ServerCraft" + File.separator + "Java"}")
|
log("Extracting Java archive to ${directory + "ServerCraft" + File.separator + "Java"}\n")
|
||||||
}
|
}
|
||||||
var stream = archiver.stream(File(directory + "ServerCraft" + File.separator + "Java" + File.separator + javaFile))
|
var stream = archiver.stream(File(directory + "ServerCraft" + File.separator + "Java" + File.separator + javaFile))
|
||||||
val dest = File(directory + "ServerCraft" + File.separator + "Java")
|
val dest = File(directory + "ServerCraft" + File.separator + "Java")
|
||||||
|
@ -477,7 +480,7 @@ class PrimaryController {
|
||||||
do {
|
do {
|
||||||
withContext(Dispatchers.JavaFx) {
|
withContext(Dispatchers.JavaFx) {
|
||||||
progressBar.progress = currentEntry/entries
|
progressBar.progress = currentEntry/entries
|
||||||
log(entry.name)
|
log(entry.name + "\n")
|
||||||
}
|
}
|
||||||
entry.extract(dest)
|
entry.extract(dest)
|
||||||
entry = stream.getNextEntry()
|
entry = stream.getNextEntry()
|
||||||
|
@ -490,37 +493,31 @@ class PrimaryController {
|
||||||
progressBar.progress = ProgressBar.INDETERMINATE_PROGRESS
|
progressBar.progress = ProgressBar.INDETERMINATE_PROGRESS
|
||||||
statusBar.text = "Building Minecraft Server..."
|
statusBar.text = "Building Minecraft Server..."
|
||||||
}
|
}
|
||||||
val builder = ProcessBuilder("java", "-jar", "BuildTools.jar", "--rev", "latest", "-o", ".." + File.separator + ".." + File.separator)
|
val builder = ProcessBuilder("${directory}ServerCraft${File.separator}Java${File.separator}jdk-20.0.1${File.separator}bin${File.separator}java", "-jar", "BuildTools.jar", "--rev", "latest", "-o", ".." + File.separator + ".." + File.separator)
|
||||||
builder.directory(File(directory + "ServerCraft" + File.separator + "Spigot"))
|
builder.directory(File(directory + "ServerCraft" + File.separator + "Spigot"))
|
||||||
val proc = builder.start()
|
val proc = builder.start()
|
||||||
val reader = InputStreamReader(proc.inputStream)
|
val reader = InputStreamReader(proc.inputStream)
|
||||||
val errors = InputStreamReader(proc.errorStream)
|
|
||||||
val br = BufferedReader(reader)
|
|
||||||
val ebr = BufferedReader(errors)
|
|
||||||
try {
|
try {
|
||||||
var line = br.readLine()
|
var cbuf = CharArray(1000)
|
||||||
var errorLine = ebr.readLine()
|
|
||||||
var currentline = 0.0
|
var currentline = 0.0
|
||||||
while (line != null || errorLine != null) {
|
while (proc.isAlive) {
|
||||||
if (!building) {
|
if (!building) {
|
||||||
proc.destroy()
|
proc.destroy()
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.JavaFx) {
|
withContext(Dispatchers.JavaFx) {log(cbuf.joinToString(separator=""))}
|
||||||
if (errorLine != null) {
|
cbuf = CharArray(1000)
|
||||||
log(errorLine)
|
reader.read(cbuf, 0, 1000)
|
||||||
}
|
|
||||||
log(line)
|
|
||||||
}
|
|
||||||
line = br.readLine()
|
|
||||||
errorLine = ebr.readLine()
|
|
||||||
currentline++
|
currentline++
|
||||||
if (currentline > 15) {
|
if (currentline > 15) {
|
||||||
withContext(Dispatchers.JavaFx) {progressBar.progress = if (spigotBuilt) {currentline/1100.0} else {currentline/14122.0} }
|
withContext(Dispatchers.JavaFx) {progressBar.progress = if (spigotBuilt) {currentline/1100.0} else {currentline/14122.0} }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
cbuf = CharArray(1000)
|
||||||
|
reader.read(cbuf, 0, 1000)
|
||||||
|
withContext(Dispatchers.JavaFx) {log(cbuf.joinToString(separator=""))}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
withContext(Dispatchers.JavaFx) {log("Stream Closed: ${e.toString()}")}
|
withContext(Dispatchers.JavaFx) {log("Stream Closed\n")}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
progressBar.isVisible = false
|
progressBar.isVisible = false
|
||||||
|
@ -568,14 +565,14 @@ class PrimaryController {
|
||||||
startButton.text = "Kill Server"
|
startButton.text = "Kill Server"
|
||||||
@Suppress("OPT_IN_USAGE")
|
@Suppress("OPT_IN_USAGE")
|
||||||
GlobalScope.launch(Dispatchers.Default) {
|
GlobalScope.launch(Dispatchers.Default) {
|
||||||
val builder = ProcessBuilder("java", "-Xmx${server.getProp("jvm-ram")}M", "-jar", "${server.jar}")
|
val builder = ProcessBuilder("${directory}ServerCraft${File.separator}Java${File.separator}jdk-20.0.1${File.separator}bin${File.separator}java", "-Xmx${server.getProp("jvm-ram")}M", "-jar", "${server.jar}")
|
||||||
builder.directory(File(directory))
|
builder.directory(File(directory))
|
||||||
val proc = builder.start()
|
val proc = builder.start()
|
||||||
val reader = InputStreamReader(proc.inputStream)
|
val reader = InputStreamReader(proc.inputStream)
|
||||||
val br = BufferedReader(reader)
|
|
||||||
try {
|
try {
|
||||||
var line = br.readLine()
|
var cbuf = CharArray(1000)
|
||||||
while (line != null) {
|
reader.read(cbuf, 0, 1000)
|
||||||
|
while (proc.isAlive) {
|
||||||
if (asyncResult) {
|
if (asyncResult) {
|
||||||
withContext(Dispatchers.JavaFx) {
|
withContext(Dispatchers.JavaFx) {
|
||||||
statusBar.text = "Killing Minecraft server..."
|
statusBar.text = "Killing Minecraft server..."
|
||||||
|
@ -583,11 +580,15 @@ class PrimaryController {
|
||||||
}
|
}
|
||||||
proc.destroy()
|
proc.destroy()
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.JavaFx) {log(line)}
|
withContext(Dispatchers.JavaFx) {log(cbuf.joinToString(separator=""))}
|
||||||
line = br.readLine()
|
cbuf = CharArray(1000)
|
||||||
|
reader.read(cbuf, 0, 1000)
|
||||||
}
|
}
|
||||||
|
cbuf = CharArray(1000)
|
||||||
|
reader.read(cbuf, 0, 1000)
|
||||||
|
withContext(Dispatchers.JavaFx) {log(cbuf.joinToString(separator=""))}
|
||||||
} catch (e: IOException) {
|
} catch (e: IOException) {
|
||||||
withContext(Dispatchers.JavaFx) {log("Stream Closed")}
|
withContext(Dispatchers.JavaFx) {log("Stream Closed\n")}
|
||||||
}
|
}
|
||||||
withContext(Dispatchers.JavaFx) {
|
withContext(Dispatchers.JavaFx) {
|
||||||
statusBar.text = if (asyncResult) {
|
statusBar.text = if (asyncResult) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue