1
0

cmWIXPatch.cxx 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2014 Kitware, Inc., Insight Software Consortium
  4. Distributed under the OSI-approved BSD License (the "License");
  5. see accompanying file Copyright.txt for details.
  6. This software is distributed WITHOUT ANY WARRANTY; without even the
  7. implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  8. See the License for more information.
  9. ============================================================================*/
  10. #include "cmWIXPatch.h"
  11. #include <CPack/cmCPackGenerator.h>
  12. cmWIXPatch::cmWIXPatch(cmCPackLog* logger):
  13. Logger(logger)
  14. {
  15. }
  16. void cmWIXPatch::LoadFragments(std::string const& patchFilePath)
  17. {
  18. cmWIXPatchParser parser(Fragments, Logger);
  19. parser.ParseFile(patchFilePath.c_str());
  20. }
  21. void cmWIXPatch::ApplyFragment(
  22. std::string const& id, cmWIXSourceWriter& writer)
  23. {
  24. cmWIXPatchParser::fragment_map_t::iterator i = Fragments.find(id);
  25. if(i == Fragments.end()) return;
  26. const cmWIXPatchElement& fragment = i->second;
  27. this->ApplyElementChildren(fragment, writer);
  28. Fragments.erase(i);
  29. }
  30. void cmWIXPatch::ApplyElementChildren(
  31. const cmWIXPatchElement& element, cmWIXSourceWriter& writer)
  32. {
  33. for(cmWIXPatchElement::child_list_t::const_iterator
  34. j = element.children.begin(); j != element.children.end(); ++j)
  35. {
  36. cmWIXPatchNode *node = *j;
  37. switch(node->type())
  38. {
  39. case cmWIXPatchNode::ELEMENT:
  40. ApplyElement(dynamic_cast<const cmWIXPatchElement&>(*node), writer);
  41. break;
  42. case cmWIXPatchNode::TEXT:
  43. writer.AddTextNode(dynamic_cast<const cmWIXPatchText&>(*node).text);
  44. break;
  45. }
  46. }
  47. }
  48. void cmWIXPatch::ApplyElement(
  49. const cmWIXPatchElement& element, cmWIXSourceWriter& writer)
  50. {
  51. writer.BeginElement(element.name);
  52. for(cmWIXPatchElement::attributes_t::const_iterator
  53. i = element.attributes.begin(); i != element.attributes.end(); ++i)
  54. {
  55. writer.AddAttribute(i->first, i->second);
  56. }
  57. this->ApplyElementChildren(element, writer);
  58. writer.EndElement(element.name);
  59. }
  60. bool cmWIXPatch::CheckForUnappliedFragments()
  61. {
  62. std::string fragmentList;
  63. for(cmWIXPatchParser::fragment_map_t::const_iterator
  64. i = Fragments.begin(); i != Fragments.end(); ++i)
  65. {
  66. if(!fragmentList.empty())
  67. {
  68. fragmentList += ", ";
  69. }
  70. fragmentList += "'";
  71. fragmentList += i->first;
  72. fragmentList += "'";
  73. }
  74. if(!fragmentList.empty())
  75. {
  76. cmCPackLogger(cmCPackLog::LOG_ERROR,
  77. "Some XML patch fragments did not have matching IDs: " <<
  78. fragmentList << std::endl);
  79. return false;
  80. }
  81. return true;
  82. }