2019-06-15 19:52:28 +10:00
|
|
|
function dl(mainWindow, lang_path, base, dirname) {
|
2020-03-06 03:51:06 +11:00
|
|
|
const electron = require('electron')
|
|
|
|
const shell = electron.shell
|
|
|
|
const fs = require('fs')
|
|
|
|
const { download } = require('electron-dl')
|
|
|
|
const BrowserWindow = electron.BrowserWindow
|
|
|
|
const dialog = electron.dialog
|
|
|
|
var updatewin = null
|
|
|
|
var ipc = electron.ipcMain
|
|
|
|
const app = electron.app
|
|
|
|
const join = require('path').join
|
|
|
|
ipc.on('update', function(e, x, y) {
|
|
|
|
var platform = process.platform
|
|
|
|
var bit = process.arch
|
|
|
|
if (platform != 'others') {
|
2019-05-19 17:39:30 +10:00
|
|
|
updatewin = new BrowserWindow({
|
2019-05-19 20:24:27 +10:00
|
|
|
webPreferences: {
|
2019-06-15 19:52:28 +10:00
|
|
|
webviewTag: false,
|
|
|
|
nodeIntegration: false,
|
|
|
|
contextIsolation: true,
|
2020-03-06 03:51:06 +11:00
|
|
|
preload: join(dirname, 'js', 'platform', 'preload.js')
|
2019-05-19 20:24:27 +10:00
|
|
|
},
|
2019-05-19 17:39:30 +10:00
|
|
|
width: 600,
|
|
|
|
height: 400,
|
2020-03-06 03:51:06 +11:00
|
|
|
transparent: false, // ウィンドウの背景を透過
|
|
|
|
frame: false, // 枠の無いウィンドウ
|
|
|
|
resizable: false
|
2019-08-26 22:06:07 +10:00
|
|
|
})
|
2020-03-06 03:51:06 +11:00
|
|
|
var lang = fs.readFileSync(lang_path, 'utf8')
|
|
|
|
updatewin.loadURL(base + lang + '/update.html')
|
|
|
|
return 'true'
|
2019-05-19 17:39:30 +10:00
|
|
|
} else {
|
2020-03-06 03:51:06 +11:00
|
|
|
return false
|
2019-05-19 17:39:30 +10:00
|
|
|
}
|
|
|
|
})
|
|
|
|
//アプデDL
|
2020-04-07 15:00:20 +10:00
|
|
|
ipc.on('download-btn', async (e, args) => {
|
2019-06-15 19:52:28 +10:00
|
|
|
function dl(url, file, dir, e) {
|
2020-03-06 03:51:06 +11:00
|
|
|
e.sender.webContents.send('mess', 'ダウンロードを開始します。')
|
2019-06-15 01:51:41 +10:00
|
|
|
const opts = {
|
|
|
|
directory: dir,
|
2020-04-07 15:00:20 +10:00
|
|
|
filename: file,
|
2019-06-15 01:51:41 +10:00
|
|
|
openFolderWhenDone: true,
|
2020-03-06 03:51:06 +11:00
|
|
|
onProgress: function(event) {
|
|
|
|
e.sender.webContents.send('prog', event)
|
2019-06-15 01:51:41 +10:00
|
|
|
},
|
|
|
|
saveAs: false
|
2020-03-06 03:51:06 +11:00
|
|
|
}
|
|
|
|
download(updatewin, url, opts)
|
2019-06-15 01:51:41 +10:00
|
|
|
.then(dl => {
|
2020-03-06 03:51:06 +11:00
|
|
|
e.sender.webContents.send('mess', 'ダウンロードが完了しました。')
|
|
|
|
app.quit()
|
2019-06-15 01:51:41 +10:00
|
|
|
})
|
2020-03-06 03:51:06 +11:00
|
|
|
.catch(console.error)
|
2019-06-15 01:51:41 +10:00
|
|
|
}
|
2020-03-06 03:51:06 +11:00
|
|
|
var platform = process.platform
|
|
|
|
var bit = process.arch
|
2020-04-07 15:00:20 +10:00
|
|
|
var options = {
|
|
|
|
title: 'Save',
|
|
|
|
defaultPath: app.getPath('home') + '/' + args[1]
|
|
|
|
}
|
|
|
|
const file = await dialog.showSaveDialog(null, options)
|
|
|
|
const savedFiles = file.filePath
|
|
|
|
console.log(savedFiles)
|
|
|
|
if (!savedFiles) {
|
|
|
|
return false
|
|
|
|
}
|
|
|
|
if (platform == 'win32') {
|
|
|
|
var m = savedFiles.match(/(.+)\\(.+)$/)
|
|
|
|
} else {
|
|
|
|
var m = savedFiles.match(/(.+)\/(.+)$/)
|
|
|
|
}
|
|
|
|
//console.log(m);
|
|
|
|
if (isExistFile(savedFiles)) {
|
|
|
|
fs.unlinkSync(savedFiles)
|
|
|
|
}
|
|
|
|
console.log(m)
|
|
|
|
dl(args[0], m[2], m[1], e)
|
2020-03-06 03:51:06 +11:00
|
|
|
})
|
2019-04-03 14:59:29 +11:00
|
|
|
|
|
|
|
function isExistFile(file) {
|
|
|
|
try {
|
2020-03-06 03:51:06 +11:00
|
|
|
fs.statSync(file)
|
2019-04-03 14:59:29 +11:00
|
|
|
return true
|
|
|
|
} catch (err) {
|
|
|
|
if (err.code === 'ENOENT') return false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-06-16 00:07:18 +10:00
|
|
|
ipc.on('general-dl', (event, args) => {
|
2020-03-06 03:51:06 +11:00
|
|
|
var name = ''
|
|
|
|
var platform = process.platform
|
|
|
|
var bit = process.arch
|
|
|
|
if (args[1] == '') {
|
|
|
|
if (platform == 'win32') {
|
|
|
|
var dir = app.getPath('home') + '\\Pictures\\TheDesk'
|
|
|
|
} else if (platform == 'linux' || platform == 'darwin') {
|
|
|
|
var dir = app.getPath('home') + '/Pictures/TheDesk'
|
2019-04-03 14:59:29 +11:00
|
|
|
}
|
|
|
|
} else {
|
2020-03-06 03:51:06 +11:00
|
|
|
var dir = args[1]
|
2019-04-03 14:59:29 +11:00
|
|
|
}
|
|
|
|
const opts = {
|
|
|
|
directory: dir,
|
|
|
|
filename: name,
|
|
|
|
openFolderWhenDone: false,
|
2020-03-06 03:51:06 +11:00
|
|
|
onProgress: function(e) {
|
|
|
|
event.sender.webContents.send('general-dl-prog', e)
|
2019-04-03 14:59:29 +11:00
|
|
|
},
|
|
|
|
saveAs: false
|
2020-03-06 03:51:06 +11:00
|
|
|
}
|
|
|
|
download(BrowserWindow.getFocusedWindow(), args[0], opts)
|
2019-04-03 14:59:29 +11:00
|
|
|
.then(dl => {
|
2020-03-06 03:51:06 +11:00
|
|
|
event.sender.webContents.send('general-dl-message', dir)
|
2019-04-03 14:59:29 +11:00
|
|
|
})
|
2020-03-06 03:51:06 +11:00
|
|
|
.catch(console.error)
|
|
|
|
})
|
2019-05-19 17:39:30 +10:00
|
|
|
ipc.on('open-finder', (e, folder) => {
|
2019-04-03 14:59:29 +11:00
|
|
|
shell.showItemInFolder(folder)
|
2020-03-06 03:51:06 +11:00
|
|
|
})
|
2019-04-03 14:59:29 +11:00
|
|
|
}
|
2020-03-06 03:51:06 +11:00
|
|
|
exports.dl = dl
|