فهرست منبع

move nameFolder under config folder to idFolder, untested

Eritque arcus 4 سال پیش
والد
کامیت
7d5bd4564e

+ 26 - 18
mirai-console/backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt

@@ -26,6 +26,7 @@ import net.mamoe.mirai.console.util.CoroutineScopeUtils.childScope
 import net.mamoe.mirai.utils.MiraiLogger
 import net.mamoe.mirai.utils.verbose
 import java.io.File
+import java.nio.file.Path
 import java.util.concurrent.ConcurrentHashMap
 
 internal object BuiltInJvmPluginLoaderImpl :
@@ -98,28 +99,16 @@ internal object BuiltInJvmPluginLoaderImpl :
 
     private val loadedPlugins = ConcurrentHashMap<JvmPlugin, Unit>()
 
-    @Throws(PluginLoadException::class)
-    override fun load(plugin: JvmPlugin) {
-        ensureActive()
-
-        if (loadedPlugins.put(plugin, Unit) != null) {
-            error("Plugin '${plugin.name}' is already loaded and cannot be reloaded.")
-        }
-        logger.verbose { "Loading plugin ${plugin.description.smartToString()}" }
-        runCatching {
-            check(plugin is JvmPluginInternal) { "A JvmPlugin must extend AbstractJvmPlugin to be loaded by JvmPluginLoader.BuiltIn" }
-            plugin.internalOnLoad()
-        }.getOrElse {
-            throw PluginLoadException("Exception while loading ${plugin.description.smartToString()}", it)
-        }
-        val nameFolder = PluginManager.pluginsDataPath.resolve(plugin.description.name).toFile()
+    private fun Path.moveNameFolder(plugin: JvmPlugin) {
+        val nameFolder = this.resolve(plugin.description.name).toFile()
         if (plugin.description.name != plugin.description.id && nameFolder.exists()) {
             // need move
-            val idFolder = PluginManager.pluginsDataPath.resolve(plugin.description.id).toFile()
-            val moveDescription = "移动 ${plugin.description.smartToString()} 的配置目录(${nameFolder.path})到 ${idFolder.path}"
+            val idFolder = this.resolve(plugin.description.id).toFile()
+            val moveDescription =
+                "移动 ${plugin.description.smartToString()} 的数据文件目录(${nameFolder.path})到 ${idFolder.path}"
             if (idFolder.exists()) {
                 if (idFolder.listFiles()?.size != 0) {
-                    logger.error("$moveDescription 失败, 原因:配置目录(${idFolder.path})被占用")
+                    logger.error("$moveDescription 失败, 原因:数据文件目录(${idFolder.path})被占用")
                     logger.error("Mirai Console 将自动关闭, 请删除或移动该目录后再启动")
                     MiraiConsole.job.cancel()
                 } else
@@ -141,6 +130,25 @@ internal object BuiltInJvmPluginLoaderImpl :
         }
     }
 
+    @Throws(PluginLoadException::class)
+    override fun load(plugin: JvmPlugin) {
+        ensureActive()
+
+        if (loadedPlugins.put(plugin, Unit) != null) {
+            error("Plugin '${plugin.name}' is already loaded and cannot be reloaded.")
+        }
+        logger.verbose { "Loading plugin ${plugin.description.smartToString()}" }
+        runCatching {
+            check(plugin is JvmPluginInternal) { "A JvmPlugin must extend AbstractJvmPlugin to be loaded by JvmPluginLoader.BuiltIn" }
+            plugin.internalOnLoad()
+        }.getOrElse {
+            throw PluginLoadException("Exception while loading ${plugin.description.smartToString()}", it)
+        }
+        // move nameFolder in config and data to idFolder
+        PluginManager.pluginsDataPath.moveNameFolder(plugin)
+        PluginManager.pluginsConfigPath.moveNameFolder(plugin)
+    }
+
     override fun enable(plugin: JvmPlugin) {
         if (plugin.isEnabled) error("Plugin '${plugin.name}' is already enabled and cannot be re-enabled.")
         ensureActive()

+ 1 - 1
mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt

@@ -76,7 +76,7 @@ internal abstract class JvmPluginInternal(
     }
 
     final override val configFolderPath: Path by lazy {
-        PluginManager.pluginsConfigPath.resolve(description.name).apply { mkdir() }
+        PluginManager.pluginsConfigPath.resolve(description.id).apply { mkdir() }
     }
 
     final override val configFolder: File by lazy {