打包优化一下

This commit is contained in:
iguigui
2022-05-31 20:47:35 +08:00
parent d392e99a99
commit 303d52bed7
9 changed files with 69 additions and 32 deletions

View File

@@ -0,0 +1,18 @@
@echo off
cd /d %~dp0
set javaPath=%cd%
cd ..
::显示上级目录路径
::设置要临时加入到path环境变量中的路径
set My_PATH=%cd%
set PATH=%PATH%;%My_PATH%
cd javaPath
::下面写你其它脚本命令
java -jar .\Maa-HTTP-0.0.1.jar -port=8848
pause

17
src/Java/Maaj/Readme.md Normal file
View File

@@ -0,0 +1,17 @@
# Maa-HTTP接口实现
本项目为通过JNA(Java-Native-Access)调用Maa核心实现的HTTP+WebSocket接口实现.
## 环境依赖
1. JDK1.8 +
2. Maa v3.9.0-alpha +
## 如何编译
.\gradlew.bat jar
## 使用方法
1. 把他丢进
2. 双击Maa-HTTP-Server-startup.bat启动.
3. 默认端口号8848钛金端口.
4.

View File

@@ -61,7 +61,6 @@ tasks.jar {
val sourcesMain = sourceSets.main.get()
sourcesMain.allSource.forEach { println("add from sources: ${it.name}") }
from(sourcesMain.output)
}
launch4j {
@@ -86,3 +85,19 @@ tasks.register<edu.sc.seis.launch4j.tasks.Launch4jLibraryTask>("MyApp-memory") {
fileDescription = "The default implementation with increased heap size"
maxHeapPercent = 50
}
tasks.withType<JavaCompile> {
options.encoding = "UTF-8"
}
val compileKotlin: org.jetbrains.kotlin.gradle.tasks.KotlinCompile by tasks
compileKotlin.kotlinOptions {
jvmTarget = "1.8"
}
val compileTestKotlin: org.jetbrains.kotlin.gradle.tasks.KotlinCompile by tasks
compileTestKotlin.kotlinOptions {
jvmTarget = "1.8"
}

View File

@@ -25,7 +25,6 @@ fun Application.module() {
configure()
httpRouting()
wsRouting()
log.info("Maa HTTP Server 启动成功 ! ")
}

View File

@@ -38,7 +38,6 @@ fun Application.httpRouting() {
with(call.receive<SetTaskParamsRequest>()) {
val result = MaaService.setTaskParams(
id,
type,
taskId,
params.jsonObject.toString()
)

View File

@@ -51,7 +51,6 @@ fun Application.wsRouting() {
with(Json.decodeFromJsonElement(SetTaskParamsRequest.serializer(), wsRequest.data)) {
val result = MaaService.setTaskParams(
id,
type,
taskId,
params.jsonObject.toString()
)

View File

@@ -72,7 +72,7 @@ class MaaInstance(
fun appendTask(type: String, params: String) = instance.AsstAppendTask(pointer, type, params)
fun setTaskParams(type: String, taskId: Int, params: String) = instance.AsstSetTaskParams(pointer, taskId, params)
fun setTaskParams(taskId: Int, params: String) = instance.AsstSetTaskParams(pointer, taskId, params)
fun start(): Boolean {
msgId.set(0)
@@ -82,9 +82,4 @@ class MaaInstance(
fun stop() = instance.AsstStop(pointer)
fun destroy() = instance.AsstDestroy(pointer)
//todo
private fun addLog(callBackLog: CallBackLog) {
}
}

View File

@@ -2,17 +2,14 @@ package com.iguigui.maaj.service
import com.iguigui.maaj.dto.*
import com.iguigui.maaj.easySample.MeoAssistant
import com.iguigui.maaj.logger
import com.sun.jna.Native
import io.ktor.websocket.*
import kotlinx.coroutines.DelicateCoroutinesApi
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
import kotlinx.coroutines.runBlocking
import java.io.File
import java.security.MessageDigest
import java.util.*
import java.util.concurrent.ConcurrentHashMap
import kotlin.collections.LinkedHashSet
object MaaService {
@@ -22,10 +19,9 @@ object MaaService {
private val wsConnection = Collections.synchronizedSet<Connection?>(LinkedHashSet())
val meoAssistant: MeoAssistant by lazy {
val f = File(this.javaClass.getResource("")?.path ?: "")
var maaPath = f.path
println(maaPath)
maaPath = "C:\\Users\\atmzx\\Desktop\\MeoAssistantArknights3"
var maaPath = File(File("").absolutePath).parent
logger.info("maaPath $maaPath")
// maaPath = "C:\\Users\\atmzx\\Desktop\\MeoAssistantArknights3"
System.setProperty("jna.library.path", maaPath)
val load = Native.load("MeoAssistant", MeoAssistant::class.java)
load.AsstLoadResource(maaPath)
@@ -51,8 +47,8 @@ object MaaService {
instancePool[id]?.appendTask(type, detailJson) ?: 0
fun setTaskParams(id: String, type: String, taskId: Int, detailJson: String) =
instancePool[id]?.setTaskParams(type, taskId, detailJson) ?: false
fun setTaskParams(id: String, taskId: Int, detailJson: String) =
instancePool[id]?.setTaskParams(taskId, detailJson) ?: false
fun start(id: String) = instancePool[id]?.start() ?: false
@@ -85,9 +81,8 @@ object MaaService {
}
@OptIn(DelicateCoroutinesApi::class)
fun callBackLog(message: CallBackLog) {
GlobalScope.launch(Dispatchers.IO) {
runBlocking {
wsConnection.forEach { it.session.send(message.wapperToWsResponse("callBack", 0).toJsonString()) }
}
}

View File

@@ -13,15 +13,15 @@ import kotlin.test.Test
class HttpRoutingKtTest {
@Test
fun testGetApiV1Getversion() = testApplication {
application {
httpRouting()
}
client.get("/API/V1/getVersion").apply {
Assert.assertEquals(status,OK)
}
}
// @Test
// fun testGetApiV1Getversion() = testApplication {
// application {
// httpRouting()
// }
// client.get("/API/V1/getVersion").apply {
// Assert.assertEquals(status,OK)
// }
// }
//
// @Test
// fun testPostApiV1Connect() = testApplication {