cmake/Source/CPack/WiX/cmWIXFilesSourceWriter.cxx

170 lines
4.7 KiB
C++
Raw Normal View History

2016-10-30 18:24:19 +01:00
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
file Copyright.txt or https://cmake.org/licensing for details. */
2020-08-30 11:54:41 +02:00
#if defined(__CYGWIN__)
// For S_IWRITE symbol
# define _DEFAULT_SOURCE
#endif
2015-04-27 22:25:09 +02:00
#include "cmWIXFilesSourceWriter.h"
2016-07-09 11:21:54 +02:00
2020-02-01 23:06:01 +01:00
#include "cm_sys_stat.h"
2015-04-27 22:25:09 +02:00
2020-02-01 23:06:01 +01:00
#include "cmCMakeToWixPath.h"
2017-07-20 19:35:53 +02:00
#include "cmInstalledFile.h"
#include "cmSystemTools.h"
#include "cmUuid.h"
2020-02-01 23:06:01 +01:00
#include "cmWIXAccessControlList.h"
2018-04-23 21:13:27 +02:00
2024-07-09 14:46:46 +02:00
cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(unsigned long wixVersion,
cmCPackLog* logger,
2016-10-30 18:24:19 +01:00
std::string const& filename,
GuidType componentGuidType)
2024-07-09 14:46:46 +02:00
: cmWIXSourceWriter(wixVersion, logger, filename, componentGuidType)
2015-04-27 22:25:09 +02:00
{
}
2016-07-09 11:21:54 +02:00
void cmWIXFilesSourceWriter::EmitShortcut(std::string const& id,
cmWIXShortcut const& shortcut,
std::string const& shortcutPrefix,
size_t shortcutIndex)
2015-04-27 22:25:09 +02:00
{
2016-10-30 18:24:19 +01:00
std::ostringstream shortcutId;
2015-08-17 11:37:30 +02:00
shortcutId << shortcutPrefix << id;
2015-04-27 22:25:09 +02:00
2016-07-09 11:21:54 +02:00
if (shortcutIndex > 0) {
shortcutId << "_" << shortcutIndex;
}
2015-04-27 22:25:09 +02:00
std::string fileId = std::string("CM_F") + id;
BeginElement("Shortcut");
2015-08-17 11:37:30 +02:00
AddAttribute("Id", shortcutId.str());
AddAttribute("Name", shortcut.label);
2015-04-27 22:25:09 +02:00
std::string target = "[#" + fileId + "]";
AddAttribute("Target", target);
AddAttribute("WorkingDirectory", shortcut.workingDirectoryId);
EndElement("Shortcut");
}
void cmWIXFilesSourceWriter::EmitRemoveFolder(std::string const& id)
{
BeginElement("RemoveFolder");
AddAttribute("Id", id);
AddAttribute("On", "uninstall");
EndElement("RemoveFolder");
}
void cmWIXFilesSourceWriter::EmitInstallRegistryValue(
2016-07-09 11:21:54 +02:00
std::string const& registryKey, std::string const& cpackComponentName,
2015-04-27 22:25:09 +02:00
std::string const& suffix)
{
std::string valueName;
2016-07-09 11:21:54 +02:00
if (!cpackComponentName.empty()) {
valueName = cpackComponentName + "_";
}
2015-04-27 22:25:09 +02:00
valueName += "installed";
valueName += suffix;
BeginElement("RegistryValue");
AddAttribute("Root", "HKCU");
AddAttribute("Key", registryKey);
AddAttribute("Name", valueName);
AddAttribute("Type", "integer");
AddAttribute("Value", "1");
AddAttribute("KeyPath", "yes");
EndElement("RegistryValue");
}
void cmWIXFilesSourceWriter::EmitUninstallShortcut(
std::string const& packageName)
{
BeginElement("Shortcut");
AddAttribute("Id", "UNINSTALL");
AddAttribute("Name", "Uninstall " + packageName);
AddAttribute("Description", "Uninstalls " + packageName);
AddAttribute("Target", "[SystemFolder]msiexec.exe");
AddAttribute("Arguments", "/x [ProductCode]");
EndElement("Shortcut");
}
std::string cmWIXFilesSourceWriter::EmitComponentCreateFolder(
2016-07-09 11:21:54 +02:00
std::string const& directoryId, std::string const& guid,
2015-04-27 22:25:09 +02:00
cmInstalledFile const* installedFile)
{
2016-07-09 11:21:54 +02:00
std::string componentId = std::string("CM_C_EMPTY_") + directoryId;
2015-04-27 22:25:09 +02:00
BeginElement("DirectoryRef");
AddAttribute("Id", directoryId);
BeginElement("Component");
AddAttribute("Id", componentId);
AddAttribute("Guid", guid);
BeginElement("CreateFolder");
2016-07-09 11:21:54 +02:00
if (installedFile) {
2015-04-27 22:25:09 +02:00
cmWIXAccessControlList acl(Logger, *installedFile, *this);
acl.Apply();
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
EndElement("CreateFolder");
EndElement("Component");
EndElement("DirectoryRef");
return componentId;
}
std::string cmWIXFilesSourceWriter::EmitComponentFile(
2016-07-09 11:21:54 +02:00
std::string const& directoryId, std::string const& id,
std::string const& filePath, cmWIXPatch& patch,
2015-04-27 22:25:09 +02:00
cmInstalledFile const* installedFile)
{
std::string componentId = std::string("CM_C") + id;
std::string fileId = std::string("CM_F") + id;
2016-10-30 18:24:19 +01:00
std::string guid = CreateGuidFromComponentId(componentId);
2015-04-27 22:25:09 +02:00
BeginElement("DirectoryRef");
AddAttribute("Id", directoryId);
BeginElement("Component");
AddAttribute("Id", componentId);
2016-10-30 18:24:19 +01:00
AddAttribute("Guid", guid);
2015-04-27 22:25:09 +02:00
2016-07-09 11:21:54 +02:00
if (installedFile) {
if (installedFile->GetPropertyAsBool("CPACK_NEVER_OVERWRITE")) {
2015-04-27 22:25:09 +02:00
AddAttribute("NeverOverwrite", "yes");
2016-07-09 11:21:54 +02:00
}
if (installedFile->GetPropertyAsBool("CPACK_PERMANENT")) {
2015-04-27 22:25:09 +02:00
AddAttribute("Permanent", "yes");
}
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
2017-07-20 19:35:53 +02:00
patch.ApplyFragment(componentId, *this);
2015-04-27 22:25:09 +02:00
BeginElement("File");
AddAttribute("Id", fileId);
2018-04-23 21:13:27 +02:00
AddAttribute("Source", CMakeToWixPath(filePath));
2015-04-27 22:25:09 +02:00
AddAttribute("KeyPath", "yes");
mode_t fileMode = 0;
cmSystemTools::GetPermissions(filePath.c_str(), fileMode);
2016-07-09 11:21:54 +02:00
if (!(fileMode & S_IWRITE)) {
2015-04-27 22:25:09 +02:00
AddAttribute("ReadOnly", "yes");
2016-07-09 11:21:54 +02:00
}
2017-07-20 19:35:53 +02:00
patch.ApplyFragment(fileId, *this);
2015-04-27 22:25:09 +02:00
2016-07-09 11:21:54 +02:00
if (installedFile) {
2015-04-27 22:25:09 +02:00
cmWIXAccessControlList acl(Logger, *installedFile, *this);
acl.Apply();
2016-07-09 11:21:54 +02:00
}
2015-04-27 22:25:09 +02:00
EndElement("File");
EndElement("Component");
EndElement("DirectoryRef");
return componentId;
}