Skip to content

Commit

Permalink
windows如果没有安装adb则自动解压一个adb到同目录
Browse files Browse the repository at this point in the history
  • Loading branch information
IoTServ committed Feb 24, 2021
1 parent afe9a75 commit 47c7d3a
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@
/test.yaml
/test/main.go
/snap.login
/utils/bindata.go
/assets/
21 changes: 17 additions & 4 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,15 @@ package config

import (
"fmt"
"github.com/IoTDevice/phicomm-r1-controler/utils"
adb "github.com/mDNSService/goadb"
"gopkg.in/yaml.v2"
"io/ioutil"
"log"
"os"
"os/exec"
"path/filepath"
"runtime"
"sync"
)

Expand Down Expand Up @@ -42,11 +45,21 @@ func InitConfigFile() {
return
}
err = WriteConfigFile(ConfigModelVar, ConfigFilePath)
if err == nil {
fmt.Println("config created")
return
if err != nil {
log.Fatalln("写入配置文件模板出错,请检查本程序是否具有写入权限!或者手动创建配置文件。")
}
fmt.Println("config created")
//如果是windows系统并且PATH没有adb则自动安装adb
if runtime.GOOS == "windows" {
if _, err := exec.LookPath("adb.exe"); err != nil {
//用户没有预先安装adb
err := utils.ExportAdb("./")
if err != nil {
log.Fatalln(err)
}
ConfigModelVar.ADBConfig.PathToAdb = "./adb.exe"
}
}
log.Fatalln("写入配置文件模板出错,请检查本程序是否具有写入权限!或者手动创建配置文件。")
}

func UseConfigFile() {
Expand Down
8 changes: 8 additions & 0 deletions scripts/generate/build_windows.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
export CGO_ENABLED=0
export GO111MODULE=on
export GOARCH=386
export GOOS=windows
go build -ldflags -w ./

export GOARCH=amd64
export GOOS=darwin
3 changes: 2 additions & 1 deletion scripts/generate/generate-bindata.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#!/usr/bin/env bash
echo "generate start..."
go get -u github.com/go-bindata/go-bindata/...
go-bindata -o utils/bindata.go -pkg utils scripts/bindata/...
rm -rf assets
go-bindata -o assets/bindata.go -pkg assets scripts/bindata/...
3 changes: 2 additions & 1 deletion utils/exportfiles.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package utils

import (
"github.com/IoTDevice/phicomm-r1-controler/assets"
"io/ioutil"
"path/filepath"
)

func ExportFiles(frompath, topath string) (err error) {
data, err := Asset(frompath)
data, err := assets.Asset(frompath)
if err != nil {
return
}
Expand Down

0 comments on commit 47c7d3a

Please sign in to comment.