1 | /* $Id: UnattendedScript.h 86659 2020-10-20 18:28:06Z vboxsync $ */
|
---|
2 | /** @file
|
---|
3 | * Classes for reading/parsing/saving scripts for unattended installation.
|
---|
4 | */
|
---|
5 |
|
---|
6 | /*
|
---|
7 | * Copyright (C) 2006-2020 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_UnattendedScript_h
|
---|
19 | #define MAIN_INCLUDED_UnattendedScript_h
|
---|
20 | #ifndef RT_WITHOUT_PRAGMA_ONCE
|
---|
21 | # pragma once
|
---|
22 | #endif
|
---|
23 |
|
---|
24 | #include "TextScript.h"
|
---|
25 |
|
---|
26 | using namespace xml;
|
---|
27 |
|
---|
28 | class Unattended;
|
---|
29 |
|
---|
30 |
|
---|
31 | /**
|
---|
32 | * Generic unattended text script template editor.
|
---|
33 | *
|
---|
34 | * This just perform variable replacements, no other editing possible.
|
---|
35 | *
|
---|
36 | * Everything happens during saveToString, parse is a noop.
|
---|
37 | */
|
---|
38 | class UnattendedScriptTemplate : public BaseTextScript
|
---|
39 | {
|
---|
40 | protected:
|
---|
41 | /** Where to get the replacement strings from. */
|
---|
42 | Unattended *mpUnattended;
|
---|
43 |
|
---|
44 | public:
|
---|
45 | UnattendedScriptTemplate(Unattended *pUnattended, const char *pszDefaultTemplateFilename, const char *pszDefaultFilename);
|
---|
46 | virtual ~UnattendedScriptTemplate() {}
|
---|
47 |
|
---|
48 | HRESULT parse() { return S_OK; }
|
---|
49 | HRESULT saveToString(Utf8Str &rStrDst);
|
---|
50 |
|
---|
51 | protected:
|
---|
52 | /**
|
---|
53 | * Gets the replacement value for the given placeholder.
|
---|
54 | *
|
---|
55 | * @returns COM status code.
|
---|
56 | * @param pachPlaceholder The placholder string. Not zero terminated.
|
---|
57 | * @param cchPlaceholder The length of the placeholder.
|
---|
58 | * @param fOutputting Indicates whether we actually need the correct value
|
---|
59 | * or is just syntax checking excluded template parts.
|
---|
60 | * @param rValue Where to return the value.
|
---|
61 | */
|
---|
62 | HRESULT getReplacement(const char *pachPlaceholder, size_t cchPlaceholder, bool fOutputting, RTCString &rValue);
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * Overridable worker for getReplacement.
|
---|
66 | *
|
---|
67 | * @returns COM status code.
|
---|
68 | * @param pachPlaceholder The placholder string. Not zero terminated.
|
---|
69 | * @param cchPlaceholder The length of the placeholder.
|
---|
70 | * @param cchFullPlaceholder The full placeholder length, including suffixes
|
---|
71 | * indicating how it should be escaped (for error
|
---|
72 | * messages).
|
---|
73 | * @param fOutputting Indicates whether we actually need the correct
|
---|
74 | * value or is just syntax checking excluded
|
---|
75 | * template parts. Intended for voiding triggering
|
---|
76 | * sanity checks regarding which replacements
|
---|
77 | * should be used and not (e.g. no Guest Additions
|
---|
78 | * path when installing GAs aren't enabled).
|
---|
79 | * @param rValue Where to return the value.
|
---|
80 | * @throws std::bad_alloc
|
---|
81 | */
|
---|
82 | virtual HRESULT getUnescapedReplacement(const char *pachPlaceholder, size_t cchPlaceholder,
|
---|
83 | size_t cchFullPlaceholder, bool fOutputting, RTCString &rValue);
|
---|
84 |
|
---|
85 |
|
---|
86 | /**
|
---|
87 | * Get the result of a conditional.
|
---|
88 | *
|
---|
89 | * @returns COM status code.
|
---|
90 | * @param pachPlaceholder The placholder string. Not zero terminated.
|
---|
91 | * @param cchPlaceholder The length of the placeholder.
|
---|
92 | * @param pfOutputting Where to return the result of the conditional.
|
---|
93 | * This holds the current outputting state on input
|
---|
94 | * in case someone want to sanity check anything.
|
---|
95 | */
|
---|
96 | virtual HRESULT getConditional(const char *pachPlaceholder, size_t cchPlaceholder, bool *pfOutputting);
|
---|
97 |
|
---|
98 | };
|
---|
99 |
|
---|
100 | #if 0 /* convert when we fix SUSE */
|
---|
101 | /**
|
---|
102 | * SUSE unattended XML file editor.
|
---|
103 | */
|
---|
104 | class UnattendedSUSEXMLScript : public UnattendedXMLScript
|
---|
105 | {
|
---|
106 | public:
|
---|
107 | UnattendedSUSEXMLScript(VirtualBoxBase *pSetError, const char *pszDefaultFilename = "autoinst.xml")
|
---|
108 | : UnattendedXMLScript(pSetError, pszDefaultFilename) {}
|
---|
109 | ~UnattendedSUSEXMLScript() {}
|
---|
110 |
|
---|
111 | HRESULT parse();
|
---|
112 |
|
---|
113 | protected:
|
---|
114 | HRESULT setFieldInElement(xml::ElementNode *pElement, const DataId enmDataId, const Utf8Str &rStrValue);
|
---|
115 |
|
---|
116 | private:
|
---|
117 | //////////////////New functions//////////////////////////////
|
---|
118 | /** @throws std::bad_alloc */
|
---|
119 | HRESULT LoopThruSections(const xml::ElementNode *pelmRoot);
|
---|
120 | /** @throws std::bad_alloc */
|
---|
121 | HRESULT HandleUserAccountsSection(const xml::ElementNode *pelmSection);
|
---|
122 | /** @throws std::bad_alloc */
|
---|
123 | Utf8Str createProbableValue(const DataId enmDataId, const xml::ElementNode *pCurElem);
|
---|
124 | /** @throws std::bad_alloc */
|
---|
125 | Utf8Str createProbableUserHomeDir(const xml::ElementNode *pCurElem);
|
---|
126 | //////////////////New functions//////////////////////////////
|
---|
127 | };
|
---|
128 | #endif
|
---|
129 |
|
---|
130 |
|
---|
131 | #endif /* !MAIN_INCLUDED_UnattendedScript_h */
|
---|
132 |
|
---|