From 68ff0f0d78d9f7f14a2e96a725f7bd744df29bd4 Mon Sep 17 00:00:00 2001 From: Bryson Steck Date: Fri, 26 May 2023 22:16:11 -0600 Subject: add properties backup --- build.gradle | 2 -- .../ServerCraft/controllers/PrimaryController.kt | 4 +++- .../xyz/brysonsteck/ServerCraft/server/Server.kt | 23 +++++++++++++++++++--- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/build.gradle b/build.gradle index 379e417..adb9fba 100644 --- a/build.gradle +++ b/build.gradle @@ -68,8 +68,6 @@ distTar { } jar { - // archiveFileName = 'ServerCraft.jar' - manifest { attributes 'Main-Class': application.mainClass } 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() { -- cgit v1.2.3