cmake/Source/CPack/WiX/cmWIXShortcut.cxx

104 lines
3.0 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. */
2015-08-17 11:37:30 +02:00
#include "cmWIXShortcut.h"
#include "cmWIXFilesSourceWriter.h"
2016-07-09 11:21:54 +02:00
void cmWIXShortcuts::insert(Type type, std::string const& id,
cmWIXShortcut const& shortcut)
2015-08-17 11:37:30 +02:00
{
this->Shortcuts[type][id].push_back(shortcut);
}
bool cmWIXShortcuts::empty(Type type) const
{
return this->Shortcuts.find(type) == this->Shortcuts.end();
}
bool cmWIXShortcuts::EmitShortcuts(
2016-07-09 11:21:54 +02:00
Type type, std::string const& registryKey,
2015-08-17 11:37:30 +02:00
std::string const& cpackComponentName,
cmWIXFilesSourceWriter& fileDefinitions) const
{
shortcut_type_map_t::const_iterator i = this->Shortcuts.find(type);
2016-07-09 11:21:54 +02:00
if (i == this->Shortcuts.end()) {
2015-08-17 11:37:30 +02:00
return false;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
shortcut_id_map_t const& id_map = i->second;
std::string shortcutPrefix;
std::string registrySuffix;
2016-07-09 11:21:54 +02:00
switch (type) {
2015-08-17 11:37:30 +02:00
case START_MENU:
shortcutPrefix = "CM_S";
break;
case DESKTOP:
shortcutPrefix = "CM_DS";
registrySuffix = "_desktop";
break;
case STARTUP:
shortcutPrefix = "CM_SS";
registrySuffix = "_startup";
break;
default:
return false;
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
2018-01-26 17:06:56 +01:00
for (auto const& j : id_map) {
std::string const& id = j.first;
shortcut_list_t const& shortcutList = j.second;
2015-08-17 11:37:30 +02:00
2016-07-09 11:21:54 +02:00
for (size_t shortcutListIndex = 0; shortcutListIndex < shortcutList.size();
++shortcutListIndex) {
2015-08-17 11:37:30 +02:00
cmWIXShortcut const& shortcut = shortcutList[shortcutListIndex];
2016-07-09 11:21:54 +02:00
fileDefinitions.EmitShortcut(id, shortcut, shortcutPrefix,
shortcutListIndex);
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
2016-07-09 11:21:54 +02:00
fileDefinitions.EmitInstallRegistryValue(registryKey, cpackComponentName,
registrySuffix);
2015-08-17 11:37:30 +02:00
return true;
}
void cmWIXShortcuts::AddShortcutTypes(std::set<Type>& types)
{
2018-01-26 17:06:56 +01:00
for (auto const& shortcut : this->Shortcuts) {
types.insert(shortcut.first);
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
void cmWIXShortcuts::CreateFromProperties(std::string const& id,
std::string const& directoryId,
cmInstalledFile const& installedFile)
2015-08-17 11:37:30 +02:00
{
2016-07-09 11:21:54 +02:00
CreateFromProperty("CPACK_START_MENU_SHORTCUTS", START_MENU, id, directoryId,
installedFile);
2015-08-17 11:37:30 +02:00
2016-07-09 11:21:54 +02:00
CreateFromProperty("CPACK_DESKTOP_SHORTCUTS", DESKTOP, id, directoryId,
installedFile);
2015-08-17 11:37:30 +02:00
2016-07-09 11:21:54 +02:00
CreateFromProperty("CPACK_STARTUP_SHORTCUTS", STARTUP, id, directoryId,
installedFile);
2015-08-17 11:37:30 +02:00
}
2016-07-09 11:21:54 +02:00
void cmWIXShortcuts::CreateFromProperty(std::string const& propertyName,
Type type, std::string const& id,
std::string const& directoryId,
cmInstalledFile const& installedFile)
2015-08-17 11:37:30 +02:00
{
std::vector<std::string> list;
installedFile.GetPropertyAsList(propertyName, list);
2018-01-26 17:06:56 +01:00
for (std::string const& label : list) {
2015-08-17 11:37:30 +02:00
cmWIXShortcut shortcut;
2018-01-26 17:06:56 +01:00
shortcut.label = label;
2015-08-17 11:37:30 +02:00
shortcut.workingDirectoryId = directoryId;
insert(type, id, shortcut);
2016-07-09 11:21:54 +02:00
}
2015-08-17 11:37:30 +02:00
}