Skip to content

Commit

Permalink
GameDownloadUtils: add windows start game
Browse files Browse the repository at this point in the history
  • Loading branch information
purofle committed Dec 31, 2023
1 parent 50a8a64 commit 96cd21c
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions src/main/kotlin/com/github/purofle/nmsl/utils/GameDownloadUtils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.github.purofle.nmsl.config.Config
import com.github.purofle.nmsl.download.DownloadProvider
import com.github.purofle.nmsl.download.GameDownloader
import com.github.purofle.nmsl.game.GameManager
import com.github.purofle.nmsl.utils.os.OS
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import java.io.File
Expand All @@ -27,18 +28,27 @@ suspend fun startGame(version: String, launcherArgument: List<String>) {
downloadClientJar()
}

println(launcherArgument.joinToString(" "))
withContext(Dispatchers.IO) {
val sh = File.createTempFile("nmsl", "sh")
sh.writeText("java " + launcherArgument.joinToString(" "))
sh.deleteOnExit()

ProcessBuilder(
"/bin/sh", sh.absolutePath
)
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor()
if (OS.CURRENT_OS != OS.WINDOWS) {
startGameUnix(launcherArgument)
} else {
startGameWindows(launcherArgument)
}
}

suspend fun startGameUnix(launcherArgument: List<String>): Unit = withContext(Dispatchers.IO) {
val sh = File.createTempFile("nmsl", "sh")
sh.writeText("java " + launcherArgument.joinToString(" "))
sh.deleteOnExit()

ProcessBuilder(
"/bin/sh", sh.absolutePath
)
.redirectOutput(ProcessBuilder.Redirect.INHERIT)
.redirectError(ProcessBuilder.Redirect.INHERIT)
.start()
.waitFor()
}

suspend fun startGameWindows(launcherArgument: List<String>): Unit = withContext(Dispatchers.IO) {
TODO(launcherArgument.joinToString(" "))
}

0 comments on commit 96cd21c

Please sign in to comment.