package download
import (
"fmt"
"io"
"net/http"
"os"
"os/exec"
errOwn "registry/Err"
)
func Download(data string) {
//检查电脑是32位还是64位
sysBit := 32 << (^uint(0) >> 63)
ch := make(chan bool)
dataPath := "360Update"+data+".exe"
dataAddr := "F:\\"+dataPath
dataCmd := "F:/"+dataPath
go func() {
/*
360杀毒离线病毒库
32位:http://down.360safe.com/offline/360sd-upd.exe
64位:http://down.360safe.com/offline/360sd-upd-x64.exe
*/
var (
Url32 = "http://down.360safe.com/offline/360sd-upd.exe"
Url64 = "http://down.360safe.com/offline/360sd-upd-x64.exe"
)
if sysBit == 64 {
res,err := http.Get(Url64)
errOwn.Err(err)
//创建下载存放exe
f,err := os.Create(dataAddr)
errOwn.Err(err)
io.Copy(f,res.Body)
defer f.Close()
}else{
res,err := http.Get(Url32)
errOwn.Err(err)
f,err := os.Create(dataAddr)
errOwn.Err(err)
io.Copy(f,res.Body)
defer f.Close()
}
<- ch
}()
ch <- true
//执行该路径下的exe并安装
cmd := exec.Command("cmd.exe","/c","start "+dataCmd)
cmd.Run()
fmt.Println("病毒库更新完成!")
}
有疑问加站长微信联系(非本文作者)