mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-04-30 06:37:29 +00:00
refactor(config): 对配置文件的 AppPath 对象更名.
先前为确保后续可以增加指定配置文件路径的功能, 在命名上标记的 DEFAULT 在现在已经不符合实际意义了, 故将 DEFAULT 前缀移除.
This commit is contained in:
parent
ae411ce829
commit
27dc26160d
@ -111,7 +111,7 @@ internal enum class AppPaths(
|
|||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
DEFAULT_CONFIG_APPLICATION({ "$DATA_ROOT/config.json" }, {
|
CONFIG_APPLICATION({ "$DATA_ROOT/config.json" }, {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
file.bufferedWriter(StandardCharsets.UTF_8).use {
|
file.bufferedWriter(StandardCharsets.UTF_8).use {
|
||||||
GsonConst.botConfigGson.toJson(
|
GsonConst.botConfigGson.toJson(
|
||||||
@ -127,7 +127,7 @@ internal enum class AppPaths(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
DEFAULT_CONFIG_BOT({ "$DATA_ROOT/bot.json" }, {
|
CONFIG_BOT({ "$DATA_ROOT/bot.json" }, {
|
||||||
if (!file.exists()) {
|
if (!file.exists()) {
|
||||||
file.bufferedWriter(StandardCharsets.UTF_8).use {
|
file.bufferedWriter(StandardCharsets.UTF_8).use {
|
||||||
GsonConst.botConfigGson.toJson(
|
GsonConst.botConfigGson.toJson(
|
||||||
@ -172,7 +172,7 @@ internal enum class AppPaths(
|
|||||||
return path
|
return path
|
||||||
}
|
}
|
||||||
|
|
||||||
private object PathConst {
|
object PathConst {
|
||||||
const val PROP_DATA_PATH = "bot.path.data"
|
const val PROP_DATA_PATH = "bot.path.data"
|
||||||
const val ENV_DATA_PATH = "BOT_DATA_PATH"
|
const val ENV_DATA_PATH = "BOT_DATA_PATH"
|
||||||
}
|
}
|
||||||
@ -208,8 +208,8 @@ private fun AppPaths.defaultInitializer() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal fun initialFiles() {
|
internal fun initialFiles() {
|
||||||
val configFilesNotInitialized = !AppPaths.DEFAULT_CONFIG_APPLICATION.file.exists()
|
val configFilesNotInitialized = !AppPaths.CONFIG_APPLICATION.file.exists()
|
||||||
&& !AppPaths.DEFAULT_CONFIG_BOT.file.exists()
|
&& !AppPaths.CONFIG_BOT.file.exists()
|
||||||
|
|
||||||
for (path in AppPaths.values()) {
|
for (path in AppPaths.values()) {
|
||||||
path.initial()
|
path.initial()
|
||||||
@ -241,7 +241,7 @@ private object GsonConst {
|
|||||||
.create()
|
.create()
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun loadAppConfig(configFile: File = AppPaths.DEFAULT_CONFIG_APPLICATION.file): AppConfig {
|
internal fun loadAppConfig(configFile: File = AppPaths.CONFIG_APPLICATION.file): AppConfig {
|
||||||
try {
|
try {
|
||||||
configFile.bufferedReader(StandardCharsets.UTF_8).use {
|
configFile.bufferedReader(StandardCharsets.UTF_8).use {
|
||||||
return GsonConst.appConfigGson.fromJson(it, AppConfig::class.java)!!
|
return GsonConst.appConfigGson.fromJson(it, AppConfig::class.java)!!
|
||||||
@ -252,7 +252,7 @@ internal fun loadAppConfig(configFile: File = AppPaths.DEFAULT_CONFIG_APPLICATIO
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
internal fun loadBotConfig(botConfigFile: File = AppPaths.DEFAULT_CONFIG_BOT.file): Set<BotConfig>? {
|
internal fun loadBotConfig(botConfigFile: File = AppPaths.CONFIG_BOT.file): Set<BotConfig>? {
|
||||||
try {
|
try {
|
||||||
botConfigFile.bufferedReader(StandardCharsets.UTF_8).use {
|
botConfigFile.bufferedReader(StandardCharsets.UTF_8).use {
|
||||||
return GsonConst.botConfigGson.fromJson(it, object : TypeToken<Set<BotConfig>>() {}.type)!!
|
return GsonConst.botConfigGson.fromJson(it, object : TypeToken<Set<BotConfig>>() {}.type)!!
|
||||||
|
Loading…
Reference in New Issue
Block a user