From fbe9fe68cfda199d3d49f491aebe3d802fffc520 Mon Sep 17 00:00:00 2001 From: onyx-and-iris <75868496+onyx-and-iris@users.noreply.github.com> Date: Tue, 4 May 2021 17:29:38 +0100 Subject: [PATCH] update to dll loading Added fetch dll path through registry. Added custom error class VBPathError in case dll path was not found Added function Setup_DLL to base.ps1 Wrapper setup stops if setup_dll returns false (no login, no class setup) --- CHANGELOG.md | 2 +- lib/Voicemeeter.psm1 | 11 +++++--- lib/base.ps1 | 61 ++++++++++++++++++++++++++++++-------------- lib/errors.ps1 | 12 +++++++++ lib/inst.ps1 | 15 +++++++++++ lib/macrobuttons.ps1 | 6 ----- 6 files changed, 77 insertions(+), 30 deletions(-) create mode 100644 lib/inst.ps1 diff --git a/CHANGELOG.md b/CHANGELOG.md index 663cdba..e12be84 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,7 +7,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 Before any minor/major patch is released all test units will be run to verify they pass. ## [Unreleased] -- [ ] +- [x] Fetch dll path through registry (support for 32 and 64 bit) ## [1.4] - 2021-05-03 ### Added diff --git a/lib/Voicemeeter.psm1 b/lib/Voicemeeter.psm1 index 725587c..d96e894 100644 --- a/lib/Voicemeeter.psm1 +++ b/lib/Voicemeeter.psm1 @@ -14,11 +14,14 @@ class Remote { } [void] Setup() { - Login -TYPE $this.type + if(Setup_DLL) { + Login -TYPE $this.type - $this.button = Buttons - $this.strip = Strips - $this.bus = Buses + $this.button = Buttons + $this.strip = Strips + $this.bus = Buses + } + else { Exit } } [void] Logout() { diff --git a/lib/base.ps1 b/lib/base.ps1 index e8698e2..67bb341 100644 --- a/lib/base.ps1 +++ b/lib/base.ps1 @@ -1,44 +1,68 @@ . $PSScriptRoot\errors.ps1 +. $PSScriptRoot\inst.ps1 . $PSScriptRoot\strip.ps1 . $PSScriptRoot\bus.ps1 . $PSScriptRoot\macrobuttons.ps1 -$Signature = @' - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] +$global:layout = $null + +Function Setup_DLL { + try { + $vb_path = Get_VBPath + + if([string]::IsNullOrWhiteSpace($vb_path)) { + throw [VBPathError]::new("ERROR: Couldn't get Voicemeeter path") + } + else { + if([Environment]::Is64BitOperatingSystem) { + $dll = Join-Path -Path $vb_path -ChildPath "VoicemeeterRemote64.dll" + } + else { + $dll = Join-Path -Path $vb_path -ChildPath "VoicemeeterRemote.dll" + } + } + } + catch [VBPathError] { + Write-Warning $_.Exception.ErrorMessage() + return $false + } + +$Signature = @" + [DllImport(@"$dll")] public static extern int VBVMR_Login(); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_Logout(); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_RunVoicemeeter(Int64 run); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_GetVoicemeeterType(ref int ptr); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_MacroButton_IsDirty(); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_MacroButton_SetStatus(Int64 id, Single state, Int64 mode); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_MacroButton_GetStatus(Int64 id, ref float ptr, Int64 mode); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_IsParametersDirty(); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_SetParameterFloat(String param, Single value); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_GetParameterFloat(String param, ref float ptr); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_SetParameterStringA(String param, String value); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_GetParameterStringA(String param, byte[] buff); - [DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] + [DllImport(@"$dll")] public static extern int VBVMR_SetParameters(String param); -'@ +"@ -Add-Type -MemberDefinition $Signature -Name Remote -Namespace Voicemeeter -PassThru | Out-Null - -$global:layout = $null + Add-Type -MemberDefinition $Signature -Name Remote -Namespace Voicemeeter -PassThru | Out-Null + return $true +} Function Param_Set_Multi { @@ -74,7 +98,6 @@ Function Param_Set_Multi { if($k -eq "state") { $mode = 1 } elseif($k -eq "stateonly") { $mode = 2 } elseif($k -eq "trigger") { $mode = 3 } - $val = if($HASH.Item($key).values -eq "True") {1} else {0} MB_Set -ID $num -SET $val -MODE $mode } diff --git a/lib/errors.ps1 b/lib/errors.ps1 index f5d69b6..1baf352 100644 --- a/lib/errors.ps1 +++ b/lib/errors.ps1 @@ -1,3 +1,15 @@ +class VBPathError : Exception { + [String]$msg + + VBPathError([String]$msg) { + $this.msg = $msg + } + + [String] ErrorMessage() { + return $this.msg + } +} + class LoginError : Exception { [String]$msg diff --git a/lib/inst.ps1 b/lib/inst.ps1 new file mode 100644 index 0000000..312156d --- /dev/null +++ b/lib/inst.ps1 @@ -0,0 +1,15 @@ +Function Get_VBPath { + @( + 'Registry::HKEY_LOCAL_MACHINE\Software\Microsoft\Windows\CurrentVersion\Uninstall', + 'Registry::HKEY_LOCAL_MACHINE\Software\WOW6432Node\Microsoft\Windows\CurrentVersion\Uninstall' + ) | ForEach-Object { + if(Test-Path -Path $_) { + (Get-ChildItem -Path $_\*) | ForEach-Object { + if($_.Name.Contains("Voicemeeter")) { + $reg = -join("Registry::", $_.Name) + return $(Get-ItemPropertyValue -Path $reg -Name UninstallString | Split-Path -Parent) + } + } + } + } +} diff --git a/lib/macrobuttons.ps1 b/lib/macrobuttons.ps1 index e5c7d98..1d011a2 100644 --- a/lib/macrobuttons.ps1 +++ b/lib/macrobuttons.ps1 @@ -17,11 +17,9 @@ class MacroButton { hidden $_state = $($this | Add-Member ScriptProperty 'state' ` { - # get $this.Getter(1) }` { - # set param ( $arg ) $this._state = $this.Setter($arg, 1) } @@ -29,11 +27,9 @@ class MacroButton { hidden $_stateonly = $($this | Add-Member ScriptProperty 'stateonly' ` { - # get $this.Getter(2) }` { - # set param ( $arg ) $this._stateonly = $this.Setter($arg, 2) } @@ -41,11 +37,9 @@ class MacroButton { hidden $_trigger = $($this | Add-Member ScriptProperty 'trigger' ` { - # get $this.Getter(3) }` { - # set param ( $arg ) $this._trigger = $this.Setter($arg, 3) }