2016-09-27 22:01:08 +03:00
|
|
|
/* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
|
|
|
file Copyright.txt or https://cmake.org/licensing for details. */
|
2014-02-25 02:21:12 +04:00
|
|
|
#include "cmWIXFilesSourceWriter.h"
|
2016-04-29 16:40:20 +03:00
|
|
|
|
2014-08-09 16:50:49 +04:00
|
|
|
#include "cmWIXAccessControlList.h"
|
2014-02-25 02:21:12 +04:00
|
|
|
|
2014-05-17 00:43:56 +04:00
|
|
|
#include <cmInstalledFile.h>
|
|
|
|
|
2016-07-20 16:32:38 +03:00
|
|
|
#include <cmSystemTools.h>
|
|
|
|
#include <cmUuid.h>
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
#include <sys/types.h>
|
2016-05-02 22:03:45 +03:00
|
|
|
// include sys/stat.h after sys/types.h
|
2014-02-25 02:21:12 +04:00
|
|
|
#include <sys/stat.h>
|
|
|
|
|
|
|
|
cmWIXFilesSourceWriter::cmWIXFilesSourceWriter(cmCPackLog* logger,
|
2016-09-06 13:11:00 +03:00
|
|
|
std::string const& filename,
|
|
|
|
GuidType componentGuidType)
|
|
|
|
: cmWIXSourceWriter(logger, filename, componentGuidType)
|
2014-02-25 02:21:12 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
void cmWIXFilesSourceWriter::EmitShortcut(std::string const& id,
|
|
|
|
cmWIXShortcut const& shortcut,
|
|
|
|
std::string const& shortcutPrefix,
|
|
|
|
size_t shortcutIndex)
|
2014-02-25 02:21:12 +04:00
|
|
|
{
|
2016-06-14 23:37:36 +03:00
|
|
|
std::ostringstream shortcutId;
|
2015-02-21 19:30:31 +03:00
|
|
|
shortcutId << shortcutPrefix << id;
|
2014-02-25 02:21:12 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (shortcutIndex > 0) {
|
|
|
|
shortcutId << "_" << shortcutIndex;
|
|
|
|
}
|
2014-02-25 02:21:12 +04:00
|
|
|
|
|
|
|
std::string fileId = std::string("CM_F") + id;
|
|
|
|
|
|
|
|
BeginElement("Shortcut");
|
2015-02-21 19:30:31 +03:00
|
|
|
AddAttribute("Id", shortcutId.str());
|
2015-02-21 14:38:14 +03:00
|
|
|
AddAttribute("Name", shortcut.label);
|
2014-02-25 02:21:12 +04: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-05-16 17:34:04 +03:00
|
|
|
std::string const& registryKey, std::string const& cpackComponentName,
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string const& suffix)
|
|
|
|
{
|
|
|
|
std::string valueName;
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!cpackComponentName.empty()) {
|
|
|
|
valueName = cpackComponentName + "_";
|
|
|
|
}
|
2014-02-25 02:21:12 +04: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");
|
|
|
|
}
|
|
|
|
|
2014-03-02 03:51:42 +04:00
|
|
|
std::string cmWIXFilesSourceWriter::EmitComponentCreateFolder(
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string const& directoryId, std::string const& guid,
|
2014-09-27 19:34:39 +04:00
|
|
|
cmInstalledFile const* installedFile)
|
2014-03-02 03:51:42 +04:00
|
|
|
{
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string componentId = std::string("CM_C_EMPTY_") + directoryId;
|
2014-03-02 03:51:42 +04:00
|
|
|
|
|
|
|
BeginElement("DirectoryRef");
|
|
|
|
AddAttribute("Id", directoryId);
|
|
|
|
|
|
|
|
BeginElement("Component");
|
|
|
|
AddAttribute("Id", componentId);
|
|
|
|
AddAttribute("Guid", guid);
|
|
|
|
|
|
|
|
BeginElement("CreateFolder");
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (installedFile) {
|
2014-09-27 19:34:39 +04:00
|
|
|
cmWIXAccessControlList acl(Logger, *installedFile, *this);
|
|
|
|
acl.Apply();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-09-27 19:34:39 +04:00
|
|
|
|
2014-03-02 03:51:42 +04:00
|
|
|
EndElement("CreateFolder");
|
|
|
|
EndElement("Component");
|
|
|
|
EndElement("DirectoryRef");
|
|
|
|
|
|
|
|
return componentId;
|
|
|
|
}
|
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
std::string cmWIXFilesSourceWriter::EmitComponentFile(
|
2016-05-16 17:34:04 +03:00
|
|
|
std::string const& directoryId, std::string const& id,
|
|
|
|
std::string const& filePath, cmWIXPatch& patch,
|
2014-05-17 00:43:56 +04:00
|
|
|
cmInstalledFile const* installedFile)
|
2014-02-25 02:21:12 +04:00
|
|
|
{
|
|
|
|
std::string componentId = std::string("CM_C") + id;
|
|
|
|
std::string fileId = std::string("CM_F") + id;
|
|
|
|
|
2016-09-06 13:11:00 +03:00
|
|
|
std::string guid = CreateGuidFromComponentId(componentId);
|
2016-07-20 16:32:38 +03:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
BeginElement("DirectoryRef");
|
|
|
|
AddAttribute("Id", directoryId);
|
|
|
|
|
|
|
|
BeginElement("Component");
|
|
|
|
AddAttribute("Id", componentId);
|
2016-07-20 16:32:38 +03:00
|
|
|
AddAttribute("Guid", guid);
|
2014-02-25 02:21:12 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (installedFile) {
|
|
|
|
if (installedFile->GetPropertyAsBool("CPACK_NEVER_OVERWRITE")) {
|
2014-05-17 00:43:56 +04:00
|
|
|
AddAttribute("NeverOverwrite", "yes");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
|
|
|
if (installedFile->GetPropertyAsBool("CPACK_PERMANENT")) {
|
2014-05-17 00:43:56 +04:00
|
|
|
AddAttribute("Permanent", "yes");
|
|
|
|
}
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-05-17 00:43:56 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
BeginElement("File");
|
|
|
|
AddAttribute("Id", fileId);
|
|
|
|
AddAttribute("Source", filePath);
|
|
|
|
AddAttribute("KeyPath", "yes");
|
|
|
|
|
|
|
|
mode_t fileMode = 0;
|
|
|
|
cmSystemTools::GetPermissions(filePath.c_str(), fileMode);
|
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (!(fileMode & S_IWRITE)) {
|
2014-02-25 02:21:12 +04:00
|
|
|
AddAttribute("ReadOnly", "yes");
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-02-25 02:21:12 +04:00
|
|
|
|
2016-05-16 17:34:04 +03:00
|
|
|
if (installedFile) {
|
2014-08-09 16:50:49 +04:00
|
|
|
cmWIXAccessControlList acl(Logger, *installedFile, *this);
|
|
|
|
acl.Apply();
|
2016-05-16 17:34:04 +03:00
|
|
|
}
|
2014-08-09 16:50:49 +04:00
|
|
|
|
2014-02-25 02:21:12 +04:00
|
|
|
patch.ApplyFragment(fileId, *this);
|
|
|
|
EndElement("File");
|
|
|
|
|
|
|
|
patch.ApplyFragment(componentId, *this);
|
|
|
|
EndElement("Component");
|
|
|
|
EndElement("DirectoryRef");
|
|
|
|
|
|
|
|
return componentId;
|
|
|
|
}
|