/
finder.go
54 lines (49 loc) · 1.11 KB
/
finder.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
package finder
import (
"errors"
"io/fs"
"os"
"path/filepath"
)
func FindDictFile(baseDir string) (string, string, string, error) {
var foundDicDir string
err := filepath.Walk(baseDir, func(path string, info fs.FileInfo, err error) error {
if err != nil {
return err
}
if info.IsDir() {
if info.Name() == "New Oxford American Dictionary.dictionary" {
foundDicDir = path
} else {
}
} else {
return nil
}
return nil
})
if err != nil {
panic(err)
}
if foundDicDir == "" {
return "", "", "", errors.New("Dictionary directory is not found")
}
bodyFilePath := foundDicDir + "/Contents/Resources/Body.data"
_, err = os.Stat(bodyFilePath)
if err != nil {
return "", "", "", err
}
cssFilePath := foundDicDir + "/Contents/Resources/DefaultStyle.css"
_, err = os.Stat(cssFilePath)
if err != nil {
return "", "", "", err
}
return foundDicDir, bodyFilePath, cssFilePath, nil
}
func FindDefaultCSSFile(dictDir string) (string, error) {
cssFile := dictDir + "/Contents/Resources/DefaultStyle.css"
_, err := os.Stat(cssFile)
if err != nil {
return "", err
}
return cssFile, nil
}