mirror of
https://github.com/mamoe/mirai.git
synced 2025-02-05 12:22:24 +08:00
Fix MultiFileSettingStorage
This commit is contained in:
parent
dc6bb61352
commit
f048890c54
@ -127,15 +127,13 @@ internal open class MultiFileSettingStorageImpl(
|
|||||||
) : SettingStorage, MultiFileSettingStorage {
|
) : SettingStorage, MultiFileSettingStorage {
|
||||||
public override fun <T : Setting> load(holder: SettingHolder, settingClass: Class<T>): T =
|
public override fun <T : Setting> load(holder: SettingHolder, settingClass: Class<T>): T =
|
||||||
with(settingClass.kotlin) {
|
with(settingClass.kotlin) {
|
||||||
val file = getSettingFile(holder, settingClass::class)
|
val file = getSettingFile(holder, this)
|
||||||
|
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
val instance = objectInstance ?: this.createInstanceOrNull() ?: kotlin.run {
|
val instance = objectInstance ?: this.createInstanceOrNull() ?: kotlin.run {
|
||||||
if (settingClass != Setting::class.java) {
|
require(settingClass == Setting::class.java) {
|
||||||
throw IllegalArgumentException(
|
"Cannot create Setting instance. Make sure settingClass is Setting::class.java or a Kotlin's object, " +
|
||||||
"Cannot create Setting instance. Make sure settingClass is Setting::class.java or a Kotlin's object, " +
|
"or has a constructor which either has no parameters or all parameters of which are optional"
|
||||||
"or has a constructor which either has no parameters or all parameters of which are optional"
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
if (holder is AutoSaveSettingHolder) {
|
if (holder is AutoSaveSettingHolder) {
|
||||||
AutoSaveSetting(holder) as T?
|
AutoSaveSetting(holder) as T?
|
||||||
@ -144,9 +142,9 @@ internal open class MultiFileSettingStorageImpl(
|
|||||||
"Cannot create Setting instance. Make sure 'holder' is a AutoSaveSettingHolder, " +
|
"Cannot create Setting instance. Make sure 'holder' is a AutoSaveSettingHolder, " +
|
||||||
"or 'setting' is an object or has a constructor which either has no parameters or all parameters of which are optional"
|
"or 'setting' is an object or has a constructor which either has no parameters or all parameters of which are optional"
|
||||||
)
|
)
|
||||||
if (file.exists() && file.isFile && file.canRead()) {
|
file.createNewFile()
|
||||||
Yaml.default.decodeFromString(instance.updaterSerializer, file.readText())
|
check(file.exists() && file.isFile && file.canRead()) { "${file.absolutePath} cannot be read" }
|
||||||
}
|
Yaml.default.decodeFromString(instance.updaterSerializer, file.readText())
|
||||||
instance
|
instance
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -96,7 +96,7 @@ public interface MemorySettingStorage : SettingStorage, Map<Class<out Setting>,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 在内存存储所有 [Setting] 实例的 [SettingStorage].
|
* 用多个文件存储 [Setting] 实例的 [SettingStorage].
|
||||||
*/
|
*/
|
||||||
public interface MultiFileSettingStorage : SettingStorage {
|
public interface MultiFileSettingStorage : SettingStorage {
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user