-
Notifications
You must be signed in to change notification settings - Fork 2
/
path.go
55 lines (47 loc) · 1.26 KB
/
path.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package voicemeeter
import (
"errors"
"fmt"
"log"
"path/filepath"
"runtime"
"strings"
"golang.org/x/sys/windows/registry"
)
// dllPath returns the Voicemeeter installation path as a string
func dllPath() (string, error) {
if runtime.GOOS != "windows" {
return "", errors.New("only Windows OS supported")
}
var regkey string
if strings.Contains(runtime.GOARCH, "64") {
regkey = `SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall`
} else {
regkey = `SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall`
}
var vmkey = `\VB:Voicemeeter {17359A74-1236-5467}`
k, err := registry.OpenKey(registry.LOCAL_MACHINE, regkey+vmkey, registry.QUERY_VALUE)
if err != nil {
return "", errors.New("unable to access registry")
}
defer k.Close()
path, _, err := k.GetStringValue(`UninstallString`)
if err != nil {
return "", errors.New("unable to read Voicemeeter path from registry")
}
var dllName string
if strings.Contains(runtime.GOARCH, "64") {
dllName = `VoicemeeterRemote64.dll`
} else {
dllName = `VoicemeeterRemote.dll`
}
return fmt.Sprintf("%v\\%s", filepath.Dir(path), dllName), nil
}
// getDllPath is a helper function for error handling
func getDllPath() string {
path, err := dllPath()
if err != nil {
log.Fatal(err)
}
return path
}