-
-
Notifications
You must be signed in to change notification settings - Fork 93
/
globalUtil.go
47 lines (39 loc) · 1.47 KB
/
globalUtil.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
package librarypath
import (
"github.com/hashload/boss/env"
"github.com/hashload/boss/msg"
"github.com/hashload/boss/utils"
"golang.org/x/sys/windows/registry"
"strings"
)
const SearchPathRegistry = "Search Path"
func updateGlobalLibraryPath() {
ideVersion := env.GetCurrentDelphiVersionFromRegisty()
if ideVersion == "" {
msg.Err("Version not found for path %s", env.GlobalConfiguration.DelphiPath)
}
library, err := registry.OpenKey(registry.CURRENT_USER, `Software\Embarcadero\BDS\`+ideVersion+`\Library`, registry.ALL_ACCESS)
if err != nil {
msg.Err(`Registry path Software\Embarcadero\BDS\` + ideVersion + `\Library not exists`)
}
libraryInfo, err := library.Stat()
platforms, err := library.ReadSubKeyNames(int(libraryInfo.SubKeyCount))
if err != nil {
msg.Err("No platform found for delphi " + ideVersion)
return
}
for _, platform := range platforms {
delphiPlatform, err := registry.OpenKey(registry.CURRENT_USER, `Software\Embarcadero\BDS\`+ideVersion+`\Library\`+platform, registry.ALL_ACCESS)
utils.HandleError(err)
paths, _, err := delphiPlatform.GetStringValue(SearchPathRegistry)
if err != nil {
msg.Warn("Failed to update library path from platform %s with delphi %s", platform, ideVersion)
continue
}
splitPaths := strings.Split(paths, ";")
newSplitPaths := GetNewPaths(splitPaths, true)
newPaths := strings.Join(newSplitPaths, ";")
err = delphiPlatform.SetStringValue(SearchPathRegistry, newPaths)
utils.HandleError(err)
}
}