Skip to content

Commit bd2d7e6

Browse files
committed
[WIN] Add dialog before drivers installation
1 parent 11edf17 commit bd2d7e6

File tree

4 files changed

+46
-15
lines changed

4 files changed

+46
-15
lines changed

tools/download.go

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ type index struct {
5353
var systems = map[string]string{
5454
"linuxamd64": "x86_64-linux-gnu",
5555
"linux386": "i686-linux-gnu",
56-
"darwinamd64": "i386-apple-darwin11",
56+
"darwinamd64": "apple-darwin",
5757
"windows386": "i686-mingw32",
5858
}
5959

@@ -71,15 +71,13 @@ func checkGPGSig(fileName string, sigFileName string) error {
7171
if err != nil {
7272
return err
7373
}
74-
7574
defer sigFile.Close()
7675

7776
// Get a Reader for the signature file
7877
file, err := os.Open(fileName)
7978
if err != nil {
8079
return err
8180
}
82-
8381
defer file.Close()
8482

8583
publicKeyBin, err := hex.DecodeString(publicKeyHex)
@@ -179,7 +177,7 @@ func (t *Tools) Download(name, version, behaviour string) error {
179177

180178
// Find the url based on system
181179
var correctSystem system
182-
max_similarity := 0.8
180+
max_similarity := 0.7
183181

184182
for _, s := range correctTool.Systems {
185183
similarity := smetrics.Jaro(s.Host, systems[runtime.GOOS+runtime.GOARCH])
@@ -252,7 +250,10 @@ func (t *Tools) Download(name, version, behaviour string) error {
252250
return err
253251
}
254252

255-
t.installDrivers(location)
253+
err = t.installDrivers(location)
254+
if err != nil {
255+
return err
256+
}
256257

257258
// Ensure that the files are executable
258259
t.Logger.Println("Ensure that the files are executable")
@@ -411,10 +412,9 @@ func extractTarGz(body []byte, location string) (string, error) {
411412
}
412413

413414
file, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode())
414-
if err != nil {
415-
//return location, err
415+
if err == nil {
416+
defer file.Close()
416417
}
417-
defer file.Close()
418418
_, err = io.Copy(file, tarReader)
419419
if err != nil {
420420
//return location, err
@@ -423,15 +423,26 @@ func extractTarGz(body []byte, location string) (string, error) {
423423
return location, nil
424424
}
425425

426-
func (t *Tools) installDrivers(location string) {
426+
func (t *Tools) installDrivers(location string) error {
427427
if runtime.GOOS == "windows" {
428428
if _, err := os.Stat(filepath.Join(location, "post_install.bat")); err == nil {
429429
t.Logger.Println("Installing drivers")
430-
oscmd := exec.Command(filepath.Join(location, "post_install.bat"))
431-
TellCommandNotToSpawnShell(oscmd)
432-
oscmd.Run()
430+
ok := MessageBox("Installing drivers", "We are about to install some drivers needed to use Arduino/Genuino boards\nDo you want to continue?")
431+
t.Logger.Println(ok)
432+
if ok == 6 {
433+
os.Chdir(location)
434+
oscmd := exec.Command("post_install.bat")
435+
TellCommandNotToSpawnShell(oscmd)
436+
t.Logger.Println(oscmd)
437+
err = oscmd.Run()
438+
t.Logger.Println(err)
439+
return err
440+
} else {
441+
return errors.New("Could not install drivers")
442+
}
433443
}
434444
}
445+
return nil
435446
}
436447

437448
func extractBz2(body []byte, location string) (string, error) {
@@ -479,10 +490,9 @@ func extractBz2(body []byte, location string) (string, error) {
479490
}
480491

481492
file, err := os.OpenFile(path, os.O_CREATE|os.O_TRUNC|os.O_WRONLY, info.Mode())
482-
if err != nil {
483-
//return location, err
493+
if err == nil {
494+
defer file.Close()
484495
}
485-
defer file.Close()
486496
_, err = io.Copy(file, tarReader)
487497
if err != nil {
488498
//return location, err

tools/hidefile_darwin.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ func hideFile(path string) {
1010

1111
func TellCommandNotToSpawnShell(_ *exec.Cmd) {
1212
}
13+
14+
func MessageBox(title, text string) int {
15+
return 0
16+
}

tools/hidefile_linux.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ func hideFile(path string) {
1010

1111
func TellCommandNotToSpawnShell(_ *exec.Cmd) {
1212
}
13+
14+
func MessageBox(title, text string) int {
15+
return 0
16+
}

tools/hidefile_windows.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package tools
33
import (
44
"os/exec"
55
"syscall"
6+
"unsafe"
67
)
78

89
func hideFile(path string) {
@@ -15,3 +16,15 @@ func hideFile(path string) {
1516
func TellCommandNotToSpawnShell(oscmd *exec.Cmd) {
1617
oscmd.SysProcAttr = &syscall.SysProcAttr{HideWindow: true}
1718
}
19+
20+
func MessageBox(title, text string) int {
21+
var mod = syscall.NewLazyDLL("user32.dll")
22+
var proc = mod.NewProc("MessageBoxW")
23+
var MB_YESNO = 0x00000004
24+
25+
ret, _, _ := proc.Call(0,
26+
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(text))),
27+
uintptr(unsafe.Pointer(syscall.StringToUTF16Ptr(title))),
28+
uintptr(MB_YESNO))
29+
return int(ret)
30+
}

0 commit comments

Comments
 (0)