1 | /* $Id: UINewVersionChecker.cpp 106061 2024-09-16 14:03:52Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UINewVersionChecker class implementation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2024 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 |
|
---|
51 | UINewVersionChecker::UINewVersionChecker(bool fForcedCall)
|
---|
52 | : m_fForcedCall(fForcedCall)
|
---|
53 | , m_url("https://update.virtualbox.org/query.php")
|
---|
54 | {
|
---|
55 | }
|
---|
56 |
|
---|
57 | void 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 |
|
---|
89 | void UINewVersionChecker::cancel()
|
---|
90 | {
|
---|
91 | cancelNetworkRequest();
|
---|
92 | }
|
---|
93 |
|
---|
94 | void UINewVersionChecker::processNetworkReplyProgress(qint64, qint64)
|
---|
95 | {
|
---|
96 | }
|
---|
97 |
|
---|
98 | void UINewVersionChecker::processNetworkReplyFailed(const QString &strError)
|
---|
99 | {
|
---|
100 | emit sigProgressFailed(strError);
|
---|
101 | }
|
---|
102 |
|
---|
103 | void UINewVersionChecker::processNetworkReplyCanceled(UINetworkReply *)
|
---|
104 | {
|
---|
105 | emit sigProgressCanceled();
|
---|
106 | }
|
---|
107 |
|
---|
108 | void 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 | const QStringList response = strResponseData.split(" ", Qt::SkipEmptyParts);
|
---|
120 | UINotificationMessage::showUpdateSuccess(response[0], response[1]);
|
---|
121 | }
|
---|
122 | /* No newer version of necessary package found: */
|
---|
123 | else
|
---|
124 | {
|
---|
125 | if (isItForcedCall())
|
---|
126 | UINotificationMessage::showUpdateNotFound();
|
---|
127 | }
|
---|
128 |
|
---|
129 | /* Increment update check counter: */
|
---|
130 | gEDataManager->incrementApplicationUpdateCheckCounter();
|
---|
131 |
|
---|
132 | /* Notify about completion: */
|
---|
133 | emit sigProgressFinished();
|
---|
134 | }
|
---|
135 |
|
---|
136 | /* static */
|
---|
137 | QString UINewVersionChecker::platformInfo()
|
---|
138 | {
|
---|
139 | /* Prepare platform report: */
|
---|
140 | QString strPlatform;
|
---|
141 |
|
---|
142 | #if defined (Q_OS_WIN)
|
---|
143 | strPlatform = "win";
|
---|
144 | #elif defined (Q_OS_LINUX)
|
---|
145 | strPlatform = "linux";
|
---|
146 | #elif defined (Q_OS_MACX)
|
---|
147 | strPlatform = "macosx";
|
---|
148 | #elif defined (Q_OS_OS2)
|
---|
149 | strPlatform = "os2";
|
---|
150 | #elif defined (Q_OS_FREEBSD)
|
---|
151 | strPlatform = "freebsd";
|
---|
152 | #elif defined (Q_OS_SOLARIS)
|
---|
153 | strPlatform = "solaris";
|
---|
154 | #else
|
---|
155 | strPlatform = "unknown";
|
---|
156 | #endif
|
---|
157 |
|
---|
158 | /* The format is <system>.<bitness>: */
|
---|
159 | strPlatform += QString(".%1").arg(ARCH_BITS);
|
---|
160 |
|
---|
161 | /* Add more system information: */
|
---|
162 | int vrc;
|
---|
163 | #ifdef Q_OS_LINUX
|
---|
164 | // WORKAROUND:
|
---|
165 | // On Linux we try to generate information using script first of all..
|
---|
166 |
|
---|
167 | /* Get script path: */
|
---|
168 | char szAppPrivPath[RTPATH_MAX];
|
---|
169 | vrc = RTPathAppPrivateNoArch(szAppPrivPath, sizeof(szAppPrivPath));
|
---|
170 | AssertRC(vrc);
|
---|
171 | if (RT_SUCCESS(vrc))
|
---|
172 | {
|
---|
173 | /* Run script: */
|
---|
174 | QByteArray result = QIProcess::singleShot(QString(szAppPrivPath) + "/VBoxSysInfo.sh");
|
---|
175 | if (!result.isNull())
|
---|
176 | strPlatform += QString(" [%1]").arg(QString(result).trimmed());
|
---|
177 | else
|
---|
178 | vrc = VERR_TRY_AGAIN; /* (take the fallback path) */
|
---|
179 | }
|
---|
180 | if (RT_FAILURE(vrc))
|
---|
181 | #endif /* Q_OS_LINUX */
|
---|
182 | {
|
---|
183 | /* Use RTSystemQueryOSInfo: */
|
---|
184 | char szTmp[256];
|
---|
185 | QStringList components;
|
---|
186 |
|
---|
187 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_PRODUCT, szTmp, sizeof(szTmp));
|
---|
188 | if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
|
---|
189 | components << QString("Product: %1").arg(szTmp);
|
---|
190 |
|
---|
191 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_RELEASE, szTmp, sizeof(szTmp));
|
---|
192 | if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
|
---|
193 | components << QString("Release: %1").arg(szTmp);
|
---|
194 |
|
---|
195 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_VERSION, szTmp, sizeof(szTmp));
|
---|
196 | if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
|
---|
197 | components << QString("Version: %1").arg(szTmp);
|
---|
198 |
|
---|
199 | vrc = RTSystemQueryOSInfo(RTSYSOSINFO_SERVICE_PACK, szTmp, sizeof(szTmp));
|
---|
200 | if ((RT_SUCCESS(vrc) || vrc == VERR_BUFFER_OVERFLOW) && szTmp[0] != '\0')
|
---|
201 | components << QString("SP: %1").arg(szTmp);
|
---|
202 |
|
---|
203 | if (!components.isEmpty())
|
---|
204 | strPlatform += QString(" [%1]").arg(components.join(" | "));
|
---|
205 | }
|
---|
206 |
|
---|
207 | return strPlatform;
|
---|
208 | }
|
---|