Changeset 76167 in vbox for trunk/src/VBox/Main/include
- Timestamp:
- Dec 11, 2018 5:03:05 PM (6 years ago)
- Location:
- trunk/src/VBox/Main/include
- Files:
-
- 1 edited
- 1 copied
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/VBox/Main/include/TextScript.h
r76159 r76167 1 1 /* $Id$ */ 2 2 /** @file 3 * Implementeation of algorithms which read/parse/save scripts for unattended installation.3 * Classes for reading/parsing/saving text scripts (unattended installation, ++). 4 4 */ 5 5 … … 16 16 */ 17 17 18 #ifndef ____H_ UNATTENDEDSCRIPT19 #define ____H_ UNATTENDEDSCRIPT18 #ifndef ____H_TEXTSCRIPT 19 #define ____H_TEXTSCRIPT 20 20 21 21 #include "VirtualBoxBase.h" … … 23 23 #include <vector> 24 24 25 using namespace xml;26 27 class Unattended;28 29 25 30 26 /** 31 27 * Base class for all the script readers/editors. 32 28 * 33 * @todo get rid of this bugger29 * @todo get rid of this silly bugger. 34 30 */ 35 31 class AbstractScript : public RTCNonCopyable … … 152 148 153 149 /** 154 * Generic unattended text script template editor.155 *156 * This just perform variable replacements, no other editing possible.157 *158 * Everything happens during saveToString, parse is a noop.159 */160 class UnattendedScriptTemplate : public BaseTextScript161 {162 protected:163 /** Where to get the replacement strings from. */164 Unattended *mpUnattended;165 166 public:167 UnattendedScriptTemplate(Unattended *pUnattended, const char *pszDefaultTemplateFilename, const char *pszDefaultFilename);168 virtual ~UnattendedScriptTemplate() {}169 170 HRESULT parse() { return S_OK; }171 HRESULT saveToString(Utf8Str &rStrDst);172 173 protected:174 /**175 * Gets the replacement value for the given placeholder.176 *177 * @returns COM status code.178 * @param pachPlaceholder The placholder string. Not zero terminated.179 * @param cchPlaceholder The length of the placeholder.180 * @param fOutputting Indicates whether we actually need the correct value181 * or is just syntax checking excluded template parts.182 * @param rValue Where to return the value.183 */184 HRESULT getReplacement(const char *pachPlaceholder, size_t cchPlaceholder, bool fOutputting, RTCString &rValue);185 186 /**187 * Overridable worker for getReplacement.188 *189 * @returns COM status code.190 * @param pachPlaceholder The placholder string. Not zero terminated.191 * @param cchPlaceholder The length of the placeholder.192 * @param cchFullPlaceholder The full placeholder length, including suffixes193 * indicating how it should be escaped (for error194 * messages).195 * @param fOutputting Indicates whether we actually need the correct196 * value or is just syntax checking excluded197 * template parts. Intended for voiding triggering198 * sanity checks regarding which replacements199 * should be used and not (e.g. no guest additions200 * path when installing GAs aren't enabled).201 * @param rValue Where to return the value.202 * @throws std::bad_alloc203 */204 virtual HRESULT getUnescapedReplacement(const char *pachPlaceholder, size_t cchPlaceholder,205 size_t cchFullPlaceholder, bool fOutputting, RTCString &rValue);206 207 208 /**209 * Get the result of a conditional.210 *211 * @returns COM status code.212 * @param pachPlaceholder The placholder string. Not zero terminated.213 * @param cchPlaceholder The length of the placeholder.214 * @param pfOutputting Where to return the result of the conditional.215 * This holds the current outputting state on input216 * in case someone want to sanity check anything.217 */218 virtual HRESULT getConditional(const char *pachPlaceholder, size_t cchPlaceholder, bool *pfOutputting);219 };220 221 222 /**223 150 * Generic line based text script editor. 224 151 * … … 298 225 299 226 300 #if 0 /* convert when we fix SUSE */ 301 /** 302 * SUSE unattended XML file editor. 303 */ 304 class UnattendedSUSEXMLScript : public UnattendedXMLScript 305 { 306 public: 307 UnattendedSUSEXMLScript(VirtualBoxBase *pSetError, const char *pszDefaultFilename = "autoinst.xml") 308 : UnattendedXMLScript(pSetError, pszDefaultFilename) {} 309 ~UnattendedSUSEXMLScript() {} 310 311 HRESULT parse(); 312 313 protected: 314 HRESULT setFieldInElement(xml::ElementNode *pElement, const DataId enmDataId, const Utf8Str &rStrValue); 315 316 private: 317 //////////////////New functions////////////////////////////// 318 /** @throws std::bad_alloc */ 319 HRESULT LoopThruSections(const xml::ElementNode *pelmRoot); 320 /** @throws std::bad_alloc */ 321 HRESULT HandleUserAccountsSection(const xml::ElementNode *pelmSection); 322 /** @throws std::bad_alloc */ 323 Utf8Str createProbableValue(const DataId enmDataId, const xml::ElementNode *pCurElem); 324 /** @throws std::bad_alloc */ 325 Utf8Str createProbableUserHomeDir(const xml::ElementNode *pCurElem); 326 //////////////////New functions////////////////////////////// 327 }; 328 #endif 329 330 331 #endif // !____H_UNATTENDEDSCRIPT 332 227 #endif // !____H_TEXTSCRIPT 228 -
trunk/src/VBox/Main/include/UnattendedScript.h
r73826 r76167 1 1 /* $Id$ */ 2 2 /** @file 3 * Implementeation of algorithms which read/parse/savescripts for unattended installation.3 * Classes for reading/parsing/saving scripts for unattended installation. 4 4 */ 5 5 … … 19 19 #define ____H_UNATTENDEDSCRIPT 20 20 21 #include "VirtualBoxBase.h" 22 #include <iprt/cpp/utils.h> 23 #include <vector> 21 #include "TextScript.h" 24 22 25 23 using namespace xml; 26 24 27 25 class Unattended; 28 29 30 /**31 * Base class for all the script readers/editors.32 *33 * @todo get rid of this bugger34 */35 class AbstractScript : public RTCNonCopyable36 {37 protected:38 /** For setting errors.39 * Yeah, class isn't entirely abstract now. */40 VirtualBoxBase *mpSetError;41 42 private: /* no default constructors for children. */43 AbstractScript() {}44 45 public:46 AbstractScript(VirtualBoxBase *pSetError) : mpSetError(pSetError) {}47 virtual ~AbstractScript() {}48 49 /**50 * Read a script from a file51 */52 virtual HRESULT read(const Utf8Str &rStrFilename) = 0;53 54 /**55 * Read a script from a VFS file handle.56 */57 virtual HRESULT readFromHandle(RTVFSFILE hVfsFile, const char *pszFilename) = 0;58 59 /**60 * Parse the script61 */62 virtual HRESULT parse() = 0;63 64 /**65 * Save a script to a string.66 *67 * This is used by save() and later others to deloy the script.68 */69 virtual HRESULT saveToString(Utf8Str &rStrDst) = 0;70 71 /**72 * Save a script to a file.73 * @param rStrPath Where to save the script. This normally points to a74 * file, but in a number of child use cases it's75 * actually giving a directory to put the script in76 * using the default deloyment filename. One day we77 * might make the caller do this path joining.78 * @param fOverwrite Whether to overwrite the file or not.79 */80 virtual HRESULT save(const Utf8Str &rStrPath, bool fOverwrite) = 0;81 82 /**83 * Path where an actual script with user's data is located84 */85 virtual const Utf8Str &getActualScriptPath() const = 0;86 };87 88 /**89 * Base class for text based script readers/editors.90 *91 * This deals with reading the file into a string data member, writing it back92 * out to a file, and remember the filenames.93 */94 class BaseTextScript : public AbstractScript95 {96 protected:97 const char * const mpszDefaultTemplateFilename; /**< The default template filename. Can be empty. */98 const char * const mpszDefaultFilename; /**< Filename to use when someone calls save() with a directory path. Can be NULL. */99 RTCString mStrScriptFullContent; /**< Raw text file content. Produced by read() and typically only used by parse(). */100 Utf8Str mStrOriginalPath; /**< Path where an original script is located (set by read()). */101 Utf8Str mStrSavedPath; /**< Path where an saved script with user's data is located (set by save()). */102 103 public:104 BaseTextScript(VirtualBoxBase *pSetError, const char *pszDefaultTemplateFilename, const char *pszDefaultFilename)105 : AbstractScript(pSetError)106 , mpszDefaultTemplateFilename(pszDefaultTemplateFilename)107 , mpszDefaultFilename(pszDefaultFilename)108 { }109 virtual ~BaseTextScript() {}110 111 HRESULT read(const Utf8Str &rStrFilename);112 HRESULT readFromHandle(RTVFSFILE hVfsFile, const char *pszFilename);113 HRESULT save(const Utf8Str &rStrFilename, bool fOverwrite);114 115 /**116 * Gets the default filename for this class of scripts (empty if none).117 *118 * @note Just the filename, no path.119 */120 const char *getDefaultFilename() const121 {122 return mpszDefaultFilename;123 }124 125 /**126 * Gets the default template filename for this class of scripts (empty if none).127 *128 * @note Just the filename, no path.129 */130 const char *getDefaultTemplateFilename() const131 {132 return mpszDefaultTemplateFilename;133 }134 135 /**136 * Path to the file we last saved the script as.137 */138 const Utf8Str &getActualScriptPath() const139 {140 return mStrSavedPath;141 }142 143 /**144 * Path where an original script is located145 */146 const Utf8Str &getOriginalScriptPath() const147 {148 return mStrOriginalPath;149 }150 };151 26 152 27 … … 219 94 }; 220 95 221 222 /**223 * Generic line based text script editor.224 *225 * This is used for editing isolinux configuratin files among other things.226 */227 class GeneralTextScript : public BaseTextScript228 {229 protected:230 RTCList<RTCString> mScriptContentByLines; /**< Content index by line. This contains the edited version. */231 bool mfDataParsed; /**< Indicates whether the script has been parse() yet. */232 233 public:234 GeneralTextScript(VirtualBoxBase *pSetError, const char *pszDefaultTemplateFilename = NULL, const char *pszDefaultFilename = NULL)235 : BaseTextScript(pSetError, pszDefaultTemplateFilename, pszDefaultFilename), mfDataParsed(false)236 {}237 virtual ~GeneralTextScript() {}238 239 HRESULT parse();240 HRESULT saveToString(Utf8Str &rStrDst);241 242 //////////////////New functions//////////////////////////////243 244 bool isDataParsed() const245 {246 return mfDataParsed;247 }248 249 /**250 * Returns the actual size of script in lines251 */252 size_t getLineNumbersOfScript() const253 {254 return mScriptContentByLines.size();255 }256 257 /**258 * Gets a read-only reference to the given line, returning Utf8Str::Empty if259 * idxLine is out of range.260 *261 * @returns Line string reference or Utf8Str::Empty.262 * @param idxLine The line number.263 *264 * @todo RTCList doesn't allow this method to be const.265 */266 RTCString const &getContentOfLine(size_t idxLine);267 268 /**269 * Set new content of line270 */271 HRESULT setContentOfLine(size_t idxLine, const Utf8Str &newContent);272 273 /**274 * Find a substring in the script275 * Returns a list with the found lines276 * @throws std::bad_alloc277 */278 std::vector<size_t> findTemplate(const Utf8Str &rStrNeedle, RTCString::CaseSensitivity enmCase = RTCString::CaseSensitive);279 280 /**281 * In line @a idxLine replace the first occurence of @a rStrNeedle with282 * @a rStrRelacement.283 */284 HRESULT findAndReplace(size_t idxLine, const Utf8Str &rStrNeedle, const Utf8Str &rStrReplacement);285 286 /**287 * Append a string into the end of the given line.288 */289 HRESULT appendToLine(size_t idxLine, const Utf8Str &rStrToAppend);290 291 /**292 * Prepend a string in the beginning of the given line.293 */294 HRESULT prependToLine(size_t idxLine, const Utf8Str &rStrToPrepend);295 296 //////////////////New functions//////////////////////////////297 };298 299 300 96 #if 0 /* convert when we fix SUSE */ 301 97 /**
Note:
See TracChangeset
for help on using the changeset viewer.