diff --git a/utils/librarypath/dproj_itil.go b/utils/librarypath/dproj_itil.go index 088bc99..5f4860a 100644 --- a/utils/librarypath/dproj_itil.go +++ b/utils/librarypath/dproj_itil.go @@ -11,16 +11,12 @@ import ( "github.com/beevik/etree" "github.com/hashload/boss/consts" - bossRegistry "github.com/hashload/boss/core/registry" "github.com/hashload/boss/env" "github.com/hashload/boss/models" "github.com/hashload/boss/msg" "github.com/hashload/boss/utils" - "golang.org/x/sys/windows/registry" ) -const BrowsingPathRegistry = "Browsing Path" - func updateDprojLibraryPath(pkg *models.Package) { var isLazarus = isLazarus() var projectNames = GetProjectNames(pkg) @@ -92,47 +88,6 @@ func createTagOtherUnitFiles(node *etree.Element) *etree.Element { return child } -func updateGlobalBrowsingByProject(dprojName string, setReadOnly bool) { - ideVersion := bossRegistry.GetCurrentDelphiVersion() - if ideVersion == "" { - msg.Err("Version not found for path %s", env.GlobalConfiguration.DelphiPath) - } - library, err := registry.OpenKey(registry.CURRENT_USER, consts.RegistryBasePath+ideVersion+`\Library`, registry.ALL_ACCESS) - - if err != nil { - msg.Err(`Registry path` + consts.RegistryBasePath + ideVersion + `\Library not exists`) - return - } - - libraryInfo, err := library.Stat() - if err != nil { - msg.Err(err.Error()) - return - } - 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, consts.RegistryBasePath+ideVersion+`\Library\`+platform, registry.ALL_ACCESS) - utils.HandleError(err) - paths, _, err := delphiPlatform.GetStringValue(BrowsingPathRegistry) - if err != nil { - msg.Debug("Failed to update library path from platform %s with delphi %s", platform, ideVersion) - continue - } - - splitPaths := strings.Split(paths, ";") - rootPath := filepath.Join(env.GetCurrentDir(), path.Dir(dprojName)) - newSplitPaths := GetNewBrowsingPaths(splitPaths, false, rootPath, setReadOnly) - newPaths := strings.Join(newSplitPaths, ";") - err = delphiPlatform.SetStringValue(BrowsingPathRegistry, newPaths) - utils.HandleError(err) - } -} - func updateGlobalBrowsingPath(pkg *models.Package) { var isLazarus = isLazarus() var projectNames = GetProjectNames(pkg) diff --git a/utils/librarypath/global_util_win.go b/utils/librarypath/global_util_win.go index e2a5462..93662e2 100644 --- a/utils/librarypath/global_util_win.go +++ b/utils/librarypath/global_util_win.go @@ -4,6 +4,8 @@ package librarypath import ( + "path" + "path/filepath" "strings" "github.com/hashload/boss/consts" @@ -16,6 +18,7 @@ import ( ) const SearchPathRegistry = "Search Path" +const BrowsingPathRegistry = "Browsing Path" func updateGlobalLibraryPath() { ideVersion := bossRegistry.GetCurrentDelphiVersion() @@ -57,3 +60,44 @@ func updateGlobalLibraryPath() { } } + +func updateGlobalBrowsingByProject(dprojName string, setReadOnly bool) { + ideVersion := bossRegistry.GetCurrentDelphiVersion() + if ideVersion == "" { + msg.Err("Version not found for path %s", env.GlobalConfiguration.DelphiPath) + } + library, err := registry.OpenKey(registry.CURRENT_USER, consts.RegistryBasePath+ideVersion+`\Library`, registry.ALL_ACCESS) + + if err != nil { + msg.Err(`Registry path` + consts.RegistryBasePath + ideVersion + `\Library not exists`) + return + } + + libraryInfo, err := library.Stat() + if err != nil { + msg.Err(err.Error()) + return + } + 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, consts.RegistryBasePath+ideVersion+`\Library\`+platform, registry.ALL_ACCESS) + utils.HandleError(err) + paths, _, err := delphiPlatform.GetStringValue(BrowsingPathRegistry) + if err != nil { + msg.Debug("Failed to update library path from platform %s with delphi %s", platform, ideVersion) + continue + } + + splitPaths := strings.Split(paths, ";") + rootPath := filepath.Join(env.GetCurrentDir(), path.Dir(dprojName)) + newSplitPaths := GetNewBrowsingPaths(splitPaths, false, rootPath, setReadOnly) + newPaths := strings.Join(newSplitPaths, ";") + err = delphiPlatform.SetStringValue(BrowsingPathRegistry, newPaths) + utils.HandleError(err) + } +}