Merge 'arguments'

This commit is contained in:
huangyuhui 2017-11-16 00:13:49 +08:00
parent b81b38f7e4
commit d2529cfc23
4 changed files with 16 additions and 4 deletions

View File

@ -20,6 +20,7 @@ package org.jackhuang.hmcl.game
import com.google.gson.annotations.SerializedName import com.google.gson.annotations.SerializedName
import org.jackhuang.hmcl.util.OS import org.jackhuang.hmcl.util.OS
import org.jackhuang.hmcl.game.CompatibilityRule.* import org.jackhuang.hmcl.game.CompatibilityRule.*
import org.jackhuang.hmcl.util.merge
class Arguments @JvmOverloads constructor( class Arguments @JvmOverloads constructor(
@SerializedName("game") @SerializedName("game")
@ -28,6 +29,16 @@ class Arguments @JvmOverloads constructor(
val jvm: List<Argument>? = null val jvm: List<Argument>? = null
) { ) {
companion object { 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<String>, keys: Map<String, String>, features: Map<String, Boolean> = emptyMap()): List<String> { fun parseStringArguments(arguments: List<String>, keys: Map<String, String>, features: Map<String, Boolean> = emptyMap()): List<String> {
return arguments.flatMap { StringArgument(it).toString(keys, features) } return arguments.flatMap { StringArgument(it).toString(keys, features) }
} }

View File

@ -131,6 +131,7 @@ open class Version(
libraries = merge(this.libraries, parent.libraries), libraries = merge(this.libraries, parent.libraries),
downloads = this.downloads ?: parent.downloads, downloads = this.downloads ?: parent.downloads,
assetIndex = this.assetIndex ?: parent.assetIndex, assetIndex = this.assetIndex ?: parent.assetIndex,
arguments = Arguments.mergeArguments(parent.arguments, this.arguments),
releaseTime = this.releaseTime, releaseTime = this.releaseTime,
inheritsFrom = null, inheritsFrom = null,
minecraftArguments = this.minecraftArguments ?: parent.minecraftArguments, minecraftArguments = this.minecraftArguments ?: parent.minecraftArguments,

View File

@ -32,11 +32,10 @@ import org.jackhuang.hmcl.util.guessLogLineError
internal class ExitWaiter(val process: ManagedProcess, val joins: Collection<Thread>, val watcher: (Int, ProcessListener.ExitType) -> Unit) : Runnable { internal class ExitWaiter(val process: ManagedProcess, val joins: Collection<Thread>, val watcher: (Int, ProcessListener.ExitType) -> Unit) : Runnable {
override fun run() { override fun run() {
try { try {
process.process.waitFor() val exitCode = process.process.waitFor()
joins.forEach { it.join() } joins.forEach { it.join() }
val exitCode = process.exitCode
val errorLines = process.lines.filter(::guessLogLineError) val errorLines = process.lines.filter(::guessLogLineError)
val exitType: ProcessListener.ExitType val exitType: ProcessListener.ExitType
// LaunchWrapper will catch the exception logged and will exit normally. // LaunchWrapper will catch the exception logged and will exit normally.

View File

@ -50,9 +50,10 @@ fun <T> copyList(list: List<T>?): MutableList<T>? =
if (list == null) null if (list == null) null
else LinkedList(list) else LinkedList(list)
fun <T> merge(vararg c: Collection<T>): List<T> = LinkedList<T>().apply { fun <T> merge(vararg c: Collection<T>?): List<T> = LinkedList<T>().apply {
for (a in c) for (a in c)
addAll(a) if (a != null)
addAll(a)
} }
fun isBlank(str: String?) = str?.isBlank() ?: true fun isBlank(str: String?) = str?.isBlank() ?: true