Support having no Tachidesk jar available

This commit is contained in:
Syer10
2021-05-30 16:30:14 -04:00
parent e69510e686
commit ad147d688e
2 changed files with 13 additions and 6 deletions

View File

@@ -43,12 +43,12 @@ class ServerService @Inject constructor(
initialized.value = ServerResult.UNUSED
}
private fun copyJar(jarFile: File) {
javaClass.getResourceAsStream("/Tachidesk.jar")?.buffered()?.use { input ->
private fun copyJar(jarFile: File): Boolean {
return javaClass.getResourceAsStream("/Tachidesk.jar")?.buffered()?.use { input ->
jarFile.outputStream().use { output ->
input.copyTo(output)
}
}
}?.let { true } ?: false
}
init {
@@ -71,7 +71,9 @@ class ServerService @Inject constructor(
val jarFile = File(userDataDir, "Tachidesk.jar")
if (!jarFile.exists()) {
info { "Copying server to resources" }
copyJar(jarFile)
if (!copyJar(jarFile)) {
initialized.value = ServerResult.NO_TACHIDESK_JAR
}
} else {
try {
val jarVersion = withIOContext {
@@ -131,6 +133,7 @@ class ServerService @Inject constructor(
enum class ServerResult {
UNUSED,
NO_TACHIDESK_JAR,
STARTING,
STARTED,
FAILED;

View File

@@ -126,10 +126,14 @@ fun main() {
ServerResult.STARTED, ServerResult.UNUSED -> {
MainMenu(rootBundle)
}
ServerResult.STARTING, ServerResult.FAILED -> {
ServerResult.STARTING, ServerResult.FAILED, ServerResult.NO_TACHIDESK_JAR -> {
LoadingScreen(
initialized == ServerResult.STARTING,
errorMessage = "Unable to start server",
errorMessage = if (initialized == ServerResult.NO_TACHIDESK_JAR) {
"Tachidesk jar does not exist, run Tachidesk yourself"
} else {
"Unable to start server"
},
retryMessage = "Start anyway",
retry = serverService::startAnyway
)