From 27dc26160d960b76225d301fa10dae377621413e Mon Sep 17 00:00:00 2001 From: LamGC Date: Thu, 30 Jun 2022 00:15:07 +0800 Subject: [PATCH] =?UTF-8?q?refactor(config):=20=E5=AF=B9=E9=85=8D=E7=BD=AE?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E7=9A=84=20AppPath=20=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E6=9B=B4=E5=90=8D.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 先前为确保后续可以增加指定配置文件路径的功能, 在命名上标记的 DEFAULT 在现在已经不符合实际意义了, 故将 DEFAULT 前缀移除. --- scalabot-app/src/main/kotlin/AppConfigs.kt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/scalabot-app/src/main/kotlin/AppConfigs.kt b/scalabot-app/src/main/kotlin/AppConfigs.kt index af2ef67..a57b9b3 100644 --- a/scalabot-app/src/main/kotlin/AppConfigs.kt +++ b/scalabot-app/src/main/kotlin/AppConfigs.kt @@ -111,7 +111,7 @@ internal enum class AppPaths( } }), - DEFAULT_CONFIG_APPLICATION({ "$DATA_ROOT/config.json" }, { + CONFIG_APPLICATION({ "$DATA_ROOT/config.json" }, { if (!file.exists()) { file.bufferedWriter(StandardCharsets.UTF_8).use { 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()) { file.bufferedWriter(StandardCharsets.UTF_8).use { GsonConst.botConfigGson.toJson( @@ -172,7 +172,7 @@ internal enum class AppPaths( return path } - private object PathConst { + object PathConst { const val PROP_DATA_PATH = "bot.path.data" const val ENV_DATA_PATH = "BOT_DATA_PATH" } @@ -208,8 +208,8 @@ private fun AppPaths.defaultInitializer() { } internal fun initialFiles() { - val configFilesNotInitialized = !AppPaths.DEFAULT_CONFIG_APPLICATION.file.exists() - && !AppPaths.DEFAULT_CONFIG_BOT.file.exists() + val configFilesNotInitialized = !AppPaths.CONFIG_APPLICATION.file.exists() + && !AppPaths.CONFIG_BOT.file.exists() for (path in AppPaths.values()) { path.initial() @@ -241,7 +241,7 @@ private object GsonConst { .create() } -internal fun loadAppConfig(configFile: File = AppPaths.DEFAULT_CONFIG_APPLICATION.file): AppConfig { +internal fun loadAppConfig(configFile: File = AppPaths.CONFIG_APPLICATION.file): AppConfig { try { configFile.bufferedReader(StandardCharsets.UTF_8).use { 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? { +internal fun loadBotConfig(botConfigFile: File = AppPaths.CONFIG_BOT.file): Set? { try { botConfigFile.bufferedReader(StandardCharsets.UTF_8).use { return GsonConst.botConfigGson.fromJson(it, object : TypeToken>() {}.type)!!