mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-10 18:40:15 +08:00
Use JSON to store data if YAML failed
This commit is contained in:
parent
71a02e7630
commit
91c5f5f134
@ -9,6 +9,8 @@
|
|||||||
|
|
||||||
package net.mamoe.mirai.console.internal.data
|
package net.mamoe.mirai.console.internal.data
|
||||||
|
|
||||||
|
import kotlinx.serialization.json.Json
|
||||||
|
import net.mamoe.mirai.console.MiraiConsole
|
||||||
import net.mamoe.mirai.console.data.*
|
import net.mamoe.mirai.console.data.*
|
||||||
import net.mamoe.mirai.console.internal.command.qualifiedNameOrTip
|
import net.mamoe.mirai.console.internal.command.qualifiedNameOrTip
|
||||||
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
import net.mamoe.mirai.console.util.ConsoleExperimentalApi
|
||||||
@ -59,23 +61,28 @@ internal open class MultiFilePluginDataStorageImpl(
|
|||||||
return file.toFile().also { it.createNewFile() }
|
return file.toFile().also { it.createNewFile() }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private val json = Json {
|
||||||
|
prettyPrint = true
|
||||||
|
ignoreUnknownKeys = true
|
||||||
|
isLenient = true
|
||||||
|
allowStructuredMapKeys = true
|
||||||
|
}
|
||||||
|
|
||||||
|
private val yaml = Yaml.default
|
||||||
|
|
||||||
@ConsoleExperimentalApi
|
@ConsoleExperimentalApi
|
||||||
public override fun store(holder: PluginDataHolder, instance: PluginData) {
|
public override fun store(holder: PluginDataHolder, instance: PluginData) {
|
||||||
val yaml =/* if (instance.saveName == "PermissionService") Json {
|
|
||||||
prettyPrint = true
|
|
||||||
ignoreUnknownKeys = true
|
|
||||||
isLenient = true
|
|
||||||
allowStructuredMapKeys = true
|
|
||||||
} /*Yaml(
|
|
||||||
configuration = YamlConfiguration(
|
|
||||||
mapSerialization = YamlConfiguration.MapSerialization.FLOW_MAP,
|
|
||||||
listSerialization = YamlConfiguration.ListSerialization.FLOW_SEQUENCE,
|
|
||||||
classSerialization = YamlConfiguration.MapSerialization.FLOW_MAP
|
|
||||||
)
|
|
||||||
)*/ else */Yaml.default
|
|
||||||
getPluginDataFile(holder, instance).writeText(
|
getPluginDataFile(holder, instance).writeText(
|
||||||
kotlin.runCatching {
|
kotlin.runCatching {
|
||||||
yaml.encodeToString(instance.updaterSerializer, Unit)
|
yaml.encodeToString(instance.updaterSerializer, Unit)
|
||||||
|
}.recoverCatching {
|
||||||
|
// Just use mainLogger for convenience.
|
||||||
|
MiraiConsole.mainLogger.warning(
|
||||||
|
"Could not save ${instance.saveName} in YAML format due to exception in YAML encoder. " +
|
||||||
|
"Please report this exception and relevant configurations to https://github.com/mamoe/mirai-console/issues/new",
|
||||||
|
it
|
||||||
|
)
|
||||||
|
json.encodeToString(instance.updaterSerializer, Unit)
|
||||||
}.getOrElse {
|
}.getOrElse {
|
||||||
throw IllegalStateException("Exception while saving $instance, saveName=${instance.saveName}", it)
|
throw IllegalStateException("Exception while saving $instance, saveName=${instance.saveName}", it)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user