refactor(launch): 更改初始化配置中, 退出进程的时机.

为了能在单元测试中检查 initialFiles 是否正常, 故将 exitProcess 移到 main 方法中, 方便进行测试.
This commit is contained in:
LamGC 2022-07-12 00:27:18 +08:00
parent 7f7b2b8895
commit 8c4e48e3eb
Signed by: LamGC
GPG Key ID: 6C5AE2A913941E1D
2 changed files with 11 additions and 4 deletions

View File

@ -18,7 +18,6 @@ import java.net.URL
import java.nio.charset.StandardCharsets import java.nio.charset.StandardCharsets
import java.util.concurrent.atomic.AtomicBoolean import java.util.concurrent.atomic.AtomicBoolean
import java.util.concurrent.atomic.AtomicInteger import java.util.concurrent.atomic.AtomicInteger
import kotlin.system.exitProcess
private val log = KotlinLogging.logger { } private val log = KotlinLogging.logger { }
@ -207,7 +206,12 @@ private fun AppPaths.defaultInitializer() {
} }
} }
internal fun initialFiles() { /**
* 执行 AppPaths 所有项目的初始化, 并检查是否停止运行, 让用户编辑配置.
*
* @return 如果需要让用户编辑配置, 则返回 `true`.
*/
internal fun initialFiles(): Boolean {
val configFilesNotInitialized = !AppPaths.CONFIG_APPLICATION.file.exists() val configFilesNotInitialized = !AppPaths.CONFIG_APPLICATION.file.exists()
&& !AppPaths.CONFIG_BOT.file.exists() && !AppPaths.CONFIG_BOT.file.exists()
@ -217,8 +221,9 @@ internal fun initialFiles() {
if (configFilesNotInitialized) { if (configFilesNotInitialized) {
log.warn { "配置文件已初始化, 请根据需要修改配置文件后重新启动本程序." } log.warn { "配置文件已初始化, 请根据需要修改配置文件后重新启动本程序." }
exitProcess(1) return true
} }
return false
} }
internal object GsonConst { internal object GsonConst {

View File

@ -30,7 +30,9 @@ fun main(args: Array<String>): Unit = runBlocking {
log.info { "ScalaBot 正在启动中..." } log.info { "ScalaBot 正在启动中..." }
log.info { "数据目录: ${AppPaths.DATA_ROOT}" } log.info { "数据目录: ${AppPaths.DATA_ROOT}" }
log.debug { "启动参数: ${args.joinToString(prefix = "[", postfix = "]")}" } log.debug { "启动参数: ${args.joinToString(prefix = "[", postfix = "]")}" }
initialFiles() if (initialFiles()) {
exitProcess(1)
}
val launcher = Launcher() val launcher = Launcher()
.registerShutdownHook() .registerShutdownHook()