From 3d3b834ad02c48a0a639ebed03be356c98b4fd28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A7=E4=BA=8B?= <545049148@qq.com> Date: Fri, 3 Mar 2023 21:40:09 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=9A=A7=20=E6=9B=B4=E6=94=B9=E4=B8=BB?= =?UTF-8?q?=E7=A8=8B=E5=BA=8F=E7=9A=84=E6=8F=8F=E8=BF=B0=E5=8F=8A=E8=A7=A3?= =?UTF-8?q?=E5=8E=8B=E7=9A=84=E8=80=97=E6=97=B6=E7=BB=9F=E8=AE=A1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup4abap_go/main.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/backup4abap_go/main.go b/backup4abap_go/main.go index 6baead1..494f6de 100644 --- a/backup4abap_go/main.go +++ b/backup4abap_go/main.go @@ -36,7 +36,7 @@ func main() { delta = "YES" if set.AutoUnZip == false { - fmt.Print("是否增量?(Yes/No) 默认 Yes:") + fmt.Print("\t程序下载\n是否增量?(Yes/No) 默认 Yes:") fmt.Scanln(&delta) } @@ -129,6 +129,8 @@ func main() { return } + UzipTime := time.Now() + // 解压 err = util.DeCompressed(filename) if err != nil { @@ -136,6 +138,9 @@ func main() { return } + useTime = time.Since(UzipTime) + fmt.Printf("\nUzip Cost Time: %s\n", useTime) + // 删除文件 err = os.Remove(filename) if err != nil { From 09d13608ca653dc7813667bc15d492867760916f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A7=E4=BA=8B?= <545049148@qq.com> Date: Fri, 3 Mar 2023 21:46:49 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=9A=A7=20=E5=B0=81=E8=A3=85=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E6=97=B6=E7=9A=84=E6=8F=90=E7=A4=BA=E4=BF=A1=E6=81=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup4abap_go/util/setting.go | 34 +++++++++++++++++++++++----------- 1 file changed, 23 insertions(+), 11 deletions(-) diff --git a/backup4abap_go/util/setting.go b/backup4abap_go/util/setting.go index b174cb8..58e48c9 100644 --- a/backup4abap_go/util/setting.go +++ b/backup4abap_go/util/setting.go @@ -109,21 +109,12 @@ func settingProcess(set *Set) error { fmt.Scanln(&set.Password) // 是否自动解压 - var autoUnZip string + set.AutoUnZip = yesOrNo("是否自动解压到当前文件夹", true) + - autoUnZip = "y" - fmt.Print("\n是否自动解压到当前文件夹(y/n):") - fmt.Scanln(&autoUnZip) - autoUnZip = strings.ToLower(autoUnZip) - autoUnZip = strings.TrimSpace(autoUnZip) - if autoUnZip[:1] == "y" { - set.AutoUnZip = true - } else { - set.AutoUnZip = false - } return nil } @@ -137,3 +128,24 @@ func checkHttpUrl(url string) error { return nil } + +func yesOrNo(choeseDest string, defBool bool) bool { + var boolChoese string + + if defBool { + boolChoese = "y" + } + + fmt.Printf("\n%s(y/n)", choeseDest) + fmt.Scanln(&boolChoese) + + boolChoese = strings.ToLower(boolChoese) + boolChoese = strings.TrimSpace(boolChoese) + + if boolChoese[:1] == "y" { + return true + } else { + return false + } + +} From fe66ed7d9ef29dadc391eed55515550100ff87ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A7=E4=BA=8B?= <545049148@qq.com> Date: Fri, 3 Mar 2023 21:47:50 +0800 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=9A=A7=20=E6=96=B0=E5=A2=9E=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6=E6=9D=A1=E8=AE=BE=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup4abap_go/util/setting.go | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/backup4abap_go/util/setting.go b/backup4abap_go/util/setting.go index 58e48c9..a837d78 100644 --- a/backup4abap_go/util/setting.go +++ b/backup4abap_go/util/setting.go @@ -13,10 +13,11 @@ import ( const ConfigFileName string = "config.json" type Set struct { - SapSever string - Username string - Password string - AutoUnZip bool + SapSever string + Username string + Password string + AutoUnZip bool + ProcessBar bool } func (set Set) IsEmpty() bool { @@ -111,10 +112,10 @@ func settingProcess(set *Set) error { // 是否自动解压 set.AutoUnZip = yesOrNo("是否自动解压到当前文件夹", true) + // 是否启用进度条 + set.ProcessBar = yesOrNo("是否启用进度条(不显示详情)", true) - - - + fmt.Println() return nil } From f6202dfd77ce88fe59e66976f78b2e20878d7d9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A7=E4=BA=8B?= <545049148@qq.com> Date: Fri, 3 Mar 2023 21:48:25 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=9A=A7=20=E6=96=B0=E5=A2=9E=E8=BF=9B?= =?UTF-8?q?=E5=BA=A6=E6=9D=A1=E6=98=BE=E7=A4=BA=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backup4abap_go/main.go | 2 +- backup4abap_go/util/probar.go | 48 +++++++++++++++++++++++++++++++++++ backup4abap_go/util/zip.go | 19 ++++++++++++-- 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 backup4abap_go/util/probar.go diff --git a/backup4abap_go/main.go b/backup4abap_go/main.go index 494f6de..0b469fb 100644 --- a/backup4abap_go/main.go +++ b/backup4abap_go/main.go @@ -132,7 +132,7 @@ func main() { UzipTime := time.Now() // 解压 - err = util.DeCompressed(filename) + err = util.DeCompressed(filename, set.ProcessBar) if err != nil { fmt.Println(err) return diff --git a/backup4abap_go/util/probar.go b/backup4abap_go/util/probar.go new file mode 100644 index 0000000..c15ff9f --- /dev/null +++ b/backup4abap_go/util/probar.go @@ -0,0 +1,48 @@ +package util + +import ( + "fmt" + "strings" +) + +type Bar struct { + percent int64 // 百分比 + curr int64 + total int64 + grap string + show string + IsInit bool +} + +func (bar *Bar) Init(total int64, grap string) { + bar.IsInit = true + bar.total = total + if grap == "" { + bar.grap = "#" + } + bar.show = strings.Repeat(bar.grap, 100) +} + +func (bar *Bar) percents() { + bar.percent = int64(float32(bar.curr) / float32(bar.total) * 100) +} + +func (bar *Bar) Add(desc string) { + if !bar.IsInit { + return + } + + bar.curr++ + + bar.percents() + + fmt.Printf("\r[%-50s]%3d%% %8d/%d %-10s", bar.show[:bar.percent/2], bar.percent, bar.curr, bar.total, desc) +} + +func (bar *Bar) End() { + if !bar.IsInit { + return + } + + fmt.Println() +} diff --git a/backup4abap_go/util/zip.go b/backup4abap_go/util/zip.go index fcfd404..010ada2 100644 --- a/backup4abap_go/util/zip.go +++ b/backup4abap_go/util/zip.go @@ -8,7 +8,9 @@ import ( "strings" ) -func DeCompressed(src string) error { +var probar Bar + +func DeCompressed(src string, procBar bool) error { ZipReader, err := zip.OpenReader(src) if err != nil { return err @@ -16,16 +18,29 @@ func DeCompressed(src string) error { defer ZipReader.Close() + fmt.Printf("解压数量:%6v\n", len(ZipReader.File)) + + if procBar { + probar.Init(int64(len(ZipReader.File)), "") + } + for _, f := range ZipReader.File { if err := deCompressed(f); err != nil { return err } } + + probar.End() + return nil } func deCompressed(f *zip.File) error { - fmt.Println(f.Name) + if probar.IsInit { + probar.Add(f.Name) + } else { + fmt.Println(f.Name) + } if f.FileInfo().IsDir() { err := os.MkdirAll(f.Name, 0755) From 73f95d0076f198034686fe1beadea61a2a33400f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=97=A7=E4=BA=8B?= <545049148@qq.com> Date: Fri, 3 Mar 2023 21:51:44 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=A4=96=20github=20action=20auto=20bui?= =?UTF-8?q?ld=20go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/go-build.yml | 36 ++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) create mode 100644 .github/workflows/go-build.yml diff --git a/.github/workflows/go-build.yml b/.github/workflows/go-build.yml new file mode 100644 index 0000000..28cc054 --- /dev/null +++ b/.github/workflows/go-build.yml @@ -0,0 +1,36 @@ +name: Go build + +# 触发事件 含标签v**g +on: + push: + tags: + - "v**g" + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + + - name: Setup Go + uses: actions/setup-go@v3 + with: + go-version: 1.19 + + - name: Change go env + run: go env -w GO111MODULE=on + + - name: Build + env: + GOOS: windows + GOARCH: amd64 + working-directory: ./backup4abap_go + run: go build -o backup.exe ./main.go + + - name: Create Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + body: "压缩代码下载器,用于从已配置 backup4abap_interface 的 ICF 服务通过 HTTP 请求下载代码包到本地,并自动解压。目前仅生成 win64 的运行程序" + files: ./backup4abap_go/backup.exe + token: ${{ secrets.RELEASE_TOKEN }}