-
-
Notifications
You must be signed in to change notification settings - Fork 95
/
env.go
98 lines (79 loc) · 2.02 KB
/
env.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package env
import (
"crypto/md5"
"encoding/hex"
"github.com/hashload/boss/consts"
"github.com/hashload/boss/msg"
"github.com/hashload/boss/utils/dcc32"
"github.com/mitchellh/go-homedir"
"os"
"path/filepath"
"strings"
)
var Global bool
var Internal = false
var GlobalConfiguration, _ = LoadConfiguration(GetBossHome())
func HashDelphiPath() string {
hasher := md5.New()
hasher.Write([]byte(strings.ToLower(GlobalConfiguration.DelphiPath)))
hashString := hex.EncodeToString(hasher.Sum(nil))
if Internal {
hashString = consts.BossInternalDir + hashString
}
return hashString
}
func GetInternalGlobalDir() string {
return filepath.Join(GetBossHome(), consts.FolderDependencies, consts.BossInternalDir+HashDelphiPath())
}
func getwd() string {
if Global {
return filepath.Join(GetBossHome(), consts.FolderDependencies, HashDelphiPath())
} else {
if dir, err := os.Getwd(); err != nil {
msg.Err("Error to get paths", err)
return ""
} else {
return dir
}
}
}
func GetCacheDir() string {
return filepath.Join(GetBossHome(), "cache")
}
func GetBossHome() string {
homeDir := os.Getenv("BOSS_HOME")
if homeDir == "" {
systemHome, e := homedir.Dir()
homeDir = systemHome
if e != nil {
msg.Err("Error to get cache paths", e)
}
homeDir = filepath.FromSlash(homeDir)
}
return filepath.Join(homeDir, consts.FolderBossHome)
}
func GetBossFile() string {
return filepath.Join(GetCurrentDir(), consts.FilePackage)
}
func GetModulesDir() string {
return filepath.Join(GetCurrentDir(), consts.FolderDependencies)
}
func GetCurrentDir() string {
return getwd()
}
func GetGlobalBinPath() string {
return filepath.Join(GetBossHome(), consts.FolderDependencies, consts.BinFolder)
}
func GetDcc32Dir() string {
if GlobalConfiguration.DelphiPath != "" {
return GlobalConfiguration.DelphiPath
}
byCmd := dcc32.GetDcc32DirByCmd()
if len(byCmd) > 0 {
return byCmd[0]
}
return ""
}
func GetCurrentDelphiVersionFromRegisty() string {
return dcc32.GetDelphiVersionNumberName(GlobalConfiguration.DelphiPath)
}