Skip to content

Commit e0aeedc

Browse files
author
AO3\andriws.luna
committed
Added Browsing path property in boss .json.
This is similar to mainsrc, but add browsing to delphi registry
1 parent 55292c0 commit e0aeedc

File tree

3 files changed

+92
-0
lines changed

3 files changed

+92
-0
lines changed

models/package.go

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ type Package struct {
1717
Version string `json:"version"`
1818
Homepage string `json:"homepage"`
1919
MainSrc string `json:"mainsrc"`
20+
BrowsingPath string `json:"browsingpath"`
2021
Projects []string `json:"projects"`
2122
Scripts interface{} `json:"scripts,omitempty"`
2223
Dependencies interface{} `json:"dependencies"`

utils/librarypath/global_util_win.go

+42
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import (
1616
)
1717

1818
const SearchPathRegistry = "Search Path"
19+
const BrowsingPathRegistry = "Browsing Path"
1920

2021
func updateGlobalLibraryPath() {
2122
ideVersion := bossRegistry.GetCurrentDelphiVersion()
@@ -57,3 +58,44 @@ func updateGlobalLibraryPath() {
5758
}
5859

5960
}
61+
62+
func updateGlobalBrowsingPath() {
63+
ideVersion := bossRegistry.GetCurrentDelphiVersion()
64+
if ideVersion == "" {
65+
msg.Err("Version not found for path %s", env.GlobalConfiguration.DelphiPath)
66+
}
67+
library, err := registry.OpenKey(registry.CURRENT_USER, consts.RegistryBasePath+ideVersion+`\Library`, registry.ALL_ACCESS)
68+
69+
if err != nil {
70+
msg.Err(`Registry path` + consts.RegistryBasePath + ideVersion + `\Library not exists`)
71+
return
72+
}
73+
74+
libraryInfo, err := library.Stat()
75+
if err != nil {
76+
msg.Err(err.Error())
77+
return
78+
}
79+
platforms, err := library.ReadSubKeyNames(int(libraryInfo.SubKeyCount))
80+
if err != nil {
81+
msg.Err("No platform found for delphi " + ideVersion)
82+
return
83+
}
84+
85+
for _, platform := range platforms {
86+
delphiPlatform, err := registry.OpenKey(registry.CURRENT_USER, consts.RegistryBasePath+ideVersion+`\Library\`+platform, registry.ALL_ACCESS)
87+
utils.HandleError(err)
88+
paths, _, err := delphiPlatform.GetStringValue(BrowsingPathRegistry)
89+
if err != nil {
90+
msg.Debug("Failed to update library path from platform %s with delphi %s", platform, ideVersion)
91+
continue
92+
}
93+
94+
splitPaths := strings.Split(paths, ";")
95+
newSplitPaths := GetNewBrowsingPaths(splitPaths, false, env.GetCurrentDir())
96+
newPaths := strings.Join(newSplitPaths, ";")
97+
err = delphiPlatform.SetStringValue(BrowsingPathRegistry, newPaths)
98+
utils.HandleError(err)
99+
}
100+
101+
}

utils/librarypath/librarypath.go

+49
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ func UpdateLibraryPath(pkg *models.Package) {
1818
updateGlobalLibraryPath()
1919
} else {
2020
updateDprojLibraryPath(pkg)
21+
updateGlobalBrowsingPath()
2122
}
2223

2324
}
@@ -40,6 +41,27 @@ func cleanPath(paths []string, fullPath bool) []string {
4041
return processedPaths
4142
}
4243

44+
func GetNewBrowsingPaths(paths []string, fullPath bool, rootPath string) []string {
45+
paths = cleanPath(paths, fullPath)
46+
var path = env.GetModulesDir()
47+
48+
matches, _ := ioutil.ReadDir(path)
49+
50+
for _, value := range matches {
51+
52+
var packagePath = filepath.Join(path, value.Name(), consts.FilePackage)
53+
if _, err := os.Stat(packagePath); !os.IsNotExist(err) {
54+
55+
other, _ := models.LoadPackageOther(packagePath)
56+
if other.BrowsingPath != "" {
57+
paths = getNewBrowsingPathsFromDir(filepath.Join(path, value.Name(), other.BrowsingPath), paths, fullPath, rootPath)
58+
}
59+
60+
}
61+
}
62+
return paths
63+
}
64+
4365
func GetNewPaths(paths []string, fullPath bool, rootPath string) []string {
4466
paths = cleanPath(paths, fullPath)
4567
var path = env.GetModulesDir()
@@ -99,6 +121,33 @@ func cleanEmpty(paths []string) []string {
99121
return paths
100122
}
101123

124+
func getNewBrowsingPathsFromDir(path string, paths []string, fullPath bool, rootPath string) []string {
125+
_, e := os.Stat(path)
126+
if os.IsNotExist(e) {
127+
return paths
128+
}
129+
130+
_ = filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
131+
matched, _ := regexp.MatchString(consts.RegexArtifacts, info.Name())
132+
if matched {
133+
dir, _ := filepath.Split(path)
134+
if !fullPath {
135+
dir, _ = filepath.Rel(rootPath, dir)
136+
}
137+
if !utils.Contains(paths, dir) {
138+
paths = append(paths, dir)
139+
}
140+
// add ..\ prefixed path -> @MeroFuruya fix #146
141+
//prefixedPath := "..\\" + dir
142+
//if !utils.Contains(paths, prefixedPath) {
143+
// paths = append(paths, prefixedPath)
144+
//}
145+
}
146+
return nil
147+
})
148+
return cleanEmpty(paths)
149+
}
150+
102151
func getNewPathsFromDir(path string, paths []string, fullPath bool, rootPath string) []string {
103152
_, e := os.Stat(path)
104153
if os.IsNotExist(e) {

0 commit comments

Comments
 (0)