-
Notifications
You must be signed in to change notification settings - Fork 1
/
filefind.go
68 lines (53 loc) · 1.97 KB
/
filefind.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
/*
Package with reusable code for discovery of files and other reusable stuff like universal ini reader
*/
package filefind
import (
"io/fs"
"path/filepath"
"strings"
"github.com/darklab8/fl-configs/configs/configs_mapped/parserutils/filefind/file"
"github.com/darklab8/fl-configs/configs/settings/logus"
"github.com/darklab8/go-typelog/typelog"
"github.com/darklab8/go-utils/goutils/utils/utils_logus"
"github.com/darklab8/go-utils/goutils/utils/utils_types"
)
type Filesystem struct {
Files []*file.File
Hashmap map[utils_types.FilePath]*file.File
}
var FreelancerFolder Filesystem
func FindConfigs(folderpath utils_types.FilePath) *Filesystem {
var filesystem *Filesystem = &Filesystem{}
filesystem.Hashmap = make(map[utils_types.FilePath]*file.File)
err := filepath.WalkDir(string(folderpath), func(path string, d fs.DirEntry, err error) error {
if !strings.Contains(path, ".ini") &&
!strings.Contains(path, ".txt") &&
!strings.Contains(path, ".xml") &&
!strings.Contains(path, ".dll") {
return nil
}
logus.Log.CheckPanic(err, "unable to read file")
file := file.NewFile(utils_types.FilePath(path))
filesystem.Files = append(filesystem.Files, file)
key := utils_types.FilePath(strings.ToLower(filepath.Base(path)))
filesystem.Hashmap[key] = file
return nil
})
logus.Log.CheckPanic(err, "unable to read files")
return filesystem
}
func (file1system Filesystem) GetFile(file1names ...utils_types.FilePath) *file.File {
for _, file1name := range file1names {
file_, ok := file1system.Hashmap[file1name]
if !ok {
logus.Log.Warn("Filesystem.GetFile, failed to find find in filesystesm file trying to recover", utils_logus.FilePath(file1name))
continue
}
logus.Log.Info("Filesystem.GetFile, found filepath=", utils_logus.FilePath(file_.GetFilepath()))
result_file := file.NewFile(file_.GetFilepath())
return result_file
}
logus.Log.Warn("failed to get file", typelog.Items[utils_types.FilePath]("filenames", file1names))
return nil
}