1 | /* $Id: UIExtension.cpp 103783 2024-03-11 17:29:21Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * VBox Qt GUI - UIExtension namespace 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 | /* GUI includes: */
|
---|
29 | #include "UIExtension.h"
|
---|
30 | #include "UIGlobalSession.h"
|
---|
31 | #include "UINotificationCenter.h"
|
---|
32 | #include "UIMessageCenter.h"
|
---|
33 | #include "VBoxLicenseViewer.h"
|
---|
34 |
|
---|
35 | /* COM includes: */
|
---|
36 | #include "CExtPack.h"
|
---|
37 |
|
---|
38 |
|
---|
39 | void UIExtension::install(const QString &strFilePath,
|
---|
40 | const QString &strDigest,
|
---|
41 | QWidget *pParent,
|
---|
42 | QString *pstrExtPackName)
|
---|
43 | {
|
---|
44 | /* If the extension pack manager isn't available, skip any attempts to install: */
|
---|
45 | CExtPackManager comExtPackManager = gpGlobalSession->virtualBox().GetExtensionPackManager();
|
---|
46 | if (comExtPackManager.isNull())
|
---|
47 | return;
|
---|
48 | /* Open the extpack tarball via IExtPackManager: */
|
---|
49 | CExtPackFile comExtPackFile;
|
---|
50 | if (strDigest.isEmpty())
|
---|
51 | comExtPackFile = comExtPackManager.OpenExtPackFile(strFilePath);
|
---|
52 | else
|
---|
53 | {
|
---|
54 | QString strFileAndHash = QString("%1::SHA-256=%2").arg(strFilePath).arg(strDigest);
|
---|
55 | comExtPackFile = comExtPackManager.OpenExtPackFile(strFileAndHash);
|
---|
56 | }
|
---|
57 | if (!comExtPackManager.isOk())
|
---|
58 | {
|
---|
59 | UINotificationMessage::cannotOpenExtPack(comExtPackManager, strFilePath);
|
---|
60 | return;
|
---|
61 | }
|
---|
62 |
|
---|
63 | if (!comExtPackFile.GetUsable())
|
---|
64 | {
|
---|
65 | UINotificationMessage::cannotReadExtPack(comExtPackFile, strFilePath);
|
---|
66 | return;
|
---|
67 | }
|
---|
68 |
|
---|
69 | const QString strPackName = comExtPackFile.GetName();
|
---|
70 | const QString strPackDescription = comExtPackFile.GetDescription();
|
---|
71 | const QString strPackVersion = QString("%1r%2%3").arg(comExtPackFile.GetVersion()).arg(comExtPackFile.GetRevision()).arg(comExtPackFile.GetEdition());
|
---|
72 |
|
---|
73 | /* Check if there is a version of the extension pack already
|
---|
74 | * installed on the system and let the user decide what to do about it. */
|
---|
75 | CExtPack comExtPackCur = comExtPackManager.Find(strPackName);
|
---|
76 | bool fReplaceIt = comExtPackCur.isOk();
|
---|
77 | if (fReplaceIt)
|
---|
78 | {
|
---|
79 | QString strPackVersionCur = QString("%1r%2%3").arg(comExtPackCur.GetVersion()).arg(comExtPackCur.GetRevision()).arg(comExtPackCur.GetEdition());
|
---|
80 | if (!msgCenter().confirmReplaceExtensionPack(strPackName, strPackVersion, strPackVersionCur, strPackDescription, pParent))
|
---|
81 | return;
|
---|
82 | }
|
---|
83 | /* If it's a new package just ask for general confirmation. */
|
---|
84 | else
|
---|
85 | {
|
---|
86 | if (!msgCenter().confirmInstallExtensionPack(strPackName, strPackVersion, strPackDescription, pParent))
|
---|
87 | return;
|
---|
88 | }
|
---|
89 |
|
---|
90 | /* Display the license dialog if required by the extension pack. */
|
---|
91 | if (comExtPackFile.GetShowLicense())
|
---|
92 | {
|
---|
93 | QString strLicense = comExtPackFile.GetLicense();
|
---|
94 | VBoxLicenseViewer licenseViewer(pParent);
|
---|
95 | if (licenseViewer.showLicenseFromString(strLicense) != QDialog::Accepted)
|
---|
96 | return;
|
---|
97 | }
|
---|
98 |
|
---|
99 | /* Install the selected package.
|
---|
100 | * Set the package name return value before doing
|
---|
101 | * this as the caller should do a refresh even on failure. */
|
---|
102 | QString strDisplayInfo;
|
---|
103 | #ifdef VBOX_WS_WIN
|
---|
104 | if (pParent)
|
---|
105 | strDisplayInfo = QString::asprintf("hwnd=%#llx", (uint64_t)(uintptr_t)pParent->winId());
|
---|
106 | #endif
|
---|
107 |
|
---|
108 | /* Install extension pack: */
|
---|
109 | UINotificationProgressExtensionPackInstall *pNotification =
|
---|
110 | new UINotificationProgressExtensionPackInstall(comExtPackFile,
|
---|
111 | fReplaceIt,
|
---|
112 | strPackName,
|
---|
113 | strDisplayInfo);
|
---|
114 | gpNotificationCenter->append(pNotification);
|
---|
115 |
|
---|
116 | /* Store the name: */
|
---|
117 | if (pstrExtPackName)
|
---|
118 | *pstrExtPackName = strPackName;
|
---|
119 | }
|
---|
120 |
|
---|
121 | bool UIExtension::isExtentionPackInstalled()
|
---|
122 | {
|
---|
123 | /* Acquire extension pack manager: */
|
---|
124 | const CVirtualBox comVBox = gpGlobalSession->virtualBox();
|
---|
125 | const CExtPackManager comEPManager = comVBox.GetExtensionPackManager();
|
---|
126 | if (!comVBox.isOk())
|
---|
127 | return false;
|
---|
128 |
|
---|
129 | /* Acquire a list of extension packs: */
|
---|
130 | const QVector<CExtPack> extensionPacks = comEPManager.GetInstalledExtPacks();
|
---|
131 | if (!comEPManager.isOk())
|
---|
132 | return false;
|
---|
133 |
|
---|
134 | /* Make sure at least one installed ext pack is usable: */
|
---|
135 | foreach (const CExtPack &comExtensionPack, extensionPacks)
|
---|
136 | {
|
---|
137 | if (!comExtensionPack.isOk())
|
---|
138 | continue;
|
---|
139 | const bool fUsable = comExtensionPack.GetUsable();
|
---|
140 | if (comExtensionPack.isOk() && fUsable)
|
---|
141 | return true;
|
---|
142 | }
|
---|
143 |
|
---|
144 | /* False by default: */
|
---|
145 | return false;
|
---|
146 | }
|
---|