cmWIXFilesSourceWriter.cxx 4.6 KB

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