From 47c7d3af93910e39d56e282a2135854620a1971a Mon Sep 17 00:00:00 2001 From: Yu Fang Date: Wed, 24 Feb 2021 14:00:28 +0800 Subject: [PATCH] =?UTF-8?q?windows=E5=A6=82=E6=9E=9C=E6=B2=A1=E6=9C=89?= =?UTF-8?q?=E5=AE=89=E8=A3=85adb=E5=88=99=E8=87=AA=E5=8A=A8=E8=A7=A3?= =?UTF-8?q?=E5=8E=8B=E4=B8=80=E4=B8=AAadb=E5=88=B0=E5=90=8C=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 +- config/config.go | 21 +++++++++++++++++---- scripts/generate/build_windows.sh | 8 ++++++++ scripts/generate/generate-bindata.sh | 3 ++- utils/exportfiles.go | 3 ++- 5 files changed, 30 insertions(+), 7 deletions(-) create mode 100755 scripts/generate/build_windows.sh diff --git a/.gitignore b/.gitignore index aab0b20..4689091 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,4 @@ /test.yaml /test/main.go /snap.login -/utils/bindata.go +/assets/ diff --git a/config/config.go b/config/config.go index 1c3d9d2..1facc2c 100644 --- a/config/config.go +++ b/config/config.go @@ -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" ) @@ -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() { diff --git a/scripts/generate/build_windows.sh b/scripts/generate/build_windows.sh new file mode 100755 index 0000000..0f43741 --- /dev/null +++ b/scripts/generate/build_windows.sh @@ -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 \ No newline at end of file diff --git a/scripts/generate/generate-bindata.sh b/scripts/generate/generate-bindata.sh index f5aeb06..9c9d1c7 100755 --- a/scripts/generate/generate-bindata.sh +++ b/scripts/generate/generate-bindata.sh @@ -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/... diff --git a/utils/exportfiles.go b/utils/exportfiles.go index 469ace1..b7286cf 100644 --- a/utils/exportfiles.go +++ b/utils/exportfiles.go @@ -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 }