diff --git a/src/runtime/os_windows.go b/src/runtime/os_windows.go index 7eb4b694..c924355b 100644 --- a/src/runtime/os_windows.go +++ b/src/runtime/os_windows.go @@ -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 } diff --git a/src/upgrade/install.go b/src/upgrade/install.go index 2b72614d..f488283f 100644 --- a/src/upgrade/install.go +++ b/src/upgrade/install.go @@ -68,5 +68,7 @@ func install(tag string) error { _ = hideFile(oldPath) } + updateRegistry(tag) + return nil } diff --git a/src/upgrade/install_noop.go b/src/upgrade/install_noop.go index ec035bed..4516aeff 100644 --- a/src/upgrade/install_noop.go +++ b/src/upgrade/install_noop.go @@ -5,3 +5,5 @@ package upgrade func hideFile(_ string) error { return nil } + +func updateRegistry(_ string) {} diff --git a/src/upgrade/install_windows.go b/src/upgrade/install_windows.go index c10f3f89..6871af04 100644 --- a/src/upgrade/install_windows.go +++ b/src/upgrade/install_windows.go @@ -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) +}