最近计划重写downloadPlus_fx98.uc.js
,原来的快速保存列表是写死的,准备改成从about:config
读取,配置项不存在则列出所有盘符。
查了一下 win32 api,有个可以获取盘符的函数
之前就写过调用dll的代码,参数的类型都没试过,只能searchfox,搜一下,有参考,那就好办了。
function getAllDrives() {
let kernel32 = ctypes.open("kernel32.dll");
let GetLogicalDriveStringsW = kernel32.declare('GetLogicalDriveStringsW', ctypes.winapi_abi, ctypes.unsigned_long, ctypes.uint32_t, ctypes.char16_t.ptr);
let buffer = new (ctypes.ArrayType(ctypes.char16_t, 1024))();
let rv = GetLogicalDriveStringsW(buffer.length, buffer);
let resultLen = parseInt(rv.toString() || "0");
let arr = [];
if (!resultLen) {
kernel32.close();
return arr;
}
for (let i = 0; i < resultLen; i++) {
arr[i] = buffer.addressOfElement(i).contents;
}
arr = arr.join('').split('\0').filter(el => el.length);
kernel32.close();
return arr;
}