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)
This commit is contained in:
onyx-and-iris 2021-05-04 17:29:38 +01:00
parent b02f6891d9
commit fbe9fe68cf
6 changed files with 77 additions and 30 deletions

View File

@ -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. Before any minor/major patch is released all test units will be run to verify they pass.
## [Unreleased] ## [Unreleased]
- [ ] - [x] Fetch dll path through registry (support for 32 and 64 bit)
## [1.4] - 2021-05-03 ## [1.4] - 2021-05-03
### Added ### Added

View File

@ -14,11 +14,14 @@ class Remote {
} }
[void] Setup() { [void] Setup() {
Login -TYPE $this.type if(Setup_DLL) {
Login -TYPE $this.type
$this.button = Buttons $this.button = Buttons
$this.strip = Strips $this.strip = Strips
$this.bus = Buses $this.bus = Buses
}
else { Exit }
} }
[void] Logout() { [void] Logout() {

View File

@ -1,44 +1,68 @@
. $PSScriptRoot\errors.ps1 . $PSScriptRoot\errors.ps1
. $PSScriptRoot\inst.ps1
. $PSScriptRoot\strip.ps1 . $PSScriptRoot\strip.ps1
. $PSScriptRoot\bus.ps1 . $PSScriptRoot\bus.ps1
. $PSScriptRoot\macrobuttons.ps1 . $PSScriptRoot\macrobuttons.ps1
$Signature = @' $global:layout = $null
[DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")]
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(); public static extern int VBVMR_Login();
[DllImport(@"C:\Program Files (x86)\VB\Voicemeeter\VoicemeeterRemote64.dll")] [DllImport(@"$dll")]
public static extern int VBVMR_Logout(); 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); 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); 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(); 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); 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); 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(); 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); 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); 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); 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); 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); public static extern int VBVMR_SetParameters(String param);
'@ "@
Add-Type -MemberDefinition $Signature -Name Remote -Namespace Voicemeeter -PassThru | Out-Null Add-Type -MemberDefinition $Signature -Name Remote -Namespace Voicemeeter -PassThru | Out-Null
return $true
$global:layout = $null }
Function Param_Set_Multi { Function Param_Set_Multi {
@ -74,7 +98,6 @@ Function Param_Set_Multi {
if($k -eq "state") { $mode = 1 } if($k -eq "state") { $mode = 1 }
elseif($k -eq "stateonly") { $mode = 2 } elseif($k -eq "stateonly") { $mode = 2 }
elseif($k -eq "trigger") { $mode = 3 } 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 MB_Set -ID $num -SET $val -MODE $mode
} }

View File

@ -1,3 +1,15 @@
class VBPathError : Exception {
[String]$msg
VBPathError([String]$msg) {
$this.msg = $msg
}
[String] ErrorMessage() {
return $this.msg
}
}
class LoginError : Exception { class LoginError : Exception {
[String]$msg [String]$msg

15
lib/inst.ps1 Normal file
View File

@ -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)
}
}
}
}
}

View File

@ -17,11 +17,9 @@ class MacroButton {
hidden $_state = $($this | Add-Member ScriptProperty 'state' ` hidden $_state = $($this | Add-Member ScriptProperty 'state' `
{ {
# get
$this.Getter(1) $this.Getter(1)
}` }`
{ {
# set
param ( $arg ) param ( $arg )
$this._state = $this.Setter($arg, 1) $this._state = $this.Setter($arg, 1)
} }
@ -29,11 +27,9 @@ class MacroButton {
hidden $_stateonly = $($this | Add-Member ScriptProperty 'stateonly' ` hidden $_stateonly = $($this | Add-Member ScriptProperty 'stateonly' `
{ {
# get
$this.Getter(2) $this.Getter(2)
}` }`
{ {
# set
param ( $arg ) param ( $arg )
$this._stateonly = $this.Setter($arg, 2) $this._stateonly = $this.Setter($arg, 2)
} }
@ -41,11 +37,9 @@ class MacroButton {
hidden $_trigger = $($this | Add-Member ScriptProperty 'trigger' ` hidden $_trigger = $($this | Add-Member ScriptProperty 'trigger' `
{ {
# get
$this.Getter(3) $this.Getter(3)
}` }`
{ {
# set
param ( $arg ) param ( $arg )
$this._trigger = $this.Setter($arg, 3) $this._trigger = $this.Setter($arg, 3)
} }