|
@@ -76,37 +76,44 @@ const downloads = function (win) {
|
|
|
download(win, downloadpath, options)
|
|
|
.then(function (dl) {
|
|
|
try {
|
|
|
+ // 判断下载的是安装包 or 压缩包
|
|
|
let zippath = path.join(__appPath, folderpath)
|
|
|
let zipname = info.savepath
|
|
|
- let exename = ''
|
|
|
- fs.createReadStream(path.join(zippath, zipname))
|
|
|
- .on('error', function (error) {
|
|
|
- throw error
|
|
|
- })
|
|
|
- .pipe(new compressing.zip.UncompressStream())
|
|
|
- .on('error', function (error) {
|
|
|
- throw error
|
|
|
- })
|
|
|
- .on('finish', function () {
|
|
|
- // 完成后删除zip压缩包
|
|
|
- fs.unlinkSync(path.join(zippath, zipname))
|
|
|
- console.log('ok')
|
|
|
- win.webContents.send('downloadsuccess', {id: args.id, savepath: path.join(zippath, exename), index: args.index})
|
|
|
- })
|
|
|
- .on('entry', function (header, stream, next) {
|
|
|
- stream.on('end', next)
|
|
|
- // header.type => file | directory
|
|
|
- // header.name => path name
|
|
|
- exename = header.name
|
|
|
- if (header.type === 'file') {
|
|
|
- stream.pipe(fs.createWriteStream(path.join(zippath, header.name)))
|
|
|
- } else { // directory
|
|
|
- mkdirp(path.join(zippath, header.name), err => {
|
|
|
- if (err) throw err
|
|
|
- stream.resume()
|
|
|
- })
|
|
|
- }
|
|
|
- })
|
|
|
+ let suffix = zipname.substring(zipname.lastIndexOf('.') + 1, zipname.length)
|
|
|
+ if (suffix === 'exe') {
|
|
|
+ console.log('ok')
|
|
|
+ win.webContents.send('downloadsuccess', {id: args.id, savepath: path.join(zippath, zipname), index: args.index})
|
|
|
+ } else {
|
|
|
+ let exename = ''
|
|
|
+ fs.createReadStream(path.join(zippath, zipname))
|
|
|
+ .on('error', function (error) {
|
|
|
+ throw error
|
|
|
+ })
|
|
|
+ .pipe(new compressing.zip.UncompressStream())
|
|
|
+ .on('error', function (error) {
|
|
|
+ throw error
|
|
|
+ })
|
|
|
+ .on('finish', function () {
|
|
|
+ // 完成后删除zip压缩包
|
|
|
+ fs.unlinkSync(path.join(zippath, zipname))
|
|
|
+ console.log('ok')
|
|
|
+ win.webContents.send('downloadsuccess', {id: args.id, savepath: path.join(zippath, exename), index: args.index})
|
|
|
+ })
|
|
|
+ .on('entry', function (header, stream, next) {
|
|
|
+ stream.on('end', next)
|
|
|
+ // header.type => file | directory
|
|
|
+ // header.name => path name
|
|
|
+ exename = header.name
|
|
|
+ if (header.type === 'file') {
|
|
|
+ stream.pipe(fs.createWriteStream(path.join(zippath, header.name)))
|
|
|
+ } else { // directory
|
|
|
+ mkdirp(path.join(zippath, header.name), err => {
|
|
|
+ if (err) throw err
|
|
|
+ stream.resume()
|
|
|
+ })
|
|
|
+ }
|
|
|
+ })
|
|
|
+ }
|
|
|
} catch (err) {
|
|
|
console.log(err)
|
|
|
}
|