mirror of
https://github.com/LamGC/ScalaBot.git
synced 2025-04-29 22:27:31 +00:00
refactor(launch): 更改初始化配置中, 退出进程的时机.
为了能在单元测试中检查 initialFiles 是否正常, 故将 exitProcess 移到 main 方法中, 方便进行测试.
This commit is contained in:
parent
7f7b2b8895
commit
8c4e48e3eb
@ -18,7 +18,6 @@ import java.net.URL
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.concurrent.atomic.AtomicBoolean
|
||||
import java.util.concurrent.atomic.AtomicInteger
|
||||
import kotlin.system.exitProcess
|
||||
|
||||
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()
|
||||
&& !AppPaths.CONFIG_BOT.file.exists()
|
||||
|
||||
@ -217,8 +221,9 @@ internal fun initialFiles() {
|
||||
|
||||
if (configFilesNotInitialized) {
|
||||
log.warn { "配置文件已初始化, 请根据需要修改配置文件后重新启动本程序." }
|
||||
exitProcess(1)
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
internal object GsonConst {
|
||||
|
@ -30,7 +30,9 @@ fun main(args: Array<String>): Unit = runBlocking {
|
||||
log.info { "ScalaBot 正在启动中..." }
|
||||
log.info { "数据目录: ${AppPaths.DATA_ROOT}" }
|
||||
log.debug { "启动参数: ${args.joinToString(prefix = "[", postfix = "]")}" }
|
||||
initialFiles()
|
||||
if (initialFiles()) {
|
||||
exitProcess(1)
|
||||
}
|
||||
|
||||
val launcher = Launcher()
|
||||
.registerShutdownHook()
|
||||
|
Loading…
Reference in New Issue
Block a user