From d8be9abcc584a51f441cec3b8b16c4a5fb139fca Mon Sep 17 00:00:00 2001 From: huangyuhui Date: Mon, 1 Jan 2018 16:21:54 +0800 Subject: [PATCH] nothing --- .../org/jackhuang/hmcl/auth/AuthInfo.kt | 14 +++++- .../auth/yggdrasil/AuthenticationRequest.kt | 2 +- .../hmcl/auth/yggdrasil/GameProfile.kt | 4 +- .../hmcl/auth/yggdrasil/RefreshRequest.kt | 2 +- .../jackhuang/hmcl/auth/yggdrasil/Response.kt | 2 +- .../org/jackhuang/hmcl/auth/yggdrasil/User.kt | 2 +- .../hmcl/auth/yggdrasil/YggdrasilAccount.kt | 16 +++---- .../download/AbstractDependencyManager.kt | 6 --- .../hmcl/download/BMCLAPIDownloadProvider.kt | 2 +- .../hmcl/download/DefaultDependencyManager.kt | 30 +++++++------ .../hmcl/download/DownloadProvider.kt | 16 +++---- .../hmcl/download/MojangDownloadProvider.kt | 4 +- .../hmcl/download/forge/ForgeRemote.kt | 8 ++-- .../hmcl/download/forge/ForgeVersionList.kt | 2 +- .../hmcl/download/game/GameDownloadTasks.kt | 4 +- .../hmcl/download/game/GameRemote.kt | 2 +- .../liteloader/LiteLoaderInstallTask.kt | 2 +- .../download/liteloader/LiteLoaderRemote.kt | 12 ++--- .../optifine/OptiFineDownloadFormatter.kt | 2 +- .../hmcl/download/optifine/OptiFineRemote.kt | 2 +- .../download/optifine/OptiFineVersionList.kt | 6 +-- .../org/jackhuang/hmcl/event/EventBus.kt | 2 +- .../org/jackhuang/hmcl/event/EventManager.kt | 2 +- .../kotlin/org/jackhuang/hmcl/event/Events.kt | 45 +++++++++---------- .../org/jackhuang/hmcl/event/ResultEvent.kt | 3 +- .../org/jackhuang/hmcl/game/AssetIndex.kt | 2 +- .../org/jackhuang/hmcl/game/AssetIndexInfo.kt | 2 +- .../org/jackhuang/hmcl/game/AssetObject.kt | 2 +- .../hmcl/game/CircleDependencyException.kt | 2 +- .../jackhuang/hmcl/game/CompatibilityRule.kt | 6 +-- .../hmcl/game/DefaultGameRepository.kt | 15 ++++--- .../org/jackhuang/hmcl/game/DownloadInfo.kt | 4 +- .../org/jackhuang/hmcl/game/ExtractRules.kt | 4 +- .../org/jackhuang/hmcl/game/GameException.kt | 2 +- .../org/jackhuang/hmcl/game/GameVersion.kt | 2 +- .../hmcl/game/LibrariesDownloadInfo.kt | 2 +- .../kotlin/org/jackhuang/hmcl/game/Library.kt | 5 +-- .../hmcl/game/LibraryDownloadInfo.kt | 2 +- .../org/jackhuang/hmcl/game/LoggingInfo.kt | 4 +- .../org/jackhuang/hmcl/game/StringArgument.kt | 2 +- .../kotlin/org/jackhuang/hmcl/game/Version.kt | 7 +-- .../hmcl/game/VersionNotFoundException.kt | 2 +- .../jackhuang/hmcl/launch/DefaultLauncher.kt | 4 +- .../org/jackhuang/hmcl/launch/ExitWaiter.kt | 10 ++--- .../org/jackhuang/hmcl/launch/Launcher.kt | 2 +- .../org/jackhuang/hmcl/launch/Log4jHandler.kt | 4 +- .../jackhuang/hmcl/mod/CurseForgeModpack.kt | 12 ++--- .../kotlin/org/jackhuang/hmcl/mod/ModInfo.kt | 2 +- .../org/jackhuang/hmcl/task/CoupleTask.kt | 2 +- .../jackhuang/hmcl/task/FileDownloadTask.kt | 4 +- .../kotlin/org/jackhuang/hmcl/task/GetTask.kt | 2 +- .../org/jackhuang/hmcl/task/Scheduler.kt | 14 ++++-- .../org/jackhuang/hmcl/task/TaskExecutor.kt | 3 +- .../org/jackhuang/hmcl/util/AutoTypingMap.kt | 2 +- .../org/jackhuang/hmcl/util/Compressors.kt | 2 - .../kotlin/org/jackhuang/hmcl/util/Gson.kt | 18 ++++---- .../kotlin/org/jackhuang/hmcl/util/IOUtils.kt | 4 +- .../org/jackhuang/hmcl/util/NetUtils.kt | 12 ++--- .../org/jackhuang/hmcl/util/SimpleMultimap.kt | 6 +-- 59 files changed, 184 insertions(+), 176 deletions(-) diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/AuthInfo.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/AuthInfo.kt index e859ecde7..f2d9b564f 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/AuthInfo.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/AuthInfo.kt @@ -17,14 +17,24 @@ */ package org.jackhuang.hmcl.auth +import org.jackhuang.hmcl.auth.yggdrasil.GameProfile import org.jackhuang.hmcl.util.Immutable +import org.jackhuang.hmcl.util.UUIDTypeAdapter @Immutable -data class AuthInfo( +data class AuthInfo @JvmOverloads constructor( val username: String, val userId: String, val authToken: String, val userType: UserType = UserType.LEGACY, val userProperties: String = "{}", val userPropertyMap: String = "{}" -) \ No newline at end of file +) { + constructor(profile: GameProfile, + authToken: String, + userType: UserType = UserType.LEGACY, + userProperties: String = "{}", + userPropertyMap: String = "{}") + : this(profile.name!!, UUIDTypeAdapter.fromUUID(profile.id!!), authToken, userType, userProperties, userPropertyMap) { + } +} \ No newline at end of file diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/AuthenticationRequest.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/AuthenticationRequest.kt index 45a2d91bc..4aa57bcc4 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/AuthenticationRequest.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/AuthenticationRequest.kt @@ -17,7 +17,7 @@ */ package org.jackhuang.hmcl.auth.yggdrasil -data class AuthenticationRequest( +data class AuthenticationRequest @JvmOverloads constructor( val username: String, val password: String, val clientToken: String, diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/GameProfile.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/GameProfile.kt index c753e37ce..69fa1a501 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/GameProfile.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/GameProfile.kt @@ -21,7 +21,7 @@ import com.google.gson.* import java.lang.reflect.Type import java.util.* -data class GameProfile( +data class GameProfile @JvmOverloads constructor( val id: UUID? = null, val name: String? = null, val properties: PropertyMap = PropertyMap(), @@ -40,7 +40,7 @@ data class GameProfile( override fun deserialize(json: JsonElement?, typeOfT: Type?, context: JsonDeserializationContext): GameProfile { if (json !is JsonObject) throw JsonParseException("The json element is not a JsonObject.") - val id = if (json.has("id")) context.deserialize(json.get("id"), UUID::class.java) else null + val id = if (json.has("id")) context.deserialize(json.get("id"), UUID::class.java) else null val name = if (json.has("name")) json.getAsJsonPrimitive("name").asString else null return GameProfile(id, name) } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/RefreshRequest.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/RefreshRequest.kt index 0c6e3b452..024227450 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/RefreshRequest.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/RefreshRequest.kt @@ -17,7 +17,7 @@ */ package org.jackhuang.hmcl.auth.yggdrasil -data class RefreshRequest( +data class RefreshRequest @JvmOverloads constructor( val clientToken: String, val accessToken: String, val selectedProfile: GameProfile? = null, diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/Response.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/Response.kt index b845ae6d0..5127a8a46 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/Response.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/Response.kt @@ -17,7 +17,7 @@ */ package org.jackhuang.hmcl.auth.yggdrasil -class Response ( +class Response @JvmOverloads constructor( val accessToken: String? = null, val clientToken: String? = null, val selectedProfile: GameProfile? = null, diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/User.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/User.kt index 9e0aeed03..b2b8225fb 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/User.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/User.kt @@ -20,7 +20,7 @@ package org.jackhuang.hmcl.auth.yggdrasil import com.google.gson.JsonParseException import org.jackhuang.hmcl.util.Validation -class User ( +class User @JvmOverloads constructor( val id: String = "", val properties: PropertyMap? = null ) : Validation { diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilAccount.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilAccount.kt index 63311ccd1..74d9be683 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilAccount.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/auth/yggdrasil/YggdrasilAccount.kt @@ -57,8 +57,7 @@ class YggdrasilAccount private constructor(override val username: String): Accou override fun logIn(proxy: Proxy): AuthInfo { if (canPlayOnline) return AuthInfo( - username = selectedProfile!!.name!!, - userId = UUIDTypeAdapter.fromUUID(selectedProfile!!.id!!), + profile = selectedProfile!!, authToken = accessToken!!, userType = userType, userProperties = GSON.toJson(userProperties) @@ -72,8 +71,7 @@ class YggdrasilAccount private constructor(override val username: String): Accou throw UnsupportedOperationException("Do not support multi-available-profiles account yet.") } else { return AuthInfo( - username = selectedProfile!!.name!!, - userId = UUIDTypeAdapter.fromUUID(selectedProfile!!.id!!), + profile = selectedProfile!!, authToken = accessToken!!, userType = userType, userProperties = GSON.toJson(userProperties) @@ -149,7 +147,7 @@ class YggdrasilAccount private constructor(override val username: String): Accou if (!profile.properties.isEmpty()) result[STORAGE_KEY_PROFILE_PROPERTIES] = profile.properties.toList() } - if (accessToken != null && accessToken!!.isNotBlank()) + if (!accessToken.isNullOrBlank()) result[STORAGE_KEY_ACCESS_TOKEN] = accessToken!! return result @@ -163,7 +161,7 @@ class YggdrasilAccount private constructor(override val username: String): Accou val response = GSON.fromJson(jsonResult) ?: return null - if (response.error?.isNotBlank() ?: false) { + if (!response.error.isNullOrBlank()) { LOG.severe("Failed to log in, the auth server returned an error: " + response.error + ", message: " + response.errorMessage + ", cause: " + response.cause) if (response.errorMessage != null) if (response.errorMessage.contains("Invalid credentials")) @@ -216,10 +214,8 @@ class YggdrasilAccount private constructor(override val username: String): Accou fun randomToken() = UUIDTypeAdapter.fromUUID(UUID.randomUUID()) - override fun fromUsername(username: String, password: String): YggdrasilAccount { - val account = YggdrasilAccount(username) - account.password = password - return account + override fun fromUsername(username: String, password: String) = YggdrasilAccount(username).apply { + this.password = password } override fun fromStorage(storage: Map): YggdrasilAccount { diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/AbstractDependencyManager.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/AbstractDependencyManager.kt index 132fa4ade..0f198a042 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/AbstractDependencyManager.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/AbstractDependencyManager.kt @@ -17,16 +17,10 @@ */ package org.jackhuang.hmcl.download -import org.jackhuang.hmcl.game.GameRepository -import java.net.Proxy - abstract class AbstractDependencyManager : DependencyManager { abstract val downloadProvider: DownloadProvider - fun getVersions(id: String, selfVersion: String) = - downloadProvider.getVersionListById(id).getVersions(selfVersion) - override fun getVersionList(id: String): VersionList<*> { return downloadProvider.getVersionListById(id) } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/BMCLAPIDownloadProvider.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/BMCLAPIDownloadProvider.kt index f6d385cd4..9f5eadbd4 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/BMCLAPIDownloadProvider.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/BMCLAPIDownloadProvider.kt @@ -25,7 +25,7 @@ import org.jackhuang.hmcl.download.optifine.OptiFineBMCLVersionList /** * @see {@link http://bmclapi2.bangbang93.com} */ -object BMCLAPIDownloadProvider : DownloadProvider() { +object BMCLAPIDownloadProvider : DownloadProvider { override val libraryBaseURL: String = "http://bmclapi2.bangbang93.com/libraries/" override val versionListURL: String = "http://bmclapi2.bangbang93.com/mc/game/version_manifest.json" override val versionBaseURL: String = "http://bmclapi2.bangbang93.com/versions/" diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultDependencyManager.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultDependencyManager.kt index 668e9a9bc..c241de889 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultDependencyManager.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DefaultDependencyManager.kt @@ -34,7 +34,7 @@ import java.net.Proxy /** * This class has no state. */ -class DefaultDependencyManager(override val repository: DefaultGameRepository, override var downloadProvider: DownloadProvider, override val proxy: Proxy = Proxy.NO_PROXY) +class DefaultDependencyManager @JvmOverloads constructor(override val repository: DefaultGameRepository, override var downloadProvider: DownloadProvider, override val proxy: Proxy = Proxy.NO_PROXY) : AbstractDependencyManager() { override fun gameBuilder(): GameBuilder = DefaultGameBuilder(this) @@ -48,17 +48,19 @@ class DefaultDependencyManager(override val repository: DefaultGameRepository, o return ParallelTask(*tasks) } - override fun installLibraryAsync(gameVersion: String, version: Version, libraryId: String, libraryVersion: String): Task { - if (libraryId == "forge") - return ForgeInstallTask(this, gameVersion, version, libraryVersion) - .then { VersionJSONSaveTask(repository, it["version"]) } - else if (libraryId == "liteloader") - return LiteLoaderInstallTask(this, gameVersion, version, libraryVersion) - .then { VersionJSONSaveTask(repository, it["version"]) } - else if (libraryId == "optifine") - return OptiFineInstallTask(this, gameVersion, version, libraryVersion) - .then { VersionJSONSaveTask(repository, it["version"]) } - else - throw IllegalArgumentException("Library id $libraryId is unrecognized.") - } + override fun installLibraryAsync(gameVersion: String, version: Version, libraryId: String, libraryVersion: String): Task = + when (libraryId) { + "forge" -> + ForgeInstallTask(this, gameVersion, version, libraryVersion) + .then { VersionJSONSaveTask(repository, it["version"]) } + "liteloader" -> + LiteLoaderInstallTask(this, gameVersion, version, libraryVersion) + .then { VersionJSONSaveTask(repository, it["version"]) } + "optifine" -> + OptiFineInstallTask(this, gameVersion, version, libraryVersion) + .then { VersionJSONSaveTask(repository, it["version"]) } + else -> + throw IllegalArgumentException("Library id $libraryId is unrecognized.") + } + } \ No newline at end of file diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DownloadProvider.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DownloadProvider.kt index 934ad5011..00d81b8a5 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DownloadProvider.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/DownloadProvider.kt @@ -20,12 +20,12 @@ package org.jackhuang.hmcl.download /** * The service provider that provides Minecraft online file downloads. */ -abstract class DownloadProvider { - abstract val libraryBaseURL: String - abstract val versionListURL: String - abstract val versionBaseURL: String - abstract val assetIndexBaseURL: String - abstract val assetBaseURL: String +interface DownloadProvider { + val libraryBaseURL: String + val versionListURL: String + val versionBaseURL: String + val assetIndexBaseURL: String + val assetBaseURL: String /** * Inject into original URL provided by Mojang and Forge. @@ -36,12 +36,12 @@ abstract class DownloadProvider { * @param baseURL original URL provided by Mojang and Forge. * @return the URL that is equivalent to [baseURL], but belongs to your own service provider. */ - abstract fun injectURL(baseURL: String): String + fun injectURL(baseURL: String): String /** * the specific version list that this download provider provides. i.e. "forge", "liteloader", "game", "optifine" * @param id the id of specific version list that this download provider provides. i.e. "forge", "liteloader", "game", "optifine" * @return the version list */ - abstract fun getVersionListById(id: String): VersionList<*> + fun getVersionListById(id: String): VersionList<*> } \ No newline at end of file diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/MojangDownloadProvider.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/MojangDownloadProvider.kt index 9bd6d15ba..49851b8ee 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/MojangDownloadProvider.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/MojangDownloadProvider.kt @@ -26,10 +26,10 @@ import java.util.* /** * @see {@link http://wiki.vg} */ -object MojangDownloadProvider : DownloadProvider() { +object MojangDownloadProvider : DownloadProvider { override val libraryBaseURL: String = "https://libraries.minecraft.net/" - override val versionBaseURL: String = "http://s3.amazonaws.com/Minecraft.Download/versions/" override val versionListURL: String = "https://launchermeta.mojang.com/mc/game/version_manifest.json" + override val versionBaseURL: String = "http://s3.amazonaws.com/Minecraft.Download/versions/" override val assetIndexBaseURL: String = "http://s3.amazonaws.com/Minecraft.Download/indexes/" override val assetBaseURL: String = "http://resources.download.minecraft.net/" diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/forge/ForgeRemote.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/forge/ForgeRemote.kt index 6bb2c186d..e8cd691db 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/forge/ForgeRemote.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/forge/ForgeRemote.kt @@ -23,7 +23,7 @@ import org.jackhuang.hmcl.util.Immutable import org.jackhuang.hmcl.util.Validation @Immutable -internal class ForgeVersion ( +internal class ForgeVersion @JvmOverloads constructor( val branch: String? = null, val mcversion: String? = null, val jobver: String? = null, @@ -40,7 +40,7 @@ internal class ForgeVersion ( } @Immutable -internal class ForgeVersionRoot ( +internal class ForgeVersionRoot @JvmOverloads constructor( val artifact: String? = null, val webpath: String? = null, val adfly: String? = null, @@ -58,7 +58,7 @@ internal class ForgeVersionRoot ( } @Immutable -internal data class Install ( +internal data class Install @JvmOverloads constructor( val profileName: String? = null, val target: String? = null, val path: String? = null, @@ -71,7 +71,7 @@ internal data class Install ( ) @Immutable -internal data class InstallProfile ( +internal data class InstallProfile @JvmOverloads constructor( @SerializedName("install") val install: Install? = null, @SerializedName("versionInfo") diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/forge/ForgeVersionList.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/forge/ForgeVersionList.kt index 801f90c3a..003e75221 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/forge/ForgeVersionList.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/forge/ForgeVersionList.kt @@ -42,7 +42,7 @@ object ForgeVersionList : VersionList() { for ((x, versions) in root.mcversion!!.entries) { val gameVersion = x.asVersion() ?: continue for (v in versions) { - val version = root.number!!.get(v) ?: continue + val version = root.number!![v] ?: continue var jar: String? = null for (file in version.files!!) if (file.getOrNull(1) == "installer") { diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameDownloadTasks.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameDownloadTasks.kt index fbf4d76db..112e4bdeb 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameDownloadTasks.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameDownloadTasks.kt @@ -102,7 +102,7 @@ class GameAssetRefreshTask(private val dependencyManager: DefaultDependencyManag val index = GSON.fromJson(assetIndexFile.readText()) val res = LinkedList>() var progress = 0 - index?.objects?.entries?.forEach { (_, assetObject) -> + index?.objects?.values?.forEach { assetObject -> res += Pair(dependencyManager.repository.getAssetObject(version.id, assetIndexInfo.id, assetObject), assetObject) updateProgress(++progress, index.objects.size) } @@ -119,7 +119,7 @@ class GameAssetRefreshTask(private val dependencyManager: DefaultDependencyManag * @param dependencyManager the dependency manager that can provides proxy settings and [GameRepository] * @param version the **resolved** version */ -class GameAssetDownloadTask(private val dependencyManager: DefaultDependencyManager, private val version: Version) : Task() { +class GameAssetDownloadTask(private val dependencyManager: DefaultDependencyManager, version: Version) : Task() { private val refreshTask = GameAssetRefreshTask(dependencyManager, version) override val dependents = listOf(refreshTask) override val dependencies = LinkedList() diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameRemote.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameRemote.kt index e37d4e1c9..4d7b6f747 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameRemote.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/game/GameRemote.kt @@ -33,7 +33,7 @@ internal class GameRemoteLatestVersions( ) @Immutable -internal class GameRemoteVersion( +internal class GameRemoteVersion @JvmOverloads constructor( @SerializedName("id") val gameVersion: String = "", @SerializedName("time") diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/liteloader/LiteLoaderInstallTask.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/liteloader/LiteLoaderInstallTask.kt index 6e5ebd6ee..e55962f26 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/liteloader/LiteLoaderInstallTask.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/liteloader/LiteLoaderInstallTask.kt @@ -44,7 +44,7 @@ class LiteLoaderInstallTask(private val dependencyManager: DefaultDependencyMana init { if (!liteLoaderVersionList.loaded) - dependents += LiteLoaderVersionList.refreshAsync(dependencyManager.downloadProvider).then { + dependents += liteLoaderVersionList.refreshAsync(dependencyManager.downloadProvider).then { remote = liteLoaderVersionList.getVersion(gameVersion, remoteVersion) ?: throw IllegalArgumentException("Remote LiteLoader version $gameVersion, $remoteVersion not found") null } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemote.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemote.kt index 9bdfb5aab..48965f045 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemote.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/liteloader/LiteLoaderRemote.kt @@ -22,7 +22,7 @@ import org.jackhuang.hmcl.game.Library import org.jackhuang.hmcl.util.Immutable @Immutable -internal data class LiteLoaderVersionsMeta ( +internal data class LiteLoaderVersionsMeta @JvmOverloads constructor( @SerializedName("description") val description: String = "", @SerializedName("authors") @@ -32,7 +32,7 @@ internal data class LiteLoaderVersionsMeta ( ) @Immutable -internal data class LiteLoaderRepository ( +internal data class LiteLoaderRepository @JvmOverloads constructor( @SerializedName("stream") val stream: String = "", @SerializedName("type") @@ -44,7 +44,7 @@ internal data class LiteLoaderRepository ( ) @Immutable -internal class LiteLoaderVersion ( +internal class LiteLoaderVersion @JvmOverloads constructor( @SerializedName("tweakClass") val tweakClass: String = "", @SerializedName("file") @@ -62,7 +62,7 @@ internal class LiteLoaderVersion ( ) @Immutable -internal class LiteLoaderBranch ( +internal class LiteLoaderBranch @JvmOverloads constructor( @SerializedName("libraries") val libraries: Collection = emptyList(), @SerializedName("com.mumfrey:liteloader") @@ -70,7 +70,7 @@ internal class LiteLoaderBranch ( ) @Immutable -internal class LiteLoaderGameVersions ( +internal class LiteLoaderGameVersions @JvmOverloads constructor( @SerializedName("repo") val repo: LiteLoaderRepository? = null, @SerializedName("artefacts") @@ -80,7 +80,7 @@ internal class LiteLoaderGameVersions ( ) @Immutable -internal class LiteLoaderVersionsRoot ( +internal class LiteLoaderVersionsRoot @JvmOverloads constructor( @SerializedName("versions") val versions: Map = emptyMap(), @SerializedName("meta") diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineDownloadFormatter.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineDownloadFormatter.kt index 2a58a620a..94014b0b9 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineDownloadFormatter.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineDownloadFormatter.kt @@ -18,4 +18,4 @@ package org.jackhuang.hmcl.download.optifine -object Opt \ No newline at end of file +object OptiFineDownloadFormatter \ No newline at end of file diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineRemote.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineRemote.kt index 1a57792c1..2f185def9 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineRemote.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineRemote.kt @@ -19,7 +19,7 @@ package org.jackhuang.hmcl.download.optifine import com.google.gson.annotations.SerializedName -data class OptiFineVersion ( +data class OptiFineVersion @JvmOverloads constructor( @SerializedName("dl") val downloadLink: String? = null, @SerializedName("ver") diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineVersionList.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineVersionList.kt index de156de12..c6b68e2a7 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineVersionList.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/download/optifine/OptiFineVersionList.kt @@ -48,15 +48,15 @@ object OptiFineVersionList : VersionList() { val doc = db.parse(ByteArrayInputStream(html.toByteArray())) val r = doc.documentElement val tables = r.getElementsByTagName("table") - for (i in 0..tables.length - 1) { + for (i in 0 until tables.length) { val e = tables.item(i) as Element if ("downloadTable" == e.getAttribute("class")) { val tr = e.getElementsByTagName("tr") - for (k in 0..tr.length - 1) { + for (k in 0 until tr.length) { val downloadLine = (tr.item(k) as Element).getElementsByTagName("td") var url: String? = null var version: String? = null - for (j in 0..downloadLine.length - 1) { + for (j in 0 until downloadLine.length) { val td = downloadLine.item(j) as Element if (td.getAttribute("class")?.startsWith("downloadLineMirror") ?: false) url = (td.getElementsByTagName("a").item(0) as Element).getAttribute("href") diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/EventBus.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/EventBus.kt index dd18c8210..2ed9ce387 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/EventBus.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/EventBus.kt @@ -21,7 +21,7 @@ import org.jackhuang.hmcl.task.Scheduler import java.util.* class EventBus { - val events = HashMap, EventManager<*>>() + private val events = HashMap, EventManager<*>>() @Suppress("UNCHECKED_CAST") fun channel(classOfT: Class): EventManager { diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/EventManager.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/EventManager.kt index 21b1a830d..46b637fdc 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/EventManager.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/EventManager.kt @@ -21,7 +21,7 @@ import org.jackhuang.hmcl.task.Scheduler import org.jackhuang.hmcl.util.SimpleMultimap import java.util.* -class EventManager(val scheduler: Scheduler = Scheduler.IMMEDIATE) { +class EventManager @JvmOverloads constructor(val scheduler: Scheduler = Scheduler.IMMEDIATE) { private val handlers = SimpleMultimap Unit>({ EnumMap(EventPriority::class.java) }, ::HashSet) private val handlers2 = SimpleMultimap Unit>({ EnumMap(EventPriority::class.java) }, ::HashSet) diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/Events.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/Events.kt index c775c7fbe..7290a04d9 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/Events.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/Events.kt @@ -22,20 +22,17 @@ import java.util.* /** * This event gets fired when loading versions in a .minecraft folder. - *

- * This event is fired on the [org.jackhuang.hmcl.api.HMCLApi.EVENT_BUS] - * @param source [org.jackhuang.hmcl.core.version.MinecraftVersionManager] - * * - * @param IMinecraftService .minecraft folder. - * * - * @author huangyuhui + *
+ * This event is fired on the [org.jackhuang.hmcl.event.EVENT_BUS] + * + * @param source [org.jackhuang.hmcl.game.GameRepository] */ class RefreshingVersionsEvent(source: Any) : EventObject(source) /** * This event gets fired when all the versions in .minecraft folder are loaded. *
- * This event is fired on the {@link org.jackhuang.hmcl.api.HMCLApi#EVENT_BUS} + * This event is fired on the [org.jackhuang.hmcl.event.EVENT_BUS] * @param source [org.jackhuang.hmcl.game.GameRepository] * @author huangyuhui */ @@ -43,9 +40,9 @@ class RefreshedVersionsEvent(source: Any) : EventObject(source) /** * This event gets fired when a minecraft version has been loaded. - *

- * This event is fired on the [org.jackhuang.hmcl.api.HMCLApi.EVENT_BUS] - * @param source [org.jackhuang.hmcl.core.version.MinecraftVersionManager] + *
+ * This event is fired on the [org.jackhuang.hmcl.event.EVENT_BUS] + * @param source [org.jackhuang.hmcl.game.GameRepository] * @param version the version id. * @author huangyuhui */ @@ -54,29 +51,29 @@ class LoadedOneVersionEvent(source: Any, val version: String) : EventObject(sour /** * This event gets fired when a JavaProcess exited abnormally and the exit code is not zero. *

- * This event is fired on the [org.jackhuang.hmcl.api.HMCLApi.EVENT_BUS] - * @param source [org.jackhuang.hmcl.util.sys.JavaProcessMonitor] - * @param JavaProcess The process that exited abnormally. + * This event is fired on the [org.jackhuang.hmcl.event.EVENT_BUS] + * @param source [org.jackhuang.hmcl.launch.ExitWaiter] + * @param value The process that exited abnormally. * @author huangyuhui */ -class JavaProcessExitedAbnormallyEvent(source: Any, val value: ManagedProcess) : EventObject(source) +class ProcessExitedAbnormallyEvent(source: Any, val value: ManagedProcess) : EventObject(source) /** * This event gets fired when minecraft process exited successfully and the exit code is 0. - *

- * This event is fired on the [org.jackhuang.hmcl.api.HMCLApi.EVENT_BUS] - * @param source [org.jackhuang.hmcl.util.sys.JavaProcessMonitor] - * @param JavaProcess minecraft process + *
+ * This event is fired on the [org.jackhuang.hmcl.event.EVENT_BUS] + * @param source [org.jackhuang.hmcl.launch.ExitWaiter] + * @param value minecraft process * @author huangyuhui */ -class JavaProcessStoppedEvent(source: Any, val value: ManagedProcess) : EventObject(source) +class ProcessStoppedEvent(source: Any, val value: ManagedProcess) : EventObject(source) /** * This event gets fired when we launch the JVM and it got crashed. - *

- * This event is fired on the [org.jackhuang.hmcl.api.HMCLApi.EVENT_BUS] - * @param source [org.jackhuang.hmcl.util.sys.JavaProcessMonitor] - * @param JavaProcess the crashed process. + *
+ * This event is fired on the [org.jackhuang.hmcl.event.EVENT_BUS] + * @param source [org.jackhuang.hmcl.launch.ExitWaiter] + * @param value the crashed process. * @author huangyuhui */ class JVMLaunchFailedEvent(source: Any, val value: ManagedProcess) : EventObject(source) diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/ResultEvent.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/ResultEvent.kt index 87a8e58c8..7ecbf4a88 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/ResultEvent.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/event/ResultEvent.kt @@ -17,5 +17,4 @@ */ package org.jackhuang.hmcl.event -open class FailedEvent(source: Any, val failedTime: Int, var newResult: T) : Event(source) { -} \ No newline at end of file +open class FailedEvent(source: Any, val failedTime: Int, var newResult: T) : Event(source) \ No newline at end of file diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetIndex.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetIndex.kt index 6cc40de8c..ff54da1c7 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetIndex.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetIndex.kt @@ -20,7 +20,7 @@ package org.jackhuang.hmcl.game import com.google.gson.annotations.SerializedName import java.util.* -class AssetIndex( +class AssetIndex @JvmOverloads constructor( @SerializedName("virtual") val virtual: Boolean = false, objects: Map = emptyMap() diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetIndexInfo.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetIndexInfo.kt index c52cb2932..9e69f7e1a 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetIndexInfo.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetIndexInfo.kt @@ -20,7 +20,7 @@ package org.jackhuang.hmcl.game import org.jackhuang.hmcl.util.Immutable @Immutable -class AssetIndexInfo( +class AssetIndexInfo @JvmOverloads constructor( url: String = "", sha1: String? = null, size: Int = 0, diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetObject.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetObject.kt index cf550bc08..8125ce4dd 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetObject.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/AssetObject.kt @@ -19,7 +19,7 @@ package org.jackhuang.hmcl.game import org.jackhuang.hmcl.util.Validation -data class AssetObject( +data class AssetObject @JvmOverloads constructor( val hash: String = "", val size: Long = 0 ): Validation { diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/CircleDependencyException.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/CircleDependencyException.kt index 5ae2b45aa..cc1a863c3 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/CircleDependencyException.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/CircleDependencyException.kt @@ -21,7 +21,7 @@ package org.jackhuang.hmcl.game * What's circle dependency? * When C inherits from B, and B inherits from something else, and finally inherits from C again. */ -class CircleDependencyException : Exception { +class CircleDependencyException : GameException { constructor() : super() {} constructor(message: String) : super(message) {} constructor(message: String, cause: Throwable) : super(message, cause) {} diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/CompatibilityRule.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/CompatibilityRule.kt index 0362f2cde..c6e274ebd 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/CompatibilityRule.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/CompatibilityRule.kt @@ -24,7 +24,7 @@ import org.jackhuang.hmcl.util.ignoreThrowable import java.util.regex.Pattern @Immutable -data class CompatibilityRule( +data class CompatibilityRule @JvmOverloads constructor( val action: Action = CompatibilityRule.Action.ALLOW, val os: OSRestriction? = null, val features: Map? = null @@ -33,8 +33,8 @@ data class CompatibilityRule( fun getAppliedAction(supportedFeatures: Map): Action? { if (os != null && !os.allow()) return null if (features != null) { - features.entries.forEach { - if (supportedFeatures[it.key] != it.value) + features.entries.forEach { (key, value) -> + if (supportedFeatures[key] != value) return null } } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/DefaultGameRepository.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/DefaultGameRepository.kt index 740ee1afa..7f8b35a44 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/DefaultGameRepository.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/DefaultGameRepository.kt @@ -57,12 +57,16 @@ open class DefaultGameRepository(var baseDirectory: File): GameRepository { * {@inheritsDoc} * @return something like ".minecraft/versions//-natives" */ - override fun getNativeDirectory(id: String) = File(getVersionRoot(id), "$id-natives") - override fun getVersionRoot(id: String) = File(baseDirectory, "versions/$id") - open fun getVersionJson(id: String) = File(getVersionRoot(id), "$id.json") + override fun getNativeDirectory(id: String) = getVersionRoot(id).resolve("$id-natives") + override fun getVersionRoot(id: String) = baseDirectory.resolve("versions/$id") + open fun getVersionJson(id: String) = getVersionRoot(id).resolve("$id.json") + + @Throws(IOException::class, JsonSyntaxException::class) open fun readVersionJson(id: String): Version? = readVersionJson(getVersionJson(id)) - @Throws(IOException::class, JsonSyntaxException::class, VersionNotFoundException::class) + + @Throws(IOException::class, JsonSyntaxException::class) open fun readVersionJson(file: File): Version? = GSON.fromJson(file.readText()) + override fun renameVersion(from: String, to: String): Boolean { try { val fromVersion = getVersion(from) @@ -87,6 +91,7 @@ open class DefaultGameRepository(var baseDirectory: File): GameRepository { return false } } + open fun removeVersionFromDisk(name: String): Boolean { val file = getVersionRoot(name) if (!file.exists()) @@ -153,7 +158,7 @@ open class DefaultGameRepository(var baseDirectory: File): GameRepository { override fun getActualAssetDirectory(version: String, assetId: String): File { try { return reconstructAssets(version, assetId) - } catch (e: IOException) { + } catch (e: Exception) { LOG.log(Level.SEVERE, "Unable to reconstruct asset directory", e) return getAssetDirectory(version, assetId) } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/DownloadInfo.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/DownloadInfo.kt index 1542fb253..e655ef92a 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/DownloadInfo.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/DownloadInfo.kt @@ -23,7 +23,7 @@ import org.jackhuang.hmcl.util.Immutable import org.jackhuang.hmcl.util.Validation @Immutable -open class DownloadInfo( +open class DownloadInfo @JvmOverloads constructor( @SerializedName("url") val url: String = "", @SerializedName("sha1") @@ -38,7 +38,7 @@ open class DownloadInfo( } @Immutable -open class IdDownloadInfo( +open class IdDownloadInfo @JvmOverloads constructor( url: String = "", sha1: String? = null, size: Int = 0, diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/ExtractRules.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/ExtractRules.kt index bbeaaadfc..04bb2542a 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/ExtractRules.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/ExtractRules.kt @@ -20,13 +20,13 @@ package org.jackhuang.hmcl.game import com.google.gson.annotations.SerializedName import java.util.* -class ExtractRules(exclude: List = emptyList()) { +class ExtractRules @JvmOverloads constructor(exclude: List = emptyList()) { val exclude: List get() = Collections.unmodifiableList(excludeImpl) @SerializedName("exclude") private val excludeImpl: MutableList = LinkedList(exclude) fun shouldExtract(path: String): Boolean = - exclude.filter { path.startsWith(it) }.isEmpty() + exclude.none { path.startsWith(it) } } \ No newline at end of file diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameException.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameException.kt index fd4b104e7..f629c1ce9 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameException.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameException.kt @@ -17,7 +17,7 @@ */ package org.jackhuang.hmcl.game -class GameException : Exception { +open class GameException : Exception { constructor() : super() {} constructor(message: String) : super(message) {} constructor(message: String, cause: Throwable) : super(message, cause) {} diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameVersion.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameVersion.kt index 4c8b715b3..b2d87b4d4 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameVersion.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/GameVersion.kt @@ -32,7 +32,7 @@ private fun lessThan32(b: ByteArray, startIndex: Int): Int { } fun matchArray(a: ByteArray, b: ByteArray): Int { - for (i in 0..a.size - b.size - 1) { + for (i in 0 until a.size - b.size) { var j = 1 for (k in b.indices) { if (b[k] == a[i + k]) diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LibrariesDownloadInfo.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LibrariesDownloadInfo.kt index 0ee688ec0..b30c39ac2 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LibrariesDownloadInfo.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LibrariesDownloadInfo.kt @@ -23,7 +23,7 @@ import java.util.* import kotlin.collections.HashMap @Immutable -class LibrariesDownloadInfo( +class LibrariesDownloadInfo @JvmOverloads constructor( @SerializedName("artifact") val artifact: LibraryDownloadInfo? = null, classifier_: Map? = null diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Library.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Library.kt index 15a5188a5..48ca65888 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Library.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Library.kt @@ -24,11 +24,9 @@ import java.lang.reflect.Type /** * A class that describes a Minecraft dependency. - * - * @see LibraryDeserializer */ @Immutable -open class Library( +open class Library @JvmOverloads constructor( val groupId: String, val artifactId: String, val version: String, @@ -100,6 +98,7 @@ open class Library( context.deserialize(jsonObject["natives"], typeOf>()), context.deserialize(jsonObject["rules"], typeOf>())) } + override fun serialize(src: Library?, typeOfSrc: Type?, context: JsonSerializationContext): JsonElement { if (src == null) return JsonNull.INSTANCE val obj = JsonObject() diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LibraryDownloadInfo.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LibraryDownloadInfo.kt index c8cf98c6c..f47393e9c 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LibraryDownloadInfo.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LibraryDownloadInfo.kt @@ -21,7 +21,7 @@ import com.google.gson.annotations.SerializedName import org.jackhuang.hmcl.util.Immutable @Immutable -class LibraryDownloadInfo( +class LibraryDownloadInfo @JvmOverloads constructor( url: String = "", sha1: String? = null, size: Int = 0, diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LoggingInfo.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LoggingInfo.kt index f37e26bf0..b3967f865 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LoggingInfo.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/LoggingInfo.kt @@ -22,9 +22,9 @@ import org.jackhuang.hmcl.util.Immutable import org.jackhuang.hmcl.util.Validation @Immutable -class LoggingInfo( +class LoggingInfo @JvmOverloads constructor( @SerializedName("file") - val file: IdDownloadInfo = IdDownloadInfo(""), + val file: IdDownloadInfo = IdDownloadInfo(), @SerializedName("argument") val argument: String = "", diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/StringArgument.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/StringArgument.kt index c2a7c0a3d..73fdace4f 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/StringArgument.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/StringArgument.kt @@ -20,7 +20,7 @@ package org.jackhuang.hmcl.game import java.util.* import java.util.regex.Pattern -class StringArgument(var argument: String) : Argument { +class StringArgument(val argument: String) : Argument { override fun toString(keys: Map, features: Map): List { var res = argument 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 f8134989b..e60edb8c8 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Version.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/Version.kt @@ -23,7 +23,7 @@ import org.jackhuang.hmcl.util.* import java.util.* @Immutable -open class Version( +open class Version @JvmOverloads constructor( @SerializedName("minecraftArguments") val minecraftArguments: String? = null, @SerializedName("arguments") @@ -88,7 +88,7 @@ open class Version( val actualAssetIndex: AssetIndexInfo get() { val id = assets ?: "legacy" - return assetIndex ?: AssetIndexInfo(id = id, url = "$DEFAULT_VERSION_DOWNLOAD_URL$id.json") + return assetIndex ?: AssetIndexInfo(id = id, url = "$DEFAULT_INDEX_URL$id.json") } fun appliesToCurrentEnvironment() = CompatibilityRule.appliesToCurrentEnvironment(compatibilityRules) @@ -134,8 +134,9 @@ open class Version( arguments = Arguments.mergeArguments(parent.arguments, this.arguments), releaseTime = this.releaseTime, inheritsFrom = null, + compatibilityRules = merge(this.compatibilityRules, parent.compatibilityRules), minecraftArguments = this.minecraftArguments ?: parent.minecraftArguments, - minimumLauncherVersion = parent.minimumLauncherVersion + minimumLauncherVersion = maxOf(minimumLauncherVersion, parent.minimumLauncherVersion) ) } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/VersionNotFoundException.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/VersionNotFoundException.kt index 7330e8c9c..3d57899fb 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/VersionNotFoundException.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/game/VersionNotFoundException.kt @@ -17,7 +17,7 @@ */ package org.jackhuang.hmcl.game -class VersionNotFoundException : Exception { +class VersionNotFoundException : GameException { constructor() : super() {} constructor(message: String) : super(message) {} constructor(message: String, cause: Throwable) : super(message, cause) {} diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/launch/DefaultLauncher.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/launch/DefaultLauncher.kt index bd57a91d2..1614e9cff 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/launch/DefaultLauncher.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/launch/DefaultLauncher.kt @@ -31,7 +31,7 @@ import kotlin.concurrent.thread * @param account The user account * @param options The launching configuration */ -open class DefaultLauncher(repository: GameRepository, versionId: String, account: AuthInfo, options: LaunchOptions, listener: ProcessListener? = null, isDaemon: Boolean = true) +open class DefaultLauncher @JvmOverloads constructor(repository: GameRepository, versionId: String, account: AuthInfo, options: LaunchOptions, listener: ProcessListener? = null, isDaemon: Boolean = true) : Launcher(repository, versionId, account, options, listener, isDaemon) { protected val native: File by lazy { repository.getNativeDirectory(version.id) } @@ -143,7 +143,7 @@ open class DefaultLauncher(repository: GameRepository, versionId: String, accoun val features = getFeatures() res.addAll(Arguments.parseArguments(version.arguments?.game ?: defaultGameArguments, configuration, features)) - res.addAll(Arguments.parseStringArguments(version.minecraftArguments?.tokenize()?.toList() ?: emptyList(), configuration)) + res.addAll(Arguments.parseStringArguments(version.minecraftArguments?.tokenize() ?: emptyList(), configuration)) // Optional Minecraft arguments if (options.height != null && options.height != 0 && options.width != null && options.width != 0) { 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 fc1057827..6df3c32a9 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/launch/ExitWaiter.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/launch/ExitWaiter.kt @@ -19,8 +19,8 @@ package org.jackhuang.hmcl.launch import org.jackhuang.hmcl.event.EVENT_BUS import org.jackhuang.hmcl.event.JVMLaunchFailedEvent -import org.jackhuang.hmcl.event.JavaProcessExitedAbnormallyEvent -import org.jackhuang.hmcl.event.JavaProcessStoppedEvent +import org.jackhuang.hmcl.event.ProcessExitedAbnormallyEvent +import org.jackhuang.hmcl.event.ProcessStoppedEvent import org.jackhuang.hmcl.util.ManagedProcess import org.jackhuang.hmcl.util.containsOne import org.jackhuang.hmcl.util.guessLogLineError @@ -34,13 +34,13 @@ internal class ExitWaiter(val process: ManagedProcess, val joins: Collection Unit) } } - override fun characters(ch: CharArray?, start: Int, length: Int) { - val line = String(ch!!, start, length) + override fun characters(ch: CharArray, start: Int, length: Int) { + val line = String(ch, start, length) if (line.trim { it <= ' ' }.isEmpty()) return if (readingMessage) message!!.append(line).append(OS.LINE_SEPARATOR) diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/CurseForgeModpack.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/CurseForgeModpack.kt index da6121bc5..8f3c0913d 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/CurseForgeModpack.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/CurseForgeModpack.kt @@ -58,7 +58,7 @@ class CurseForgeModpackManifest @JvmOverloads constructor( } } -class CurseForgeModpackManifestMinecraft ( +class CurseForgeModpackManifestMinecraft @JvmOverloads constructor( @SerializedName("version") val gameVersion: String = "", @SerializedName("modLoaders") @@ -69,7 +69,7 @@ class CurseForgeModpackManifestMinecraft ( } } -class CurseForgeModpackManifestModLoader ( +class CurseForgeModpackManifestModLoader @JvmOverloads constructor( @SerializedName("id") val id: String = "", @SerializedName("primary") @@ -80,7 +80,7 @@ class CurseForgeModpackManifestModLoader ( } } -class CurseForgeModpackManifestFile ( +class CurseForgeModpackManifestFile @JvmOverloads constructor( @SerializedName("projectID") val projectID: Int = 0, @SerializedName("fileID") @@ -185,10 +185,10 @@ class CurseForgeModpackCompletionTask(dependencyManager: DependencyManager, vers val manifestFile = repository.getVersionRoot(version).resolve("manifest.json") if (!manifestFile.exists()) manifest = null else { - manifest = GSON.fromJson(repository.getVersionRoot(version).resolve("manifest.json").readText())!! + manifest = GSON.fromJson(manifestFile.readText())!! - // Because in China, the CurseForge is too difficult to visit. - // So caching the file name is necessary. + // Because in China, CurseForge is too difficult to visit, + // caching the file name is necessary. for (f in manifest!!.files) { if (f.fileName.isBlank()) dependents += task { f.fileName = f.url.detectFileName(proxy) } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/ModInfo.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/ModInfo.kt index 6f8727da4..073c02b8a 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/ModInfo.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/mod/ModInfo.kt @@ -22,7 +22,7 @@ import org.jackhuang.hmcl.util.getValue import org.jackhuang.hmcl.util.setValue import java.io.File -class ModInfo ( +class ModInfo @JvmOverloads constructor( var file: File, val name: String, val description: String = "", diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/CoupleTask.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/CoupleTask.kt index 9afc30960..6a70a3840 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/CoupleTask.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/CoupleTask.kt @@ -24,7 +24,7 @@ import org.jackhuang.hmcl.util.AutoTypingMap * * @param pred the task that runs before [succ] * @param succ a callback that returns the task runs after [pred], [succ] will be executed asynchronously. You can do something that relies on the result of [pred]. - * @param reliant true if this task chain will be broken when task [pred] fails. + * @param reliesOnDependents true if this task chain will be broken when task [pred] fails. */ internal class CoupleTask(pred: P, private val succ: (AutoTypingMap) -> Task?, override val reliesOnDependents: Boolean) : Task() { override val hidden: Boolean = true diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/FileDownloadTask.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/FileDownloadTask.kt index 7e3413156..d330a6ca9 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/FileDownloadTask.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/FileDownloadTask.kt @@ -46,7 +46,7 @@ class FileDownloadTask @JvmOverloads constructor(val url: URL, val file: File, v /** * Once downloading fails, this event will be fired to gain the substitute URL. */ - var onFailed = EventManager>() + val onFailed = EventManager>() private var rFile: RandomAccessFile? = null private var stream: InputStream? = null @@ -81,7 +81,7 @@ class FileDownloadTask @JvmOverloads constructor(val url: URL, val file: File, v try { updateProgress(0.0) - val conn = url.createConnection(proxy) + val conn = currentURL.createConnection(proxy) conn.connect() if (conn.responseCode / 100 != 2) diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/GetTask.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/GetTask.kt index 48bd7bc89..0e0a5ece8 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/GetTask.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/GetTask.kt @@ -56,9 +56,9 @@ class GetTask @JvmOverloads constructor(val url: URL, val encoding: Charset = Ch val len = input.read(buf) if (len == -1) break - read += len baos.write(buf, 0, len) + read += len updateProgress(read, size) if (Thread.currentThread().isInterrupted) diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Scheduler.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Scheduler.kt index 837cb4964..cd500a898 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Scheduler.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/Scheduler.kt @@ -57,11 +57,13 @@ interface Scheduler { val e = wrapper.get() if (e != null) throw ExecutionException(e) } + override fun get() { latch.await() val e = wrapper.get() if (e != null) throw ExecutionException(e) } + override fun isDone() = latch.count == 0L override fun isCancelled() = false override fun cancel(mayInterruptIfRunning: Boolean) = false @@ -117,19 +119,25 @@ interface Scheduler { * A scheduler that always create new threads to execute tasks. * For tasks that do not do heavy operations. */ - val NEW_THREAD: Scheduler = SchedulerExecutorService(CACHED_EXECUTOR) + val NEW_THREAD: Scheduler by lazy { + SchedulerExecutorService(CACHED_EXECUTOR) + } /** * A scheduler that exclusively executes tasks that do I/O operations. * The number tasks that do I/O operations in the meantime cannot be larger then 6. */ - val IO: Scheduler = SchedulerExecutorService(IO_EXECUTOR) + val IO: Scheduler by lazy { + SchedulerExecutorService(IO_EXECUTOR) + } /** * A scheduler that exclusively executes tasks that do computations. * The best way to do computations is an event queue. */ - val COMPUTATION: Scheduler = SchedulerExecutorService(SINGLE_EXECUTOR) + val COMPUTATION: Scheduler by lazy { + SchedulerExecutorService(SINGLE_EXECUTOR) + } /** * The default scheduler for tasks to be executed. diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/TaskExecutor.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/TaskExecutor.kt index 93aa0e75f..0979f9dad 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/TaskExecutor.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/task/TaskExecutor.kt @@ -35,6 +35,7 @@ class TaskExecutor(private val task: Task) { val totTask = AtomicInteger(0) val variables = AutoTypingMap(mutableMapOf()) var lastException: Exception? = null + private set private val workerQueue = ConcurrentLinkedQueue>() /** @@ -151,7 +152,7 @@ class TaskExecutor(private val task: Task) { return flag } - private inner class Invoker(val task: Task, val latch: CountDownLatch, val boolean: AtomicBoolean): Callable { + private inner class Invoker(private val task: Task, private val latch: CountDownLatch, private val boolean: AtomicBoolean): Callable { override fun call() { try { Thread.currentThread().name = task.title diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/AutoTypingMap.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/AutoTypingMap.kt index 4af694013..704d0d549 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/AutoTypingMap.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/AutoTypingMap.kt @@ -28,7 +28,7 @@ class AutoTypingMap(private val impl: MutableMap) { operator fun get(key: K): V = impl[key] as V operator fun set(key: K, value: Any?) { if (value != null) - impl.set(key, value) + impl[key] = value } val values get() = impl.values val keys get() = impl.keys diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Compressors.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Compressors.kt index 88b80ca5f..b61aaa052 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Compressors.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Compressors.kt @@ -151,7 +151,6 @@ fun File.uncompressTo(dest: File, subDirectory: String = "", callback: ((String) /** * Read the text content of a file in zip. * - * @param f the zip file * @param name the location of the text in zip file, something like A/B/C/D.txt * @throws IOException if the file is not a valid zip file. * @return the content of given file. @@ -167,7 +166,6 @@ fun File.readTextZipEntry(name: String): String { /** * Read the text content of a file in zip. * - * @param f the zip file * @param location the location of the text in zip file, something like A/B/C/D.txt * @return the content of given file. */ diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Gson.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Gson.kt index d4b6838ad..a4b57e7eb 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Gson.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/Gson.kt @@ -78,16 +78,16 @@ interface Validation { object ValidationTypeAdapterFactory : TypeAdapterFactory { override fun create(gson: Gson, type: TypeToken?): TypeAdapter { - val delgate = gson.getDelegateAdapter(this, type) + val delegate = gson.getDelegateAdapter(this, type) return object : TypeAdapter() { override fun write(out: JsonWriter?, value: T?) { if (value is Validation) value.validate() - delgate.write(out, value) + delegate.write(out, value) } override fun read(reader: JsonReader?): T? { - val value = delgate.read(reader) + val value = delegate.read(reader) if (value is Validation) value.validate() return value @@ -160,7 +160,7 @@ object DateTypeAdapter : JsonSerializer, JsonDeserializer { if (json !is JsonPrimitive) { throw JsonParseException("The date should be a string value") } else { - val date = this.deserializeToDate(json.getAsString()) + val date = this.deserializeToDate(json.asString) if (typeOfT === Date::class.java) { return date } else { @@ -170,23 +170,23 @@ object DateTypeAdapter : JsonSerializer, JsonDeserializer { } override fun serialize(src: Date, typeOfSrc: Type, context: JsonSerializationContext): JsonElement { - synchronized(this.enUsFormat) { + synchronized(enUsFormat) { return JsonPrimitive(this.serializeToString(src)) } } fun deserializeToDate(string: String): Date { - synchronized(this.enUsFormat) { + synchronized(enUsFormat) { try { - return this.enUsFormat.parse(string) + return enUsFormat.parse(string) } catch (ex1: ParseException) { try { - return this.iso8601Format.parse(string) + return iso8601Format.parse(string) } catch (ex2: ParseException) { try { var cleaned = string.replace("Z", "+00:00") cleaned = cleaned.substring(0, 22) + cleaned.substring(23) - return this.iso8601Format.parse(cleaned) + return iso8601Format.parse(cleaned) } catch (e: Exception) { throw JsonSyntaxException("Invalid date: " + string, e) } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/IOUtils.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/IOUtils.kt index 281b0e329..0f5f0d9ac 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/IOUtils.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/IOUtils.kt @@ -30,9 +30,7 @@ fun Closeable.closeQuietly() { fun InputStream.readFully(): ByteArrayOutputStream { try { - val ans = ByteArrayOutputStream() - copyTo(ans) - return ans + return ByteArrayOutputStream().apply { copyTo(this) } } finally { this.closeQuietly() } diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/NetUtils.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/NetUtils.kt index cd4258803..e948d070e 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/NetUtils.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/NetUtils.kt @@ -47,14 +47,14 @@ fun initHttps() { if (INIT_HTTPS) return INIT_HTTPS = true - System.setProperty("https.protocols", "SSLv3,TLSv1"); + System.setProperty("https.protocols", "SSLv3,TLSv1") try { - val c = SSLContext.getInstance("SSL"); - c.init(null, arrayOf(XTM), SecureRandom()); - HttpsURLConnection.setDefaultSSLSocketFactory(c.getSocketFactory()); + val c = SSLContext.getInstance("SSL") + c.init(null, arrayOf(XTM), SecureRandom()) + HttpsURLConnection.setDefaultSSLSocketFactory(c.socketFactory) } catch (e: GeneralSecurityException) { } - HttpsURLConnection.setDefaultHostnameVerifier(HNV); + HttpsURLConnection.setDefaultHostnameVerifier(HNV) } var DEFAULT_USER_AGENT: () -> String = { RandomUserAgent.randomUserAgent } @@ -144,7 +144,7 @@ fun URL.detectFileName(proxy: Proxy = Proxy.NO_PROXY): String { fun HttpURLConnection.detectFileName(): String { val disposition = getHeaderField("Content-Disposition") - if (disposition == null || disposition.indexOf("filename=") == -1) { + if (disposition == null || !disposition.contains("filename=")) { val u = url.toString() return u.substringAfterLast('/') } else diff --git a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/SimpleMultimap.kt b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/SimpleMultimap.kt index 73506a046..2d58ddbb1 100644 --- a/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/SimpleMultimap.kt +++ b/HMCLCore/src/main/kotlin/org/jackhuang/hmcl/util/SimpleMultimap.kt @@ -23,8 +23,8 @@ import java.util.* * A simple implementation of Multimap. * Just a combination of map and set. */ -class SimpleMultimap(val maper: () -> MutableMap>, val valuer: () -> MutableCollection) { - private val map = HashMap>() +class SimpleMultimap(mapper: () -> MutableMap>, private val valuer: () -> MutableCollection) { + private val map = mapper() private val valuesImpl: MutableCollection = valuer() val size = valuesImpl.size @@ -35,7 +35,7 @@ class SimpleMultimap(val maper: () -> MutableMap>, val va val isEmpty: Boolean = size == 0 val isNotEmpty: Boolean = size != 0 - fun containsKey(key: K): Boolean = map.containsKey(key) + fun containsKey(key: K): Boolean = map[key]?.isNotEmpty() ?: false operator fun get(key: K): Collection = map.getOrPut(key, valuer) fun put(key: K, value: V) {