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:
parent
007a10346d
commit
546b90c4c9
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue
Block a user