mirror of
https://github.com/DarkMatterCore/nxdumptool.git
synced 2025-04-29 14:09:25 -04:00
host: add macOS support
Update USB initialization to explicitly check a few common libusb locations on macOS (both Intel and Apple Silicon) and prompt the user to install libusb via Homebrew if not found.
This commit is contained in:
parent
8dcb46365e
commit
d0b7c65e99
2 changed files with 29 additions and 1 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -21,3 +21,6 @@ host/nxdumptool
|
|||
# TODO: remove this after the PoC builds are no longer needed.
|
||||
main.cpp
|
||||
/code_templates/tmp/*
|
||||
|
||||
# macOS
|
||||
*.DS_Store
|
||||
|
|
|
@ -46,6 +46,7 @@ import time
|
|||
import struct
|
||||
import usb.core
|
||||
import usb.util
|
||||
import usb.backend.libusb1
|
||||
import warnings
|
||||
import base64
|
||||
|
||||
|
@ -644,6 +645,25 @@ def usbGetDeviceEndpoints() -> bool:
|
|||
usb_ep_in_lambda = lambda ep: usb.util.endpoint_direction(ep.bEndpointAddress) == usb.util.ENDPOINT_IN
|
||||
usb_ep_out_lambda = lambda ep: usb.util.endpoint_direction(ep.bEndpointAddress) == usb.util.ENDPOINT_OUT
|
||||
|
||||
# Try to find libusb backend explicitly on macOS
|
||||
backend = None
|
||||
if platform.system() == 'Darwin':
|
||||
possible_paths = [
|
||||
'/usr/local/lib/libusb-1.0.dylib', # Intel Homebrew
|
||||
'/opt/homebrew/lib/libusb-1.0.dylib', # Apple Silicon Homebrew
|
||||
'/usr/lib/libusb-1.0.dylib' # System location
|
||||
]
|
||||
|
||||
for path in possible_paths:
|
||||
if os.path.exists(path):
|
||||
g_logger.debug(f'Using libusb from: {path}')
|
||||
backend = usb.backend.libusb1.get_backend(find_library=lambda x: path)
|
||||
break
|
||||
|
||||
if not backend:
|
||||
g_logger.error('Could not find libusb library. Please install it using: brew install libusb')
|
||||
return False
|
||||
|
||||
if g_cliMode:
|
||||
g_logger.info(SERVER_START_MSG)
|
||||
|
||||
|
@ -658,6 +678,9 @@ def usbGetDeviceEndpoints() -> bool:
|
|||
# Find a connected USB device with a matching VID/PID pair.
|
||||
# Using == here to compare both device instances would also compare the backend, so we'll just compare certain elements manually.
|
||||
try:
|
||||
if backend:
|
||||
cur_dev = usb.core.find(find_all=False, idVendor=USB_DEV_VID, idProduct=USB_DEV_PID, backend=backend)
|
||||
else:
|
||||
cur_dev = usb.core.find(find_all=False, idVendor=USB_DEV_VID, idProduct=USB_DEV_PID)
|
||||
except:
|
||||
if not g_cliMode:
|
||||
|
@ -667,6 +690,8 @@ def usbGetDeviceEndpoints() -> bool:
|
|||
|
||||
if g_isWindows:
|
||||
g_logger.error('Try reinstalling the libusbK driver using Zadig.')
|
||||
elif backend:
|
||||
g_logger.error('On macOS, make sure libusb is installed: brew install libusb')
|
||||
|
||||
return False
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue