mirror of
https://github.com/JanDeDobbeleer/oh-my-posh.git
synced 2025-02-02 05:41:10 -08:00
feat(windows): update registry on upgrade
This commit is contained in:
parent
c865759e2f
commit
58fd8e5f82
|
@ -137,7 +137,7 @@ func (term *Terminal) CachePath() string {
|
|||
func (term *Terminal) WindowsRegistryKeyValue(path string) (*WindowsRegistryValue, error) {
|
||||
term.Trace(time.Now(), path)
|
||||
|
||||
// Format:sudo -u postgres psql
|
||||
// Format:
|
||||
// "HKLM\Software\Microsoft\Windows NT\CurrentVersion\EditionID"
|
||||
// 1 | 2 | 3
|
||||
//
|
||||
|
@ -187,6 +187,7 @@ func (term *Terminal) WindowsRegistryKeyValue(path string) (*WindowsRegistryValu
|
|||
term.Error(err)
|
||||
return nil, err
|
||||
}
|
||||
|
||||
_, valType, err := k.GetValue(regKey, nil)
|
||||
if err != nil {
|
||||
term.Error(err)
|
||||
|
@ -214,6 +215,7 @@ func (term *Terminal) WindowsRegistryKeyValue(path string) (*WindowsRegistryValu
|
|||
errorLogMsg := fmt.Sprintf("Error, no formatter for type: %d", valType)
|
||||
return nil, errors.New(errorLogMsg)
|
||||
}
|
||||
|
||||
term.Debug(fmt.Sprintf("%s(%s): %s", regKey, regValue.ValueType, regValue.String))
|
||||
return regValue, nil
|
||||
}
|
||||
|
|
|
@ -68,5 +68,7 @@ func install(tag string) error {
|
|||
_ = hideFile(oldPath)
|
||||
}
|
||||
|
||||
updateRegistry(tag)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
|
|
@ -5,3 +5,5 @@ package upgrade
|
|||
func hideFile(_ string) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateRegistry(_ string) {}
|
||||
|
|
|
@ -1,8 +1,12 @@
|
|||
package upgrade
|
||||
|
||||
import (
|
||||
"strconv"
|
||||
"strings"
|
||||
"syscall"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows/registry"
|
||||
)
|
||||
|
||||
func hideFile(path string) error {
|
||||
|
@ -22,3 +26,43 @@ func hideFile(path string) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func updateRegistry(version string) {
|
||||
key, err := getRegistryKey()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
version = strings.TrimLeft(version, "v")
|
||||
|
||||
_ = key.SetStringValue("DisplayVersion", version)
|
||||
_ = key.SetStringValue("DisplayName", "Oh My Posh")
|
||||
|
||||
splitted := strings.Split(version, ".")
|
||||
if len(splitted) < 3 {
|
||||
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)
|
||||
}
|
||||
}
|
||||
|
||||
func getRegistryKey() (registry.Key, error) {
|
||||
path := `Software\Microsoft\Windows\CurrentVersion\Uninstall\Oh My Posh_is1`
|
||||
|
||||
key, err := registry.OpenKey(registry.CURRENT_USER, path, registry.WRITE)
|
||||
if err == nil {
|
||||
return key, nil
|
||||
}
|
||||
|
||||
return registry.OpenKey(registry.LOCAL_MACHINE, path, registry.WRITE)
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue