VirtualBox

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

Last change on this file since 93584 was 93584, checked in by vboxsync, 3 years ago

Main/Unattended: Update detectedOS* attributes when setting imageIndex and we've detectedImages info handy. Ditto for prepare() and detectIsoOS(). Parse LANGUAGES from the XML data in install.xim. Stop windows detection if we seems to have found the necessary info in the XML section of install.wim. bugref:9781

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

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