add properties backup
This commit is contained in:
parent
01f6beb513
commit
68ff0f0d78
3 changed files with 23 additions and 6 deletions
|
@ -68,8 +68,6 @@ distTar {
|
|||
}
|
||||
|
||||
jar {
|
||||
// archiveFileName = 'ServerCraft.jar'
|
||||
|
||||
manifest {
|
||||
attributes 'Main-Class': application.mainClass
|
||||
}
|
||||
|
|
|
@ -765,8 +765,10 @@ class PrimaryController {
|
|||
statusBar.text = "Ready."
|
||||
if (result) {
|
||||
startButton.isDisable = false
|
||||
File(directory + "ServerCraft").mkdir()
|
||||
buildButton.text = "Build Server"
|
||||
server.loadProps(dir, convert=true)
|
||||
}
|
||||
server.loadProps(dir)
|
||||
return result
|
||||
} else {
|
||||
// assume clean directory
|
||||
|
|
|
@ -2,6 +2,7 @@ package xyz.brysonsteck.ServerCraft.server
|
|||
|
||||
import java.io.File
|
||||
import java.io.InputStream
|
||||
import java.io.FileNotFoundException
|
||||
import java.util.Properties
|
||||
|
||||
public class Server {
|
||||
|
@ -36,11 +37,27 @@ public class Server {
|
|||
writeProps()
|
||||
}
|
||||
|
||||
public fun loadProps(dir: String) {
|
||||
public fun loadProps(dir: String, convert: Boolean = false) {
|
||||
var ins = File(dir + File.separator + "server.properties").inputStream()
|
||||
props.load(ins)
|
||||
ins = File(dir + File.separator + "ServerCraft" + File.separator + "ServerCraft.properties").inputStream()
|
||||
props.load(ins)
|
||||
try {
|
||||
ins = File(dir + File.separator + "ServerCraft" + File.separator + "ServerCraft.properties").inputStream()
|
||||
props.load(ins)
|
||||
} catch (e: FileNotFoundException) {
|
||||
if (convert) {
|
||||
// create the file in question, as this is an external server being converted into a ServerCraft managed one
|
||||
File(dir + File.separator + "ServerCraft" + File.separator + "ServerCraft.properties").createNewFile()
|
||||
// also apply app-specific properties
|
||||
props.setProperty("jvm-ram", 1024.toString())
|
||||
// then write to file
|
||||
val temp = Properties()
|
||||
val outs = File(dir + File.separator + "ServerCraft" + File.separator + "ServerCraft.properties").outputStream()
|
||||
temp.setProperty("jvm-ram", props.getProperty("jvm-ram"))
|
||||
temp.store(outs, "ServerCraft settings backup\nSometimes, Minecraft will completely overwrite the server.properties file,\ncompletely destroying these app-specific settings. This file backs up these settings\njust in case. :)\nhttps://codeberg.org/brysonsteck/ServerCraft")
|
||||
} else {
|
||||
println(e)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private fun writeProps() {
|
||||
|
|
Loading…
Add table
Reference in a new issue