Skip to content

Commit

Permalink
Implemented detection of the Firefox flavor on Windows and fixed regi…
Browse files Browse the repository at this point in the history
…stry detection (#350)
  • Loading branch information
Paulo Manrique committed Oct 31, 2020
1 parent 91148e8 commit 4a082a5
Showing 1 changed file with 50 additions and 5 deletions.
55 changes: 50 additions & 5 deletions interfacer/src/browsh/firefox_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,11 @@ import (

func getFirefoxPath() string {
versionString := getWindowsFirefoxVersionString()
flavor := getFirefoxFlavor()

k, err := registry.OpenKey(
registry.CURRENT_USER,
`Software\Mozilla\Mozilla Firefox\`+versionString+`\Main`,
registry.LOCAL_MACHINE,
`Software\Mozilla\`+flavor+` `+versionString+`\bin`,
registry.QUERY_VALUE)
if err != nil {
Shutdown(errors.New("Error reading Windows registry: " + fmt.Sprintf("%s", err)))
Expand All @@ -29,16 +30,18 @@ func getFirefoxPath() string {
}

func getWindowsFirefoxVersionString() string {
flavor := getFirefoxFlavor()

k, err := registry.OpenKey(
registry.CURRENT_USER,
`Software\Mozilla\Mozilla Firefox`,
registry.LOCAL_MACHINE,
`Software\Mozilla\`+flavor,
registry.QUERY_VALUE)
if err != nil {
Shutdown(errors.New("Error reading Windows registry: " + fmt.Sprintf("%s", err)))
}
defer k.Close()

versionString, _, err := k.GetStringValue("CurrentVersion")
versionString, _, err := k.GetStringValue("")
if err != nil {
Shutdown(errors.New("Error reading Windows registry: " + fmt.Sprintf("%s", err)))
}
Expand All @@ -48,6 +51,48 @@ func getWindowsFirefoxVersionString() string {
return versionString
}

func getFirefoxFlavor() string {
var flavor = "null"
k, err := registry.OpenKey(
registry.LOCAL_MACHINE,
`Software\Mozilla\Mozilla Firefox`,
registry.QUERY_VALUE)

if err == nil {
flavor = "Mozilla Firefox"
}
defer k.Close()

if flavor == "null" {
k, err := registry.OpenKey(
registry.LOCAL_MACHINE,
`Software\Mozilla\Firefox Developer Edition`,
registry.QUERY_VALUE)

if err == nil {
flavor = "Firefox Developer Edition"
}
defer k.Close()
}

if flavor == "null" {
k, err := registry.OpenKey(
registry.LOCAL_MACHINE,
`Software\Mozilla\Nightly`,
registry.QUERY_VALUE)

if err == nil {
flavor = "Nightly"
}
defer k.Close()
}

if flavor == "null" {
Shutdown(errors.New("Could not find Firefox on your registry"))
}
return flavor
}

func ensureFirefoxVersion(path string) {
versionString := getWindowsFirefoxVersionString()
pieces := strings.Split(versionString, " ")
Expand Down

0 comments on commit 4a082a5

Please sign in to comment.