Skip to content

Commit

Permalink
修复翻译包下载失败的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Jrohy committed Sep 25, 2022
1 parent f20b7d5 commit 817067b
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
22 changes: 11 additions & 11 deletions data.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,35 +136,35 @@ func transDownloadUrl() string {
transWay = "BoyceLig/Clash_Chinese_Patch"
}
}
findFileName := func() string {
return webFirstMatchKey(fmt.Sprintf("https://github.com/%s/releases/tag/%s", transWay, tagMap[transWay]),
path.Join(tagMap[transWay], "app.7z"), path.Join(tagMap[transWay], "app.zip"), path.Join(tagMap[transWay], "app.asar"), path.Join(tagMap[transWay], "app.rar"))
findFileUrl := func() string {
return webFindUrl(fmt.Sprintf("https://github.com/%s/releases/download/%s", transWay, tagMap[transWay]),
"app.7z", "app.zip", "app.asar", "app.rar")
}
tagExists := func() bool {
tagNotExists := func() bool {
return webSearch(fmt.Sprintf("https://github.com/%s/tags", transWay), cfwVersion) == ""
}

fmt.Println(fmt.Sprintf("正在获取%s的%s版本汉化包...", transWay, cfwVersion))
if cfwVersion == cfwVersionList[0] && tagExists() {
if cfwVersion == cfwVersionList[0] && tagNotExists() {
fmt.Println(fmt.Sprintf("%s的%s汉化补丁尚未发布, 正在切换到另一种汉化补丁..", transWay, cfwVersion))
exchange()
if tagExists() {
if tagNotExists() {
fmt.Println(fmt.Sprintf("%s的汉化补丁尚未发布, 若要汉化等后续补丁发布后重新运行工具来更新即可\n", cfwVersion))
return ""
}
}
fileName := findFileName()
if fileName == "" {
downloadUrl := findFileUrl()
if downloadUrl == "" {
fmt.Println(fmt.Sprintf("%s的%s汉化补丁不存在, 正在切换到另一种汉化补丁..", transWay, cfwVersion))
exchange()
fileName = findFileName()
if fileName == "" {
downloadUrl = findFileUrl()
if downloadUrl == "" {
fmt.Println(fmt.Sprintf("%s版本的汉化补丁不存在\n", cfwVersion))
return ""
}
}
updateTrans = true
return fmt.Sprintf("https://github.com/%s/releases/download/%s", transWay, fileName)
return downloadUrl
}

func tranSelect() {
Expand Down
20 changes: 9 additions & 11 deletions utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,18 +177,16 @@ func webSearch(url, key string) string {
return searchText(resp.Body, key)
}

func webFirstMatchKey(url string, keys ...string) string {
var content string
resp := httpGet(url)
defer resp.Body.Close()
if c, err := io.ReadAll(resp.Body); err == nil {
content = string(c)
} else {
return ""
}
func webFindUrl(url string, keys ...string) string {
var (
err error
resp *http.Response
)
for _, v := range keys {
if strings.Contains(content, v) {
return v
downloadUrl := fmt.Sprintf("%s/%s", url, v)
resp, err = http.Get(downloadUrl)
if err == nil && resp.StatusCode != 404 {
return downloadUrl
}
}
return ""
Expand Down

0 comments on commit 817067b

Please sign in to comment.