Auto-installing
This commit is contained in:
@@ -51,13 +51,13 @@ class DefaultDependencyManager(override val repository: DefaultGameRepository, o
|
||||
override fun installLibraryAsync(gameVersion: String, version: Version, libraryId: String, libraryVersion: String): Task {
|
||||
if (libraryId == "forge")
|
||||
return ForgeInstallTask(this, gameVersion, version, libraryVersion)
|
||||
.then { VersionJSONSaveTask(this, it["version"]) }
|
||||
.then { VersionJSONSaveTask(repository, it["version"]) }
|
||||
else if (libraryId == "liteloader")
|
||||
return LiteLoaderInstallTask(this, gameVersion, version, libraryVersion)
|
||||
.then { VersionJSONSaveTask(this, it["version"]) }
|
||||
.then { VersionJSONSaveTask(repository, it["version"]) }
|
||||
else if (libraryId == "optifine")
|
||||
return OptiFineInstallTask(this, gameVersion, version, libraryVersion)
|
||||
.then { VersionJSONSaveTask(this, it["version"]) }
|
||||
.then { VersionJSONSaveTask(repository, it["version"]) }
|
||||
else
|
||||
throw IllegalArgumentException("Library id $libraryId is unrecognized.")
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class DefaultGameBuilder(val dependencyManager: DefaultDependencyManager): GameB
|
||||
GameLoggingDownloadTask(dependencyManager, version),
|
||||
GameDownloadTask(version),
|
||||
GameLibrariesTask(dependencyManager, version) // Game libraries will be downloaded for multiple times partly, this time is for vanilla libraries.
|
||||
) then VersionJSONSaveTask(dependencyManager, version)
|
||||
) then VersionJSONSaveTask(dependencyManager.repository, version)
|
||||
|
||||
if (toolVersions.containsKey("forge"))
|
||||
result = result then libraryTaskHelper(gameVersion, "forge")
|
||||
|
||||
@@ -20,10 +20,7 @@ package org.jackhuang.hmcl.download.game
|
||||
import org.jackhuang.hmcl.download.AbstractDependencyManager
|
||||
import org.jackhuang.hmcl.download.DefaultDependencyManager
|
||||
import org.jackhuang.hmcl.download.DependencyManager
|
||||
import org.jackhuang.hmcl.game.AssetIndex
|
||||
import org.jackhuang.hmcl.game.AssetObject
|
||||
import org.jackhuang.hmcl.game.DownloadType
|
||||
import org.jackhuang.hmcl.game.Version
|
||||
import org.jackhuang.hmcl.game.*
|
||||
import org.jackhuang.hmcl.task.FileDownloadTask
|
||||
import org.jackhuang.hmcl.task.Task
|
||||
import org.jackhuang.hmcl.task.TaskResult
|
||||
@@ -164,12 +161,12 @@ class GameAssetDownloadTask(private val dependencyManager: DefaultDependencyMana
|
||||
|
||||
/**
|
||||
* This task is to save the version json.
|
||||
* @param dependencyManager the dependency manager that can provides proxy settings and [GameRepository]
|
||||
* @param repository the game repository
|
||||
* @param version the **resolved** version
|
||||
*/
|
||||
class VersionJSONSaveTask(private val dependencyManager: DefaultDependencyManager, private val version: Version): Task() {
|
||||
class VersionJSONSaveTask(private val repository: DefaultGameRepository, private val version: Version): Task() {
|
||||
override fun execute() {
|
||||
val json = dependencyManager.repository.getVersionJson(version.id).absoluteFile
|
||||
val json = repository.getVersionJson(version.id).absoluteFile
|
||||
if (!json.makeFile())
|
||||
throw IOException("Cannot create file $json")
|
||||
json.writeText(GSON.toJson(version))
|
||||
|
||||
@@ -74,12 +74,13 @@ open class Library(
|
||||
companion object LibrarySerializer : JsonDeserializer<Library>, JsonSerializer<Library> {
|
||||
fun fromName(name: String, url: String? = null, downloads: LibrariesDownloadInfo? = null, extract: ExtractRules? = null, natives: Map<OS, String>? = null, rules: List<CompatibilityRule>? = null): Library {
|
||||
val arr = name.split(":".toRegex(), 3)
|
||||
if (arr.size != 3)
|
||||
if (arr.size != 3 && arr.size != 4)
|
||||
throw IllegalArgumentException("Library name is malformed. Correct example: group:artifact:version.")
|
||||
return Library(
|
||||
groupId = arr[0].replace("\\", "/"),
|
||||
artifactId = arr[1],
|
||||
version = arr[2],
|
||||
classifier_ = arr.getOrNull(3),
|
||||
url = url,
|
||||
downloads = downloads,
|
||||
extract = extract,
|
||||
|
||||
@@ -65,6 +65,10 @@ class GetTask @JvmOverloads constructor(val url: URL, val encoding: Charset = Ch
|
||||
return
|
||||
}
|
||||
|
||||
if (size > 0 && size != read) {
|
||||
throw IllegalStateException("Not completed! Readed: $read, Size: $size")
|
||||
}
|
||||
|
||||
result = baos.toString(encoding.name())
|
||||
return
|
||||
} catch (e: IOException) {
|
||||
|
||||
@@ -50,7 +50,7 @@ abstract class Task {
|
||||
*/
|
||||
open val reliant: Boolean = true
|
||||
|
||||
var title: String = this.javaClass.toString()
|
||||
open var title: String = this.javaClass.toString()
|
||||
|
||||
var variables: AutoTypingMap<String>? = null
|
||||
|
||||
|
||||
Reference in New Issue
Block a user