parent
acd7ae96a6
commit
d77f99981e
|
@ -0,0 +1,3 @@
|
|||
// 加密关键字
|
||||
const keyword = 'BDQH'
|
||||
export { keyword }
|
|
@ -1,5 +1,69 @@
|
|||
import { app, BrowserWindow } from 'electron'
|
||||
import { app, BrowserWindow, dialog } from 'electron'
|
||||
import { MainWindow } from './window/localSoftware/MainWindow'
|
||||
import { keyword } from './KeyWord'
|
||||
|
||||
const child_process = require('child_process')
|
||||
const crypto = require('crypto')
|
||||
|
||||
function queryPass(passPath: string, passValue: string) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
child_process.exec(`reg query ${passPath} /v ${passValue}`, (error: Error, stdout: string, stderr: string) => {
|
||||
if (error) {
|
||||
reject(error)
|
||||
return
|
||||
}
|
||||
resolve({stdout, stderr})
|
||||
});
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function queryKey(keyPath: string, keyValue: string) {
|
||||
return new Promise(function (resolve, reject) {
|
||||
try {
|
||||
child_process.exec(`reg query ${keyPath} /v ${keyValue}`, (error: Error, stdout: string, stderr: string) => {
|
||||
if (error) {
|
||||
reject(error)
|
||||
return
|
||||
}
|
||||
resolve({stdout, stderr})
|
||||
})
|
||||
} catch (error) {
|
||||
reject(error)
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
function cryptMD5(GUID: string) {
|
||||
let md5 = crypto.createHash('md5')
|
||||
let ciphertext = md5.update(GUID).digest('hex')
|
||||
return ciphertext.slice(0,8)+'-'+ciphertext.slice(8,12)+'-'+ciphertext.slice(12,16)+'-'+ciphertext.slice(16,20)+'-'+ciphertext.slice(20,32)
|
||||
}
|
||||
|
||||
const passPath = 'HKEY_CURRENT_USER\\SOFTWARE\\HwaSmart'
|
||||
const passValue = 'BDAuthorization'
|
||||
const keyPath = 'HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Cryptography'
|
||||
const keyValue = 'MachineGuid'
|
||||
|
||||
async function checkLaunchEnv() {
|
||||
try {
|
||||
const passResult: any = await queryPass(passPath, passValue)
|
||||
const keyResult: any = await queryKey(keyPath, keyValue)
|
||||
if(cryptMD5(keyResult.stdout.slice(83,119) + keyword) == passResult.stdout.slice(72,108)){
|
||||
return true
|
||||
}else{
|
||||
return false
|
||||
}
|
||||
// 成功
|
||||
// 查询到 有这个app启动项
|
||||
} catch (error) {
|
||||
// 没有查询到该app启动项目
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
app.commandLine.appendSwitch('enable-features', 'ElectronSerialChooser')
|
||||
|
||||
|
@ -8,7 +72,6 @@ const createMainWindow = () => {
|
|||
mainWindow = new MainWindow()
|
||||
|
||||
|
||||
|
||||
mainWindow.webContents.session.on('select-serial-port', (event, portList, webContents, callback) => {
|
||||
//Add listeners to handle ports being added or removed before the callback for `select-serial-port`
|
||||
//is called.
|
||||
|
@ -49,6 +112,20 @@ const createMainWindow = () => {
|
|||
})
|
||||
}
|
||||
|
||||
async function main() {
|
||||
// 异步代码
|
||||
const checkReault: any = await checkLaunchEnv()
|
||||
console.log('env right:', checkReault)
|
||||
|
||||
// 异步代码执行完毕后执行的代码
|
||||
if (checkReault) {
|
||||
createMainWindow()
|
||||
} else {
|
||||
dialog.showErrorBox('系统提示', '软件启动出错,请联系售后技术支持人员')
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
const gotTheLock = app.requestSingleInstanceLock()
|
||||
|
||||
if (!gotTheLock) {
|
||||
|
@ -63,14 +140,14 @@ if (!gotTheLock) {
|
|||
})
|
||||
|
||||
// 创建 mainWindow, 加载应用的其余部分, etc...
|
||||
app.once('ready', createMainWindow)
|
||||
app.once('ready', main)
|
||||
|
||||
app.on('window-all-closed', () => {
|
||||
if (process.platform !== 'darwin') app.quit()
|
||||
})
|
||||
|
||||
app.on('activate', () => {
|
||||
if (BrowserWindow.getAllWindows().length === 0) createMainWindow()
|
||||
if (BrowserWindow.getAllWindows().length === 0) main()
|
||||
})
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue