cmWIXSourceWriter.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include <string>
  5. #include <vector>
  6. #include "cmsys/FStream.hxx"
  7. #include "cmCPackLog.h"
  8. /** \class cmWIXSourceWriter
  9. * \brief Helper class to generate XML WiX source files
  10. */
  11. class cmWIXSourceWriter
  12. {
  13. public:
  14. enum GuidType
  15. {
  16. WIX_GENERATED_GUID,
  17. CMAKE_GENERATED_GUID
  18. };
  19. enum RootElementType
  20. {
  21. WIX_ELEMENT_ROOT,
  22. INCLUDE_ELEMENT_ROOT
  23. };
  24. cmWIXSourceWriter(cmCPackLog* logger, std::string const& filename,
  25. GuidType componentGuidType,
  26. RootElementType rootElementType = WIX_ELEMENT_ROOT);
  27. ~cmWIXSourceWriter();
  28. void BeginElement(std::string const& name);
  29. void EndElement(std::string const& name);
  30. void AddTextNode(std::string const& text);
  31. void AddProcessingInstruction(std::string const& target,
  32. std::string const& content);
  33. void AddAttribute(std::string const& key, std::string const& value);
  34. void AddAttributeUnlessEmpty(std::string const& key,
  35. std::string const& value);
  36. std::string CreateGuidFromComponentId(std::string const& componentId);
  37. static std::string EscapeAttributeValue(std::string const& value);
  38. protected:
  39. cmCPackLog* Logger;
  40. private:
  41. enum State
  42. {
  43. DEFAULT,
  44. BEGIN
  45. };
  46. void WriteXMLDeclaration();
  47. void Indent(size_t count);
  48. cmsys::ofstream File;
  49. State State;
  50. std::vector<std::string> Elements;
  51. std::string SourceFilename;
  52. GuidType ComponentGuidType;
  53. };