|
@@ -7,7 +7,7 @@
|
|
|
* @date 2018/6/20
|
|
|
* @version
|
|
|
*/
|
|
|
-import db from '../../database/index'
|
|
|
+import db from '../../database'
|
|
|
const fs = require('fs')
|
|
|
const fse = require('fs-extra')
|
|
|
const path = require('path')
|
|
@@ -32,44 +32,52 @@ const updateInstall = function (win) {
|
|
|
await productAndExeDataIsshow()
|
|
|
let softwarelist = result.data.keys
|
|
|
let promiseArr = []
|
|
|
+ let promiseArr2 = []
|
|
|
for (let i in softwarelist) {
|
|
|
if (softwarelist[i].indexOf('SmartCost_') !== -1) {
|
|
|
- await getExeDataList(softwarelist[i])
|
|
|
+ promiseArr2.push(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)
|
|
|
+ await Promise.all(promiseArr2)
|
|
|
.then(async function (result) {
|
|
|
- let delnum = await delProductAndExeDataAsync()
|
|
|
- await db.read().set('sc_hadInstall.first', false).write()
|
|
|
- let exeInfo = await db.read().get('sc_exeData').last().value()
|
|
|
- let gourl = exeInfo.pid === undefined ? 1 : exeInfo.pid
|
|
|
- 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' })
|
|
|
+ await sleep(5000)
|
|
|
+ if (globalSoftware !== []) {
|
|
|
+ for (let i in globalSoftware) {
|
|
|
+ globalSoftware[i].exeName = globalExe[i]
|
|
|
+ promiseArr.push(insertData(globalSoftware[i]))
|
|
|
+ }
|
|
|
}
|
|
|
+ await Promise.all(promiseArr)
|
|
|
+ .then(async function (result) {
|
|
|
+ console.log(globalSoftware)
|
|
|
+ let delnum = await delProductAndExeDataAsync()
|
|
|
+ await db.read().set('sc_hadInstall.first', false).write()
|
|
|
+ let exeInfo = await db.read().get('sc_exeData').last().value()
|
|
|
+ let gourl = exeInfo === '{}' || exeInfo.pid === undefined ? 1 : exeInfo.pid
|
|
|
+ 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)
|
|
|
+ } else {
|
|
|
+ win.webContents.send('failedUpdate', {id: '1', error: 200})
|
|
|
+ }
|
|
|
+ globalNUM = 0
|
|
|
+ globalSoftware = []
|
|
|
+ globalExe = []
|
|
|
+ })
|
|
|
+ .catch(function (err) {
|
|
|
+ win.webContents.send('failedUpdate', {id: '1', error: err})
|
|
|
+ console.log(err)
|
|
|
+ globalNUM = 0
|
|
|
+ globalSoftware = []
|
|
|
+ globalExe = []
|
|
|
+ })
|
|
|
})
|
|
|
.catch(function (err) {
|
|
|
- win.webContents.send('failedUpdate', { id: '1' })
|
|
|
console.log(err)
|
|
|
- globalNUM = 0
|
|
|
- globalSoftware = []
|
|
|
- globalExe = []
|
|
|
})
|
|
|
- } catch (err) {
|
|
|
- console.log(err)
|
|
|
+ } catch (error) {
|
|
|
+ console.log(error)
|
|
|
}
|
|
|
})
|
|
|
})
|
|
@@ -224,28 +232,31 @@ const updateInstall = function (win) {
|
|
|
* @param Info
|
|
|
*/
|
|
|
function getExeDataList (Info) {
|
|
|
+ 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 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])
|
|
|
+ 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])
|
|
|
+ }
|
|
|
+ }
|
|
|
+ })
|
|
|
+ resolve('ok')
|
|
|
})
|
|
|
}
|
|
|
}
|