Merge remote-tracking branch 'origin/master'

# Conflicts:
#	buildSrc/src/main/kotlin/versions.kt
This commit is contained in:
Him188 2020-05-06 14:41:57 +08:00
commit e813b27227
6 changed files with 63 additions and 16 deletions

View File

@ -28,7 +28,9 @@ Mirai 是一个在全平台下运行,提供 QQ Android 和 TIM PC 协议支持
**[下载(download)](https://github.com/mamoe/mirai-console/releases)**
请下载最新的 `mirai-console-wrapper-x.x.x-all.jar`
你也可以下载这里的一键安装包来快速启动mirai-console **[下载地址](https://suihou-my.sharepoint.com/:f:/g/personal/user18_5tb_site/ErWGr97FpPVDjkboIDmDAJkBID-23ZMNbTPggGajf1zvGw?e=51NZWM)**
#### 对于Windows用户
你可以下载这里的一键安装包来快速启动mirai-console这是最简单的方法 **[下载地址](https://suihou-my.sharepoint.com/:f:/g/personal/user18_5tb_site/ErWGr97FpPVDjkboIDmDAJkBID-23ZMNbTPggGajf1zvGw?e=51NZWM)**
**请注意**
* 使用时请留意安装包里的说明文字
@ -36,6 +38,10 @@ Mirai 是一个在全平台下运行,提供 QQ Android 和 TIM PC 协议支持
* 关于安装包本身的一切问题请到QQ群内反馈
* 如果上面的链接下载过慢你可以到QQ群内高速下载
#### 对于Linux用户
运行本软件需要openjdk11请在上面的链接下载`mirai-console-wrapper-x.x.x-all.jar`直接运行即可
#### 如何启动
如果是打包好的软件, 双击<br>
如果是命令行运行, 请注意运行目录, 推荐cd到jar的文件夹下运行, 运行目录与Console的全部配置文件储存位置有关

View File

@ -12,7 +12,7 @@ import org.gradle.kotlin.dsl.DependencyHandlerScope
object Versions {
object Mirai {
const val core = "1.0-RC"
const val console = "0.4.11"
const val console = "0.5.0"
const val consoleGraphical = "0.0.7"
const val consoleWrapper = "1.0.0"
}

View File

@ -55,7 +55,7 @@ object MiraiConsole {
/**
* Console运行路径
*/
var path: String = System.getProperty("user.dir")
lateinit var path: String
internal set
/**
@ -68,19 +68,47 @@ object MiraiConsole {
private var started = false
@Deprecated("for binary compatibility", level = DeprecationLevel.HIDDEN)
@Suppress("FunctionName")
@JvmSynthetic
@JvmStatic
fun /* synthetic */`start$default`(
miraiConsole: MiraiConsole,
miraiConsoleUI: MiraiConsoleUI?,
string: String?,
string2: String?,
n: Int,
@Suppress("UNUSED_PARAMETER") `object`: Any?
) {
@Suppress("NAME_SHADOWING")
var string = string
@Suppress("NAME_SHADOWING")
var string2 = string2
if (n and 2 != 0) {
string = "0.0.0"
}
if (n and 4 != 0) {
string2 = "0.0.0"
}
miraiConsole.start(miraiConsoleUI!!, string!!, string2!!)
}
/**
* 启动Console
*/
@JvmOverloads
fun start(
frontEnd: MiraiConsoleUI,
coreVersion: String = "0.0.0",
consoleVersion: String = "0.0.0"
consoleVersion: String = "0.0.0",
path:String = System.getProperty("user.dir")
) {
if (started) {
return
}
started = true
this.path = path
/* 初始化前端 */
this.version = consoleVersion
this.frontEnd = frontEnd

View File

@ -39,7 +39,7 @@ object DefaultCommands {
try {
MiraiConsole.frontEnd.prePushBot(account)
val bot = Bot(account, password) {
fileBasedDeviceInfo()
fileBasedDeviceInfo(MiraiConsole.path + "/device.json")
this.loginSolver = MiraiConsole.frontEnd.createLoginSolver()
this.botLoggerSupplier = {
SimpleLogger("BOT $account]") { _, message, e ->

View File

@ -29,7 +29,7 @@ import java.util.jar.JarFile
object PluginManager {
internal val pluginsPath = (System.getProperty("user.dir") + "/plugins/").replace("//", "/").also {
internal val pluginsPath = (MiraiConsole.path + "/plugins/").replace("//", "/").also {
File(it).mkdirs()
}
@ -372,6 +372,7 @@ object PluginManager {
return null
}
/**
* 根据插件名字找Jar中的文件
* null => 没找到

View File

@ -103,15 +103,25 @@ internal class PluginClassLoader(
files: File,
private val pluginsLoader: PluginsLoader,
parent: ClassLoader
) :
URLClassLoader(arrayOf((files.toURI().toURL())), parent) {
) {
private val classesCache = mutableMapOf<String, Class<*>?>()
private var classLoader: ClassLoader
override fun findClass(name: String): Class<*>? {
return this.findClass(name, true)
init {
classLoader = try {
//兼容Android
val loaderClass = Class.forName("dalvik.system.PathClassLoader")
loaderClass.getConstructor(String::class.java, ClassLoader::class.java)
.newInstance(files.absolutePath, parent) as ClassLoader
} catch (e: ClassNotFoundException) {
URLClassLoader(arrayOf((files.toURI().toURL())), parent)
}
}
fun findClass(name: String, isSearchDependent: Boolean): Class<*>? {
fun loadClass(className: String): Class<*> = classLoader.loadClass(className)!!
fun findClass(name: String, isSearchDependent: Boolean = true): Class<*>? {
var clz: Class<*>? = null
// 缓存中找
if (classesCache.containsKey(name)) {
@ -122,9 +132,9 @@ internal class PluginClassLoader(
if (isSearchDependent) {
clz = pluginsLoader.loadDependentClass(name)
}
// 交给super去findClass
// 好像没有findClass直接load
if (clz == null) {
clz = super.findClass(name)
clz = classLoader.loadClass(name)
}
// 加入缓存
if (clz != null) {
@ -137,8 +147,10 @@ internal class PluginClassLoader(
return clz
}
override fun close() {
super.close()
fun close() {
if (classLoader is URLClassLoader) {
(classLoader as URLClassLoader).close()
}
classesCache.clear()
}
}