Browse Source

Windows updater: Create backup and restore it on failure

pull/774/head
Tux3 / Mlkj / !Lev.uXFMLA 11 years ago
parent
commit
546b90c4c9
No known key found for this signature in database
GPG Key ID: 7E086DD661263264
  1. 36
      updater/widget.cpp
  2. 3
      updater/widget.h

36
updater/widget.cpp

@ -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

3
updater/widget.h

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

Loading…
Cancel
Save