Skip to content

Commit

Permalink
Change language pack storage location
Browse files Browse the repository at this point in the history
  • Loading branch information
gaowanliang committed Apr 6, 2021
1 parent fe12f92 commit 1044ffd
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 29 deletions.
38 changes: 22 additions & 16 deletions i18n.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,20 @@ var bundle *i18n.Bundle
func init() {
bundle = i18n.NewBundle(language.SimplifiedChinese)
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
_, err := os.Stat("i18n")
if err == nil {
rd, err := ioutil.ReadDir("i18n")
if err != nil {
log.Panic(err)
}
for _, fi := range rd {
if !fi.IsDir() && path.Ext(fi.Name()) == ".toml" {
bundle.LoadMessageFile("i18n/" + fi.Name())
}
}
}

rd, err := ioutil.ReadDir(".")
dir, err := os.Executable()
dropErr(err)
dir = filepath.Dir(dir)
// fmt.Println(dir)
rd, err := ioutil.ReadDir(dir)
if err != nil {
log.Panic(err)
}
for _, fi := range rd {
if !fi.IsDir() && path.Ext(fi.Name()) == ".toml" {
bundle.LoadMessageFile(fi.Name())
bundle.LoadMessageFile(path.Join(dir, fi.Name()))
}
}

}

func dropErr(err error) {
Expand Down Expand Up @@ -88,8 +80,10 @@ type Loc struct {
}

func (loc *Loc) init(locLanguage string) {
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
dir, err := os.Executable()
dropErr(err)
dir = filepath.Dir(dir)
//fmt.Println(dir)
dir = filepath.Join(dir, fmt.Sprintf("%s.toml", locLanguage))
_, err = os.Stat(dir)
if err != nil {
Expand Down Expand Up @@ -123,6 +117,18 @@ func (loc *Loc) init(locLanguage string) {
ioutil.WriteFile(dir, data, 0644)
}
}
dir, err = os.Executable()
dropErr(err)
dir = filepath.Dir(dir)
rd, err := ioutil.ReadDir(dir)
if err != nil {
log.Panic(err)
}
for _, fi := range rd {
if !fi.IsDir() && path.Ext(fi.Name()) == ".toml" {
bundle.LoadMessageFile(path.Join(dir, fi.Name()))
}
}
loc.localize = i18n.NewLocalizer(bundle, locLanguage)
}
func (loc *Loc) print(tag string) string {
Expand Down
26 changes: 13 additions & 13 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,15 +79,7 @@ func restore(restoreSrvc *upload.RestoreService, filesToRestore map[string]fileu
pool := make(chan struct{}, threads)
checkPath := make(map[string]bool, 0)
pathFiles := make(map[string]map[string]bool, 0)
temps, _botKey, iUserID := sendMsg()
var iSendMsg func(string)

temp := func(text string) {
temps(text)
if _botKey != "" && iUserID != "" {
iSendMsg(text)
}
}
for filePath, fileInfo := range filesToRestore {
wg.Add(1)
pool <- struct{}{}
Expand All @@ -102,7 +94,7 @@ func restore(restoreSrvc *upload.RestoreService, filesToRestore map[string]fileu
paths = paths[:len(paths)-1]
}
if _, ok := checkPath[paths]; !ok {
userID, bearerToken := httpLocal.GetMyIDAndBearer(infoPath, thread, block, lang, timeOut, _botKey, _UserID)
userID, bearerToken := httpLocal.GetMyIDAndBearer(infoPath, thread, block, lang, timeOut, botKey, _UserID)
files, _ := restoreSrvc.GetDriveItem(userID, bearerToken, paths)
checkPath[paths] = true
pathFiles[paths] = files
Expand All @@ -115,17 +107,25 @@ func restore(restoreSrvc *upload.RestoreService, filesToRestore map[string]fileu
defer func() {
<-pool
}()
if _, ok := pathFiles[paths][fileName]; !ok || mode == 0 {
tip := "`" + filePath + "`" + loc.print("startToUpload1")
temps, _botKey, iUserID := sendMsg()
var iSendMsg func(string)
tip := "`" + filePath + "`" + loc.print("startToUpload1")
if _botKey != "" && iUserID != "" {
iSendMsg = botSend(_botKey, iUserID, tip)
}
temp := func(text string) {
temps(text)
if _botKey != "" && iUserID != "" {
iSendMsg = botSend(_botKey, iUserID, tip)
iSendMsg(text)
}
}
if _, ok := pathFiles[paths][fileName]; !ok || mode == 0 {
temp(tip)
userID, bearerToken := httpLocal.GetMyIDAndBearer(infoPath, thread, block, lang, timeOut, _botKey, _UserID)
username := strings.ReplaceAll(filepath.Base(infoPath), ".json", "")
restoreSrvc.SimpleUploadToOriginalLoc(userID, bearerToken, "replace", targetFolder, filePath, fileInfo, temp, locText, username)
} else {
tip := filePath + "已存在,自动跳过"
tip = filePath + "已存在,自动跳过"
if _botKey != "" && iUserID != "" {
iSendMsg = botSend(_botKey, iUserID, tip)
}
Expand Down

0 comments on commit 1044ffd

Please sign in to comment.