|
@@ -10,6 +10,7 @@ import (
|
|
|
"os"
|
|
"os"
|
|
|
"strings"
|
|
"strings"
|
|
|
"sync"
|
|
"sync"
|
|
|
|
|
+ "time"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
// 配置文件
|
|
// 配置文件
|
|
@@ -80,26 +81,27 @@ type Downloader struct {
|
|
|
Current int64
|
|
Current int64
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func printProgressBar(progress int, total int) {
|
|
|
|
|
- bar := ""
|
|
|
|
|
- numSlashes := progress * 100 / total / 5
|
|
|
|
|
- for i := 0; i < numSlashes; i++ {
|
|
|
|
|
- bar += "\u2588" // 这是一个完整的块字符
|
|
|
|
|
- }
|
|
|
|
|
- fmt.Printf("下载进度: [%-21s] %.2f%%\r", bar, float64(progress*100.0/total))
|
|
|
|
|
|
|
+func printProgressBar(progress int64, total int64) {
|
|
|
|
|
+ // bar := ""
|
|
|
|
|
+ // numSlashes := progress * 100 / total / 5
|
|
|
|
|
+ // for i := 0; i < numSlashes; i++ {
|
|
|
|
|
+ // bar += "\u2588" // 这是一个完整的块字符
|
|
|
|
|
+ // }
|
|
|
|
|
+ // fmt.Printf("下载进度: [%-21s] %.2f%%\r", bar, float64(progress*100.0/total))
|
|
|
|
|
+ fmt.Printf(" 正在下载:%d / %d bytes (%.2f%%)\r", progress, total, float32(progress*10000/total)/100)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func (d *Downloader) Read(p []byte) (n int, err error) {
|
|
func (d *Downloader) Read(p []byte) (n int, err error) {
|
|
|
n, err = d.Reader.Read(p)
|
|
n, err = d.Reader.Read(p)
|
|
|
d.Current += int64(n)
|
|
d.Current += int64(n)
|
|
|
|
|
|
|
|
- printProgressBar(int(d.Current*10000/d.Total), 10000)
|
|
|
|
|
|
|
+ printProgressBar(d.Current, d.Total)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-func downloadFile(url, filePath string) {
|
|
|
|
|
|
|
+func downloadFile(item int, url string, filePath string) {
|
|
|
defer wg.Done()
|
|
defer wg.Done()
|
|
|
- fmt.Println("下载", filePath)
|
|
|
|
|
|
|
+ fmt.Printf("%d.下载%s\n", item, filePath)
|
|
|
resp, err := http.Get(url)
|
|
resp, err := http.Get(url)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
log.Fatalln(err)
|
|
log.Fatalln(err)
|
|
@@ -108,6 +110,11 @@ func downloadFile(url, filePath string) {
|
|
|
_ = resp.Body.Close()
|
|
_ = resp.Body.Close()
|
|
|
}()
|
|
}()
|
|
|
file, err := os.Create(filePath)
|
|
file, err := os.Create(filePath)
|
|
|
|
|
+ if err != nil {
|
|
|
|
|
+ fmt.Println("文件创建失败:", err)
|
|
|
|
|
+ // 其他处理
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
defer func() {
|
|
defer func() {
|
|
|
_ = file.Close()
|
|
_ = file.Close()
|
|
|
}()
|
|
}()
|
|
@@ -133,7 +140,7 @@ func http_down(project string, down_list string, proxy string) {
|
|
|
folderPath := latest_version
|
|
folderPath := latest_version
|
|
|
err := os.MkdirAll(folderPath, os.ModePerm)
|
|
err := os.MkdirAll(folderPath, os.ModePerm)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
- fmt.Println("创建文件夹错误: %v", err)
|
|
|
|
|
|
|
+ fmt.Printf("创建文件夹错误: %v\n", err)
|
|
|
return
|
|
return
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -150,11 +157,16 @@ func http_down(project string, down_list string, proxy string) {
|
|
|
task[git_down_url+filename] = folderPath + "/" + filename
|
|
task[git_down_url+filename] = folderPath + "/" + filename
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ item := 1
|
|
|
for k, v := range task {
|
|
for k, v := range task {
|
|
|
wg.Add(1)
|
|
wg.Add(1)
|
|
|
- downloadFile(k, v)
|
|
|
|
|
|
|
+ downloadFile(item, k, v)
|
|
|
|
|
+ item += 1
|
|
|
}
|
|
}
|
|
|
wg.Wait()
|
|
wg.Wait()
|
|
|
|
|
+
|
|
|
|
|
+ fmt.Println("下载完成")
|
|
|
|
|
+ time.Sleep(1 * time.Second)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
func main() {
|
|
func main() {
|