VirtualBox

source: vbox/trunk/src/VBox/Frontends/VirtualBox/src/networking/UIUpdateManager.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: 12.4 KB
Line 
1/* $Id: UIUpdateManager.cpp 98103 2023-01-17 14:15:46Z vboxsync $ */
2/** @file
3 * VBox Qt GUI - UIUpdateManager 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 <QDir>
30#include <QTimer>
31
32/* GUI includes: */
33#include "UICommon.h"
34#include "UIExecutionQueue.h"
35#include "UIExtension.h"
36#include "UIExtraDataManager.h"
37#include "UIMessageCenter.h"
38#include "UIModalWindowManager.h"
39#include "UINotificationCenter.h"
40#include "UIUpdateDefs.h"
41#include "UIUpdateManager.h"
42
43/* COM includes: */
44#include "CExtPack.h"
45#include "CExtPackManager.h"
46
47
48/** UIExecutionStep extension to check for the new VirtualBox version. */
49class UIUpdateStepVirtualBox : public UIExecutionStep
50{
51 Q_OBJECT;
52
53public:
54
55 /** Constructs extension step.
56 * @param fForcedCall Brings whether this customer has forced privelegies. */
57 UIUpdateStepVirtualBox(bool fForcedCall);
58
59 /** Executes the step. */
60 virtual void exec() RT_OVERRIDE;
61
62private:
63
64 /** Holds whether this customer has forced privelegies. */
65 bool m_fForcedCall;
66
67};
68
69
70/** UIExecutionStep extension to check for the new VirtualBox Extension Pack version. */
71class UIUpdateStepVirtualBoxExtensionPack : public UIExecutionStep
72{
73 Q_OBJECT;
74
75public:
76
77 /** Constructs extension step. */
78 UIUpdateStepVirtualBoxExtensionPack();
79
80 /** Executes the step. */
81 virtual void exec() RT_OVERRIDE;
82
83private slots:
84
85 /** Handles downloaded Extension Pack.
86 * @param strSource Brings the EP source.
87 * @param strTarget Brings the EP target.
88 * @param strDigest Brings the EP digest. */
89 void sltHandleDownloadedExtensionPack(const QString &strSource,
90 const QString &strTarget,
91 const QString &strDigest);
92};
93
94
95/*********************************************************************************************************************************
96* Class UIUpdateStepVirtualBox implementation. *
97*********************************************************************************************************************************/
98
99UIUpdateStepVirtualBox::UIUpdateStepVirtualBox(bool fForcedCall)
100 : m_fForcedCall(fForcedCall)
101{
102 Q_UNUSED(fForcedCall);
103}
104
105void UIUpdateStepVirtualBox::exec()
106{
107 /* Check for new VirtualBox version: */
108 UINotificationProgressNewVersionChecker *pNotification =
109 new UINotificationProgressNewVersionChecker(m_fForcedCall);
110 connect(pNotification, &UINotificationProgressNewVersionChecker::sigProgressFinished,
111 this, &UIUpdateStepVirtualBox::sigStepFinished);
112 gpNotificationCenter->append(pNotification);
113}
114
115
116/*********************************************************************************************************************************
117* Class UIUpdateStepVirtualBoxExtensionPack implementation. *
118*********************************************************************************************************************************/
119
120UIUpdateStepVirtualBoxExtensionPack::UIUpdateStepVirtualBoxExtensionPack()
121{
122}
123
124void UIUpdateStepVirtualBoxExtensionPack::exec()
125{
126 /* Return if VirtualBox Manager issued a direct request to install EP: */
127 if (gUpdateManager->isEPInstallationRequested())
128 {
129 emit sigStepFinished();
130 return;
131 }
132
133 /* Return if already downloading: */
134 if (UINotificationDownloaderExtensionPack::exists())
135 {
136 gpNotificationCenter->invoke();
137 emit sigStepFinished();
138 return;
139 }
140
141 /* Get extension pack manager: */
142 CExtPackManager extPackManager = uiCommon().virtualBox().GetExtensionPackManager();
143 /* Return if extension pack manager is NOT available: */
144 if (extPackManager.isNull())
145 {
146 emit sigStepFinished();
147 return;
148 }
149
150 /* Get extension pack: */
151 CExtPack extPack = extPackManager.Find(GUI_ExtPackName);
152 /* Return if extension pack is NOT installed: */
153 if (extPack.isNull())
154 {
155 emit sigStepFinished();
156 return;
157 }
158
159 /* Get VirtualBox version: */
160 UIVersion vboxVersion(uiCommon().vboxVersionStringNormalized());
161 /* Get extension pack version: */
162 QString strExtPackVersion(extPack.GetVersion());
163
164 /* If this version being developed: */
165 if (vboxVersion.z() % 2 == 1)
166 {
167 /* If this version being developed on release branch (we use released one): */
168 if (vboxVersion.z() < 97)
169 vboxVersion.setZ(vboxVersion.z() - 1);
170 /* If this version being developed on trunk (we skip check at all): */
171 else
172 {
173 emit sigStepFinished();
174 return;
175 }
176 }
177
178 /* Get updated VirtualBox version: */
179 const QString strVBoxVersion = vboxVersion.toString();
180
181 /* Skip the check if the extension pack is equal to or newer than VBox. */
182 if (UIVersion(strExtPackVersion) >= vboxVersion)
183 {
184 emit sigStepFinished();
185 return;
186 }
187
188 QString strExtPackEdition(extPack.GetEdition());
189 if (strExtPackEdition.contains("ENTERPRISE"))
190 {
191 /* Inform the user that he should update the extension pack: */
192 UINotificationMessage::askUserToDownloadExtensionPack(GUI_ExtPackName, strExtPackVersion, strVBoxVersion);
193 /* Never try to download for ENTERPRISE version: */
194 emit sigStepFinished();
195 return;
196 }
197
198 /* Ask the user about extension pack downloading: */
199 if (!msgCenter().confirmLookingForExtensionPack(GUI_ExtPackName, strExtPackVersion))
200 {
201 emit sigStepFinished();
202 return;
203 }
204
205 /* Download extension pack: */
206 UINotificationDownloaderExtensionPack *pNotification = UINotificationDownloaderExtensionPack::instance(GUI_ExtPackName);
207 /* After downloading finished => propose to install the Extension Pack: */
208 connect(pNotification, &UINotificationDownloaderExtensionPack::sigExtensionPackDownloaded,
209 this, &UIUpdateStepVirtualBoxExtensionPack::sltHandleDownloadedExtensionPack);
210 /* Handle any signal as step-finished: */
211 connect(pNotification, &UINotificationDownloaderExtensionPack::sigProgressFailed,
212 this, &UIUpdateStepVirtualBoxExtensionPack::sigStepFinished);
213 connect(pNotification, &UINotificationDownloaderExtensionPack::sigProgressCanceled,
214 this, &UIUpdateStepVirtualBoxExtensionPack::sigStepFinished);
215 connect(pNotification, &UINotificationDownloaderExtensionPack::sigProgressFinished,
216 this, &UIUpdateStepVirtualBoxExtensionPack::sigStepFinished);
217 /* Append and start notification: */
218 gpNotificationCenter->append(pNotification);
219}
220
221void UIUpdateStepVirtualBoxExtensionPack::sltHandleDownloadedExtensionPack(const QString &strSource,
222 const QString &strTarget,
223 const QString &strDigest)
224{
225 /* Warn the user about extension pack was downloaded and saved, propose to install it: */
226 if (msgCenter().proposeInstallExtentionPack(GUI_ExtPackName, strSource, QDir::toNativeSeparators(strTarget)))
227 UIExtension::install(strTarget, strDigest, windowManager().mainWindowShown(), NULL);
228 /* Propose to delete the downloaded extension pack: */
229 if (msgCenter().proposeDeleteExtentionPack(QDir::toNativeSeparators(strTarget)))
230 {
231 /* Delete the downloaded extension pack: */
232 QFile::remove(QDir::toNativeSeparators(strTarget));
233 /* Get the list of old extension pack files in VirtualBox homefolder: */
234 const QStringList oldExtPackFiles = QDir(uiCommon().homeFolder()).entryList(QStringList("*.vbox-extpack"),
235 QDir::Files);
236 /* Propose to delete old extension pack files if there are any: */
237 if (oldExtPackFiles.size())
238 {
239 if (msgCenter().proposeDeleteOldExtentionPacks(oldExtPackFiles))
240 {
241 foreach (const QString &strExtPackFile, oldExtPackFiles)
242 {
243 /* Delete the old extension pack file: */
244 QFile::remove(QDir::toNativeSeparators(QDir(uiCommon().homeFolder()).filePath(strExtPackFile)));
245 }
246 }
247 }
248 }
249}
250
251
252/*********************************************************************************************************************************
253* Class UIUpdateManager implementation. *
254*********************************************************************************************************************************/
255
256/* static */
257UIUpdateManager* UIUpdateManager::s_pInstance = 0;
258
259UIUpdateManager::UIUpdateManager()
260 : m_pQueue(new UIExecutionQueue(this))
261 , m_fIsRunning(false)
262 , m_uTime(1 /* day */ * 24 /* hours */ * 60 /* minutes */ * 60 /* seconds */ * 1000 /* ms */)
263 , m_fEPInstallationRequested(false)
264{
265 /* Prepare instance: */
266 if (s_pInstance != this)
267 s_pInstance = this;
268
269 /* Configure queue: */
270 connect(m_pQueue, &UIExecutionQueue::sigQueueFinished, this, &UIUpdateManager::sltHandleUpdateFinishing);
271
272#ifdef VBOX_WITH_UPDATE_REQUEST
273 /* Ask updater to check for the first time, for Selector UI only: */
274 if (gEDataManager->applicationUpdateEnabled() && uiCommon().uiType() == UICommon::UIType_SelectorUI)
275 QTimer::singleShot(0, this, SLOT(sltCheckIfUpdateIsNecessary()));
276#endif /* VBOX_WITH_UPDATE_REQUEST */
277}
278
279UIUpdateManager::~UIUpdateManager()
280{
281 /* Cleanup instance: */
282 if (s_pInstance == this)
283 s_pInstance = 0;
284}
285
286/* static */
287void UIUpdateManager::schedule()
288{
289 /* Ensure instance is NOT created: */
290 if (s_pInstance)
291 return;
292
293 /* Create instance: */
294 new UIUpdateManager;
295}
296
297/* static */
298void UIUpdateManager::shutdown()
299{
300 /* Ensure instance is created: */
301 if (!s_pInstance)
302 return;
303
304 /* Delete instance: */
305 delete s_pInstance;
306}
307
308void UIUpdateManager::sltForceCheck()
309{
310 /* Force call for new version check: */
311 sltCheckIfUpdateIsNecessary(true /* force call */);
312}
313
314void UIUpdateManager::sltCheckIfUpdateIsNecessary(bool fForcedCall /* = false */)
315{
316 /* If already running: */
317 if (m_fIsRunning)
318 {
319 /* And we have a force-call: */
320 if (fForcedCall)
321 gpNotificationCenter->invoke();
322 return;
323 }
324
325 /* Set as running: */
326 m_fIsRunning = true;
327
328 /* Load/decode curent update data: */
329 VBoxUpdateData currentData;
330 CHost comHost = uiCommon().host();
331 currentData.load(comHost);
332
333 /* If update is really necessary: */
334 if (
335#ifdef VBOX_NEW_VERSION_TEST
336 true ||
337#endif
338 fForcedCall || currentData.isCheckRequired())
339 {
340 /* Prepare update queue: */
341 m_pQueue->enqueue(new UIUpdateStepVirtualBox(fForcedCall));
342 m_pQueue->enqueue(new UIUpdateStepVirtualBoxExtensionPack);
343 /* Start update queue: */
344 m_pQueue->start();
345 }
346 else
347 sltHandleUpdateFinishing();
348}
349
350void UIUpdateManager::sltHandleUpdateFinishing()
351{
352 /* Load/decode curent update data: */
353 VBoxUpdateData currentData;
354 CHost comHost = uiCommon().host();
355 currentData.load(comHost);
356 /* Encode/save new update data: */
357 VBoxUpdateData newData(currentData.isCheckEnabled(), currentData.updatePeriod(), currentData.updateChannel());
358 newData.save(comHost);
359
360#ifdef VBOX_WITH_UPDATE_REQUEST
361 /* Ask updater to check for the next time: */
362 QTimer::singleShot(m_uTime, this, SLOT(sltCheckIfUpdateIsNecessary()));
363#endif /* VBOX_WITH_UPDATE_REQUEST */
364
365 /* Set as not running: */
366 m_fIsRunning = false;
367}
368
369
370#include "UIUpdateManager.moc"
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