From 2d500776dcd6fbc1fe4152afd9b54339d31983a8 Mon Sep 17 00:00:00 2001 From: DavidXanatos Date: Mon, 22 Aug 2022 21:06:43 +0200 Subject: [PATCH] 1.3.2 --- SandboxiePlus/SandMan/OnlineUpdater.cpp | 70 ++++++++++++++++++++----- SandboxiePlus/SandMan/OnlineUpdater.h | 5 +- SandboxiePlus/SandMan/SandMan.cpp | 26 +++++---- 3 files changed, 75 insertions(+), 26 deletions(-) diff --git a/SandboxiePlus/SandMan/OnlineUpdater.cpp b/SandboxiePlus/SandMan/OnlineUpdater.cpp index abd39419..068e5dba 100644 --- a/SandboxiePlus/SandMan/OnlineUpdater.cpp +++ b/SandboxiePlus/SandMan/OnlineUpdater.cpp @@ -83,7 +83,7 @@ void COnlineUpdater::GetUpdates(QObject* receiver, const char* member, const QVa m_JobQueue.insert(pReply, pJob); } -void COnlineUpdater::CheckForUpdates(bool bManual) +void COnlineUpdater::CheckForUpdates(bool bManual, bool bDownload) { if (!m_pUpdateProgress.isNull()) return; @@ -94,6 +94,7 @@ void COnlineUpdater::CheckForUpdates(bool bManual) QVariantMap Params; Params["manual"] = bManual; + Params["download"] = bDownload; GetUpdates(this, SLOT(OnUpdateData(const QVariantMap&, const QVariantMap&)), Params); } @@ -117,6 +118,7 @@ void COnlineUpdater::OnUpdateCheck() void COnlineUpdater::OnUpdateData(const QVariantMap& Data, const QVariantMap& Params) { bool bManual = Params["manual"].toBool(); + bool bDownload = Params["download"].toBool(); if (!m_pUpdateProgress.isNull()) { m_pUpdateProgress->Finish(SB_OK); @@ -181,15 +183,7 @@ void COnlineUpdater::OnUpdateData(const QVariantMap& Data, const QVariantMap& Pa QString VersionStr = Data["version"].toString(); if (!VersionStr.isEmpty()) //&& VersionStr != GetVersion()) { - quint8 myVersion[4] = { VERSION_UPD, VERSION_REV, VERSION_MIN, VERSION_MJR }; // ntohl - quint32 MyVersion = *(quint32*)&myVersion; - - quint32 Version = 0; - QStringList Nums = VersionStr.split("."); - for (int i = 0, Bits = 24; i < Nums.count() && Bits >= 0; i++, Bits -= 8) - Version |= (Nums[i].toInt() & 0xFF) << Bits; - - if (Version > MyVersion) + if (IsVersionNewer(VersionStr)) if (bManual || !IgnoredUpdates.contains(VersionStr)) // when checked manually always show result { bNothing = false; @@ -199,14 +193,17 @@ void COnlineUpdater::OnUpdateData(const QVariantMap& Data, const QVariantMap& Pa // 'sha256' // 'signature' - if (!DownloadUrl.isEmpty() && theConf->GetInt("Options/DownloadUpdates", 0) == 1) + if (!DownloadUrl.isEmpty() && (bDownload || theConf->GetInt("Options/DownloadUpdates", 0) == 1)) + { + theConf->SetValue("Options/PendingUpdateVersion", VersionStr); DownloadUpdates(DownloadUrl, bManual); + } else { QString UpdateMsg = Data["updateMsg"].toString(); QString UpdateUrl = Data["updateUrl"].toString(); - QString FullMessage = UpdateMsg.isEmpty() ? tr("

There is a new version of Sandboxie-Plus available.
New version: %1

").arg(VersionStr) : UpdateMsg; + QString FullMessage = UpdateMsg.isEmpty() ? tr("

There is a new version of Sandboxie-Plus available.
New version: %1

").arg(VersionStr) : UpdateMsg; if (!DownloadUrl.isEmpty()) FullMessage += tr("

Do you want to download the latest version?

"); else if (!UpdateUrl.isEmpty()) @@ -230,22 +227,35 @@ void COnlineUpdater::OnUpdateData(const QVariantMap& Data, const QVariantMap& Pa mb.exec(); - if (mb.isChecked()) + if (mb.isChecked()) { + theConf->DelValue("Options/PendingUpdateVersion"); + theGUI->UpdateLabel(); theConf->SetValue("Options/IgnoredUpdates", IgnoredUpdates << VersionStr); + } if (mb.clickedStandardButton() == QDialogButtonBox::Yes) { - if (!DownloadUrl.isEmpty()) + if (!DownloadUrl.isEmpty()) + { + theConf->SetValue("Options/PendingUpdateVersion", VersionStr); DownloadUpdates(DownloadUrl, bManual); + } else QDesktopServices::openUrl(UpdateUrl); } + else if (!mb.isChecked()) + { + theConf->SetValue("Options/PendingUpdateVersion", VersionStr); + theGUI->UpdateLabel(); + } } } } if (bNothing) { + theConf->DelValue("Options/PendingUpdateVersion"); + theGUI->UpdateLabel(); theConf->SetValue("Options/NextCheckForUpdates", QDateTime::currentDateTime().addDays(7).toSecsSinceEpoch()); if (bManual) { @@ -321,6 +331,38 @@ void COnlineUpdater::OnUpdateDownload() InstallUpdate(); } +bool COnlineUpdater::IsVersionNewer(const QString& VersionStr) +{ +#ifdef _DEBUG + if (QApplication::keyboardModifiers() & Qt::ControlModifier) + return true; +#endif + + quint8 myVersion[4] = { VERSION_UPD, VERSION_REV, VERSION_MIN, VERSION_MJR }; // ntohl + quint32 MyVersion = *(quint32*)&myVersion; + + quint32 Version = 0; + QStringList Nums = VersionStr.split("."); + for (int i = 0, Bits = 24; i < Nums.count() && Bits >= 0; i++, Bits -= 8) + Version |= (Nums[i].toInt() & 0xFF) << Bits; + + return (Version > MyVersion); +} + +void COnlineUpdater::CheckPendingUpdate() +{ + QString VersionStr = theConf->GetString("Options/PendingUpdateVersion"); + if (!IsVersionNewer(VersionStr)) { + theConf->DelValue("Options/PendingUpdateVersion"); + theConf->DelValue("Options/PendingUpdatePackage"); + } +} + +void COnlineUpdater::DownloadUpdate() +{ + CheckForUpdates(true, true); +} + void COnlineUpdater::InstallUpdate() { QString FilePath = theConf->GetString("Options/PendingUpdatePackage"); diff --git a/SandboxiePlus/SandMan/OnlineUpdater.h b/SandboxiePlus/SandMan/OnlineUpdater.h index 0c4feed2..8a3136d1 100644 --- a/SandboxiePlus/SandMan/OnlineUpdater.h +++ b/SandboxiePlus/SandMan/OnlineUpdater.h @@ -34,11 +34,13 @@ public: void GetUpdates(QObject* receiver, const char* member, const QVariantMap& Params = QVariantMap()); + void DownloadUpdate(); void InstallUpdate(); void UpdateCert(); - void CheckForUpdates(bool bManual = true); + void CheckPendingUpdate(); + void CheckForUpdates(bool bManual = true, bool bDownload = false); void DownloadUpdates(const QString& DownloadUrl, bool bManual); private slots: @@ -52,6 +54,7 @@ private slots: void OnCertCheck(); protected: + bool IsVersionNewer(const QString& VersionStr); CNetworkAccessManager* m_RequestManager; CSbieProgressPtr m_pUpdateProgress; diff --git a/SandboxiePlus/SandMan/SandMan.cpp b/SandboxiePlus/SandMan/SandMan.cpp index 82cf26c4..fed69ab2 100644 --- a/SandboxiePlus/SandMan/SandMan.cpp +++ b/SandboxiePlus/SandMan/SandMan.cpp @@ -745,6 +745,8 @@ void CSandMan::CreateLabel() //fnt.setWeight(QFont::DemiBold); m_pLabel->setFont(fnt); + COnlineUpdater::Instance()->CheckPendingUpdate(); + UpdateLabel(); } @@ -753,24 +755,24 @@ void CSandMan::UpdateLabel() QString LabelText; QString LabelTip; - if (!theConf->GetString("Options/PendingUpdatePackage").isEmpty()) + if (!theConf->GetString("Options/PendingUpdatePackage").isEmpty()) { - LabelText = tr("There is a new build of Sandboxie-Plus available"); - - //QPalette palette = m_pLabel->palette(); - //palette.setColor(QPalette::Link, Qt::red); - //palette.setColor(m_pLabel->backgroundRole(), Qt::yellow); - //palette.setColor(m_pLabel->foregroundRole(), Qt::red); - //m_pLabel->setAutoFillBackground(true); - //m_pLabel->setPalette(palette); - - //m_pLabel->setStyleSheet("QLabel { link-color : red; }"); + LabelText = tr("There is a new build of Sandboxie-Plus ready"); LabelTip = tr("Click to install update"); //auto neon = new CNeonEffect(10, 4, 180); // 140 //m_pLabel->setGraphicsEffect(NULL); } + else if (!theConf->GetString("Options/PendingUpdateVersion").isEmpty()) + { + LabelText = tr("There is a new build of Sandboxie-Plus available"); + + LabelTip = tr("Click to download update"); + + //auto neon = new CNeonEffect(10, 4, 180); // 140 + //m_pLabel->setGraphicsEffect(NULL); + } else if (g_Certificate.isEmpty()) { LabelText = tr("Support Sandboxie-Plus on Patreon"); @@ -2618,6 +2620,8 @@ void CSandMan::OpenUrl(const QUrl& url) QString query = url.query(); if (scheme == "sbie") { + if (path == "/check") + return COnlineUpdater::Instance()->DownloadUpdate(); if (path == "/package") return COnlineUpdater::Instance()->InstallUpdate(); if (path == "/cert")