1
0

cmWIXFilesSourceWriter.cxx 4.9 KB

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