From d2529cfc23c676f845aa5e88439bfabdf59ae232 Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Thu, 16 Nov 2017 00:13:49 +0800 Subject: [PATCH] Merge 'arguments' --- .../main/kotlin/org/jackhuang/hmcl/game/Arguments.kt | 11 +++++++++++ .../main/kotlin/org/jackhuang/hmcl/game/Version.kt | 1 + .../kotlin/org/jackhuang/hmcl/launch/ExitWaiter.kt | 3 +-- .../src/main/kotlin/org/jackhuang/hmcl/util/Lang.kt | 5 +++-- 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Arguments.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Arguments.kt index b8d726ded..91bcfdc8c 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Arguments.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Arguments.kt @@ -20,6 +20,7 @@ package org.jackhuang.hmcl.game import com.google.gson.annotations.SerializedName import org.jackhuang.hmcl.util.OS import org.jackhuang.hmcl.game.CompatibilityRule.* +import org.jackhuang.hmcl.util.merge class Arguments @JvmOverloads constructor( @SerializedName("game") @@ -28,6 +29,16 @@ class Arguments @JvmOverloads constructor( val jvm: List? = null ) { companion object { + fun mergeArguments(a: Arguments?, b: Arguments?): Arguments? { + if (a == null && b == null) return null + else if (a == null) return b + else if (b == null) return a + else return Arguments( + game = merge(a.game, b.game), + jvm = merge(a.jvm, b.jvm) + ) + } + fun parseStringArguments(arguments: List, keys: Map, features: Map = emptyMap()): List { return arguments.flatMap { StringArgument(it).toString(keys, features) } } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Version.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Version.kt index 66a1578ca..f8134989b 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Version.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Version.kt @@ -131,6 +131,7 @@ open class Version( libraries = merge(this.libraries, parent.libraries), downloads = this.downloads ?: parent.downloads, assetIndex = this.assetIndex ?: parent.assetIndex, + arguments = Arguments.mergeArguments(parent.arguments, this.arguments), releaseTime = this.releaseTime, inheritsFrom = null, minecraftArguments = this.minecraftArguments ?: parent.minecraftArguments, diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/launch/ExitWaiter.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/launch/ExitWaiter.kt index 043f431fe..fc1057827 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/launch/ExitWaiter.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/launch/ExitWaiter.kt @@ -32,11 +32,10 @@ import org.jackhuang.hmcl.util.guessLogLineError internal class ExitWaiter(val process: ManagedProcess, val joins: Collection, val watcher: (Int, ProcessListener.ExitType) -> Unit) : Runnable { override fun run() { try { - process.process.waitFor() + val exitCode = process.process.waitFor() joins.forEach { it.join() } - val exitCode = process.exitCode val errorLines = process.lines.filter(::guessLogLineError) val exitType: ProcessListener.ExitType // LaunchWrapper will catch the exception logged and will exit normally. diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Lang.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Lang.kt index 7ef82d122..84c3cfa0b 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Lang.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Lang.kt @@ -50,9 +50,10 @@ fun copyList(list: List?): MutableList? = if (list == null) null else LinkedList(list) -fun merge(vararg c: Collection): List = LinkedList().apply { +fun merge(vararg c: Collection?): List = LinkedList().apply { for (a in c) - addAll(a) + if (a != null) + addAll(a) } fun isBlank(str: String?) = str?.isBlank() ?: true