winusb-driver-generator 1.5.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.versionbot/CHANGELOG.yml +15 -1
- package/CHANGELOG.md +6 -0
- package/binding.gyp +5 -1
- package/package.json +6 -6
- package/src/generator.cpp +64 -39
- package/src/generator.h +3 -3
|
@@ -1,3 +1,17 @@
|
|
|
1
|
+
- commits:
|
|
2
|
+
- subject: "patch: fix linting long lines"
|
|
3
|
+
hash: 1c449945e94871e64d477284c2ec0d3f0cc8adf1
|
|
4
|
+
body: ""
|
|
5
|
+
footer: {}
|
|
6
|
+
author: mcraa
|
|
7
|
+
- subject: "major: migrate to NAPI"
|
|
8
|
+
hash: de012670ef0b6abe303cb345774cab9d6412962e
|
|
9
|
+
body: ""
|
|
10
|
+
footer: {}
|
|
11
|
+
author: mcraa
|
|
12
|
+
version: 2.0.0
|
|
13
|
+
title: ""
|
|
14
|
+
date: 2023-02-13T14:55:46.389Z
|
|
1
15
|
- commits:
|
|
2
16
|
- subject: Add support for Node 18
|
|
3
17
|
hash: f366578887174f2dea005735f92f16ff5cd2f5f8
|
|
@@ -8,7 +22,7 @@
|
|
|
8
22
|
author: Akis Kesoglou
|
|
9
23
|
version: 1.5.0
|
|
10
24
|
title: ""
|
|
11
|
-
date: 2023-01-20T10:
|
|
25
|
+
date: 2023-01-20T10:11:05.406Z
|
|
12
26
|
- commits:
|
|
13
27
|
- subject: "chore(deps): update deps/libwdi digest to 6722681"
|
|
14
28
|
hash: cf7f1a17a93adff95ebed2809f9bfd5c71cdc9e0
|
package/CHANGELOG.md
CHANGED
package/binding.gyp
CHANGED
|
@@ -193,9 +193,13 @@
|
|
|
193
193
|
{
|
|
194
194
|
"target_name": "Generator",
|
|
195
195
|
"include_dirs" : [
|
|
196
|
-
"
|
|
196
|
+
"<!@(node -p \"require('node-addon-api').include\")",
|
|
197
197
|
"."
|
|
198
198
|
],
|
|
199
|
+
'dependencies': ["<!(node -p \"require('node-addon-api').gyp\")"],
|
|
200
|
+
"defines": [
|
|
201
|
+
"NAPI_VERSION=<(napi_build_version)"
|
|
202
|
+
],
|
|
199
203
|
"conditions": [
|
|
200
204
|
[ "OS=='win'", {
|
|
201
205
|
"dependencies" : [
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "winusb-driver-generator",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"main": "index.js",
|
|
5
5
|
"description": "Associate a USB vendor/product ID pair with WinUSB",
|
|
6
6
|
"homepage": "https://github.com/resin-io-modules/winusb-driver-generator",
|
|
@@ -19,14 +19,14 @@
|
|
|
19
19
|
"configure": "node-gyp configure",
|
|
20
20
|
"build-windows": "node-gyp rebuild",
|
|
21
21
|
"build": "echo npm run build-windows",
|
|
22
|
-
"rebuild": "prebuild-install || node-gyp rebuild",
|
|
22
|
+
"rebuild": "prebuild-install --runtime napi || node-gyp rebuild",
|
|
23
23
|
"lint-js": "eslint *.js",
|
|
24
24
|
"lint-cpp": "cpplint --recursive src",
|
|
25
25
|
"lint": "npm run lint-js && npm run lint-cpp",
|
|
26
26
|
"test-windows": "npm run lint",
|
|
27
27
|
"test": "echo npm run test-windows",
|
|
28
|
-
"install": "prebuild-install || node-gyp rebuild",
|
|
29
|
-
"prebuilds": "prebuild"
|
|
28
|
+
"install": "prebuild-install --runtime napi || node-gyp rebuild",
|
|
29
|
+
"prebuilds": "prebuild --runtime napi"
|
|
30
30
|
},
|
|
31
31
|
"author": "Juan Cruz Viotti <juan@resin.io>",
|
|
32
32
|
"license": "Apache-2.0",
|
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
},
|
|
42
42
|
"dependencies": {
|
|
43
43
|
"bindings": "^1.5.0",
|
|
44
|
-
"
|
|
44
|
+
"node-addon-api": "^5.0.0",
|
|
45
45
|
"prebuild-install": "^7.1.1"
|
|
46
46
|
},
|
|
47
47
|
"gypfile": true,
|
|
@@ -52,6 +52,6 @@
|
|
|
52
52
|
"node": ">=16 < 19"
|
|
53
53
|
},
|
|
54
54
|
"versionist": {
|
|
55
|
-
"publishedAt": "2023-
|
|
55
|
+
"publishedAt": "2023-02-13T14:55:46.578Z"
|
|
56
56
|
}
|
|
57
57
|
}
|
package/src/generator.cpp
CHANGED
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
17
|
#include "src/generator.h"
|
|
18
|
+
#include <napi.h>
|
|
18
19
|
|
|
19
20
|
static int
|
|
20
21
|
generator_list_driverless_devices(struct wdi_device_info **result) {
|
|
@@ -46,10 +47,11 @@ generator_install_winusb_inf(struct wdi_device_info *device,
|
|
|
46
47
|
return wdi_install_driver(device, path, name, NULL);
|
|
47
48
|
}
|
|
48
49
|
|
|
49
|
-
|
|
50
|
+
Napi::Value ListDriverlessDevices(const Napi::CallbackInfo& info) {
|
|
50
51
|
int code = WDI_SUCCESS;
|
|
51
52
|
struct wdi_device_info *device_list_node;
|
|
52
|
-
|
|
53
|
+
Napi::Env env = info.Env();
|
|
54
|
+
Napi::Object devices = Napi::Array::New(env);
|
|
53
55
|
wdi_set_log_level(WDI_LOG_LEVEL_WARNING);
|
|
54
56
|
|
|
55
57
|
code = generator_list_driverless_devices(&device_list_node);
|
|
@@ -57,22 +59,24 @@ NAN_METHOD(listDriverlessDevices) {
|
|
|
57
59
|
uint32_t index = 0;
|
|
58
60
|
for (; device_list_node != NULL
|
|
59
61
|
; device_list_node = device_list_node->next) {
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
62
|
+
Napi::Object device = Napi::Object::New(env);
|
|
63
|
+
device.Set(Napi::String::New(env, "vid"),
|
|
64
|
+
Napi::Number::New(env, static_cast<double>(device_list_node->vid)));
|
|
65
|
+
device.Set(Napi::String::New(env, "pid"),
|
|
66
|
+
Napi::Number::New(env, static_cast<double>(device_list_node->pid)));
|
|
67
|
+
device.Set(Napi::String::New(env, "hid"),
|
|
68
|
+
Napi::String::New(env, device_list_node->hardware_id));
|
|
69
|
+
device.Set(Napi::String::New(env, "did"),
|
|
70
|
+
Napi::String::New(env, device_list_node->device_id));
|
|
71
|
+
device.Set(index, device);
|
|
70
72
|
index++;
|
|
71
73
|
}
|
|
72
74
|
|
|
73
75
|
code = wdi_destroy_list(device_list_node);
|
|
74
76
|
if (code != WDI_SUCCESS) {
|
|
75
|
-
|
|
77
|
+
Napi::TypeError::New(env, wdi_strerror(code))
|
|
78
|
+
.ThrowAsJavaScriptException();
|
|
79
|
+
return env.Null();
|
|
76
80
|
}
|
|
77
81
|
|
|
78
82
|
// This means the returned list is empty.
|
|
@@ -81,37 +85,45 @@ NAN_METHOD(listDriverlessDevices) {
|
|
|
81
85
|
// If the list of driverless devices is empty, then we
|
|
82
86
|
// can assume every device has a driver.
|
|
83
87
|
} else if (code != WDI_ERROR_NO_DEVICE) {
|
|
84
|
-
|
|
88
|
+
Napi::TypeError::New(env, wdi_strerror(code))
|
|
89
|
+
.ThrowAsJavaScriptException();
|
|
90
|
+
return env.Null();
|
|
85
91
|
}
|
|
86
92
|
|
|
87
|
-
|
|
93
|
+
return devices;
|
|
88
94
|
}
|
|
89
95
|
|
|
90
|
-
|
|
96
|
+
Napi::Value Associate(const Napi::CallbackInfo& info) {
|
|
97
|
+
Napi::Env env = info.Env();
|
|
98
|
+
|
|
91
99
|
if (info.Length() != 3) {
|
|
92
|
-
|
|
100
|
+
Napi::TypeError::New(env, "This function expects 3 arguments")
|
|
101
|
+
.ThrowAsJavaScriptException();
|
|
102
|
+
return env.Null();
|
|
93
103
|
}
|
|
94
104
|
|
|
95
|
-
if (!info[0]
|
|
96
|
-
|
|
105
|
+
if (!info[0].IsNumber()) {
|
|
106
|
+
Napi::TypeError::New(env, "Product id must be a number")
|
|
107
|
+
.ThrowAsJavaScriptException();
|
|
108
|
+
return env.Null();
|
|
97
109
|
}
|
|
98
110
|
|
|
99
|
-
if (!info[1]
|
|
100
|
-
|
|
111
|
+
if (!info[1].IsNumber()) {
|
|
112
|
+
Napi::TypeError::New(env, "Vendor id must be a number")
|
|
113
|
+
.ThrowAsJavaScriptException();
|
|
114
|
+
return env.Null();
|
|
101
115
|
}
|
|
102
116
|
|
|
103
|
-
if (!info[2]
|
|
104
|
-
|
|
117
|
+
if (!info[2].IsString()) {
|
|
118
|
+
Napi::TypeError::New(env, "Description must be a string")
|
|
119
|
+
.ThrowAsJavaScriptException();
|
|
120
|
+
return env.Null();
|
|
105
121
|
}
|
|
106
122
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
const uint16_t vendor = info[0]->Uint32Value(context).ToChecked();
|
|
110
|
-
const uint16_t product = info[1]->Uint32Value(context).ToChecked();
|
|
123
|
+
const uint32_t vendor = info[0].As<Napi::Number>().Uint32Value();
|
|
124
|
+
const uint32_t product = info[1].As<Napi::Number>().Uint32Value();
|
|
111
125
|
|
|
112
|
-
|
|
113
|
-
Nan::Utf8String description_v8(info[2]->ToString(context).ToLocalChecked());
|
|
114
|
-
std::string description_string = std::string(*description_v8);
|
|
126
|
+
std::string description_string = info[2].As<Napi::String>().Utf8Value();
|
|
115
127
|
char *description = new char[description_string.length() + 1];
|
|
116
128
|
// cpplint suggests snprintf over strcpy, but the former
|
|
117
129
|
// is not implemented in Visual Studio 2013.
|
|
@@ -140,7 +152,9 @@ NAN_METHOD(associate) {
|
|
|
140
152
|
std::cout << "Extracting driver files" << std::endl;
|
|
141
153
|
code = generator_generate_winusb_inf(&device, INF_NAME, INF_PATH);
|
|
142
154
|
if (code != WDI_SUCCESS) {
|
|
143
|
-
|
|
155
|
+
Napi::TypeError::New(env, wdi_strerror(code))
|
|
156
|
+
.ThrowAsJavaScriptException();
|
|
157
|
+
return env.Null();
|
|
144
158
|
}
|
|
145
159
|
|
|
146
160
|
std::cout << "Installing driver" << std::endl;
|
|
@@ -158,28 +172,39 @@ NAN_METHOD(associate) {
|
|
|
158
172
|
} else if (code == WDI_ERROR_NO_DEVICE) {
|
|
159
173
|
matching_device_found = false;
|
|
160
174
|
} else {
|
|
161
|
-
|
|
175
|
+
Napi::TypeError::New(env, wdi_strerror(code))
|
|
176
|
+
.ThrowAsJavaScriptException();
|
|
177
|
+
return env.Null();
|
|
162
178
|
}
|
|
163
179
|
|
|
164
180
|
code = generator_install_winusb_inf(&device, INF_NAME, INF_PATH);
|
|
165
181
|
if (code != WDI_SUCCESS) {
|
|
166
|
-
|
|
182
|
+
Napi::TypeError::New(env, wdi_strerror(code))
|
|
183
|
+
.ThrowAsJavaScriptException();
|
|
184
|
+
return env.Null();
|
|
167
185
|
}
|
|
168
186
|
|
|
169
187
|
if (matching_device_found) {
|
|
170
188
|
code = wdi_destroy_list(device_list_node);
|
|
171
189
|
if (code != WDI_SUCCESS) {
|
|
172
|
-
|
|
190
|
+
Napi::TypeError::New(env, wdi_strerror(code))
|
|
191
|
+
.ThrowAsJavaScriptException();
|
|
192
|
+
return env.Null();
|
|
173
193
|
}
|
|
174
194
|
}
|
|
175
195
|
|
|
176
196
|
delete [] description;
|
|
177
|
-
|
|
197
|
+
return env.Undefined();
|
|
178
198
|
}
|
|
179
199
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
200
|
+
Napi::Object Init(Napi::Env env, Napi::Object exports) {
|
|
201
|
+
exports.Set(
|
|
202
|
+
Napi::String::New(env, "listDriverlessDevices"),
|
|
203
|
+
Napi::Function::New(env, ListDriverlessDevices));
|
|
204
|
+
exports.Set(
|
|
205
|
+
Napi::String::New(env, "associate"),
|
|
206
|
+
Napi::Function::New(env, Associate));
|
|
207
|
+
return exports;
|
|
183
208
|
}
|
|
184
209
|
|
|
185
|
-
|
|
210
|
+
NODE_API_MODULE(Generator, Init)
|
package/src/generator.h
CHANGED
|
@@ -18,7 +18,7 @@
|
|
|
18
18
|
*/
|
|
19
19
|
|
|
20
20
|
#include <stdio.h>
|
|
21
|
-
#include <
|
|
21
|
+
#include <napi.h>
|
|
22
22
|
#include <libwdi.h>
|
|
23
23
|
#include <string>
|
|
24
24
|
#include <iostream>
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
#pragma warning(disable:28159)
|
|
33
33
|
#endif
|
|
34
34
|
|
|
35
|
-
|
|
36
|
-
|
|
35
|
+
Napi::Value listDriverlessDevices(const Napi::CallbackInfo& info);
|
|
36
|
+
Napi::Value associate(const Napi::CallbackInfo& info);
|
|
37
37
|
|
|
38
38
|
#endif // SRC_GENERATOR_H_
|