mirror of
https://github.com/onyx-and-iris/voicemeeter-api-python.git
synced 2026-05-01 17:53:30 +00:00
the platform check is mostly redundant because import winreg will have already failed on most python installations
swith to ct.WinDLL which is intended for C APIs using stdcall convention.
This commit is contained in:
@@ -1,15 +1,22 @@
|
|||||||
import ctypes as ct
|
import ctypes as ct
|
||||||
import platform
|
import platform
|
||||||
import winreg
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
from .error import InstallError
|
from .error import InstallError, VMError
|
||||||
|
|
||||||
|
try:
|
||||||
|
import winreg
|
||||||
|
except ImportError as e:
|
||||||
|
ERR_MSG = 'winreg module not found, only Windows OS supported'
|
||||||
|
raise VMError(ERR_MSG) from e
|
||||||
|
|
||||||
|
# Defense against edge cases where winreg imports but we're not on Windows
|
||||||
|
if platform.system() != 'Windows':
|
||||||
|
ERR_MSG = f'Unsupported OS: {platform.system()}, only Windows OS supported'
|
||||||
|
raise VMError(ERR_MSG)
|
||||||
|
|
||||||
BITS = 64 if ct.sizeof(ct.c_void_p) == 8 else 32
|
BITS = 64 if ct.sizeof(ct.c_void_p) == 8 else 32
|
||||||
|
|
||||||
if platform.system() != 'Windows':
|
|
||||||
raise InstallError('Only Windows OS supported')
|
|
||||||
|
|
||||||
|
|
||||||
VM_KEY = 'VB:Voicemeeter {17359A74-1236-5467}'
|
VM_KEY = 'VB:Voicemeeter {17359A74-1236-5467}'
|
||||||
REG_KEY = '\\'.join(
|
REG_KEY = '\\'.join(
|
||||||
@@ -37,12 +44,14 @@ def get_vmpath():
|
|||||||
try:
|
try:
|
||||||
vm_parent = Path(get_vmpath()).parent
|
vm_parent = Path(get_vmpath()).parent
|
||||||
except FileNotFoundError as e:
|
except FileNotFoundError as e:
|
||||||
raise InstallError('Unable to fetch DLL path from the registry') from e
|
ERR_MSG = 'Unable to fetch DLL path from the registry'
|
||||||
|
raise InstallError(ERR_MSG) from e
|
||||||
|
|
||||||
DLL_NAME = f'VoicemeeterRemote{"64" if BITS == 64 else ""}.dll'
|
DLL_NAME = f'VoicemeeterRemote{"64" if BITS == 64 else ""}.dll'
|
||||||
|
|
||||||
dll_path = vm_parent.joinpath(DLL_NAME)
|
dll_path = vm_parent.joinpath(DLL_NAME)
|
||||||
if not dll_path.is_file():
|
if not dll_path.is_file():
|
||||||
raise InstallError(f'Could not find {dll_path}')
|
ERR_MSG = f'Could not find {dll_path}'
|
||||||
|
raise InstallError(ERR_MSG)
|
||||||
|
|
||||||
libc = ct.CDLL(str(dll_path))
|
libc = ct.WinDLL(str(dll_path))
|
||||||
|
|||||||
Reference in New Issue
Block a user