Prefer device.json and auto-rename from deviceInfo.json

This commit is contained in:
Him188 2021-02-03 15:46:35 +08:00
parent a9ca815627
commit b250092e4e

View File

@ -148,15 +148,26 @@ public interface MiraiConsole : CoroutineScope {
mainLogger.verbose { "Bot $id working in $workingDir" } mainLogger.verbose { "Bot $id working in $workingDir" }
// copy root/device.json to bots/id/deviceInfo.json val deviceInRoot = MiraiConsole.rootDir.resolve("device.json")
val deviceInfoInRoot = MiraiConsole.rootDir.resolve("device.json") val deviceInWorkingDir = workingDir.resolve("device.json")
val deviceInfoTarget = workingDir.resolve("deviceInfo.json")
if (deviceInfoInRoot.isFile && !deviceInfoTarget.isFile) { val deviceInfoInWorkingDir = workingDir.resolve("deviceInfo.json")
mainLogger.verbose { "Coping $deviceInfoInRoot to $deviceInfoTarget" } if (!deviceInWorkingDir.exists()) {
deviceInfoInRoot.copyTo(deviceInfoTarget) when {
deviceInfoInWorkingDir.exists() -> {
// rename bots/id/deviceInfo.json to bots/id/device.json
mainLogger.verbose { "Renaming $deviceInfoInWorkingDir to $deviceInWorkingDir" }
deviceInfoInWorkingDir.renameTo(deviceInWorkingDir)
}
deviceInRoot.exists() -> {
// copy root/device.json to bots/id/device.json
mainLogger.verbose { "Coping $deviceInRoot to $deviceInWorkingDir" }
deviceInRoot.copyTo(deviceInWorkingDir)
}
}
} }
fileBasedDeviceInfo("deviceInfo.json") fileBasedDeviceInfo("device.json")
redirectNetworkLogToDirectory() redirectNetworkLogToDirectory()
this.botLoggerSupplier = { this.botLoggerSupplier = {