|
|
|
@ -65,6 +65,7 @@ void Widget::fatalError(QString message)
@@ -65,6 +65,7 @@ void Widget::fatalError(QString message)
|
|
|
|
|
{ |
|
|
|
|
QMessageBox::critical(this,tr("Error"), message+'\n'+tr("qTox will restart now.")); |
|
|
|
|
deleteUpdate(); |
|
|
|
|
restoreBackups(); |
|
|
|
|
startQToxAndExit(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -80,6 +81,18 @@ void Widget::startQToxAndExit()
@@ -80,6 +81,18 @@ void Widget::startQToxAndExit()
|
|
|
|
|
exit(0); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Widget::deleteBackups() |
|
|
|
|
{ |
|
|
|
|
for (QString file : backups) |
|
|
|
|
QFile(file+".bak").remove(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Widget::restoreBackups() |
|
|
|
|
{ |
|
|
|
|
for (QString file : backups) |
|
|
|
|
QFile(file+".bak").rename(file); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
void Widget::update() |
|
|
|
|
{ |
|
|
|
|
/// 1. Find and parse the update (0-5%)
|
|
|
|
@ -138,17 +151,26 @@ void Widget::update()
@@ -138,17 +151,26 @@ void Widget::update()
|
|
|
|
|
float installProgress = 50; |
|
|
|
|
for (UpdateFileMeta fileMeta : diff) |
|
|
|
|
{ |
|
|
|
|
QFile fileFile(updateDirStr+fileMeta.installpath); |
|
|
|
|
if (!fileFile.copy(fileMeta.installpath)) |
|
|
|
|
fatalError(tr("Unable to copy the update's files.")); |
|
|
|
|
|
|
|
|
|
installProgress += installProgressStep; |
|
|
|
|
setProgress(installProgress); |
|
|
|
|
// Backup old files
|
|
|
|
|
if (QFile(fileMeta.installpath).exists()) |
|
|
|
|
{ |
|
|
|
|
QFile(fileMeta.installpath).rename(fileMeta.installpath+".bak"); |
|
|
|
|
backups.append(fileMeta.installpath); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
// Install new ones
|
|
|
|
|
QFile fileFile(updateDirStr+fileMeta.installpath); |
|
|
|
|
if (!fileFile.copy(fileMeta.installpath)) |
|
|
|
|
fatalError(tr("Unable to copy the update's files.")); |
|
|
|
|
installProgress += installProgressStep; |
|
|
|
|
setProgress(installProgress); |
|
|
|
|
} |
|
|
|
|
setProgress(95); |
|
|
|
|
|
|
|
|
|
/// 4. Delete the update (95-100%)
|
|
|
|
|
/// 4. Delete the update and backups (95-100%)
|
|
|
|
|
deleteUpdate(); |
|
|
|
|
setProgress(97); |
|
|
|
|
deleteBackups(); |
|
|
|
|
setProgress(100); |
|
|
|
|
|
|
|
|
|
/// 5. Start qTox and exit
|
|
|
|
|