Skin portrait

This commit is contained in:
huangyuhui
2017-08-18 22:42:11 +08:00
parent dc468f1a76
commit 27939c6b61
24 changed files with 213 additions and 142 deletions

View File

@@ -17,7 +17,7 @@
*/
package org.jackhuang.hmcl.auth
class AuthenticationException : Exception {
open class AuthenticationException : Exception {
constructor() : super() {}
constructor(message: String) : super(message) {}
constructor(message: String, cause: Throwable) : super(message, cause) {}

View File

@@ -0,0 +1,24 @@
/*
* Hello Minecraft! Launcher.
* Copyright (C) 2017 huangyuhui <huanghongxun2008@126.com>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see {http://www.gnu.org/licenses/}.
*/
package org.jackhuang.hmcl.auth.yggdrasil
import org.jackhuang.hmcl.auth.AuthenticationException
class InvalidTokenException(val account: YggdrasilAccount) : AuthenticationException()
class InvalidCredentialsException(val account: YggdrasilAccount) : AuthenticationException()

View File

@@ -36,7 +36,8 @@ class YggdrasilAccount private constructor(override val username: String): Accou
private var clientToken: String = UUID.randomUUID().toString()
private var isOnline: Boolean = false
private var userProperties = PropertyMap()
private var selectedProfile: GameProfile? = null
var selectedProfile: GameProfile? = null
private set
private var profiles: Array<GameProfile>? = null
private var userType: UserType = UserType.LEGACY
@@ -166,7 +167,11 @@ class YggdrasilAccount private constructor(override val username: String): Accou
if (response.error?.isNotBlank() ?: false) {
LOG.severe("Failed to log in, the auth server returned an error: " + response.error + ", message: " + response.errorMessage + ", cause: " + response.cause)
throw AuthenticationException("Request error: ${response.errorMessage}")
throw when (response.errorMessage) {
"Invalid token." -> InvalidTokenException(this)
"Invalid credentials. Invalid username or password." -> InvalidCredentialsException(this)
else -> AuthenticationException("Request error: ${response.errorMessage}")
}
}
return response

View File

@@ -34,7 +34,7 @@ import java.math.BigInteger
import java.util.logging.Level
class FileDownloadTask @JvmOverloads constructor(val url: URL, val file: File, val hash: String? = null, val retry: Int = 5, val proxy: Proxy = Proxy.NO_PROXY): Task() {
override val scheduler: Scheduler = Scheduler.IO_THREAD
override val scheduler: Scheduler = Scheduler.IO
var onFailed = EventManager<FailedEvent<URL>>()
private var rFile: RandomAccessFile? = null

View File

@@ -26,7 +26,7 @@ import java.net.URL
import java.nio.charset.Charset
class GetTask @JvmOverloads constructor(val url: URL, val encoding: Charset = Charsets.UTF_8, private val retry: Int = 5, private val proxy: Proxy = Proxy.NO_PROXY): TaskResult<String>() {
override val scheduler: Scheduler = Scheduler.IO_THREAD
override val scheduler: Scheduler = Scheduler.IO
override val id = ID
override fun execute() {

View File

@@ -62,7 +62,7 @@ interface Scheduler {
val NEW_THREAD: Scheduler = object : Scheduler {
override fun schedule(block: Callable<Unit>) = CACHED_EXECUTOR.submit(block)
}
val IO_THREAD: Scheduler = object : Scheduler {
val IO: Scheduler = object : Scheduler {
override fun schedule(block: Callable<Unit>) = IO_EXECUTOR.submit(block)
}
val DEFAULT = NEW_THREAD

View File

@@ -58,7 +58,6 @@ abstract class Task {
@Throws(Exception::class)
abstract fun execute()
infix fun parallel(couple: Task): Task = ParallelTask(this, couple)
infix fun then(b: Task): Task = CoupleTask(this, { b }, true)
infix fun with(b: Task): Task = CoupleTask(this, { b }, false)
@@ -116,7 +115,7 @@ abstract class Task {
fun executor() = TaskExecutor().submit(this)
fun executor(taskListener: TaskListener) = TaskExecutor().submit(this).apply { this.taskListener = taskListener }
fun start() = executor().start()
fun subscribe(subscriber: Task) = executor().apply {
submit(subscriber).start()
}

View File

@@ -82,7 +82,7 @@ data class JavaVersion internal constructor(
val parsedVersion = parseVersion(thisVersion)
if (parsedVersion == UNKNOWN)
throw IOException("Java version '$thisVersion' can not be recognized")
return JavaVersion(file.parentFile, thisVersion, platform)
return JavaVersion(file, thisVersion, platform)
}
private fun fromExecutable(file: File, version: String) =

View File

@@ -26,14 +26,14 @@ import java.util.logging.*
import java.util.logging.Formatter
val LOG = Logger.getLogger("HMCL").apply {
level = Level.FINER
level = Level.FINEST
useParentHandlers = false
addHandler(FileHandler("hmcl.log").apply {
level = Level.FINER
level = Level.FINEST
formatter = DefaultFormatter
})
addHandler(ConsoleHandler().apply {
level = Level.FINER
level = Level.FINEST
formatter = DefaultFormatter
})
}

View File

@@ -50,10 +50,6 @@ open class ImmediateStringProperty(bean: Any, name: String, initialValue: String
init {
addListener(changeListener)
}
public override fun fireValueChangedEvent() {
super.fireValueChangedEvent()
}
}
open class ImmediateBooleanProperty(bean: Any, name: String, initialValue: Boolean): SimpleBooleanProperty(bean, name, initialValue) {
@@ -85,10 +81,6 @@ open class ImmediateBooleanProperty(bean: Any, name: String, initialValue: Boole
init {
addListener(changeListener)
}
public override fun fireValueChangedEvent() {
super.fireValueChangedEvent()
}
}
open class ImmediateIntegerProperty(bean: Any, name: String, initialValue: Int): SimpleIntegerProperty(bean, name, initialValue) {
@@ -120,10 +112,6 @@ open class ImmediateIntegerProperty(bean: Any, name: String, initialValue: Int):
init {
addListener(changeListener)
}
public override fun fireValueChangedEvent() {
super.fireValueChangedEvent()
}
}
open class ImmediateDoubleProperty(bean: Any, name: String, initialValue: Double): SimpleDoubleProperty(bean, name, initialValue) {
@@ -155,10 +143,6 @@ open class ImmediateDoubleProperty(bean: Any, name: String, initialValue: Double
init {
addListener(changeListener)
}
public override fun fireValueChangedEvent() {
super.fireValueChangedEvent()
}
}
open class ImmediateObjectProperty<T>(bean: Any, name: String, initialValue: T): SimpleObjectProperty<T>(bean, name, initialValue) {
@@ -185,13 +169,10 @@ open class ImmediateObjectProperty<T>(bean: Any, name: String, initialValue: T):
fun setChangedListener(listener: (T) -> Unit) {
myListener = listener
listener(get())
}
init {
addListener(changeListener)
}
public override fun fireValueChangedEvent() {
super.fireValueChangedEvent()
}
}