voicemeeter-rb/lib/voicemeeter/install.rb

42 lines
904 B
Ruby
Raw Normal View History

2023-07-07 02:30:05 +01:00
require "win32/registry"
require "pathname"
require "ffi"
require_relative "logger"
require_relative "errors"
2023-07-07 02:30:05 +01:00
module Voicemeeter
private
module Install
extend Logging
2023-07-14 12:01:41 +01:00
OS_BITS = (FFI::Platform::CPU.downcase == "x64") ? 64 : 32
2023-07-07 02:30:05 +01:00
2023-07-14 12:01:41 +01:00
def get_vmpath
2023-07-07 02:30:05 +01:00
reg_key = [
:Software,
2023-07-14 12:01:41 +01:00
((OS_BITS == 64) ? :WOW6432Node : nil),
2023-07-07 02:30:05 +01:00
:Microsoft,
:Windows,
:CurrentVersion,
:Uninstall,
2023-07-14 12:01:41 +01:00
:"VB:Voicemeeter {17359A74-1236-5467}"
2023-07-07 02:30:05 +01:00
]
Win32::Registry::HKEY_LOCAL_MACHINE.open(
reg_key.compact.join("\\")
) do |reg|
value = reg["UninstallString"]
2023-07-07 02:30:05 +01:00
Pathname.new(value).dirname
end
rescue Win32::Registry::Error => e
logger.error "#{e.class.name}: #{e.message}"
raise Errors::VMInstallError.new "unable to read Voicemeeter path from the registry"
2023-07-07 02:30:05 +01:00
end
module_function :get_vmpath
end
end