mirror of
https://github.com/onyx-and-iris/voicemeeter-api-powershell.git
synced 2025-01-18 05:10:48 +00:00
Login refactor.
Return Exit value -2 for multiple login attempts.
This commit is contained in:
parent
3b1bb06c7d
commit
3b1e469d2d
41
lib/base.ps1
41
lib/base.ps1
@ -11,41 +11,40 @@
|
|||||||
|
|
||||||
function Login {
|
function Login {
|
||||||
param(
|
param(
|
||||||
[string]$KIND = $null
|
[string]$kindId
|
||||||
)
|
)
|
||||||
try {
|
try {
|
||||||
$retval = [int][Voicemeeter.Remote]::VBVMR_Login()
|
$retval = [int][Voicemeeter.Remote]::VBVMR_Login()
|
||||||
if (-not $retval) { "LOGGED IN" | Write-Verbose }
|
if (-not $retval) {
|
||||||
|
"LOGGED IN" | Write-Verbose
|
||||||
|
}
|
||||||
elseif ($retval -eq 1) {
|
elseif ($retval -eq 1) {
|
||||||
"VM NOT RUNNING" | Write-Verbose
|
"VM NOT RUNNING" | Write-Verbose
|
||||||
New-Variable -Name vm_exe -Value 0
|
New-Variable -Name vmExe -Value 0
|
||||||
|
|
||||||
switch ($KIND) {
|
if ( $kindId -eq "basic" ) { $vmExe = 1 }
|
||||||
'basic' { $vm_exe = 1; break }
|
elseif ( $kindId -eq "banana" ) { $vmExe = 2 }
|
||||||
'banana' { $vm_exe = 2; break }
|
elseif ( $kindId -eq "potato" ) {
|
||||||
'potato' {
|
$vmExe = $(if ([Environment]::Is64BitOperatingSystem) { 6 } else { 3 })
|
||||||
if ([Environment]::Is64BitOperatingSystem) {
|
|
||||||
$vm_exe = 6
|
|
||||||
}
|
|
||||||
else { $vm_exe = 3 }
|
|
||||||
break
|
|
||||||
}
|
|
||||||
default { throw [LoginError]::new('Unknown Voicemeeter type') }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$retval = [int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([int64]$vm_exe)
|
$retval = [int][Voicemeeter.Remote]::VBVMR_RunVoicemeeter([int64]$vmExe)
|
||||||
if (-not $retval) { "STARTING VOICEMEETER" | Write-Verbose }
|
if (-not $retval) {
|
||||||
else { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
"STARTING VOICEMEETER" | Write-Verbose
|
||||||
Start-Sleep -s 1
|
Start-Sleep -s 1
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
throw [CAPIError]::new($retval, $MyInvocation.MyCommand)
|
||||||
|
}
|
||||||
|
}
|
||||||
elseif ($retval -eq -2) {
|
elseif ($retval -eq -2) {
|
||||||
throw [LoginError]::new('Login may only be called once per session')
|
throw [LoginError]::new('login may only be called once per session')
|
||||||
}
|
}
|
||||||
else { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
else { throw [CAPIError]::new($retval, $MyInvocation.MyCommand) }
|
||||||
}
|
}
|
||||||
catch [LoginError], [CAPIError] {
|
catch [LoginError] {
|
||||||
Write-Warning $_.Exception.ErrorMessage()
|
Write-Warning "$($_.Exception.ErrorMessage()). Fatal error, exiting..."
|
||||||
throw
|
exit -2
|
||||||
}
|
}
|
||||||
|
|
||||||
while (P_Dirty -or M_Dirty) { Start-Sleep -m 1 }
|
while (P_Dirty -or M_Dirty) { Start-Sleep -m 1 }
|
||||||
|
Loading…
Reference in New Issue
Block a user