cmWIXFilesSourceWriter.cxx 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2014-2015 Kitware, Inc.
  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 "cmWIXFilesSourceWriter.h"
  11. #include "cmWIXAccessControlList.h"
  12. #include <cmInstalledFile.h>
  13. #include <sys/types.h>
  14. // include sys/stat.h after sys/types.h
  15. #include <sys/stat.h>
  16. cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger,
  17. std::string const& filename)
  18. : cmWIXSourceWriter(logger, filename)
  19. {
  20. }
  21. void cmWIXFilesSourceWriter::EmitShortcut(std::string const& id,
  22. cmWIXShortcut const& shortcut,
  23. std::string const& shortcutPrefix,
  24. size_t shortcutIndex)
  25. {
  26. std::stringstream shortcutId;
  27. shortcutId << shortcutPrefix << id;
  28. if (shortcutIndex > 0) {
  29. shortcutId << "_" << shortcutIndex;
  30. }
  31. std::string fileId = std::string("CM_F") + id;
  32. BeginElement("Shortcut");
  33. AddAttribute("Id", shortcutId.str());
  34. AddAttribute("Name", shortcut.label);
  35. std::string target = "[#" + fileId + "]";
  36. AddAttribute("Target", target);
  37. AddAttribute("WorkingDirectory", shortcut.workingDirectoryId);
  38. EndElement("Shortcut");
  39. }
  40. void cmWIXFilesSourceWriter::EmitRemoveFolder(std::string const& id)
  41. {
  42. BeginElement("RemoveFolder");
  43. AddAttribute("Id", id);
  44. AddAttribute("On", "uninstall");
  45. EndElement("RemoveFolder");
  46. }
  47. void cmWIXFilesSourceWriter::EmitInstallRegistryValue(
  48. std::string const& registryKey, std::string const& cpackComponentName,
  49. std::string const& suffix)
  50. {
  51. std::string valueName;
  52. if (!cpackComponentName.empty()) {
  53. valueName = cpackComponentName + "_";
  54. }
  55. valueName += "installed";
  56. valueName += suffix;
  57. BeginElement("RegistryValue");
  58. AddAttribute("Root", "HKCU");
  59. AddAttribute("Key", registryKey);
  60. AddAttribute("Name", valueName);
  61. AddAttribute("Type", "integer");
  62. AddAttribute("Value", "1");
  63. AddAttribute("KeyPath", "yes");
  64. EndElement("RegistryValue");
  65. }
  66. void cmWIXFilesSourceWriter::EmitUninstallShortcut(
  67. std::string const& packageName)
  68. {
  69. BeginElement("Shortcut");
  70. AddAttribute("Id", "UNINSTALL");
  71. AddAttribute("Name", "Uninstall " + packageName);
  72. AddAttribute("Description", "Uninstalls " + packageName);
  73. AddAttribute("Target", "[SystemFolder]msiexec.exe");
  74. AddAttribute("Arguments", "/x [ProductCode]");
  75. EndElement("Shortcut");
  76. }
  77. std::string cmWIXFilesSourceWriter::EmitComponentCreateFolder(
  78. std::string const& directoryId, std::string const& guid,
  79. cmInstalledFile const* installedFile)
  80. {
  81. std::string componentId = std::string("CM_C_EMPTY_") + directoryId;
  82. BeginElement("DirectoryRef");
  83. AddAttribute("Id", directoryId);
  84. BeginElement("Component");
  85. AddAttribute("Id", componentId);
  86. AddAttribute("Guid", guid);
  87. BeginElement("CreateFolder");
  88. if (installedFile) {
  89. cmWIXAccessControlList acl(Logger, *installedFile, *this);
  90. acl.Apply();
  91. }
  92. EndElement("CreateFolder");
  93. EndElement("Component");
  94. EndElement("DirectoryRef");
  95. return componentId;
  96. }
  97. std::string cmWIXFilesSourceWriter::EmitComponentFile(
  98. std::string const& directoryId, std::string const& id,
  99. std::string const& filePath, cmWIXPatch& patch,
  100. cmInstalledFile const* installedFile)
  101. {
  102. std::string componentId = std::string("CM_C") + id;
  103. std::string fileId = std::string("CM_F") + id;
  104. BeginElement("DirectoryRef");
  105. AddAttribute("Id", directoryId);
  106. BeginElement("Component");
  107. AddAttribute("Id", componentId);
  108. AddAttribute("Guid", "*");
  109. if (installedFile) {
  110. if (installedFile->GetPropertyAsBool("CPACK_NEVER_OVERWRITE")) {
  111. AddAttribute("NeverOverwrite", "yes");
  112. }
  113. if (installedFile->GetPropertyAsBool("CPACK_PERMANENT")) {
  114. AddAttribute("Permanent", "yes");
  115. }
  116. }
  117. BeginElement("File");
  118. AddAttribute("Id", fileId);
  119. AddAttribute("Source", filePath);
  120. AddAttribute("KeyPath", "yes");
  121. mode_t fileMode = 0;
  122. cmSystemTools::GetPermissions(filePath.c_str(), fileMode);
  123. if (!(fileMode & S_IWRITE)) {
  124. AddAttribute("ReadOnly", "yes");
  125. }
  126. if (installedFile) {
  127. cmWIXAccessControlList acl(Logger, *installedFile, *this);
  128. acl.Apply();
  129. }
  130. patch.ApplyFragment(fileId, *this);
  131. EndElement("File");
  132. patch.ApplyFragment(componentId, *this);
  133. EndElement("Component");
  134. EndElement("DirectoryRef");
  135. return componentId;
  136. }