From 7d5bd4564e2fe2dd9fdd6903cd2fffb098746f2b Mon Sep 17 00:00:00 2001 From: Eritque arcus <1930893235@qq.com> Date: Thu, 16 Dec 2021 10:14:43 +0800 Subject: [PATCH] move nameFolder under config folder to idFolder, untested --- .../plugin/BuiltInJvmPluginLoaderImpl.kt | 44 +++++++++++-------- .../src/internal/plugin/JvmPluginInternal.kt | 2 +- 2 files changed, 27 insertions(+), 19 deletions(-) diff --git a/mirai-console/backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt b/mirai-console/backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt index 37a9047be..d4ec87650 100644 --- a/mirai-console/backend/mirai-console/src/internal/plugin/BuiltInJvmPluginLoaderImpl.kt +++ b/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() - @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() diff --git a/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt b/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt index d68e57689..dfebc38fb 100644 --- a/mirai-console/backend/mirai-console/src/internal/plugin/JvmPluginInternal.kt +++ b/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 {