From b250092e4ebb97b3883c9a5ee80ea70b17e50113 Mon Sep 17 00:00:00 2001 From: Him188 Date: Wed, 3 Feb 2021 15:46:35 +0800 Subject: [PATCH] Prefer device.json and auto-rename from deviceInfo.json --- backend/mirai-console/src/MiraiConsole.kt | 25 ++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/backend/mirai-console/src/MiraiConsole.kt b/backend/mirai-console/src/MiraiConsole.kt index a00edbc29..2f7b9eddd 100644 --- a/backend/mirai-console/src/MiraiConsole.kt +++ b/backend/mirai-console/src/MiraiConsole.kt @@ -148,15 +148,26 @@ public interface MiraiConsole : CoroutineScope { mainLogger.verbose { "Bot $id working in $workingDir" } - // copy root/device.json to bots/id/deviceInfo.json - val deviceInfoInRoot = MiraiConsole.rootDir.resolve("device.json") - val deviceInfoTarget = workingDir.resolve("deviceInfo.json") - if (deviceInfoInRoot.isFile && !deviceInfoTarget.isFile) { - mainLogger.verbose { "Coping $deviceInfoInRoot to $deviceInfoTarget" } - deviceInfoInRoot.copyTo(deviceInfoTarget) + val deviceInRoot = MiraiConsole.rootDir.resolve("device.json") + val deviceInWorkingDir = workingDir.resolve("device.json") + + val deviceInfoInWorkingDir = workingDir.resolve("deviceInfo.json") + if (!deviceInWorkingDir.exists()) { + 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() this.botLoggerSupplier = {