Skip to content

Commit

Permalink
mcl自动处理并不稳定
Browse files Browse the repository at this point in the history
  • Loading branch information
EricTianC committed Feb 22, 2021
1 parent 54f6b74 commit 8dbd8f6
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 40 deletions.
1 change: 1 addition & 0 deletions download/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
下载相关
1 change: 1 addition & 0 deletions environment/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
环境处理相关
45 changes: 11 additions & 34 deletions environment/mcl.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package environment

import (
"bufio"
"fmt"
"log"
"os"
"os/exec"
"path/filepath"
Expand Down Expand Up @@ -56,41 +56,16 @@ func (es *EnvSpace) CheckMcl() error {

func firstRunMcl(es *EnvSpace) error {
cmd := es.MclCommand(nil)
stdin, err := cmd.StdinPipe()
if err != nil {
return err
}
stdout, err := cmd.StdoutPipe()
if err != nil {
return err
}
cmd.Stderr = os.Stderr
err = cmd.Start()
if err != nil {
return err
}
finished := make(chan struct{})
go func() {
scanner := bufio.NewScanner(stdout)
for scanner.Scan() {
text := scanner.Text()
if strings.Contains(text, "mirai-console started successfully.") {
finished <- struct{}{}
}
fmt.Println(text)
}
}()
go func() {
defer stdin.Close()
<-finished
stdin.Write([]byte("stop\n"))
}()
cmd.Wait()

//因mcl原因无法获取
//stdin, err := cmd.StdinPipe()
//if err != nil {
// return fmt.Errorf("获取Stdin管道错误:%v", err)
//}
log.Println("请在mcl自动下载完毕后手动输入stop并回车,后面会自动配置mah")
cmd.Run()
mahargs := strings.Split("--update-package net.mamoe:mirai-api-http --channel stable --type plugin", " ")
cmd = es.MclCommand(mahargs)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
return nil
}
Expand All @@ -104,6 +79,8 @@ func (es *EnvSpace) MclCommand(args []string) *exec.Cmd {
}
cmd := exec.Command("java", args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
once.Do(func() {
var sep string //分隔符
switch runtime.GOOS {
Expand Down
3 changes: 2 additions & 1 deletion environment/python.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package environment
import (
"fmt"
"log"
"os"
"os/exec"
"path"
"path/filepath"
Expand Down Expand Up @@ -76,7 +77,7 @@ func downloadPyWindows(es *EnvSpace) {
cmd := exec.Command("./"+name, "/passive", "TargetDir="+targetDir, "PrependPath=1")
cmd.Run()
pyse.LookForExecFileinSpace(es)

os.Remove(name)
}

func getPyVersion() (string, error) {
Expand Down
5 changes: 0 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package main

import (
"os"

env "github.com/EricTianC/GraiaOK/environment"
)

Expand All @@ -15,9 +13,6 @@ func main() {

go func() {
mcl := globalES.MclCommand(nil)
mcl.Stdin = os.Stdin
mcl.Stdout = os.Stdout
mcl.Stderr = os.Stderr
mcl.Run()
}()

Expand Down

0 comments on commit 8dbd8f6

Please sign in to comment.