-
Notifications
You must be signed in to change notification settings - Fork 0
/
tool.go
127 lines (114 loc) · 3 KB
/
tool.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
package tool
import (
"errors"
"fmt"
"github.com/gookit/color"
"github.com/gookit/goutil/sysutil"
"github.com/hashicorp/go-version"
"os"
"runtime"
"strings"
"time"
)
// CheckGo check golang
func CheckGo() bool {
var Outgo, err = sysutil.QuickExec("go version")
if err != nil {
ErrorPrint("Unable to find Go")
return false
}
te := strings.Split(Outgo, " ")
Vergo, err := version.NewVersion(te[2][2:])
if err != nil {
ErrorPrint("Error go version:" + te[2][2:])
return false
}
constraints, err := version.NewConstraint(">=1.15")
if constraints.Check(Vergo) != true {
return false
}
return true
}
// IsEbitenGame check ebitengine game project
func IsEbitenGame() (ebitengame bool, gomod bool) {
var Versions string
f, err := os.ReadFile("./go.mod")
if err != nil {
f2, err := os.ReadFile("./main.go")
for _, v := range strings.Split(string(f2), "\n") {
if strings.Contains(v, "github.com/hajimehoshi/ebiten/v2") {
Versions = "2.x"
}
}
if err != nil {
WarnPrint("No Ebitengine project in the dir.")
return false, false
}
}
for _, v := range strings.Split(string(f), "\n") {
if strings.Contains(v, "github.com/hajimehoshi/ebiten/v2") {
Versions = v[strings.LastIndex(v, "v2")+1:]
}
}
if Versions == "" {
return false, false
}
//DebugPrint(fmt.Sprintf("ebiten version=%v", Versions))
if Versions == "2.x" {
return true, false
}
return true, true
}
// GetEbitenVer Get Ebitengine version
func GetEbitenVer() (string, error) {
var Versions string
f, err := os.ReadFile("./go.mod")
if err != nil {
f2, err := os.ReadFile("./main.go")
for _, v := range strings.Split(string(f2), "\n") {
if strings.Contains(v, "github.com/hajimehoshi/ebiten/v2") {
Versions = "2.x"
}
}
if err != nil {
return "", errors.New("no Ebitengine project in the dir")
}
}
for _, v := range strings.Split(string(f), "\n") {
if strings.Contains(v, "github.com/hajimehoshi/ebiten/v2") {
Versions = v[strings.LastIndex(v, "v2")+1:]
}
}
if Versions == "" {
return "", errors.New("unable to locate ebitengine version number")
}
DebugPrint(fmt.Sprintf("ebiten version=%v", Versions))
return Versions, nil
}
func DebugPrint(s interface{}) {
if DebugMode {
color.Debug.Printf("[Debug]%s: %v \n", time.Now().Format("2006/01/02 15:04:05.000"), s)
}
}
func InfoPrint(s interface{}) {
color.Info.Printf("[Info]%s: %v \n", time.Now().Format("2006/01/02 15:04:05.000"), s)
}
func ErrorPrint(s interface{}) {
color.Error.Printf("[Error]%s: %v \n", time.Now().Format("2006/01/02 15:04:05.000"), s)
}
func StepPrint(s interface{}) {
color.FgMagenta.Printf("[Step]%s: %v \n", time.Now().Format("2006/01/02 15:04:05.000"), s)
}
func SuccessPrint(s interface{}) {
color.Success.Printf("[Success]%s: %v \n", time.Now().Format("2006/01/02 15:04:05.000"), s)
}
func WarnPrint(s interface{}) {
color.Warn.Printf("[Warn]%s: %v \n", time.Now().Format("2006/01/02 15:04:05.000"), s)
}
func ExecName(s string) string {
switch runtime.GOOS {
case `windows`:
s = s + ".exe"
}
return s
}