mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-19 04:15:14 -04:00
save favicon again
This commit is contained in:
parent
ea3e15fc09
commit
2bdb4b9c79
@ -33,12 +33,12 @@ class Server(
|
|||||||
/**
|
/**
|
||||||
* Server-address as string. May contain the port
|
* Server-address as string. May contain the port
|
||||||
*/
|
*/
|
||||||
var address by delegate(address)
|
var address by delegate(address) { check(it.isNotBlank()) { "Server address must not be blank!" } }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Server name (showed in eros)
|
* Server name (showed in eros)
|
||||||
*/
|
*/
|
||||||
var name by delegate(name)
|
var name by delegate(name) { check(it.message.isNotBlank()) { "Server name must not be blank!" } }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Profiles to use for the connection to the server.
|
* Profiles to use for the connection to the server.
|
||||||
@ -56,5 +56,5 @@ class Server(
|
|||||||
var forcedVersion by backingDelegate(getter = { Versions.getVersionByName(_forcedVersion) }, setter = { _forcedVersion = it?.name })
|
var forcedVersion by backingDelegate(getter = { Versions.getVersionByName(_forcedVersion) }, setter = { _forcedVersion = it?.name })
|
||||||
|
|
||||||
@get:JsonInclude(JsonInclude.Include.NON_DEFAULT)
|
@get:JsonInclude(JsonInclude.Include.NON_DEFAULT)
|
||||||
var faviconHash: String? by delegate(null)
|
var faviconHash: String? by delegate(null) { if (it != null) check(it.length == 40) { "Not a valid sha1 hash!" } }
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,7 @@ import de.bixilon.minosoft.gui.eros.controller.EmbeddedJavaFXController
|
|||||||
import de.bixilon.minosoft.gui.eros.dialog.ServerModifyDialog
|
import de.bixilon.minosoft.gui.eros.dialog.ServerModifyDialog
|
||||||
import de.bixilon.minosoft.gui.eros.dialog.SimpleErosConfirmationDialog
|
import de.bixilon.minosoft.gui.eros.dialog.SimpleErosConfirmationDialog
|
||||||
import de.bixilon.minosoft.gui.eros.dialog.connection.KickDialog
|
import de.bixilon.minosoft.gui.eros.dialog.connection.KickDialog
|
||||||
|
import de.bixilon.minosoft.gui.eros.main.play.server.card.FaviconManager.saveFavicon
|
||||||
import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCard
|
import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCard
|
||||||
import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCardController
|
import de.bixilon.minosoft.gui.eros.main.play.server.card.ServerCardController
|
||||||
import de.bixilon.minosoft.gui.eros.main.play.server.type.types.ServerType
|
import de.bixilon.minosoft.gui.eros.main.play.server.type.types.ServerType
|
||||||
@ -270,7 +271,7 @@ class ServerListController : EmbeddedJavaFXController<Pane>(), Refreshable {
|
|||||||
server.forcedVersion = forcedVersion
|
server.forcedVersion = forcedVersion
|
||||||
server.profiles = profiles.toMutableMap()
|
server.profiles = profiles.toMutableMap()
|
||||||
if (server.address != address) {
|
if (server.address != address) {
|
||||||
serverCard.rawFavicon = null
|
server.faviconHash?.let { hash -> server.saveFavicon(null, hash) }
|
||||||
|
|
||||||
server.address = address
|
server.address = address
|
||||||
|
|
||||||
|
@ -0,0 +1,45 @@
|
|||||||
|
package de.bixilon.minosoft.gui.eros.main.play.server.card
|
||||||
|
|
||||||
|
import de.bixilon.minosoft.config.profile.profiles.eros.server.entries.Server
|
||||||
|
import de.bixilon.minosoft.data.assets.AssetsUtil
|
||||||
|
import de.bixilon.minosoft.util.Util
|
||||||
|
import javafx.scene.image.Image
|
||||||
|
import java.io.File
|
||||||
|
import java.io.FileInputStream
|
||||||
|
import java.io.FileOutputStream
|
||||||
|
import java.util.zip.GZIPInputStream
|
||||||
|
import java.util.zip.GZIPOutputStream
|
||||||
|
|
||||||
|
object FaviconManager {
|
||||||
|
|
||||||
|
val Server.favicon: Image?
|
||||||
|
get() {
|
||||||
|
val hash = this.faviconHash ?: return null
|
||||||
|
try {
|
||||||
|
val path = AssetsUtil.getAssetDiskPath(hash, true)
|
||||||
|
return Image(GZIPInputStream(FileInputStream(path)))
|
||||||
|
} catch (exception: Throwable) {
|
||||||
|
this.faviconHash = null
|
||||||
|
}
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
|
||||||
|
fun Server.saveFavicon(favicon: ByteArray?, faviconHash: String = Util.sha1(favicon)) {
|
||||||
|
if (this.faviconHash == faviconHash) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
this.faviconHash = faviconHash
|
||||||
|
val file = File(AssetsUtil.getAssetDiskPath(faviconHash, true))
|
||||||
|
if (file.exists()) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
if (favicon == null) {
|
||||||
|
file.delete() // ToDo: Check if other servers are using it
|
||||||
|
return
|
||||||
|
}
|
||||||
|
val outputStream = GZIPOutputStream(FileOutputStream(file))
|
||||||
|
outputStream.write(favicon)
|
||||||
|
outputStream.close()
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -22,7 +22,6 @@ import de.bixilon.minosoft.protocol.network.connection.status.StatusConnectionSt
|
|||||||
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
|
import de.bixilon.minosoft.util.KUtil.synchronizedMapOf
|
||||||
import de.bixilon.minosoft.util.KUtil.synchronizedSetOf
|
import de.bixilon.minosoft.util.KUtil.synchronizedSetOf
|
||||||
import de.bixilon.minosoft.util.collections.SynchronizedMap
|
import de.bixilon.minosoft.util.collections.SynchronizedMap
|
||||||
import javafx.scene.image.Image
|
|
||||||
|
|
||||||
class ServerCard(
|
class ServerCard(
|
||||||
val server: Server,
|
val server: Server,
|
||||||
@ -30,9 +29,6 @@ class ServerCard(
|
|||||||
var ping: StatusConnection? = null
|
var ping: StatusConnection? = null
|
||||||
val connections: MutableSet<PlayConnection> = synchronizedSetOf()
|
val connections: MutableSet<PlayConnection> = synchronizedSetOf()
|
||||||
|
|
||||||
var rawFavicon: ByteArray? = null
|
|
||||||
val favicon: Image? = null // ToDo: Image(ByteArrayInputStream(it))
|
|
||||||
|
|
||||||
var statusReceiveInvoker: EventInvoker? = null
|
var statusReceiveInvoker: EventInvoker? = null
|
||||||
set(value) {
|
set(value) {
|
||||||
field = value
|
field = value
|
||||||
|
@ -19,6 +19,8 @@ import de.bixilon.minosoft.data.text.ChatComponent
|
|||||||
import de.bixilon.minosoft.gui.eros.card.AbstractCardController
|
import de.bixilon.minosoft.gui.eros.card.AbstractCardController
|
||||||
import de.bixilon.minosoft.gui.eros.card.CardFactory
|
import de.bixilon.minosoft.gui.eros.card.CardFactory
|
||||||
import de.bixilon.minosoft.gui.eros.main.play.server.ServerListController
|
import de.bixilon.minosoft.gui.eros.main.play.server.ServerListController
|
||||||
|
import de.bixilon.minosoft.gui.eros.main.play.server.card.FaviconManager.favicon
|
||||||
|
import de.bixilon.minosoft.gui.eros.main.play.server.card.FaviconManager.saveFavicon
|
||||||
import de.bixilon.minosoft.gui.eros.modding.invoker.JavaFXEventInvoker
|
import de.bixilon.minosoft.gui.eros.modding.invoker.JavaFXEventInvoker
|
||||||
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
|
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil
|
||||||
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.ctext
|
import de.bixilon.minosoft.gui.eros.util.JavaFXUtil.ctext
|
||||||
@ -30,6 +32,7 @@ import de.bixilon.minosoft.modding.event.events.connection.status.StatusPongRece
|
|||||||
import de.bixilon.minosoft.util.KUtil.text
|
import de.bixilon.minosoft.util.KUtil.text
|
||||||
import de.bixilon.minosoft.util.KUtil.thousands
|
import de.bixilon.minosoft.util.KUtil.thousands
|
||||||
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
import de.bixilon.minosoft.util.KUtil.toResourceLocation
|
||||||
|
import de.bixilon.minosoft.util.task.pool.DefaultThreadPool
|
||||||
import javafx.fxml.FXML
|
import javafx.fxml.FXML
|
||||||
import javafx.scene.control.Label
|
import javafx.scene.control.Label
|
||||||
import javafx.scene.image.Image
|
import javafx.scene.image.Image
|
||||||
@ -74,7 +77,7 @@ class ServerCardController : AbstractCardController<ServerCard>() {
|
|||||||
item.unregister()
|
item.unregister()
|
||||||
item.ping()
|
item.ping()
|
||||||
|
|
||||||
item.favicon?.let { faviconFX.image = it }
|
item.server.favicon?.let { faviconFX.image = it }
|
||||||
|
|
||||||
item.statusReceiveInvoker = JavaFXEventInvoker.of<ServerStatusReceiveEvent> {
|
item.statusReceiveInvoker = JavaFXEventInvoker.of<ServerStatusReceiveEvent> {
|
||||||
if (this.item != item || it.connection.error != null) {
|
if (this.item != item || it.connection.error != null) {
|
||||||
@ -87,7 +90,7 @@ class ServerCardController : AbstractCardController<ServerCard>() {
|
|||||||
|
|
||||||
faviconFX.image = it.status.favicon?.let { favicon -> Image(ByteArrayInputStream(favicon)) } ?: JavaFXUtil.MINOSOFT_LOGO
|
faviconFX.image = it.status.favicon?.let { favicon -> Image(ByteArrayInputStream(favicon)) } ?: JavaFXUtil.MINOSOFT_LOGO
|
||||||
|
|
||||||
it.status.favicon?.let { favicon -> item.rawFavicon = favicon }
|
it.status.favicon?.let { favicon -> DefaultThreadPool += { item.server.saveFavicon(favicon) } } // ToDo: This is running every event?
|
||||||
serverList?.onPingUpdate(item)
|
serverList?.onPingUpdate(item)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,7 +15,6 @@ package de.bixilon.minosoft.protocol.status
|
|||||||
|
|
||||||
import de.bixilon.minosoft.data.text.ChatComponent
|
import de.bixilon.minosoft.data.text.ChatComponent
|
||||||
import de.bixilon.minosoft.util.KUtil.toInt
|
import de.bixilon.minosoft.util.KUtil.toInt
|
||||||
import de.bixilon.minosoft.util.Util
|
|
||||||
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast
|
import de.bixilon.minosoft.util.nbt.tag.NBTUtil.compoundCast
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
|
||||||
@ -37,8 +36,6 @@ class ServerStatus(
|
|||||||
|
|
||||||
var favicon: ByteArray? = null
|
var favicon: ByteArray? = null
|
||||||
private set
|
private set
|
||||||
var faviconHash: String? = null
|
|
||||||
private set
|
|
||||||
|
|
||||||
init {
|
init {
|
||||||
data["version"]?.compoundCast()?.let {
|
data["version"]?.compoundCast()?.let {
|
||||||
@ -55,7 +52,6 @@ class ServerStatus(
|
|||||||
|
|
||||||
data["favicon"]?.toString()?.let {
|
data["favicon"]?.toString()?.let {
|
||||||
val favicon = Base64.getDecoder().decode(it.replace("data:image/png;base64,", "").replace("\n", ""))
|
val favicon = Base64.getDecoder().decode(it.replace("data:image/png;base64,", "").replace("\n", ""))
|
||||||
faviconHash = Util.sha1(favicon)
|
|
||||||
this.favicon = favicon
|
this.favicon = favicon
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user