diff options
author | Bryson Steck <brysonsteck@protonmail.com> | 2023-05-26 22:16:11 -0600 |
---|---|---|
committer | Bryson Steck <brysonsteck@protonmail.com> | 2023-05-26 22:16:11 -0600 |
commit | 68ff0f0d78d9f7f14a2e96a725f7bd744df29bd4 (patch) | |
tree | fcec4bac2edb6d10756eeb4982f7be246404030f /src/main/kotlin/xyz | |
parent | 01f6beb5139d98b29a13bfe389e59bb36c9861a3 (diff) | |
download | ServerCraft-68ff0f0d78d9f7f14a2e96a725f7bd744df29bd4.tar ServerCraft-68ff0f0d78d9f7f14a2e96a725f7bd744df29bd4.tar.gz ServerCraft-68ff0f0d78d9f7f14a2e96a725f7bd744df29bd4.tar.bz2 |
add properties backup
Diffstat (limited to 'src/main/kotlin/xyz')
-rw-r--r-- | src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt | 4 | ||||
-rw-r--r-- | src/main/kotlin/xyz/brysonsteck/ServerCraft/server/Server.kt | 23 |
2 files changed, 23 insertions, 4 deletions
diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt index 211c18c..2282d13 100644 --- a/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt +++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/controllers/PrimaryController.kt @@ -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 diff --git a/src/main/kotlin/xyz/brysonsteck/ServerCraft/server/Server.kt b/src/main/kotlin/xyz/brysonsteck/ServerCraft/server/Server.kt index 0c3a7d1..141b477 100644 --- a/src/main/kotlin/xyz/brysonsteck/ServerCraft/server/Server.kt +++ b/src/main/kotlin/xyz/brysonsteck/ServerCraft/server/Server.kt @@ -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() { |