Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
M
Mirai
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
0
Issues
0
List
Boards
Labels
Service Desk
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Packages
Packages
List
Container Registry
Analytics
Analytics
CI / CD
Code Review
Insights
Issues
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
MyCard
Mirai
Commits
bb2bed42
Commit
bb2bed42
authored
Feb 14, 2020
by
Him188
Browse files
Options
Browse Files
Download
Plain Diff
Merge remote-tracking branch 'origin/master'
parents
a7055ed9
d4321152
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
64 additions
and
16 deletions
+64
-16
mirai-console/build.gradle.kts
mirai-console/build.gradle.kts
+2
-0
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
...i-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
+1
-1
mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/ConfigSection.kt
.../src/main/kotlin/net/mamoe/mirai/plugins/ConfigSection.kt
+61
-15
No files found.
mirai-console/build.gradle.kts
View file @
bb2bed42
...
@@ -40,5 +40,7 @@ dependencies {
...
@@ -40,5 +40,7 @@ dependencies {
runtimeOnly
(
files
(
"../mirai-core/build/classes/kotlin/jvm/main"
))
runtimeOnly
(
files
(
"../mirai-core/build/classes/kotlin/jvm/main"
))
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
=
"com.moandjiezana.toml"
,
name
=
"toml4j"
,
version
=
"0.7.2"
)
// classpath is not set correctly by IDE
// classpath is not set correctly by IDE
}
}
\ No newline at end of file
mirai-console/src/main/kotlin/net/mamoe/mirai/MiraiConsole.kt
View file @
bb2bed42
...
@@ -267,7 +267,7 @@ object MiraiConsole {
...
@@ -267,7 +267,7 @@ object MiraiConsole {
}
}
object
MiraiProperties
{
object
MiraiProperties
{
var
config
=
File
(
"$path/mirai.
json
"
).
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
}
...
...
mirai-console/src/main/kotlin/net/mamoe/mirai/plugins/ConfigSection.kt
View file @
bb2bed42
...
@@ -13,8 +13,12 @@ import com.alibaba.fastjson.JSON
...
@@ -13,8 +13,12 @@ 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.yaml.snakeyaml.Yaml
import
java.io.File
import
java.io.File
import
java.util.*
import
java.util.concurrent.ConcurrentHashMap
import
java.util.concurrent.ConcurrentHashMap
import
kotlin.properties.ReadWriteProperty
import
kotlin.properties.ReadWriteProperty
import
kotlin.reflect.KClass
import
kotlin.reflect.KClass
...
@@ -63,11 +67,11 @@ interface Config {
...
@@ -63,11 +67,11 @@ interface Config {
"yml"
->
YamlConfig
(
file
)
"yml"
->
YamlConfig
(
file
)
"yaml"
->
YamlConfig
(
file
)
"yaml"
->
YamlConfig
(
file
)
"mirai"
->
YamlConfig
(
file
)
"mirai"
->
YamlConfig
(
file
)
"ini"
->
Ini
Config
(
file
)
"ini"
->
Toml
Config
(
file
)
"toml"
->
Ini
Config
(
file
)
"toml"
->
Toml
Config
(
file
)
"properties"
->
Ini
Config
(
file
)
"properties"
->
Toml
Config
(
file
)
"property"
->
Ini
Config
(
file
)
"property"
->
Toml
Config
(
file
)
"data"
->
Ini
Config
(
file
)
"data"
->
Toml
Config
(
file
)
else
->
error
(
"Unsupported file config type ${file.extension.toLowerCase()}"
)
else
->
error
(
"Unsupported file config type ${file.extension.toLowerCase()}"
)
}
}
}
}
...
@@ -191,8 +195,7 @@ fun <T : Any> Config._smartCast(propertyName: String, _class: KClass<T>): T {
...
@@ -191,8 +195,7 @@ fun <T : Any> Config._smartCast(propertyName: String, _class: KClass<T>): T {
}
}
interface
ConfigSection
:
Config
,
MutableMap
<
String
,
Any
>
{
interface
ConfigSection
:
Config
{
override
fun
getConfigSection
(
key
:
String
):
ConfigSection
{
override
fun
getConfigSection
(
key
:
String
):
ConfigSection
{
return
(
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
))
as
ConfigSection
return
(
get
(
key
)
?:
error
(
"ConfigSection does not contain $key "
))
as
ConfigSection
}
}
...
@@ -281,6 +284,22 @@ open class ConfigSectionImpl() : ConcurrentHashMap<String, Any>(), ConfigSection
...
@@ -281,6 +284,22 @@ open class ConfigSectionImpl() : ConcurrentHashMap<String, Any>(), ConfigSection
}
}
}
}
open
class
ConfigSectionDelegation
(
private
val
delegation
:
MutableMap
<
String
,
Any
>
)
:
ConfigSection
,
MutableMap
<
String
,
Any
>
by
delegation
{
override
fun
set
(
key
:
String
,
value
:
Any
)
{
delegation
.
put
(
key
,
value
)
}
override
fun
asMap
():
Map
<
String
,
Any
>
{
return
delegation
}
override
fun
save
()
{
}
}
interface
FileConfig
:
Config
{
interface
FileConfig
:
Config
{
fun
deserialize
(
content
:
String
):
ConfigSection
fun
deserialize
(
content
:
String
):
ConfigSection
...
@@ -297,6 +316,18 @@ abstract class FileConfigImpl internal constructor(
...
@@ -297,6 +316,18 @@ abstract class FileConfigImpl internal constructor(
deserialize
(
file
.
readText
())
deserialize
(
file
.
readText
())
}
}
override
val
size
:
Int
get
()
=
content
.
size
override
val
entries
:
MutableSet
<
MutableMap
.
MutableEntry
<
String
,
Any
>>
get
()
=
content
.
entries
override
val
keys
:
MutableSet
<
String
>
get
()
=
content
.
keys
override
val
values
:
MutableCollection
<
Any
>
get
()
=
content
.
values
override
fun
containsKey
(
key
:
String
):
Boolean
=
content
.
containsKey
(
key
)
override
fun
containsValue
(
value
:
Any
):
Boolean
=
content
.
containsValue
(
value
)
override
fun
put
(
key
:
String
,
value
:
Any
):
Any
?
=
content
.
put
(
key
,
value
)
override
fun
isEmpty
():
Boolean
=
content
.
isEmpty
()
override
fun
putAll
(
from
:
Map
<
out
String
,
Any
>)
=
content
.
putAll
(
from
)
override
fun
clear
()
=
content
.
clear
()
override
fun
remove
(
key
:
String
):
Any
?
=
content
.
remove
(
key
)
override
fun
save
()
{
override
fun
save
()
{
if
(!
file
.
exists
())
{
if
(!
file
.
exists
())
{
file
.
createNewFile
()
file
.
createNewFile
()
...
@@ -318,7 +349,9 @@ abstract class FileConfigImpl internal constructor(
...
@@ -318,7 +349,9 @@ abstract class FileConfigImpl internal constructor(
}
}
class
JsonConfig
internal
constructor
(
file
:
File
)
:
FileConfigImpl
(
file
)
{
class
JsonConfig
internal
constructor
(
file
:
File
)
:
FileConfigImpl
(
file
)
{
@UnstableDefault
@UnstableDefault
override
fun
deserialize
(
content
:
String
):
ConfigSection
{
override
fun
deserialize
(
content
:
String
):
ConfigSection
{
if
(
content
.
isEmpty
()
||
content
.
isBlank
()
||
content
==
"{}"
)
{
if
(
content
.
isEmpty
()
||
content
.
isBlank
()
||
content
==
"{}"
)
{
...
@@ -339,22 +372,35 @@ class JsonConfig internal constructor(file: File) : FileConfigImpl(file) {
...
@@ -339,22 +372,35 @@ class JsonConfig internal constructor(file: File) : FileConfigImpl(file) {
class
YamlConfig
internal
constructor
(
file
:
File
)
:
FileConfigImpl
(
file
)
{
class
YamlConfig
internal
constructor
(
file
:
File
)
:
FileConfigImpl
(
file
)
{
override
fun
deserialize
(
content
:
String
):
ConfigSection
{
override
fun
deserialize
(
content
:
String
):
ConfigSection
{
TODO
(
"崔崔还没有写"
)
//To change body of created functions use File | Settings | File Templates.
if
(
content
.
isEmpty
()
||
content
.
isBlank
())
{
return
ConfigSectionImpl
()
}
return
ConfigSectionDelegation
(
Collections
.
synchronizedMap
(
Yaml
().
load
<
LinkedHashMap
<
String
,
Any
>>(
content
)
as
LinkedHashMap
<
String
,
Any
>
)
)
}
}
override
fun
serialize
(
config
:
ConfigSection
):
String
{
override
fun
serialize
(
config
:
ConfigSection
):
String
{
TODO
(
"崔崔还没有写"
)
//To change body of created functions use File | Settings | File Templates.
return
Yaml
().
dumpAsMap
(
config
)
}
}
}
}
class
Ini
Config
internal
constructor
(
file
:
File
)
:
FileConfigImpl
(
file
)
{
class
Toml
Config
internal
constructor
(
file
:
File
)
:
FileConfigImpl
(
file
)
{
override
fun
deserialize
(
content
:
String
):
ConfigSection
{
override
fun
deserialize
(
content
:
String
):
ConfigSection
{
TODO
(
"崔崔还没有写"
)
//To change body of created functions use File | Settings | File Templates.
if
(
content
.
isEmpty
()
||
content
.
isBlank
())
{
return
ConfigSectionImpl
()
}
return
ConfigSectionDelegation
(
Collections
.
synchronizedMap
(
Toml
().
read
(
content
).
toMap
()
)
)
}
}
override
fun
serialize
(
config
:
ConfigSection
):
String
{
override
fun
serialize
(
config
:
ConfigSection
):
String
{
TODO
(
"崔崔还没有写"
)
//To change body of created functions use File | Settings | File Templates.
return
TomlWriter
().
write
(
config
)
}
}
}
}
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment