forked from LXY1226/MiraiOK
-
Notifications
You must be signed in to change notification settings - Fork 0
/
checkJRE.go
53 lines (49 loc) · 984 Bytes
/
checkJRE.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//+build !386
package main
import (
"bytes"
"gitee.com/LXY1226/logging"
"os/exec"
"strings"
)
func checkJava() {
//检测本地java
if checkJavaBin() {
return
}
f, err := exec.LookPath("java")
if err == nil {
javaPath = f
if checkJavaBin() {
return
}
}
logging.INFO("未发现JRE,准备下载...")
global.Add(1)
go func() {
if unpackRAR(downFile("mirai-repo/shadow/jre-" + logging.RTStr + ".rar")) {
if checkJavaBin() {
global.Done()
return
}
}
logging.FATAL("无法获取JRE,即将退出...")
panic("error in gathering JRE")
}()
}
func checkJavaBin() bool {
var stdo bytes.Buffer
logging.DEBUG("Trying Locating JRE:", javaPath)
cmd := exec.Command(javaPath, "-version")
cmd.Stdout = &stdo
cmd.Stderr = &stdo
err := cmd.Run()
if err != nil {
return false
}
for str, err := stdo.ReadString('\n'); err == nil; {
logging.INFO("JRE:", strings.TrimRight(str, "\r\n"))
str, err = stdo.ReadString('\n')
}
return true
}