Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable-3.6] use correct version copmparison on NSIS updater: fix update from rc #5053

Merged
merged 3 commits into from
Oct 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 31 additions & 44 deletions src/gui/updater/ocupdater.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,12 @@

namespace OCC {

static const char updateAvailableC[] = "Updater/updateAvailable";
static const char updateTargetVersionC[] = "Updater/updateTargetVersion";
static const char updateTargetVersionStringC[] = "Updater/updateTargetVersionString";
static const char seenVersionC[] = "Updater/seenVersion";
static const char autoUpdateAttemptedC[] = "Updater/autoUpdateAttempted";

namespace {
const auto updateAvailableC = QStringLiteral("Updater/updateAvailable");
const auto updateTargetVersionC = QStringLiteral("Updater/updateTargetVersion");
const auto updateTargetVersionStringC = QStringLiteral("Updater/updateTargetVersionString");
const auto autoUpdateAttemptedC = QStringLiteral("Updater/autoUpdateAttempted");
}

UpdaterScheduler::UpdaterScheduler(QObject *parent)
: QObject(parent)
Expand Down Expand Up @@ -259,6 +259,7 @@ bool OCUpdater::updateSucceeded() const

void OCUpdater::slotVersionInfoArrived()
{
qCDebug(lcUpdater) << "received a reply";
_timeoutWatchdog->stop();
auto *reply = qobject_cast<QNetworkReply *>(sender());
reply->deleteLater();
Expand Down Expand Up @@ -347,12 +348,9 @@ void NSISUpdater::versionInfoArrived(const UpdateInfo &info)
ConfigFile cfg;
QSettings settings(cfg.configFile(), QSettings::IniFormat);
qint64 infoVersion = Helper::stringVersionToInt(info.version());
auto seenString = settings.value(seenVersionC).toString();
qint64 seenVersion = Helper::stringVersionToInt(seenString);
qint64 currVersion = Helper::currentVersionToInt();
qCInfo(lcUpdater) << "Version info arrived:"
<< "Your version:" << currVersion
<< "Skipped version:" << seenVersion << seenString
<< "Available version:" << infoVersion << info.version()
<< "Available version string:" << info.versionString()
<< "Web url:" << info.web()
Expand All @@ -361,28 +359,32 @@ void NSISUpdater::versionInfoArrived(const UpdateInfo &info)
{
qCInfo(lcUpdater) << "No version information available at the moment";
setDownloadState(UpToDate);
} else if (infoVersion <= currVersion
|| infoVersion <= seenVersion) {
qCInfo(lcUpdater) << "Client is on latest version!";
setDownloadState(UpToDate);
} else {
QString url = info.downloadUrl();
if (url.isEmpty()) {
showNoUrlDialog(info);
const auto currentVer = Helper::currentVersionToInt();
const auto remoteVer = Helper::stringVersionToInt(info.version());

if (info.version().isEmpty() || currentVer >= remoteVer) {
qCInfo(lcUpdater) << "Client is on latest version!";
setDownloadState(UpToDate);
} else {
_targetFile = cfg.configPath() + url.mid(url.lastIndexOf('/')+1);
if (QFile(_targetFile).exists()) {
setDownloadState(DownloadComplete);
const auto url = info.downloadUrl();
if (url.isEmpty()) {
showNoUrlDialog(info);
} else {
auto request = QNetworkRequest(QUrl(url));
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
QNetworkReply *reply = qnam()->get(request);
connect(reply, &QIODevice::readyRead, this, &NSISUpdater::slotWriteFile);
connect(reply, &QNetworkReply::finished, this, &NSISUpdater::slotDownloadFinished);
setDownloadState(Downloading);
_file.reset(new QTemporaryFile);
_file->setAutoRemove(true);
_file->open();
_targetFile = cfg.configPath() + url.mid(url.lastIndexOf('/')+1);
if (QFile(_targetFile).exists()) {
setDownloadState(DownloadComplete);
} else {
auto request = QNetworkRequest(QUrl(url));
request.setAttribute(QNetworkRequest::RedirectPolicyAttribute, QNetworkRequest::NoLessSafeRedirectPolicy);
QNetworkReply *reply = qnam()->get(request);
connect(reply, &QIODevice::readyRead, this, &NSISUpdater::slotWriteFile);
connect(reply, &QNetworkReply::finished, this, &NSISUpdater::slotDownloadFinished);
setDownloadState(Downloading);
_file.reset(new QTemporaryFile);
_file->setAutoRemove(true);
_file->open();
}
}
}
}
Expand Down Expand Up @@ -423,15 +425,12 @@ void NSISUpdater::showNoUrlDialog(const UpdateInfo &info)
hlayout->addWidget(lbl);

auto *bb = new QDialogButtonBox;
QPushButton *skip = bb->addButton(tr("Skip this version"), QDialogButtonBox::ResetRole);
QPushButton *reject = bb->addButton(tr("Skip this time"), QDialogButtonBox::AcceptRole);
QPushButton *getupdate = bb->addButton(tr("Get update"), QDialogButtonBox::AcceptRole);

connect(skip, &QAbstractButton::clicked, msgBox, &QDialog::reject);
connect(reject, &QAbstractButton::clicked, msgBox, &QDialog::reject);
connect(getupdate, &QAbstractButton::clicked, msgBox, &QDialog::accept);

connect(skip, &QAbstractButton::clicked, this, &NSISUpdater::slotSetSeenVersion);
connect(getupdate, &QAbstractButton::clicked, this, &NSISUpdater::slotOpenUpdateUrl);

layout->addWidget(bb);
Expand Down Expand Up @@ -473,20 +472,14 @@ void NSISUpdater::showUpdateErrorDialog(const QString &targetVersion)
hlayout->addWidget(lbl);

auto bb = new QDialogButtonBox;
auto skip = bb->addButton(tr("Skip this version"), QDialogButtonBox::ResetRole);
auto askagain = bb->addButton(tr("Ask again later"), QDialogButtonBox::ResetRole);
auto retry = bb->addButton(tr("Restart and update"), QDialogButtonBox::AcceptRole);
auto getupdate = bb->addButton(tr("Update manually"), QDialogButtonBox::AcceptRole);

connect(skip, &QAbstractButton::clicked, msgBox, &QDialog::reject);
connect(askagain, &QAbstractButton::clicked, msgBox, &QDialog::reject);
connect(retry, &QAbstractButton::clicked, msgBox, &QDialog::accept);
connect(getupdate, &QAbstractButton::clicked, msgBox, &QDialog::accept);

connect(skip, &QAbstractButton::clicked, this, [this]() {
wipeUpdateData();
slotSetSeenVersion();
});
// askagain: do nothing
connect(retry, &QAbstractButton::clicked, this, [this]() {
slotStartInstaller();
Expand Down Expand Up @@ -531,13 +524,6 @@ bool NSISUpdater::handleStartup()
return false;
}

void NSISUpdater::slotSetSeenVersion()
{
ConfigFile cfg;
QSettings settings(cfg.configFile(), QSettings::IniFormat);
settings.setValue(seenVersionC, updateInfo().version());
}

////////////////////////////////////////////////////////////////////////

PassiveUpdateNotifier::PassiveUpdateNotifier(const QUrl &url)
Expand Down Expand Up @@ -573,6 +559,7 @@ void PassiveUpdateNotifier::versionInfoArrived(const UpdateInfo &info)
qCInfo(lcUpdater) << "Client is on latest version!";
setDownloadState(UpToDate);
} else {
qCInfo(lcUpdater) << "Client is on older version. We will update!";
setDownloadState(UpdateOnlyAvailableThroughSystem);
}
}
Expand Down
1 change: 0 additions & 1 deletion src/gui/updater/ocupdater.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class NSISUpdater : public OCUpdater
explicit NSISUpdater(const QUrl &url);
bool handleStartup() override;
private slots:
void slotSetSeenVersion();
void slotDownloadFinished();
void slotWriteFile();

Expand Down