Skip to content

Commit

Permalink
'下次一定随手commit,修复mcl无法启动的问题'
Browse files Browse the repository at this point in the history
  • Loading branch information
EricTianC committed Mar 7, 2021
1 parent 0750d77 commit 808ea7c
Show file tree
Hide file tree
Showing 8 changed files with 71 additions and 23 deletions.
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -6,8 +6,8 @@
## 用法
1. 前往[release][release]处下载符合你操作系统的可执行程序
2. 把它放在你希望自动配置的目录,配置的环境将在`.env`文件夹下,请提前确认磁盘上是否有足够空间
3. windows下直接双击即可,如果从命令行启动,所有参数将传给mcl
3. windows下直接双击即可,如果从命令行启动,所有参数将传给`mcl`


[release]: https://github.com/EricTianC/GraiaOk/releases
[Graia]: https://github.com/GraiaProject/Application
[Graia]: https://github.com/GraiaProject/Application
14 changes: 12 additions & 2 deletions environment/environment.go
Expand Up @@ -136,11 +136,21 @@ func (es *EnvSpace) Envs() []string {
return envs
}

//查找指定SimEnv
func (es *EnvSpace) FindSimEnv(name string) (SimEnv, error) {
for _, se := range es.EnvList {
if se.Name == name {
return se, nil
}
}
return *&SimEnv{}, fmt.Errorf("未找到")
}

func yesorNot(question string, defau bool) bool {
if defau == false {
fmt.Print(question + "[y/n](默认n):")
fmt.Print(question + "([y]/n):")
} else {
fmt.Print(question + "[y/n]:")
fmt.Print(question + "(y/[n]):")
}
var opt string
for {
Expand Down
15 changes: 15 additions & 0 deletions environment/environment_test.go
@@ -0,0 +1,15 @@
package environment

import (
"testing"
)

func TestCheckJava(t *testing.T) {
es := NewEnvSpace()
javaExists := make(chan bool)
es.CheckJava(javaExists)
_, err := es.FindSimEnv("Java")
if err != nil {
t.Error("并没有JavaSimEnv")
}
}
31 changes: 19 additions & 12 deletions environment/mcl.go
Expand Up @@ -6,7 +6,6 @@ import (
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
"sync"

Expand Down Expand Up @@ -77,20 +76,28 @@ func (es *EnvSpace) MclCommand(args []string) *exec.Cmd {
} else {
args = append([]string{"-jar", mclse.ExecName}, args...)
}
cmd := exec.Command("java", args...)
javaSimEnv, err := es.FindSimEnv("Java")
var javaPath string
if err != nil {
javaPath, _ = exec.LookPath("Java")
} else {
javaPath = javaSimEnv.ExecPath
}
javaPath, _ = filepath.Abs(javaPath)
cmd := exec.Command(filepath.Join(javaPath, "java"), args...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
once.Do(func() {
var sep string //分隔符
switch runtime.GOOS {
case "windows":
sep = ";"
default:
sep = ":"
}
os.Setenv("PATH", os.Getenv("PATH")+strings.Join(es.Envs(), sep))
})
// once.Do(func() {
// var sep string //分隔符
// switch runtime.GOOS {
// case "windows":
// sep = ";"
// default:
// sep = ":"
// }
// os.Setenv("PATH", os.Getenv("PATH")+sep+strings.Join(es.Envs(), sep))
// })
cmd.Dir = filepath.Join(es.BasePath, mclse.BasePath)
return cmd
}
13 changes: 9 additions & 4 deletions environment/python.go
Expand Up @@ -28,8 +28,13 @@ var pyse = &SimEnv{

func (es *EnvSpace) CheckPython(pys chan<- bool) {
if pyse.IsInstalled() {
ver, _ := getPyVersion()
verNum, _ := strconv.ParseFloat(ver[:3], 32)
ver, err := getPyVersion()
if err != nil {
log.Printf("获取Python版本失败,请确认Python版本是否大于等于3.8")
}
verNum, _ := strconv.ParseFloat(ver[:3], 64)
// TODO: 截取前三个字符会出现3.10变成3.1的问题,但其实多截一位还是会有3.10 < 3.8的问题
//预计后面使用数据结构来表示版本
if verNum < 3.8 {
pys <- false
return
Expand All @@ -56,12 +61,12 @@ func (es *EnvSpace) DownloadPy(gwg *sync.WaitGroup, javacomplete <-chan struct{}
downloadPyLinux()
} else {
<-javacomplete
log.Print("您的系统暂不支持,请手动配置Python3.8以上版本(含3.8)")
log.Print("您的系统暂不支持自动配置,请手动配置Python3.8以上版本(含3.8)")
}
}

func downloadPyLinux() {
log.Println()
log.Println("")
}

func downloadPyWindows(es *EnvSpace) {
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Expand Up @@ -14,4 +14,6 @@ require (
github.com/qianlnk/to v0.0.0-20191230085244-91e712717368 // indirect
github.com/ulikunitz/xz v0.5.7 // indirect
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 // indirect
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect
)
10 changes: 8 additions & 2 deletions go.sum
Expand Up @@ -35,9 +35,15 @@ github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8 h1:nIPpBwaJSVYIxUFsDv3M8ofm
github.com/xi2/xz v0.0.0-20171230120015-48954b6210f8/go.mod h1:HUYIGzjTL3rfEspMxjDjgmT5uz5wzYJKVo23qUhYTos=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2 h1:CCH4IOTTfewWjGOlSp+zGcjutRKlBEZQ6wTn8ozI/nI=
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 h1:go1bK/D/BFZV2I8cIQd1NKEZ+0owSTG1fDTci4IqFcE=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
5 changes: 4 additions & 1 deletion main.go
Expand Up @@ -13,7 +13,10 @@ func main() {

//go func() {
mcl := globalES.MclCommand(nil)
mcl.Run()
err := mcl.Run()
if err != nil {
panic(err)
}
//}()

// go func() {
Expand Down

0 comments on commit 808ea7c

Please sign in to comment.