This commit is contained in:
DavidXanatos 2022-08-22 21:06:43 +02:00
parent 41d31d5874
commit 2d500776dc
3 changed files with 75 additions and 26 deletions

View File

@ -83,7 +83,7 @@ void COnlineUpdater::GetUpdates(QObject* receiver, const char* member, const QVa
m_JobQueue.insert(pReply, pJob); m_JobQueue.insert(pReply, pJob);
} }
void COnlineUpdater::CheckForUpdates(bool bManual) void COnlineUpdater::CheckForUpdates(bool bManual, bool bDownload)
{ {
if (!m_pUpdateProgress.isNull()) if (!m_pUpdateProgress.isNull())
return; return;
@ -94,6 +94,7 @@ void COnlineUpdater::CheckForUpdates(bool bManual)
QVariantMap Params; QVariantMap Params;
Params["manual"] = bManual; Params["manual"] = bManual;
Params["download"] = bDownload;
GetUpdates(this, SLOT(OnUpdateData(const QVariantMap&, const QVariantMap&)), Params); 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) void COnlineUpdater::OnUpdateData(const QVariantMap& Data, const QVariantMap& Params)
{ {
bool bManual = Params["manual"].toBool(); bool bManual = Params["manual"].toBool();
bool bDownload = Params["download"].toBool();
if (!m_pUpdateProgress.isNull()) { if (!m_pUpdateProgress.isNull()) {
m_pUpdateProgress->Finish(SB_OK); m_pUpdateProgress->Finish(SB_OK);
@ -181,15 +183,7 @@ void COnlineUpdater::OnUpdateData(const QVariantMap& Data, const QVariantMap& Pa
QString VersionStr = Data["version"].toString(); QString VersionStr = Data["version"].toString();
if (!VersionStr.isEmpty()) //&& VersionStr != GetVersion()) if (!VersionStr.isEmpty()) //&& VersionStr != GetVersion())
{ {
quint8 myVersion[4] = { VERSION_UPD, VERSION_REV, VERSION_MIN, VERSION_MJR }; // ntohl if (IsVersionNewer(VersionStr))
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 (bManual || !IgnoredUpdates.contains(VersionStr)) // when checked manually always show result if (bManual || !IgnoredUpdates.contains(VersionStr)) // when checked manually always show result
{ {
bNothing = false; bNothing = false;
@ -199,14 +193,17 @@ void COnlineUpdater::OnUpdateData(const QVariantMap& Data, const QVariantMap& Pa
// 'sha256' // 'sha256'
// 'signature' // '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); DownloadUpdates(DownloadUrl, bManual);
}
else else
{ {
QString UpdateMsg = Data["updateMsg"].toString(); QString UpdateMsg = Data["updateMsg"].toString();
QString UpdateUrl = Data["updateUrl"].toString(); QString UpdateUrl = Data["updateUrl"].toString();
QString FullMessage = UpdateMsg.isEmpty() ? tr("<p>There is a new version of Sandboxie-Plus available.<br /><font color='red'>New version:</font> <b>%1</b></p>").arg(VersionStr) : UpdateMsg; QString FullMessage = UpdateMsg.isEmpty() ? tr("<p>There is a new version of Sandboxie-Plus available.<br /><b><font color='red'>New version:</font> %1</b></p>").arg(VersionStr) : UpdateMsg;
if (!DownloadUrl.isEmpty()) if (!DownloadUrl.isEmpty())
FullMessage += tr("<p>Do you want to download the latest version?</p>"); FullMessage += tr("<p>Do you want to download the latest version?</p>");
else if (!UpdateUrl.isEmpty()) else if (!UpdateUrl.isEmpty())
@ -230,22 +227,35 @@ void COnlineUpdater::OnUpdateData(const QVariantMap& Data, const QVariantMap& Pa
mb.exec(); mb.exec();
if (mb.isChecked()) if (mb.isChecked()) {
theConf->DelValue("Options/PendingUpdateVersion");
theGUI->UpdateLabel();
theConf->SetValue("Options/IgnoredUpdates", IgnoredUpdates << VersionStr); theConf->SetValue("Options/IgnoredUpdates", IgnoredUpdates << VersionStr);
}
if (mb.clickedStandardButton() == QDialogButtonBox::Yes) if (mb.clickedStandardButton() == QDialogButtonBox::Yes)
{ {
if (!DownloadUrl.isEmpty()) if (!DownloadUrl.isEmpty())
{
theConf->SetValue("Options/PendingUpdateVersion", VersionStr);
DownloadUpdates(DownloadUrl, bManual); DownloadUpdates(DownloadUrl, bManual);
}
else else
QDesktopServices::openUrl(UpdateUrl); QDesktopServices::openUrl(UpdateUrl);
} }
else if (!mb.isChecked())
{
theConf->SetValue("Options/PendingUpdateVersion", VersionStr);
theGUI->UpdateLabel();
}
} }
} }
} }
if (bNothing) if (bNothing)
{ {
theConf->DelValue("Options/PendingUpdateVersion");
theGUI->UpdateLabel();
theConf->SetValue("Options/NextCheckForUpdates", QDateTime::currentDateTime().addDays(7).toSecsSinceEpoch()); theConf->SetValue("Options/NextCheckForUpdates", QDateTime::currentDateTime().addDays(7).toSecsSinceEpoch());
if (bManual) { if (bManual) {
@ -321,6 +331,38 @@ void COnlineUpdater::OnUpdateDownload()
InstallUpdate(); 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() void COnlineUpdater::InstallUpdate()
{ {
QString FilePath = theConf->GetString("Options/PendingUpdatePackage"); QString FilePath = theConf->GetString("Options/PendingUpdatePackage");

View File

@ -34,11 +34,13 @@ public:
void GetUpdates(QObject* receiver, const char* member, const QVariantMap& Params = QVariantMap()); void GetUpdates(QObject* receiver, const char* member, const QVariantMap& Params = QVariantMap());
void DownloadUpdate();
void InstallUpdate(); void InstallUpdate();
void UpdateCert(); void UpdateCert();
void CheckForUpdates(bool bManual = true); void CheckPendingUpdate();
void CheckForUpdates(bool bManual = true, bool bDownload = false);
void DownloadUpdates(const QString& DownloadUrl, bool bManual); void DownloadUpdates(const QString& DownloadUrl, bool bManual);
private slots: private slots:
@ -52,6 +54,7 @@ private slots:
void OnCertCheck(); void OnCertCheck();
protected: protected:
bool IsVersionNewer(const QString& VersionStr);
CNetworkAccessManager* m_RequestManager; CNetworkAccessManager* m_RequestManager;
CSbieProgressPtr m_pUpdateProgress; CSbieProgressPtr m_pUpdateProgress;

View File

@ -745,6 +745,8 @@ void CSandMan::CreateLabel()
//fnt.setWeight(QFont::DemiBold); //fnt.setWeight(QFont::DemiBold);
m_pLabel->setFont(fnt); m_pLabel->setFont(fnt);
COnlineUpdater::Instance()->CheckPendingUpdate();
UpdateLabel(); UpdateLabel();
} }
@ -755,22 +757,22 @@ void CSandMan::UpdateLabel()
if (!theConf->GetString("Options/PendingUpdatePackage").isEmpty()) if (!theConf->GetString("Options/PendingUpdatePackage").isEmpty())
{ {
LabelText = tr("<a href=\"sbie://update/package\" style=\"color: red;\">There is a new build of Sandboxie-Plus available</a>"); LabelText = tr("<a href=\"sbie://update/package\" style=\"color: red;\">There is a new build of Sandboxie-Plus ready</a>");
//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; }");
LabelTip = tr("Click to install update"); LabelTip = tr("Click to install update");
//auto neon = new CNeonEffect(10, 4, 180); // 140 //auto neon = new CNeonEffect(10, 4, 180); // 140
//m_pLabel->setGraphicsEffect(NULL); //m_pLabel->setGraphicsEffect(NULL);
} }
else if (!theConf->GetString("Options/PendingUpdateVersion").isEmpty())
{
LabelText = tr("<a href=\"sbie://update/check\" style=\"color: red;\">There is a new build of Sandboxie-Plus available</a>");
LabelTip = tr("Click to download update");
//auto neon = new CNeonEffect(10, 4, 180); // 140
//m_pLabel->setGraphicsEffect(NULL);
}
else if (g_Certificate.isEmpty()) else if (g_Certificate.isEmpty())
{ {
LabelText = tr("<a href=\"https://sandboxie-plus.com/go.php?to=patreon\">Support Sandboxie-Plus on Patreon</a>"); LabelText = tr("<a href=\"https://sandboxie-plus.com/go.php?to=patreon\">Support Sandboxie-Plus on Patreon</a>");
@ -2618,6 +2620,8 @@ void CSandMan::OpenUrl(const QUrl& url)
QString query = url.query(); QString query = url.query();
if (scheme == "sbie") { if (scheme == "sbie") {
if (path == "/check")
return COnlineUpdater::Instance()->DownloadUpdate();
if (path == "/package") if (path == "/package")
return COnlineUpdater::Instance()->InstallUpdate(); return COnlineUpdater::Instance()->InstallUpdate();
if (path == "/cert") if (path == "/cert")