VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/networking/UINewVersionChecker.cpp

Last change on this file was 103793, checked in by vboxsync, 2 months ago

FE/Qt: UICommon: Move versioning related functionality to UIVersion / UIVersionInfo; Rework user cases accordingly.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 6.8 KB
Line 
1/* $Id: UINewVersionChecker.cpp 103793 2024-03-11 19:17:31Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UINewVersionChecker class implementation.
4 */
5
6/*
7 * Copyright (C) 2006-2023 Oracle and/or its affiliates.
8 *
9 * This file is part of VirtualBox base platform packages, as
10 * available from https://www.virtualbox.org.
11 *
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation, in version 3 of the
15 * License.
16 *
17 * This program is distributed in the hope that it will be useful, but
18 * WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20 * General Public License for more details.
21 *
22 * You should have received a copy of the GNU General Public License
23 * along with this program; if not, see <https://www.gnu.org/licenses>.
24 *
25 * SPDX-License-Identifier: GPL-3.0-only
26 */
27
28/* Qt includes: */
29#include <QRegularExpression>
30#include <QUrlQuery>
31
32/* GUI includes: */
33#include "UIExtraDataManager.h"
34#include "UIGlobalSession.h"
35#include "UINetworkReply.h"
36#include "UINewVersionChecker.h"
37#include "UINotificationCenter.h"
38#include "UIUpdateDefs.h"
39#include "UIVersion.h"
40#ifdef Q_OS_LINUX
41# include "QIProcess.h"
42#endif
43
44/* Other VBox includes: */
45#include <iprt/system.h>
46#ifdef Q_OS_LINUX
47# include <iprt/path.h>
48#endif
49
50
51UINewVersionChecker::UINewVersionChecker(bool fForcedCall)
52 : m_fForcedCall(fForcedCall)
53 , m_url("https://update.virtualbox.org/query.php")
54{
55}
56
57void UINewVersionChecker::start()
58{
59 /* Compose query: */
60 QUrlQuery url;
61 url.addQueryItem("platform", gpGlobalSession->virtualBox().GetPackageType());
62 /* Check if branding is active: */
63 if (UIVersionInfo::brandingIsActive())
64 {
65 /* Branding: Check whether we have a local branding file which tells us our version suffix "FOO"
66 (e.g. 3.06.54321_FOO) to identify this installation: */
67 url.addQueryItem("version", QString("%1_%2_%3").arg(gpGlobalSession->virtualBox().GetVersion())
68 .arg(gpGlobalSession->virtualBox().GetRevision())
69 .arg(UIVersionInfo::brandingGetKey("VerSuffix")));
70 }
71 else
72 {
73 /* Use hard coded version set by VBOX_VERSION_STRING: */
74 url.addQueryItem("version", QString("%1_%2").arg(gpGlobalSession->virtualBox().GetVersion())
75 .arg(gpGlobalSession->virtualBox().GetRevision()));
76 }
77 url.addQueryItem("count", QString::number(gEDataManager->applicationUpdateCheckCounter()));
78 url.addQueryItem("branch", VBoxUpdateData(gEDataManager->applicationUpdateData()).updateChannelName());
79 const QString strUserAgent(QString("VirtualBox %1 <%2>").arg(gpGlobalSession->virtualBox().GetVersion()).arg(platformInfo()));
80
81 /* Send GET request: */
82 UserDictionary headers;
83 headers["User-Agent"] = strUserAgent;
84 QUrl fullUrl(m_url);
85 fullUrl.setQuery(url);
86 createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << fullUrl, QString(), headers);
87}
88
89void UINewVersionChecker::cancel()
90{
91 cancelNetworkRequest();
92}
93
94void UINewVersionChecker::processNetworkReplyProgress(qint64, qint64)
95{
96}
97
98void UINewVersionChecker::processNetworkReplyFailed(const QString &strError)
99{
100 emit sigProgressFailed(strError);
101}
102
103void UINewVersionChecker::processNetworkReplyCanceled(UINetworkReply *)
104{
105 emit sigProgressCanceled();
106}
107
108void UINewVersionChecker::processNetworkReplyFinished(UINetworkReply *pReply)
109{
110 /* Deserialize incoming data: */
111 const QString strResponseData(pReply->readAll());
112
113#ifdef VBOX_NEW_VERSION_TEST
114 strResponseData = VBOX_NEW_VERSION_TEST;
115#endif
116 /* Newer version of necessary package found: */
117 if (strResponseData.indexOf(QRegularExpression("^\\d+\\.\\d+\\.\\d+(_[0-9A-Z]+)? \\S+$")) == 0)
118 {
119#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
120 const QStringList response = strResponseData.split(" ", Qt::SkipEmptyParts);
121#else
122 const QStringList response = strResponseData.split(" ", QString::SkipEmptyParts);
123#endif
124 UINotificationMessage::showUpdateSuccess(response[0], response[1]);
125 }
126 /* No newer version of necessary package found: */
127 else
128 {
129 if (isItForcedCall())
130 UINotificationMessage::showUpdateNotFound();
131 }
132
133 /* Increment update check counter: */
134 gEDataManager->incrementApplicationUpdateCheckCounter();
135
136 /* Notify about completion: */
137 emit sigProgressFinished();
138}
139
140/* static */
141QString UINewVersionChecker::platformInfo()
142{
143 /* Prepare platform report: */
144 QString strPlatform;
145
146#if defined (Q_OS_WIN)
147 strPlatform = "win";
148#elif defined (Q_OS_LINUX)
149 strPlatform = "linux";
150#elif defined (Q_OS_MACX)
151 strPlatform = "macosx";
152#elif defined (Q_OS_OS2)
153 strPlatform = "os2";
154#elif defined (Q_OS_FREEBSD)
155 strPlatform = "freebsd";
156#elif defined (Q_OS_SOLARIS)
157 strPlatform = "solaris";
158#else
159 strPlatform = "unknown";
160#endif
161
162 /* The format is <system>.<bitness>: */
163 strPlatform += QString(".%1").arg(ARCH_BITS);
164
165 /* Add more system information: */
166 int vrc;
167#ifdef Q_OS_LINUX
168 // WORKAROUND:
169 // On Linux we try to generate information using script first of all..
170
171 /* Get script path: */
172 char szAppPrivPath[RTPATH_MAX];
173 vrc = RTPathAppPrivateNoArch(szAppPrivPath, sizeof(szAppPrivPath));
174 AssertRC(vrc);
175 if (RT_SUCCESS(vrc))
176 {
177 /* Run script: */
178 QByteArray result = QIProcess::singleShot(QString(szAppPrivPath) + "/VBoxSysInfo.sh");
179 if (!result.isNull())
180 strPlatform += QString(" [%1]").arg(QString(result).trimmed());
181 else
182 vrc = VERR_TRY_AGAIN; /* (take the fallback path) */
183 }
184 if (RT_FAILURE(vrc))
185#endif /* Q_OS_LINUX */
186 {
187 /* Use RTSystemQueryOSInfo: */
188 char szTmp[256];
189 QStringList components;
190
191 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
192 if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
193 components << QString("Product: %1").arg(szTmp);
194
195 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
196 if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
197 components << QString("Release: %1").arg(szTmp);
198
199 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
200 if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
201 components << QString("Version: %1").arg(szTmp);
202
203 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp));
204 if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
205 components << QString("SP: %1").arg(szTmp);
206
207 if (!components.isEmpty())
208 strPlatform += QString(" [%1]").arg(components.join(" | "));
209 }
210
211 return strPlatform;
212}
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use