|
@@ -19,6 +19,8 @@ const regeditPath32 = 'HKLM\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Unins
|
|
|
const regeditPath = isOSWin64() ? regeditPath64 : regeditPath32
|
|
|
const regedit = require('regedit')
|
|
|
let globalNUM = 0
|
|
|
+let globalSoftware = []
|
|
|
+let globalExe = []
|
|
|
|
|
|
const updateInstall = function (win) {
|
|
|
ipcMain.on('updateInstall', function () {
|
|
@@ -32,7 +34,14 @@ const updateInstall = function (win) {
|
|
|
let promiseArr = []
|
|
|
for (let i in softwarelist) {
|
|
|
if (softwarelist[i].indexOf('SmartCost_') !== -1) {
|
|
|
- promiseArr.push(getExeDataList(softwarelist[i]))
|
|
|
+ await getExeDataList(softwarelist[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ await sleep(3000)
|
|
|
+ if (globalSoftware !== []) {
|
|
|
+ for (let i in globalSoftware) {
|
|
|
+ globalSoftware[i].exeName = globalExe[i]
|
|
|
+ promiseArr.push(insertData(globalSoftware[i]))
|
|
|
}
|
|
|
}
|
|
|
await Promise.all(promiseArr)
|
|
@@ -44,13 +53,20 @@ const updateInstall = function (win) {
|
|
|
await db.read().set('sc_hadInstall.url', '/softwarestartup/' + gourl).write()
|
|
|
if (promiseArr !== undefined && promiseArr.length !== 0) {
|
|
|
win.webContents.send('successUpdate', { id: gourl, num: globalNUM, delnum: delnum })
|
|
|
+ console.log(globalSoftware)
|
|
|
globalNUM = 0
|
|
|
+ globalSoftware = []
|
|
|
+ globalExe = []
|
|
|
} else {
|
|
|
win.webContents.send('failedUpdate', { id: '1' })
|
|
|
}
|
|
|
})
|
|
|
- .catch(function () {
|
|
|
+ .catch(function (err) {
|
|
|
win.webContents.send('failedUpdate', { id: '1' })
|
|
|
+ console.log(err)
|
|
|
+ globalNUM = 0
|
|
|
+ globalSoftware = []
|
|
|
+ globalExe = []
|
|
|
})
|
|
|
} catch (err) {
|
|
|
console.log(err)
|
|
@@ -94,6 +110,24 @@ const updateInstall = function (win) {
|
|
|
setTimeout(resolve, timeout)
|
|
|
})
|
|
|
|
|
|
+ // 取文件名不带后缀
|
|
|
+ function GetFileNameNoExt (filepath) {
|
|
|
+ if (filepath !== '') {
|
|
|
+ let names = filepath.split('\\')
|
|
|
+ let pos = names[names.length - 1].lastIndexOf('.')
|
|
|
+ return names[names.length - 1].substring(0, pos)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ // 产生随机数函数
|
|
|
+ function RndNum (n) {
|
|
|
+ let rnd = ''
|
|
|
+ for (let i = 0; i < n; i++) {
|
|
|
+ rnd += Math.floor(Math.random() * 10)
|
|
|
+ }
|
|
|
+ return rnd
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 判断文件名是否包含纵横软件exe的部分名称
|
|
|
* @param item
|
|
@@ -113,90 +147,105 @@ const updateInstall = function (win) {
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * node 循环和异步解决方案
|
|
|
- * @param Info
|
|
|
+ * 数据入库
|
|
|
+ *
|
|
|
*/
|
|
|
- function getExeDataList (Info) {
|
|
|
+ function insertData (exeData) {
|
|
|
return new Promise(resolve => {
|
|
|
- // setTimeout(function () {
|
|
|
- regedit.list(regeditPath + '\\' + Info).on('data', async function (result) {
|
|
|
- let values = result.data.values
|
|
|
- let simpleVersion = values['DisplayVersion'] === undefined || values['DisplayVersion'] === null ? '' : values['DisplayVersion'].value.split('_')
|
|
|
- let exeData = {
|
|
|
- path: values['Inno Setup: App Path'].value,
|
|
|
- name: values['DisplayName'].value,
|
|
|
- regeditName: Info,
|
|
|
- fileName: values['Inno Setup: Icon Group'].value,
|
|
|
- simpleName: simpleVersion === '' ? '' : simpleVersion[0],
|
|
|
- versionName: simpleVersion === '' ? '' : simpleVersion[1]
|
|
|
- }
|
|
|
- let dirname = await fs.readdirSync(exeData.path)
|
|
|
- dirname.forEach(async function (item, index) {
|
|
|
- if (path.extname(item) === '.exe' && existSoftwareName(item)) {
|
|
|
- let pathstr = path.join('data/fileInfo.dll')
|
|
|
- let libm = ffi.Library(pathstr, {
|
|
|
- 'GetFileInfo': ['string', ['string']]
|
|
|
- })
|
|
|
- let fileinfo = JSON.parse(await libm.GetFileInfo(path.join(exeData.path, item)))
|
|
|
- exeData.fileVersion = fileinfo.FileVersion
|
|
|
- exeData.productName = fileinfo.ProductName
|
|
|
- exeData.productVersion = fileinfo.ProductVersion
|
|
|
- exeData.exeName = item
|
|
|
- let dbExeData = await db.read().get('sc_exeData').find({ exeName: exeData.exeName, path: exeData.path, fileVersion: exeData.fileVersion }).value()
|
|
|
- if (dbExeData === undefined || dbExeData === null) {
|
|
|
- // 先判断是否存在该产品数据库(同时关联到sc_sofeware.json文件数据),再加入安装包数据库
|
|
|
- if (exeData.simpleName !== '') {
|
|
|
- let softwarejson = path.join('data/sc_software.json')
|
|
|
- let productInfo = await db.read().get('sc_productData').find({ title: exeData.simpleName }).value()
|
|
|
- if (productInfo === undefined || productInfo === null) {
|
|
|
- let productlist = await fse.readJsonSync(softwarejson).sc_product
|
|
|
- for (let i in productlist) {
|
|
|
- if (productlist[i].title === exeData.simpleName) {
|
|
|
- let productInfo2 = {
|
|
|
- readid: productlist[i].product_id,
|
|
|
- title: productlist[i].title,
|
|
|
- productName: productlist[i].productName,
|
|
|
- src: productlist[i].src,
|
|
|
- addtime: Date.parse(new Date()) / 1000,
|
|
|
- isshow: true
|
|
|
- }
|
|
|
- let insertproudct = await db.read().get('sc_productData').insert(productInfo2).write()
|
|
|
- exeData.pid = insertproudct.id
|
|
|
- productInfo = insertproudct
|
|
|
- break
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- exeData.pid = productInfo.id
|
|
|
- await db.read().get('sc_productData').updateById(productInfo.id, { isshow: true }).write()
|
|
|
- }
|
|
|
- // 获取json文件中的锁号,更新到exe当中
|
|
|
- let downlist = await fse.readJsonSync(softwarejson).sc_down
|
|
|
- for (let j in downlist) {
|
|
|
- if (productInfo.readid === downlist[j].product_id && exeData.versionName === downlist[j].title) {
|
|
|
- exeData.keyNumber = downlist[j].key_number
|
|
|
- break
|
|
|
- }
|
|
|
+ let pathstr = path.join('data/fileInfo.dll')
|
|
|
+ let libm = ffi.Library(pathstr, {
|
|
|
+ 'GetFileInfo': ['string', ['string']]
|
|
|
+ })
|
|
|
+ let fileinfo = JSON.parse(libm.GetFileInfo(path.join(exeData.path, exeData.exeName)))
|
|
|
+ exeData.fileVersion = fileinfo.FileVersion
|
|
|
+ exeData.productName = fileinfo.ProductName
|
|
|
+ exeData.productVersion = fileinfo.ProductVersion
|
|
|
+ exeData.fileDescription = fileinfo.FileDescription
|
|
|
+ let dbExeData = db.read().get('sc_exeData').find({ exeName: exeData.exeName, path: exeData.path, fileVersion: exeData.fileVersion }).value()
|
|
|
+ if (dbExeData === undefined || dbExeData === null) {
|
|
|
+ // 先判断是否存在该产品数据库(同时关联到sc_sofeware.json文件数据),再加入安装包数据库
|
|
|
+ if (exeData.simpleName !== '') {
|
|
|
+ let softwarejson = path.join('data/sc_software.json')
|
|
|
+ let productInfo = db.read().get('sc_productData').find({ title: exeData.simpleName }).value()
|
|
|
+ if (productInfo === undefined || productInfo === null) {
|
|
|
+ let productlist = fse.readJsonSync(softwarejson).sc_product
|
|
|
+ for (let i in productlist) {
|
|
|
+ if (productlist[i].title === exeData.simpleName) {
|
|
|
+ let productInfo2 = {
|
|
|
+ readid: productlist[i].product_id,
|
|
|
+ title: productlist[i].title,
|
|
|
+ productName: productlist[i].productName,
|
|
|
+ src: productlist[i].src,
|
|
|
+ content: productlist[i].content,
|
|
|
+ addtime: Date.parse(new Date()) / 1000,
|
|
|
+ isshow: true
|
|
|
}
|
|
|
- } else {
|
|
|
- exeData.pid = '1'
|
|
|
- exeData.keyNumber = ''
|
|
|
- await db.read().get('sc_productData').updateById('1', { isshow: true }).write()
|
|
|
+ let insertproudct = db.read().get('sc_productData').insert(productInfo2).write()
|
|
|
+ exeData.pid = insertproudct.id
|
|
|
+ productInfo = insertproudct
|
|
|
+ break
|
|
|
}
|
|
|
- exeData.addtime = Date.parse(new Date()) / 1000
|
|
|
- exeData.isshow = true
|
|
|
- exeData.auto = true
|
|
|
- ++globalNUM
|
|
|
- await db.read().get('sc_exeData').insert(exeData).write()
|
|
|
- } else {
|
|
|
- await db.read().get('sc_productData').updateById(dbExeData.pid, { isshow: true }).write()
|
|
|
- await db.read().get('sc_exeData').updateById(dbExeData.id, { isshow: true }).write()
|
|
|
}
|
|
|
+ } else {
|
|
|
+ exeData.pid = productInfo.id
|
|
|
+ db.read().get('sc_productData').updateById(productInfo.id, { isshow: true }).write()
|
|
|
}
|
|
|
- })
|
|
|
- resolve()
|
|
|
- })
|
|
|
- // }, 1000)
|
|
|
+ // 获取json文件中的锁号,更新到exe当中
|
|
|
+ let downlist = fse.readJsonSync(softwarejson).sc_down
|
|
|
+ for (let j in downlist) {
|
|
|
+ if (productInfo.readid === downlist[j].product_id && exeData.versionName === downlist[j].title) {
|
|
|
+ exeData.keyNumber = downlist[j].key_number
|
|
|
+ exeData.keytype = downlist[j].keytype
|
|
|
+ break
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ exeData.pid = '1'
|
|
|
+ exeData.keyNumber = ''
|
|
|
+ exeData.keytype = ''
|
|
|
+ db.read().get('sc_productData').updateById('1', { isshow: true }).write()
|
|
|
+ }
|
|
|
+ exeData.addtime = Date.parse(new Date()) / 1000
|
|
|
+ exeData.isshow = true
|
|
|
+ exeData.auto = true
|
|
|
+ exeData.id = GetFileNameNoExt(exeData.exeName) + '-' + RndNum(10)
|
|
|
+ ++globalNUM
|
|
|
+ db.read().get('sc_exeData').insert(exeData).write()
|
|
|
+ } else {
|
|
|
+ db.read().get('sc_productData').updateById(dbExeData.pid, { isshow: true }).write()
|
|
|
+ db.read().get('sc_exeData').updateById(dbExeData.id, { isshow: true }).write()
|
|
|
+ }
|
|
|
+ resolve(exeData)
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * node 循环和异步解决方案
|
|
|
+ * @param Info
|
|
|
+ */
|
|
|
+ function getExeDataList (Info) {
|
|
|
+ // setTimeout(function () {
|
|
|
+ regedit.list(regeditPath + '\\' + Info).on('data', async function (result) {
|
|
|
+ let values = result.data.values
|
|
|
+ let simpleVersion = values['DisplayVersion'] === undefined || values['DisplayVersion'] === null ? '' : values['DisplayVersion'].value.split('_')
|
|
|
+ let regeditData = {
|
|
|
+ path: values['Inno Setup: App Path'].value,
|
|
|
+ name: values['DisplayName'].value,
|
|
|
+ regeditName: Info,
|
|
|
+ fileName: values['Inno Setup: Icon Group'].value,
|
|
|
+ simpleName: simpleVersion === '' ? '' : simpleVersion[0],
|
|
|
+ versionName: simpleVersion === '' ? '' : simpleVersion[1]
|
|
|
+ }
|
|
|
+ let dirname = await fs.readdirSync(regeditData.path)
|
|
|
+ for (let i in dirname) {
|
|
|
+ if (path.extname(dirname[i]) === '.exe' && existSoftwareName(dirname[i])) {
|
|
|
+ let exeData = regeditData
|
|
|
+ // exeData.exeName = diraname[i]
|
|
|
+ // 这里必须分离2个数组记录值并在外面合并,push才不会出错,否则会重复exeName名,未知bug,坑
|
|
|
+ globalSoftware.push(exeData)
|
|
|
+ globalExe.push(dirname[i])
|
|
|
+ }
|
|
|
+ }
|
|
|
})
|
|
|
}
|
|
|
}
|