1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

Windows updater: Create backup and restore it on failure

This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2014-11-16 11:24:15 +01:00
parent 007a10346d
commit 546b90c4c9
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
2 changed files with 31 additions and 6 deletions

View File

@ -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()
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()
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."));
// Backup old files
if (QFile(fileMeta.installpath).exists())
{
QFile(fileMeta.installpath).rename(fileMeta.installpath+".bak");
backups.append(fileMeta.installpath);
}
installProgress += installProgressStep;
setProgress(installProgress);
// 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

View File

@ -33,6 +33,8 @@ public:
~Widget();
// Utilities
void deleteBackups();
void restoreBackups();
void setProgress(int value);
// Noreturn
@ -46,6 +48,7 @@ public slots:
private:
Ui::Widget *ui;
QStringList backups;
};
#endif // WIDGET_H