| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960 |
- 'use strict'
- /**
- * 软件锁检测
- *
- * @author EllisRan.
- * @date 2018/6/20
- * @version
- */
- const path = require('path')
- const ffi = require('ffi')
- const electron = require('electron')
- const Notification = electron.Notification
- const ipcMain = electron.ipcMain
- const usb = require('usb')
- const usbffi = function (win) {
- ipcMain.on('testUsb', function () {
- testUsb(win.webContents)
- })
- usb.on('attach', function (device) {
- testUsb(win.webContents)
- })
- usb.on('detach', function (device) {
- win.webContents.send('usbOut')
- const notification = new Notification({
- title: '软件锁',
- body: '你的软件锁已拔出'
- })
- notification.show()
- })
- }
- async function testUsb (webContents) {
- try {
- let pathstr = path.join('data/zhlData.dll')
- let libm = ffi.Library(pathstr, {
- 'GetProductIDList': ['string', []]
- })
- console.log(await libm.GetProductIDList())
- let alllist = await libm.GetProductIDList()
- if (alllist !== '') {
- // let productlist = alllist.split('|')
- // for (let i in productlist) {
- // let productNum = productlist[i].split(':')[0]
- // let productVerList = productlist[i].split(':')[1].split(';')
- // }
- }
- webContents.send('usbIn')
- const notification = new Notification({
- title: '软件锁',
- body: '启动器检测到软件锁'
- })
- notification.show()
- } catch (err) {
- console.error(err)
- }
- }
- export default usbffi
|