Commit 34d61d1a authored by Medicean's avatar Medicean

fix update progress error

parent 15aa4cb6
...@@ -112,15 +112,19 @@ class Update { ...@@ -112,15 +112,19 @@ class Update {
.pipe(through( .pipe(through(
(chunk) => { (chunk) => {
downsize += chunk.length; downsize += chunk.length;
var progress = parseInt(downsize/totalsize*100);
tempData.push(chunk); tempData.push(chunk);
event.sender.send(`update-dlprogress-${hash}`, progress); if(totalsize>0){
var progress = parseInt(downsize/totalsize*100);
event.sender.send(`update-dlprogress-${hash}`, progress, true);
}else{
event.sender.send(`update-dlprogress-${hash}`, downsize, false);
}
}, },
() => { () => {
that.logger.debug("Download end."); that.logger.debug("Download end.");
let tempDataBuffer = Buffer.concat(tempData); let tempDataBuffer = Buffer.concat(tempData);
if (downsize != totalsize) { if (totalsize > 0 && downsize != totalsize) {
event.sender.send(`update-error-${hash}`, "Download Error."); event.sender.send(`update-error-${hash}`, "Download Error.");
return return
} }
......
...@@ -264,6 +264,14 @@ ipcRenderer ...@@ -264,6 +264,14 @@ ipcRenderer
let n = new Notification(antSword['language']['update']['title'], { let n = new Notification(antSword['language']['update']['title'], {
body: antSword['language']['update']['body'](opt['ver']) body: antSword['language']['update']['body'](opt['ver'])
}); });
// 文件大小计算
const getFileSize = (t) => {
let i = false;
let b = ["b","Kb","Mb","Gb","Tb","Pb","Eb"];
for (let q=0; q<b.length; q++) if (t > 1024) t = t / 1024; else if (i === false) i = q;
if (i === false) i = b.length-1;
return Math.round(t*100)/100+" "+b[i];
}
n.addEventListener('click', () => { n.addEventListener('click', () => {
antSword.shell.openExternal(opt['url']); antSword.shell.openExternal(opt['url']);
}); });
...@@ -307,8 +315,12 @@ ipcRenderer ...@@ -307,8 +315,12 @@ ipcRenderer
win.win.progressOn(); win.win.progressOn();
win.setTitle(LANG["message"]["prepare"]); win.setTitle(LANG["message"]["prepare"]);
antSword['ipcRenderer'] antSword['ipcRenderer']
.on(`update-dlprogress-${hash}`, (event, progress)=>{ .on(`update-dlprogress-${hash}`, (event, progress, isprogress)=>{
win.setTitle(LANG["message"]["dling"](progress)); if(isprogress==true){
win.setTitle(LANG["message"]["dling"](progress));
}else{
win.setTitle(LANG["message"]["dlingnp"](getFileSize(progress)));
}
}) })
.once(`update-dlend-${hash}`,(event)=>{ .once(`update-dlend-${hash}`,(event)=>{
win.setTitle(LANG["message"]["dlend"]); win.setTitle(LANG["message"]["dlend"]);
......
...@@ -456,6 +456,7 @@ module.exports = { ...@@ -456,6 +456,7 @@ module.exports = {
message: { message: {
prepare: "Connecte to server...", prepare: "Connecte to server...",
dling: (progress)=> `Downloading...${progress}%`, dling: (progress)=> `Downloading...${progress}%`,
dlingnp: (size)=> `Downloading...${size}`,
dlend: "Download completed", dlend: "Download completed",
extract: "Unpacking, don't close AntSword", extract: "Unpacking, don't close AntSword",
ing: 'Downloading..', ing: 'Downloading..',
......
...@@ -457,6 +457,7 @@ module.exports = { ...@@ -457,6 +457,7 @@ module.exports = {
message: { message: {
prepare: "连接更新服务器...", prepare: "连接更新服务器...",
dling: (progress)=> `正在下载更新包...${progress}%`, dling: (progress)=> `正在下载更新包...${progress}%`,
dlingnp: (size)=> `正在下载更新包...${size}`,
dlend: "下载完毕", dlend: "下载完毕",
extract: "正在解压, 请务关闭程序", extract: "正在解压, 请务关闭程序",
ing: '努力更新中。。', ing: '努力更新中。。',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment