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

Windows updater: Improve reliability

And fix a bug that caused the progress to be displayed improperly
This commit is contained in:
Tux3 / Mlkj / !Lev.uXFMLA 2015-01-27 00:23:27 +01:00
parent ac2700fdeb
commit 4907661752
No known key found for this signature in database
GPG Key ID: 7E086DD661263264

View File

@ -58,6 +58,7 @@ Widget::~Widget()
void Widget::setProgress(int value)
{
ui->progress->setValue(value);
ui->progress->repaint();
qApp->processEvents();
}
@ -126,7 +127,7 @@ void Widget::update()
setProgress(5);
/// 2. Check the update (5-50%)
float checkProgressStep = 45/diff.size();
float checkProgressStep = 45.0/(float)diff.size();
float checkProgress = 5;
for (UpdateFileMeta fileMeta : diff)
{
@ -152,21 +153,23 @@ void Widget::update()
setProgress(50);
/// 3. Install the update (50-95%)
float installProgressStep = 45/diff.size();
float installProgressStep = 45.0/(float)diff.size();
float installProgress = 50;
for (UpdateFileMeta fileMeta : diff)
{
// Backup old files
if (QFile(fileMeta.installpath).exists())
{
QFile(fileMeta.installpath+".bak").remove();
QFile(fileMeta.installpath).rename(fileMeta.installpath+".bak");
backups.append(fileMeta.installpath);
}
// Install new ones
QDir().mkpath(QFileInfo(fileMeta.installpath).absolutePath());
QFile fileFile(updateDirStr+fileMeta.installpath);
if (!fileFile.copy(fileMeta.installpath))
fatalError(tr("Unable to copy the update's files."));
fatalError(tr("Unable to copy the update's files from ")+(updateDirStr+fileMeta.installpath)+" to "+fileMeta.installpath);
installProgress += installProgressStep;
setProgress(installProgress);
}