Skip to content

Commit 1044ffd

Browse files
committed
Change language pack storage location
1 parent fe12f92 commit 1044ffd

File tree

2 files changed

+35
-29
lines changed

2 files changed

+35
-29
lines changed

i18n.go

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,20 @@ var bundle *i18n.Bundle
2020
func init() {
2121
bundle = i18n.NewBundle(language.SimplifiedChinese)
2222
bundle.RegisterUnmarshalFunc("toml", toml.Unmarshal)
23-
_, err := os.Stat("i18n")
24-
if err == nil {
25-
rd, err := ioutil.ReadDir("i18n")
26-
if err != nil {
27-
log.Panic(err)
28-
}
29-
for _, fi := range rd {
30-
if !fi.IsDir() && path.Ext(fi.Name()) == ".toml" {
31-
bundle.LoadMessageFile("i18n/" + fi.Name())
32-
}
33-
}
34-
}
35-
36-
rd, err := ioutil.ReadDir(".")
23+
dir, err := os.Executable()
24+
dropErr(err)
25+
dir = filepath.Dir(dir)
26+
// fmt.Println(dir)
27+
rd, err := ioutil.ReadDir(dir)
3728
if err != nil {
3829
log.Panic(err)
3930
}
4031
for _, fi := range rd {
4132
if !fi.IsDir() && path.Ext(fi.Name()) == ".toml" {
42-
bundle.LoadMessageFile(fi.Name())
33+
bundle.LoadMessageFile(path.Join(dir, fi.Name()))
4334
}
4435
}
36+
4537
}
4638

4739
func dropErr(err error) {
@@ -88,8 +80,10 @@ type Loc struct {
8880
}
8981

9082
func (loc *Loc) init(locLanguage string) {
91-
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
83+
dir, err := os.Executable()
9284
dropErr(err)
85+
dir = filepath.Dir(dir)
86+
//fmt.Println(dir)
9387
dir = filepath.Join(dir, fmt.Sprintf("%s.toml", locLanguage))
9488
_, err = os.Stat(dir)
9589
if err != nil {
@@ -123,6 +117,18 @@ func (loc *Loc) init(locLanguage string) {
123117
ioutil.WriteFile(dir, data, 0644)
124118
}
125119
}
120+
dir, err = os.Executable()
121+
dropErr(err)
122+
dir = filepath.Dir(dir)
123+
rd, err := ioutil.ReadDir(dir)
124+
if err != nil {
125+
log.Panic(err)
126+
}
127+
for _, fi := range rd {
128+
if !fi.IsDir() && path.Ext(fi.Name()) == ".toml" {
129+
bundle.LoadMessageFile(path.Join(dir, fi.Name()))
130+
}
131+
}
126132
loc.localize = i18n.NewLocalizer(bundle, locLanguage)
127133
}
128134
func (loc *Loc) print(tag string) string {

main.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -79,15 +79,7 @@ func restore(restoreSrvc *upload.RestoreService, filesToRestore map[string]fileu
7979
pool := make(chan struct{}, threads)
8080
checkPath := make(map[string]bool, 0)
8181
pathFiles := make(map[string]map[string]bool, 0)
82-
temps, _botKey, iUserID := sendMsg()
83-
var iSendMsg func(string)
8482

85-
temp := func(text string) {
86-
temps(text)
87-
if _botKey != "" && iUserID != "" {
88-
iSendMsg(text)
89-
}
90-
}
9183
for filePath, fileInfo := range filesToRestore {
9284
wg.Add(1)
9385
pool <- struct{}{}
@@ -102,7 +94,7 @@ func restore(restoreSrvc *upload.RestoreService, filesToRestore map[string]fileu
10294
paths = paths[:len(paths)-1]
10395
}
10496
if _, ok := checkPath[paths]; !ok {
105-
userID, bearerToken := httpLocal.GetMyIDAndBearer(infoPath, thread, block, lang, timeOut, _botKey, _UserID)
97+
userID, bearerToken := httpLocal.GetMyIDAndBearer(infoPath, thread, block, lang, timeOut, botKey, _UserID)
10698
files, _ := restoreSrvc.GetDriveItem(userID, bearerToken, paths)
10799
checkPath[paths] = true
108100
pathFiles[paths] = files
@@ -115,17 +107,25 @@ func restore(restoreSrvc *upload.RestoreService, filesToRestore map[string]fileu
115107
defer func() {
116108
<-pool
117109
}()
118-
if _, ok := pathFiles[paths][fileName]; !ok || mode == 0 {
119-
tip := "`" + filePath + "`" + loc.print("startToUpload1")
110+
temps, _botKey, iUserID := sendMsg()
111+
var iSendMsg func(string)
112+
tip := "`" + filePath + "`" + loc.print("startToUpload1")
113+
if _botKey != "" && iUserID != "" {
114+
iSendMsg = botSend(_botKey, iUserID, tip)
115+
}
116+
temp := func(text string) {
117+
temps(text)
120118
if _botKey != "" && iUserID != "" {
121-
iSendMsg = botSend(_botKey, iUserID, tip)
119+
iSendMsg(text)
122120
}
121+
}
122+
if _, ok := pathFiles[paths][fileName]; !ok || mode == 0 {
123123
temp(tip)
124124
userID, bearerToken := httpLocal.GetMyIDAndBearer(infoPath, thread, block, lang, timeOut, _botKey, _UserID)
125125
username := strings.ReplaceAll(filepath.Base(infoPath), ".json", "")
126126
restoreSrvc.SimpleUploadToOriginalLoc(userID, bearerToken, "replace", targetFolder, filePath, fileInfo, temp, locText, username)
127127
} else {
128-
tip := filePath + "已存在,自动跳过"
128+
tip = filePath + "已存在,自动跳过"
129129
if _botKey != "" && iUserID != "" {
130130
iSendMsg = botSend(_botKey, iUserID, tip)
131131
}

0 commit comments

Comments
 (0)