-
Notifications
You must be signed in to change notification settings - Fork 2
/
rabbitRPA.go
107 lines (86 loc) · 1.99 KB
/
rabbitRPA.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
package main
import (
"fmt"
"io/ioutil"
"os"
"os/exec"
"strings"
"github.com/rakyll/statik/fs"
_ "github.com/yasutakatou/rabbitRPA/statik"
//_ "./statik"
)
//FYI: https://journal.lampetty.net/entry/capturing-stdout-in-golang
type Capturer struct {
saved *os.File
bufferChannel chan string
out *os.File
in *os.File
}
func main() {
Debug := false
args := ""
for i, v := range os.Args {
if strings.Index(v, "-debug") != -1 {
Debug = true
}
if i > 0 {
args += v + " "
}
}
checkExeDlls()
if Debug == true {
fmt.Println("launch> do.exe " + args)
}
Execmd("do.exe " + args)
os.Exit(0)
}
func Execmd(command string) {
cmd := exec.Command("cmd", "/C", command)
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Stdin = os.Stdin
cmd.Run()
}
func Exists(filename string) bool {
_, err := os.Stat(filename)
return err == nil
}
//statik -src=./ -include=*.dll,*.exe
func checkExeDlls() {
exeDlls := []string{"do.exe", "libopencv_calib3d430.dll", "libopencv_core430.dll", "libopencv_dnn430.dll", "libopencv_features2d430.dll",
"libopencv_flann430.dll", "libopencv_highgui430.dll", "libopencv_imgcodecs430.dll", "libopencv_imgproc430.dll",
"libopencv_objdetect430.dll", "libopencv_video430.dll", "libopencv_videoio430.dll"}
for i := 0; i < len(exeDlls); i++ {
if Exists(exeDlls[i]) == false {
if makeFile(exeDlls[i]) == false {
fmt.Println("create failure: ", exeDlls[i])
os.Exit(1)
}
}
}
}
func makeFile(filename string) bool {
statikFS, err := fs.New()
if err != nil {
return false
}
r, err := statikFS.Open("/" + filename)
if err != nil {
return false
}
defer r.Close()
contents, err := ioutil.ReadAll(r)
if err != nil {
return false
}
file, err := os.Create(filename)
defer file.Close()
if err != nil {
return false
}
_, err = file.Write(contents)
if err != nil {
return false
}
return true
}