mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-03-05 20:49:04 -08:00
chore(install): do not update registry
Some checks failed
Code QL / code-ql (push) Has been cancelled
Azure Static Web Apps CI/CD / Build and Deploy (push) Has been cancelled
Release / changelog (push) Has been cancelled
Release / artifacts (push) Has been cancelled
Release / msi (arm64) (push) Has been cancelled
Release / msi (x64) (push) Has been cancelled
Release / msi (x86) (push) Has been cancelled
Release / release (push) Has been cancelled
Some checks failed
Code QL / code-ql (push) Has been cancelled
Azure Static Web Apps CI/CD / Build and Deploy (push) Has been cancelled
Release / changelog (push) Has been cancelled
Release / artifacts (push) Has been cancelled
Release / msi (arm64) (push) Has been cancelled
Release / msi (x64) (push) Has been cancelled
Release / msi (x86) (push) Has been cancelled
Release / release (push) Has been cancelled
This commit is contained in:
parent
06a372424f
commit
2ddb3b1486
|
@ -71,7 +71,5 @@ func install(cfg *Config) error {
|
|||
_ = hideFile(oldPath)
|
||||
}
|
||||
|
||||
updateRegistry(cfg.Version, executable)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -1,14 +1,8 @@
|
|||
package upgrade
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"path/filepath"
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows/registry"
|
||||
)
|
||||
|
||||
func hideFile(path string) error {
|
||||
|
@ -28,89 +22,3 @@ func hideFile(path string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateRegistry(version, executable string) {
|
||||
// needs to be the parent directory of the executable's bin directory
|
||||
// with a trailing backslash to match the registry key
|
||||
// in case this wasn't installed with the installer, nothing will match
|
||||
// and we don't set the registry keys
|
||||
installLocation := filepath.Dir(executable)
|
||||
installLocation = filepath.Dir(installLocation)
|
||||
installLocation += `\`
|
||||
|
||||
key, err := getRegistryKey(installLocation)
|
||||
if err != nil {
|
||||
key.Close()
|
||||
return
|
||||
}
|
||||
|
||||
version = strings.TrimLeft(version, "v")
|
||||
|
||||
_ = key.SetStringValue("DisplayVersion", version)
|
||||
_ = key.SetStringValue("DisplayName", "Oh My Posh")
|
||||
|
||||
splitted := strings.Split(version, ".")
|
||||
if len(splitted) < 3 {
|
||||
key.Close()
|
||||
return
|
||||
}
|
||||
|
||||
if u64, err := strconv.ParseUint(splitted[0], 10, 32); err == nil {
|
||||
major := uint32(u64)
|
||||
_ = key.SetDWordValue("MajorVersion", major)
|
||||
_ = key.SetDWordValue("VersionMajor", major)
|
||||
}
|
||||
|
||||
if u64, err := strconv.ParseUint(splitted[1], 10, 32); err == nil {
|
||||
minor := uint32(u64)
|
||||
_ = key.SetDWordValue("MinorVersion", minor)
|
||||
_ = key.SetDWordValue("VersionMinor", minor)
|
||||
}
|
||||
|
||||
key.Close()
|
||||
}
|
||||
|
||||
// getRegistryKey tries all known registry paths to find the one we need to adjust (if any)
|
||||
func getRegistryKey(installLocation string) (registry.Key, error) {
|
||||
knownRegistryPaths := []struct {
|
||||
Path string
|
||||
Key registry.Key
|
||||
}{
|
||||
{`Software\Microsoft\Windows\CurrentVersion\Uninstall`, registry.CURRENT_USER},
|
||||
{`Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall`, registry.CURRENT_USER},
|
||||
{`Software\Microsoft\Windows\CurrentVersion\Uninstall`, registry.LOCAL_MACHINE},
|
||||
{`Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall`, registry.LOCAL_MACHINE},
|
||||
}
|
||||
|
||||
for _, path := range knownRegistryPaths {
|
||||
key, ok := tryRegistryKey(path.Key, path.Path, installLocation)
|
||||
if ok {
|
||||
return key, nil
|
||||
}
|
||||
}
|
||||
|
||||
return registry.CURRENT_USER, errors.New("could not find registry key")
|
||||
}
|
||||
|
||||
// tryRegistryKey tries to open the registry key for the given path
|
||||
// and checks if the install location matches with the current executable's location
|
||||
func tryRegistryKey(key registry.Key, path, installLocation string) (registry.Key, bool) {
|
||||
path += `\Oh My Posh_is1`
|
||||
|
||||
readKey, err := registry.OpenKey(key, path, registry.READ)
|
||||
if err != nil {
|
||||
return key, false
|
||||
}
|
||||
|
||||
location, _, err := readKey.GetStringValue("InstallLocation")
|
||||
if err != nil {
|
||||
return key, false
|
||||
}
|
||||
|
||||
if location != installLocation {
|
||||
return key, false
|
||||
}
|
||||
|
||||
key, err = registry.OpenKey(key, path, registry.WRITE)
|
||||
return key, err == nil
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue