MOAR ERROR FIXING

This commit is contained in:
wuggy 2026-09-19 14:23:38 -07:00
commit ce566c2870
2 changed files with 19 additions and 16 deletions

View file

@ -64,10 +64,10 @@ struct USBControlTransferInfo {
uint16_t mIndex = 0; uint16_t mIndex = 0;
}; };
class USBDeviceHandle : public nsISupports class USBDeviceHandle
{ {
public: public:
NS_DECL_ISUPPORTS NS_INLINE_DECL_REFCOUNTING(USBDeviceHandle)
virtual nsresult Open() = 0; virtual nsresult Open() = 0;
virtual void Close() = 0; virtual void Close() = 0;

View file

@ -40,7 +40,8 @@ public:
return NS_ERROR_INVALID_ARG; return NS_ERROR_INVALID_ARG;
} }
mDevice = CreateFileW(reinterpret_cast<const wchar_t*>(mPath.get()), mDevice = CreateFileW(reinterpret_cast<const wchar_t*>(
static_cast<const void*>(mPath.get())),
GENERIC_READ | GENERIC_WRITE, GENERIC_READ | GENERIC_WRITE,
FILE_SHARE_READ | FILE_SHARE_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE,
nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, nullptr, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
@ -173,22 +174,25 @@ public:
nsresult ClaimInterface(uint8_t aInterfaceNumber) override nsresult ClaimInterface(uint8_t aInterfaceNumber) override
{ {
return mInterface && WinUsb_ClaimInterface(mInterface, aInterfaceNumber) // WinUSB owns the interface represented by mInterface. There is no
? NS_OK : NS_ERROR_FAILURE; // ClaimInterface API; interface 0 is already claimed by the handle.
return mInterface && aInterfaceNumber == 0
? NS_OK : NS_ERROR_NOT_IMPLEMENTED;
} }
nsresult ReleaseInterface(uint8_t aInterfaceNumber) override nsresult ReleaseInterface(uint8_t aInterfaceNumber) override
{ {
return mInterface && WinUsb_ReleaseInterface(mInterface, aInterfaceNumber) return mInterface && aInterfaceNumber == 0
? NS_OK : NS_ERROR_FAILURE; ? NS_OK : NS_ERROR_NOT_IMPLEMENTED;
} }
nsresult SelectAlternateInterface(uint8_t aInterfaceNumber, nsresult SelectAlternateInterface(uint8_t aInterfaceNumber,
uint8_t aAlternateSetting) override uint8_t aAlternateSetting) override
{ {
return mInterface && if (!mInterface || aInterfaceNumber != 0) {
WinUsb_SetCurrentAlternateSetting(mInterface, aInterfaceNumber, return NS_ERROR_NOT_IMPLEMENTED;
aAlternateSetting) }
return WinUsb_SetCurrentAlternateSetting(mInterface, aAlternateSetting)
? NS_OK : NS_ERROR_FAILURE; ? NS_OK : NS_ERROR_FAILURE;
} }
@ -204,8 +208,7 @@ public:
nsresult Reset() override nsresult Reset() override
{ {
return mInterface && WinUsb_ResetDevice(mInterface) return NS_ERROR_NOT_IMPLEMENTED;
? NS_OK : NS_ERROR_FAILURE;
} }
nsresult ControlTransferIn(const USBControlTransferInfo& aSetup, nsresult ControlTransferIn(const USBControlTransferInfo& aSetup,
@ -310,8 +313,6 @@ private:
WINUSB_INTERFACE_HANDLE mInterface; WINUSB_INTERFACE_HANDLE mInterface;
}; };
NS_IMPL_ISUPPORTS(WinUSBDeviceHandle, USBDeviceHandle)
bool bool
ParseHex(const wchar_t* aValue, uint32_t aLength, uint16_t& aResult) ParseHex(const wchar_t* aValue, uint32_t aLength, uint16_t& aResult)
{ {
@ -377,7 +378,8 @@ ParseHardwareId(const nsString& aHardwareId, USBDeviceInfo& aInfo)
(id[i + 1] == 'I' || id[i + 1] == 'i') && (id[i + 1] == 'I' || id[i + 1] == 'i') &&
(id[i + 2] == 'D' || id[i + 2] == 'd') && id[i + 3] == '_') { (id[i + 2] == 'D' || id[i + 2] == 'd') && id[i + 3] == '_') {
uint16_t value; uint16_t value;
if (ParseHex(reinterpret_cast<const wchar_t*>(id + i + 4), 4, value)) { if (ParseHex(reinterpret_cast<const wchar_t*>(
static_cast<const void*>(id + i + 4)), 4, value)) {
aInfo.mVendorId = value; aInfo.mVendorId = value;
} }
} }
@ -386,7 +388,8 @@ ParseHardwareId(const nsString& aHardwareId, USBDeviceInfo& aInfo)
(id[i + 1] == 'I' || id[i + 1] == 'i') && (id[i + 1] == 'I' || id[i + 1] == 'i') &&
(id[i + 2] == 'D' || id[i + 2] == 'd') && id[i + 3] == '_') { (id[i + 2] == 'D' || id[i + 2] == 'd') && id[i + 3] == '_') {
uint16_t value; uint16_t value;
if (ParseHex(reinterpret_cast<const wchar_t*>(id + i + 4), 4, value)) { if (ParseHex(reinterpret_cast<const wchar_t*>(
static_cast<const void*>(id + i + 4)), 4, value)) {
aInfo.mProductId = value; aInfo.mProductId = value;
} }
} }