Skip to content

Commit 8312d00

Browse files
committed
feat: add new param -H
1 parent 9adfe30 commit 8312d00

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

.github/workflows/release.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ jobs:
1515

1616
- name: Set up Go
1717
uses: actions/setup-go@master
18+
with:
19+
go-version: 1.22
1820

1921
- name: Run GoReleaser
2022
uses: goreleaser/goreleaser-action@master

main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func main() {
3333
wait := flag.Uint("w", 4, "connection waiting seconds")
3434
ua := flag.String("ua", defua, "customize user agent")
3535
h := flag.Bool("h", false, "display this help")
36+
home := flag.String("H", ".", "download under this path")
3637
flag.BoolVar(&notui, "notui", false, "use plain text instead of TUI")
3738
flag.Parse()
3839
args := flag.Args()
@@ -44,6 +45,11 @@ func main() {
4445
fmt.Println(cmdlst.String())
4546
return
4647
}
48+
err := os.MkdirAll(*home, 0755)
49+
if err != nil {
50+
logrus.Errorln("mkdirs of path", *home, "err:", err)
51+
return
52+
}
4753
if notui {
4854
logrus.Infoln("RVC Models Downloader start at", time.Now().Local().Format(time.DateTime+" (MST)"))
4955
logrus.Infof("operating system: %s, architecture: %s", runtime.GOOS, runtime.GOARCH)
@@ -89,7 +95,7 @@ func main() {
8995
}
9096
ch := make(chan struct{})
9197
go func() {
92-
err := usercfg.download(args[0], "", *ua, time.Second*time.Duration(*wait), *cust, !*ntrs, *force)
98+
err := usercfg.download(args[0], "", *home, *ua, time.Second*time.Duration(*wait), *cust, !*ntrs, *force)
9399
ch <- struct{}{}
94100
if err != nil {
95101
errorln(err)

net.go

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"io"
66
"net/http"
77
"os"
8+
"path"
89
"runtime"
910
"strconv"
1011
"strings"
@@ -15,16 +16,16 @@ import (
1516
"github.com/pkg/errors"
1617
)
1718

18-
func (c *config) download(path, prefix, ua string, waits time.Duration, usecust, usetrs, force bool) error {
19+
func (c *config) download(p, prefix, home, ua string, waits time.Duration, usecust, usetrs, force bool) error {
1920
for i, t := range c.Targets {
2021
if t.Refer != "" {
21-
refp := path[:strings.LastIndex(path, "/")+1] + t.Refer
22+
refp := p[:strings.LastIndex(p, "/")+1] + t.Refer
2223
infof("#%s%d refer to target '%s'.", prefix, i+1, refp)
2324
refcfg, err := readconfig(refp, usecust)
2425
if err != nil {
2526
return err
2627
}
27-
err = refcfg.download(refp, prefix+strconv.Itoa(i+1)+".", ua, waits, usecust, usetrs, force)
28+
err = refcfg.download(refp, prefix+strconv.Itoa(i+1)+".", home, ua, waits, usecust, usetrs, force)
2829
if err != nil {
2930
return err
3031
}
@@ -38,11 +39,12 @@ func (c *config) download(path, prefix, ua string, waits time.Duration, usecust,
3839
warnf("#%s%d target required Arch: %s but you are %s, skip.", prefix, i+1, t.Arch, runtime.GOARCH)
3940
continue
4041
}
41-
err := os.MkdirAll(t.Folder, 0755)
42+
homefolder := path.Join(home, t.Folder)
43+
err := os.MkdirAll(homefolder, 0755)
4244
if err != nil {
43-
return errors.Wrap(err, fmt.Sprintf("#%s%d make target folder '%s'", prefix, i+1, t.Folder))
45+
return errors.Wrap(err, fmt.Sprintf("#%s%d make target folder '%s'", prefix, i+1, homefolder))
4446
}
45-
infof("#%s%d open target folder '%s'.", prefix, i+1, t.Folder)
47+
infof("#%s%d open target folder '%s'.", prefix, i+1, homefolder)
4648
if len(t.Copy) == 0 {
4749
warnf("#%s%d empty copy target.", prefix, i+1)
4850
continue
@@ -57,7 +59,7 @@ func (c *config) download(path, prefix, ua string, waits time.Duration, usecust,
5759
if sleep > time.Millisecond {
5860
time.Sleep(sleep)
5961
}
60-
fname := t.Folder + "/" + cp[strings.LastIndex(cp, "/")+1:]
62+
fname := path.Join(homefolder, cp[strings.LastIndex(cp, "/")+1:])
6163
if !force {
6264
if _, err := os.Stat(fname); err == nil || os.IsExist(err) {
6365
warnf("#%s%d skip exist file %s", prefix, i+1, fname)

0 commit comments

Comments
 (0)