Skip to content

Commit

Permalink
Isolate windows code
Browse files Browse the repository at this point in the history
  • Loading branch information
AO3\andriws.luna committed May 31, 2024
1 parent a871697 commit 6667c71
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 45 deletions.
45 changes: 0 additions & 45 deletions utils/librarypath/dproj_itil.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
44 changes: 44 additions & 0 deletions utils/librarypath/global_util_win.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package librarypath

import (
"path"
"path/filepath"
"strings"

"github.com/hashload/boss/consts"
Expand All @@ -16,6 +18,7 @@ import (
)

const SearchPathRegistry = "Search Path"
const BrowsingPathRegistry = "Browsing Path"

func updateGlobalLibraryPath() {
ideVersion := bossRegistry.GetCurrentDelphiVersion()
Expand Down Expand Up @@ -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)
}
}

0 comments on commit 6667c71

Please sign in to comment.