/// <summary> /// Logs into the Voicemeeter application. Starts the given application (Voicemeeter, Bananna, Potato) if it is not already runnning. /// </summary> /// <param name="voicemeeterType">The Voicemeeter program to run</param> /// <returns>IDisposable class to dispose when finished with the remote.</returns> public static async Task <IDisposable> Initialize(RunVoicemeeterParam voicemeeterType) { if (handle.HasValue == false) { // Find current version from the registry const string key = @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall"; const string key32 = @"HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall"; const string uninstKey = "VB:Voicemeeter {17359A74-1236-5467}"; var voicemeeter = Registry.GetValue($"{key}\\{uninstKey}", "UninstallString", null); if (voicemeeter == null && Environment.Is64BitProcess) { // Fall back to 32-bits registry voicemeeter = Registry.GetValue($"{key32}\\{uninstKey}", "UninstallString", null); } if (voicemeeter == null) { throw new Exception("Voicemeeter not installed"); } handle = Wrapper.LoadLibrary( System.IO.Path.Combine(System.IO.Path.GetDirectoryName(voicemeeter.ToString()), Environment.Is64BitProcess ? "VoicemeeterRemote64.dll" : "VoicemeeterRemote.dll")); } var startVoiceMeeter = voicemeeterType != RunVoicemeeterParam.None; if (await Login(voicemeeterType, startVoiceMeeter).ConfigureAwait(false)) { return(new VoicemeeterClient()); } return(null); }
/// <summary> /// Start the VoiceMeeter program /// </summary> /// <param name="voicemeterType"></param> public static void Start(RunVoicemeeterParam voicemeterType) { switch (RemoteWrapper.InternalRunVoicemeeter((int)voicemeterType)) { case 0: return; case -1: throw new Exception("Not installed"); default: throw new Exception("Unknown"); } }
public static async Task <bool> Login(RunVoicemeeterParam voicemeeterType, bool retry = true) { switch ((LoginResponse)RemoteWrapper.LoginVoicemeeter()) { case LoginResponse.OK: case LoginResponse.AlreadyLoggedIn: return(true); case LoginResponse.VoicemeeterNotRunning: if (retry) { // Run voicemeeter program Start(voicemeeterType); await Task.Delay(2000).ConfigureAwait(false); return(await Login(voicemeeterType, false).ConfigureAwait(false)); } break; } return(false); }