VirtualBox

source: vbox/trunk/src/VBox/Main/include/UnattendedImpl.h@ 102381

Last change on this file since 102381 was 102381, checked in by vboxsync, 6 months ago

Main/Unattended: Added stubs for IUnattended:keyboardLayout + IUnattended:keyboardVariant attributes. bugref:10553

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
File size: 13.8 KB
Line 
1/* $Id: UnattendedImpl.h 102381 2023-11-29 14:51:33Z vboxsync $ */
2/** @file
3 * Unattended class header
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#ifndef MAIN_INCLUDED_UnattendedImpl_h
29#define MAIN_INCLUDED_UnattendedImpl_h
30#ifndef RT_WITHOUT_PRAGMA_ONCE
31# pragma once
32#endif
33
34#include <VBox/ostypes.h>
35#include <iprt/time.h>
36#include "UnattendedWrap.h"
37
38/* Forward declarations. */
39class UnattendedInstaller;
40struct UnattendedInstallationDisk;
41struct ControllerSlot;
42
43/**
44 * A data type to store image data which is read from intall.wim file.
45 * Currently relevant only for Windows OSs.
46 */
47struct WIMImage
48{
49 Utf8Str mName;
50 Utf8Str mVersion;
51 Utf8Str mArch;
52 Utf8Str mFlavor;
53 RTCList<RTCString, RTCString *> mLanguages;
54 Utf8Str mDefaultLanguage;
55 uint32_t mImageIndex;
56 VBOXOSTYPE mOSType;
57 WIMImage() : mImageIndex(0), mOSType(VBOXOSTYPE_Unknown) { }
58 const Utf8Str &formatName(Utf8Str &r_strName) const;
59};
60
61/**
62 * Class implementing the IUnattended interface.
63 *
64 * This class is instantiated on the request by IMachine::getUnattended.
65 */
66class ATL_NO_VTABLE Unattended
67 : public UnattendedWrap
68{
69public:
70 DECLARE_COMMON_CLASS_METHODS(Unattended)
71
72 HRESULT FinalConstruct();
73 void FinalRelease();
74
75 // public initializer/uninitializer for internal purposes only
76 HRESULT initUnattended(VirtualBox *aParent);
77 void uninit();
78
79 // public methods for internal purposes
80 Utf8Str const &i_getIsoPath() const;
81 Utf8Str const &i_getUser() const;
82 Utf8Str const &i_getPassword() const;
83 Utf8Str const &i_getFullUserName() const;
84 Utf8Str const &i_getProductKey() const;
85 Utf8Str const &i_getProxy() const;
86 Utf8Str const &i_getAdditionsIsoPath() const;
87 bool i_getInstallGuestAdditions() const;
88 Utf8Str const &i_getValidationKitIsoPath() const;
89 bool i_getInstallTestExecService() const;
90 Utf8Str const &i_getUserPayloadIsoPath() const;
91 bool i_getInstallUserPayload() const;
92 Utf8Str const &i_getTimeZone() const;
93 PCRTTIMEZONEINFO i_getTimeZoneInfo() const;
94 Utf8Str const &i_getLocale() const;
95 Utf8Str const &i_getLanguage() const;
96 Utf8Str const &i_getCountry() const;
97 bool i_isMinimalInstallation() const;
98 Utf8Str const &i_getHostname() const;
99 Utf8Str const &i_getAuxiliaryBasePath() const;
100 ULONG i_getImageIndex() const;
101 Utf8Str const &i_getScriptTemplatePath() const;
102 Utf8Str const &i_getPostInstallScriptTemplatePath() const;
103 Utf8Str const &i_getPostInstallCommand() const;
104 /** The directory where the unattended install config and script is
105 * located, from the perspective of the running unattended install. */
106 Utf8Str const &i_getAuxiliaryInstallDir() const;
107 Utf8Str const &i_getExtraInstallKernelParameters() const;
108 Utf8Str const &i_getAdditionsInstallPackage() const;
109
110 bool i_isRtcUsingUtc() const;
111 bool i_isGuestOs64Bit() const;
112 bool i_isFirmwareEFI() const;
113 Utf8Str const &i_getDetectedOSVersion();
114 bool i_getAvoidUpdatesOverNetwork() const;
115
116private:
117 ComPtr<VirtualBox> const mParent; /**< Strong reference to the parent object (VirtualBox/IMachine). */
118 ComPtr<Machine> mMachine; /**< Strong reference to the machine object (Machine/IMachine). */
119 Guid mMachineUuid; /**< The machine UUID. */
120 RTNATIVETHREAD mhThreadReconfigureVM; /**< Set when reconfigureVM is running. */
121 Utf8Str mStrGuestOsTypeId; /**< Guest OS type ID (set by prepare). */
122 bool mfRtcUseUtc; /**< Copy of IMachine::RTCUseUTC (locking reasons). */
123 bool mfGuestOs64Bit; /**< 64-bit (true) or 32-bit guest OS (set by prepare). */
124 FirmwareType_T menmFirmwareType; /**< Firmware type BIOS/EFI (set by prepare). */
125 UnattendedInstaller *mpInstaller; /**< The installer instance (set by prepare, deleted by done). */
126
127 /** @name Values of the IUnattended attributes.
128 * @{ */
129 Utf8Str mStrUser;
130 Utf8Str mStrPassword;
131 Utf8Str mStrFullUserName;
132 Utf8Str mStrProductKey;
133 Utf8Str mStrIsoPath;
134 Utf8Str mStrAdditionsIsoPath;
135 bool mfInstallGuestAdditions;
136 bool mfInstallTestExecService;
137 Utf8Str mStrValidationKitIsoPath;
138 Utf8Str mStrUserPayloadIsoPath;
139 bool mfInstallUserPayload;
140 Utf8Str mStrTimeZone;
141 PCRTTIMEZONEINFO mpTimeZoneInfo;
142 Utf8Str mStrLocale;
143 Utf8Str mStrLanguage; /**< (only relevant for windows at the moment) */
144 Utf8Str mStrCountry;
145 RTCList<RTCString, RTCString *> mPackageSelectionAdjustments;
146 Utf8Str mStrHostname;
147 Utf8Str mStrAuxiliaryBasePath;
148 bool mfIsDefaultAuxiliaryBasePath;
149 ULONG midxImage;
150 Utf8Str mStrScriptTemplatePath;
151 Utf8Str mStrPostInstallScriptTemplatePath;
152 Utf8Str mStrPostInstallCommand;
153 Utf8Str mStrExtraInstallKernelParameters;
154 Utf8Str mStrProxy;
155 Utf8Str mStrAdditionsInstallPackage;
156
157 bool mfDoneDetectIsoOS; /**< Set by detectIsoOS(), cleared by setIsoPath(). */
158 Utf8Str mStrDetectedOSTypeId;
159 Utf8Str mStrDetectedOSVersion;
160 Utf8Str mStrDetectedOSFlavor;
161 VBOXOSTYPE mEnmOsType;
162 RTCList<RTCString, RTCString *> mDetectedOSLanguages; /**< (only relevant for windows at the moment) */
163 Utf8Str mStrDetectedOSHints;
164 RTCList<WIMImage> mDetectedImages;
165 bool mfAvoidUpdatesOverNetwork;
166 /** @} */
167
168 // wrapped IUnattended functions:
169
170 /**
171 * Checks what mStrIsoPath points to and sets the detectedOS* properties.
172 */
173 HRESULT detectIsoOS();
174
175 /**
176 * Prepare any data, environment, etc.
177 */
178 HRESULT prepare();
179
180 /**
181 * Prepare installation ISO/floppy.
182 */
183 HRESULT constructMedia();
184
185 /**
186 * Prepare a VM to run an unattended installation
187 */
188 HRESULT reconfigureVM();
189
190 /**
191 * Done with all media construction and VM configuration and stuff.
192 */
193 HRESULT done();
194
195 // wrapped IUnattended attributes:
196 HRESULT getIsoPath(com::Utf8Str &isoPath);
197 HRESULT setIsoPath(const com::Utf8Str &isoPath);
198 HRESULT getUser(com::Utf8Str &user);
199 HRESULT setUser(const com::Utf8Str &user);
200 HRESULT getPassword(com::Utf8Str &password);
201 HRESULT setPassword(const com::Utf8Str &password);
202 HRESULT getFullUserName(com::Utf8Str &user);
203 HRESULT setFullUserName(const com::Utf8Str &user);
204 HRESULT getProductKey(com::Utf8Str &productKey);
205 HRESULT setProductKey(const com::Utf8Str &productKey);
206 HRESULT getAdditionsIsoPath(com::Utf8Str &additionsIsoPath);
207 HRESULT setAdditionsIsoPath(const com::Utf8Str &additionsIsoPath);
208 HRESULT getInstallGuestAdditions(BOOL *installGuestAdditions);
209 HRESULT setInstallGuestAdditions(BOOL installGuestAdditions);
210 HRESULT getValidationKitIsoPath(com::Utf8Str &aValidationKitIsoPath);
211 HRESULT setValidationKitIsoPath(const com::Utf8Str &aValidationKitIsoPath);
212 HRESULT getInstallTestExecService(BOOL *aInstallTestExecService);
213 HRESULT setInstallTestExecService(BOOL aInstallTestExecService);
214 HRESULT getUserPayloadIsoPath(com::Utf8Str &aUserPayloadIsoPath);
215 HRESULT setUserPayloadIsoPath(const com::Utf8Str &aUserPayloadIsoPath);
216 HRESULT getInstallUserPayload(BOOL *aInstallUserPayload);
217 HRESULT setInstallUserPayload(BOOL aInstallUserPayload);
218 HRESULT getTimeZone(com::Utf8Str &aTimezone);
219 HRESULT setTimeZone(const com::Utf8Str &aTimezone);
220 HRESULT getKeyboardLayout(com::Utf8Str &aKeyboardLayout);
221 HRESULT setKeyboardLayout(const com::Utf8Str &aKeyboardLayout);
222 HRESULT getKeyboardVariant(com::Utf8Str &aKeyboardVariant);
223 HRESULT setKeyboardVariant(const com::Utf8Str &aKeyboardVariant);
224 HRESULT getLocale(com::Utf8Str &aLocale);
225 HRESULT setLocale(const com::Utf8Str &aLocale);
226 HRESULT getLanguage(com::Utf8Str &aLanguage);
227 HRESULT setLanguage(const com::Utf8Str &aLanguage);
228 HRESULT getCountry(com::Utf8Str &aCountry);
229 HRESULT setCountry(const com::Utf8Str &aCountry);
230 HRESULT getProxy(com::Utf8Str &aProxy);
231 HRESULT setProxy(const com::Utf8Str &aProxy);
232 HRESULT getPackageSelectionAdjustments(com::Utf8Str &aPackageSelectionAdjustments);
233 HRESULT setPackageSelectionAdjustments(const com::Utf8Str &aPackageSelectionAdjustments);
234 HRESULT getHostname(com::Utf8Str &aHostname);
235 HRESULT setHostname(const com::Utf8Str &aHostname);
236 HRESULT getAuxiliaryBasePath(com::Utf8Str &aAuxiliaryBasePath);
237 HRESULT setAuxiliaryBasePath(const com::Utf8Str &aAuxiliaryBasePath);
238 HRESULT getImageIndex(ULONG *index);
239 HRESULT setImageIndex(ULONG index);
240 HRESULT getMachine(ComPtr<IMachine> &aMachine);
241 HRESULT setMachine(const ComPtr<IMachine> &aMachine);
242 HRESULT getScriptTemplatePath(com::Utf8Str &aScriptTemplatePath);
243 HRESULT setScriptTemplatePath(const com::Utf8Str &aScriptTemplatePath);
244 HRESULT getPostInstallScriptTemplatePath(com::Utf8Str &aPostInstallScriptTemplatePath);
245 HRESULT setPostInstallScriptTemplatePath(const com::Utf8Str &aPostInstallScriptTemplatePath);
246 HRESULT getPostInstallCommand(com::Utf8Str &aPostInstallCommand);
247 HRESULT setPostInstallCommand(const com::Utf8Str &aPostInstallCommand);
248 HRESULT getExtraInstallKernelParameters(com::Utf8Str &aExtraInstallKernelParameters);
249 HRESULT setExtraInstallKernelParameters(const com::Utf8Str &aExtraInstallKernelParameters);
250 HRESULT getDetectedOSTypeId(com::Utf8Str &aDetectedOSTypeId);
251 HRESULT getDetectedOSVersion(com::Utf8Str &aDetectedOSVersion);
252 HRESULT getDetectedOSLanguages(com::Utf8Str &aDetectedOSLanguages);
253 HRESULT getDetectedOSFlavor(com::Utf8Str &aDetectedOSFlavor);
254 HRESULT getDetectedOSHints(com::Utf8Str &aDetectedOSHints);
255 HRESULT getDetectedImageNames(std::vector<com::Utf8Str> &aDetectedImageNames);
256 HRESULT getDetectedImageIndices(std::vector<ULONG> &aDetectedImageIndices);
257 HRESULT getIsUnattendedInstallSupported(BOOL *aIsUnattendedInstallSupported);
258 HRESULT getAvoidUpdatesOverNetwork(BOOL *aAvoidUpdatesOverNetwork);
259 HRESULT setAvoidUpdatesOverNetwork(BOOL aAvoidUpdatesOverNetwork);
260 //internal functions
261
262 /**
263 * Worker for detectIsoOs().
264 *
265 * @returns COM status code.
266 * @retval S_OK if detected.
267 * @retval S_FALSE if not detected.
268 *
269 * @param hVfsIso The ISO file system handle.
270 */
271 HRESULT i_innerDetectIsoOS(RTVFS hVfsIso);
272 typedef union DETECTBUFFER
273 {
274 char sz[4096];
275 char ach[4096];
276 uint8_t ab[4096];
277 uint32_t au32[1024];
278 } DETECTBUFFER;
279 HRESULT i_innerDetectIsoOSWindows(RTVFS hVfsIso, DETECTBUFFER *puBuf);
280 HRESULT i_innerDetectIsoOSLinux(RTVFS hVfsIso, DETECTBUFFER *puBuf);
281 HRESULT i_innerDetectIsoOSLinuxFedora(RTVFS hVfsIso, DETECTBUFFER *puBuf, char *pszVolId);
282 HRESULT i_innerDetectIsoOSOs2(RTVFS hVfsIso, DETECTBUFFER *puBuf);
283 HRESULT i_innerDetectIsoOSFreeBsd(RTVFS hVfsIso, DETECTBUFFER *puBuf);
284
285 /**
286 * Worker for reconfigureVM().
287 * The caller makes sure to close the session whatever happens.
288 */
289 HRESULT i_innerReconfigureVM(AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus,
290 ComPtr<IMachine> const &rPtrSessionMachine);
291 HRESULT i_reconfigureFloppy(com::SafeIfaceArray<IStorageController> &rControllers,
292 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
293 ComPtr<IMachine> const &rPtrSessionMachine,
294 AutoMultiWriteLock2 &rAutoLock);
295 HRESULT i_reconfigureIsos(com::SafeIfaceArray<IStorageController> &rControllers,
296 std::vector<UnattendedInstallationDisk> &rVecInstallatationDisks,
297 ComPtr<IMachine> const &rPtrSessionMachine,
298 AutoMultiWriteLock2 &rAutoLock, StorageBus_T enmRecommendedStorageBus);
299
300 /**
301 * Adds all free slots on the controller to @a rOutput.
302 */
303 HRESULT i_findOrCreateNeededFreeSlots(const Utf8Str &rStrControllerName, StorageBus_T enmStorageBus,
304 ComPtr<IMachine> const &rPtrSessionMachine, uint32_t cSlotsNeeded,
305 std::list<ControllerSlot> &rDvdSlots);
306
307 /**
308 * Attach to VM a disk
309 */
310 HRESULT i_attachImage(UnattendedInstallationDisk const *pImage, ComPtr<IMachine> const &rPtrSessionMachine,
311 AutoMultiWriteLock2 &rLock);
312
313 /*
314 * Wrapper functions
315 */
316
317 /**
318 * Check whether guest is 64bit platform or not
319 */
320 bool i_isGuestOSArchX64(Utf8Str const &rStrGuestOsTypeId);
321
322 /**
323 * Updates the detected attributes when the image index or image list changes.
324 *
325 * @returns true if we've got all necessary stuff for a successful detection.
326 */
327 bool i_updateDetectedAttributeForImage(WIMImage const &rImage);
328
329};
330
331#endif /* !MAIN_INCLUDED_UnattendedImpl_h */
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use