VirtualBox

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

Last change on this file since 100347 was 98103, checked in by vboxsync, 2 years ago

Copyright year updates by scm.

  • 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 98103 2023-01-17 14:15:46Z 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 "UICommon.h"
34#include "UIExtraDataManager.h"
35#include "UINetworkReply.h"
36#include "UINewVersionChecker.h"
37#include "UINotificationCenter.h"
38#include "UIUpdateDefs.h"
39#ifdef Q_OS_LINUX
40# include "QIProcess.h"
41#endif
42
43/* Other VBox includes: */
44#include <iprt/system.h>
45#ifdef Q_OS_LINUX
46# include <iprt/path.h>
47#endif
48
49
50UINewVersionChecker::UINewVersionChecker(bool fForcedCall)
51 : m_fForcedCall(fForcedCall)
52 , m_url("https://update.virtualbox.org/query.php")
53{
54}
55
56void UINewVersionChecker::start()
57{
58 /* Compose query: */
59 QUrlQuery url;
60 url.addQueryItem("platform", uiCommon().virtualBox().GetPackageType());
61 /* Check if branding is active: */
62 if (uiCommon().brandingIsActive())
63 {
64 /* Branding: Check whether we have a local branding file which tells us our version suffix "FOO"
65 (e.g. 3.06.54321_FOO) to identify this installation: */
66 url.addQueryItem("version", QString("%1_%2_%3").arg(uiCommon().virtualBox().GetVersion())
67 .arg(uiCommon().virtualBox().GetRevision())
68 .arg(uiCommon().brandingGetKey("VerSuffix")));
69 }
70 else
71 {
72 /* Use hard coded version set by VBOX_VERSION_STRING: */
73 url.addQueryItem("version", QString("%1_%2").arg(uiCommon().virtualBox().GetVersion())
74 .arg(uiCommon().virtualBox().GetRevision()));
75 }
76 url.addQueryItem("count", QString::number(gEDataManager->applicationUpdateCheckCounter()));
77 url.addQueryItem("branch", VBoxUpdateData(gEDataManager->applicationUpdateData()).updateChannelName());
78 const QString strUserAgent(QString("VirtualBox %1 <%2>").arg(uiCommon().virtualBox().GetVersion()).arg(platformInfo()));
79
80 /* Send GET request: */
81 UserDictionary headers;
82 headers["User-Agent"] = strUserAgent;
83 QUrl fullUrl(m_url);
84 fullUrl.setQuery(url);
85 createNetworkRequest(UINetworkRequestType_GET, QList<QUrl>() << fullUrl, QString(), headers);
86}
87
88void UINewVersionChecker::cancel()
89{
90 cancelNetworkRequest();
91}
92
93void UINewVersionChecker::processNetworkReplyProgress(qint64, qint64)
94{
95}
96
97void UINewVersionChecker::processNetworkReplyFailed(const QString &strError)
98{
99 emit sigProgressFailed(strError);
100}
101
102void UINewVersionChecker::processNetworkReplyCanceled(UINetworkReply *)
103{
104 emit sigProgressCanceled();
105}
106
107void UINewVersionChecker::processNetworkReplyFinished(UINetworkReply *pReply)
108{
109 /* Deserialize incoming data: */
110 const QString strResponseData(pReply->readAll());
111
112#ifdef VBOX_NEW_VERSION_TEST
113 strResponseData = VBOX_NEW_VERSION_TEST;
114#endif
115 /* Newer version of necessary package found: */
116 if (strResponseData.indexOf(QRegularExpression("^\\d+\\.\\d+\\.\\d+(_[0-9A-Z]+)? \\S+$")) == 0)
117 {
118#if QT_VERSION >= QT_VERSION_CHECK(5, 14, 0)
119 const QStringList response = strResponseData.split(" ", Qt::SkipEmptyParts);
120#else
121 const QStringList response = strResponseData.split(" ", QString::SkipEmptyParts);
122#endif
123 UINotificationMessage::showUpdateSuccess(response[0], response[1]);
124 }
125 /* No newer version of necessary package found: */
126 else
127 {
128 if (isItForcedCall())
129 UINotificationMessage::showUpdateNotFound();
130 }
131
132 /* Increment update check counter: */
133 gEDataManager->incrementApplicationUpdateCheckCounter();
134
135 /* Notify about completion: */
136 emit sigProgressFinished();
137}
138
139/* static */
140QString UINewVersionChecker::platformInfo()
141{
142 /* Prepare platform report: */
143 QString strPlatform;
144
145#if defined (Q_OS_WIN)
146 strPlatform = "win";
147#elif defined (Q_OS_LINUX)
148 strPlatform = "linux";
149#elif defined (Q_OS_MACX)
150 strPlatform = "macosx";
151#elif defined (Q_OS_OS2)
152 strPlatform = "os2";
153#elif defined (Q_OS_FREEBSD)
154 strPlatform = "freebsd";
155#elif defined (Q_OS_SOLARIS)
156 strPlatform = "solaris";
157#else
158 strPlatform = "unknown";
159#endif
160
161 /* The format is <system>.<bitness>: */
162 strPlatform += QString(".%1").arg(ARCH_BITS);
163
164 /* Add more system information: */
165 int vrc;
166#ifdef Q_OS_LINUX
167 // WORKAROUND:
168 // On Linux we try to generate information using script first of all..
169
170 /* Get script path: */
171 char szAppPrivPath[RTPATH_MAX];
172 vrc = RTPathAppPrivateNoArch(szAppPrivPath, sizeof(szAppPrivPath));
173 AssertRC(vrc);
174 if (RT_SUCCESS(vrc))
175 {
176 /* Run script: */
177 QByteArray result = QIProcess::singleShot(QString(szAppPrivPath) + "/VBoxSysInfo.sh");
178 if (!result.isNull())
179 strPlatform += QString(" [%1]").arg(QString(result).trimmed());
180 else
181 vrc = VERR_TRY_AGAIN; /* (take the fallback path) */
182 }
183 if (RT_FAILURE(vrc))
184#endif /* Q_OS_LINUX */
185 {
186 /* Use RTSystemQueryOSInfo: */
187 char szTmp[256];
188 QStringList components;
189
190 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
191 if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
192 components << QString("Product: %1").arg(szTmp);
193
194 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
195 if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
196 components << QString("Release: %1").arg(szTmp);
197
198 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
199 if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
200 components << QString("Version: %1").arg(szTmp);
201
202 vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp));
203 if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
204 components << QString("SP: %1").arg(szTmp);
205
206 if (!components.isEmpty())
207 strPlatform += QString(" [%1]").arg(components.join(" | "));
208 }
209
210 return strPlatform;
211}
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette