mirror of
https://github.com/mamoe/mirai.git
synced 2025-01-20 01:09:10 +08:00
Ini config supported(TOML)
This commit is contained in:
parent
1c6a3800d1
commit
15c84bd38e
@ -41,6 +41,6 @@ dependencies {
|
|||||||
api(kotlin("serialization"))
|
api(kotlin("serialization"))
|
||||||
api(group = "com.alibaba", name = "fastjson", version = "1.2.62")
|
api(group = "com.alibaba", name = "fastjson", version = "1.2.62")
|
||||||
api(group = "org.yaml", name = "snakeyaml", version = "1.25")
|
api(group = "org.yaml", name = "snakeyaml", version = "1.25")
|
||||||
api(group = "org.ini4j", name = "ini4j", version = "0.5.4")
|
api(group = "com.moandjiezana.toml", name = "toml4j", version = "0.7.2")
|
||||||
// classpath is not set correctly by IDE
|
// classpath is not set correctly by IDE
|
||||||
}
|
}
|
@ -267,7 +267,7 @@ object MiraiConsole {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object MiraiProperties {
|
object MiraiProperties {
|
||||||
var config = File("$path/mirai.yml").loadAsConfig()
|
var config = File("$path/mirai.properties").loadAsConfig()
|
||||||
|
|
||||||
var HTTP_API_ENABLE: Boolean by config.withDefaultWrite { true }
|
var HTTP_API_ENABLE: Boolean by config.withDefaultWrite { true }
|
||||||
var HTTP_API_PORT: Int by config.withDefaultWrite { 8080 }
|
var HTTP_API_PORT: Int by config.withDefaultWrite { 8080 }
|
||||||
|
@ -13,6 +13,8 @@ import com.alibaba.fastjson.JSON
|
|||||||
import com.alibaba.fastjson.JSONObject
|
import com.alibaba.fastjson.JSONObject
|
||||||
import com.alibaba.fastjson.TypeReference
|
import com.alibaba.fastjson.TypeReference
|
||||||
import com.alibaba.fastjson.parser.Feature
|
import com.alibaba.fastjson.parser.Feature
|
||||||
|
import com.moandjiezana.toml.Toml
|
||||||
|
import com.moandjiezana.toml.TomlWriter
|
||||||
import kotlinx.serialization.*
|
import kotlinx.serialization.*
|
||||||
import org.ini4j.Wini
|
import org.ini4j.Wini
|
||||||
import org.yaml.snakeyaml.Yaml
|
import org.yaml.snakeyaml.Yaml
|
||||||
@ -396,38 +398,15 @@ class YamlConfig internal constructor(file: File) : FileConfigImpl(file) {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class IniConfig internal constructor(val file: File) : FileConfigImpl(file) {
|
class IniConfig internal constructor(file: File) : FileConfigImpl(file) {
|
||||||
private val iniObj by lazy {
|
|
||||||
Wini(file)
|
|
||||||
}
|
|
||||||
private val rootSection
|
|
||||||
get() = iniObj["root"]
|
|
||||||
|
|
||||||
override fun asMap(): Map<String, Any> {
|
|
||||||
return JSON.parseObject<ConfigSectionImpl>(
|
|
||||||
JSONObject.toJSONString(rootSection),
|
|
||||||
object : TypeReference<ConfigSectionImpl>() {},
|
|
||||||
Feature.OrderedField
|
|
||||||
).asMap()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun set(key: String, value: Any) {
|
|
||||||
iniObj.put("root", key, value)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun get(key: String): Any? {
|
|
||||||
return iniObj.get("root", key)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun save() {
|
|
||||||
iniObj.store()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun deserialize(content: String): ConfigSection {
|
override fun deserialize(content: String): ConfigSection {
|
||||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
if (content.isEmpty() || content.isBlank()) {
|
||||||
|
return ConfigSectionImpl()
|
||||||
|
}
|
||||||
|
return ConfigSectionDelegation(Toml().read(content).toMap())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun serialize(config: ConfigSection): String {
|
override fun serialize(config: ConfigSection): String {
|
||||||
TODO("not implemented") //To change body of created functions use File | Settings | File Templates.
|
return TomlWriter().write(config)
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in New Issue
Block a user