cmWIXShortcut.cxx 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #include "cmWIXShortcut.h"
  4. #include "cmWIXFilesSourceWriter.h"
  5. void cmWIXShortcuts::insert(Type type, std::string const& id,
  6. cmWIXShortcut const& shortcut)
  7. {
  8. this->Shortcuts[type][id].push_back(shortcut);
  9. }
  10. bool cmWIXShortcuts::empty(Type type) const
  11. {
  12. return this->Shortcuts.find(type) == this->Shortcuts.end();
  13. }
  14. bool cmWIXShortcuts::EmitShortcuts(
  15. Type type, std::string const& registryKey,
  16. std::string const& cpackComponentName,
  17. cmWIXFilesSourceWriter& fileDefinitions) const
  18. {
  19. shortcut_type_map_t::const_iterator i = this->Shortcuts.find(type);
  20. if (i == this->Shortcuts.end()) {
  21. return false;
  22. }
  23. shortcut_id_map_t const& id_map = i->second;
  24. std::string shortcutPrefix;
  25. std::string registrySuffix;
  26. switch (type) {
  27. case START_MENU:
  28. shortcutPrefix = "CM_S";
  29. break;
  30. case DESKTOP:
  31. shortcutPrefix = "CM_DS";
  32. registrySuffix = "_desktop";
  33. break;
  34. case STARTUP:
  35. shortcutPrefix = "CM_SS";
  36. registrySuffix = "_startup";
  37. break;
  38. default:
  39. return false;
  40. }
  41. for (auto const& j : id_map) {
  42. std::string const& id = j.first;
  43. shortcut_list_t const& shortcutList = j.second;
  44. for (size_t shortcutListIndex = 0; shortcutListIndex < shortcutList.size();
  45. ++shortcutListIndex) {
  46. cmWIXShortcut const& shortcut = shortcutList[shortcutListIndex];
  47. fileDefinitions.EmitShortcut(id, shortcut, shortcutPrefix,
  48. shortcutListIndex);
  49. }
  50. }
  51. fileDefinitions.EmitInstallRegistryValue(registryKey, cpackComponentName,
  52. registrySuffix);
  53. return true;
  54. }
  55. void cmWIXShortcuts::AddShortcutTypes(std::set<Type>& types)
  56. {
  57. for (auto const& shortcut : this->Shortcuts) {
  58. types.insert(shortcut.first);
  59. }
  60. }
  61. void cmWIXShortcuts::CreateFromProperties(std::string const& id,
  62. std::string const& directoryId,
  63. cmInstalledFile const& installedFile)
  64. {
  65. CreateFromProperty("CPACK_START_MENU_SHORTCUTS", START_MENU, id, directoryId,
  66. installedFile);
  67. CreateFromProperty("CPACK_DESKTOP_SHORTCUTS", DESKTOP, id, directoryId,
  68. installedFile);
  69. CreateFromProperty("CPACK_STARTUP_SHORTCUTS", STARTUP, id, directoryId,
  70. installedFile);
  71. }
  72. void cmWIXShortcuts::CreateFromProperty(std::string const& propertyName,
  73. Type type, std::string const& id,
  74. std::string const& directoryId,
  75. cmInstalledFile const& installedFile)
  76. {
  77. std::vector<std::string> list;
  78. installedFile.GetPropertyAsList(propertyName, list);
  79. for (std::string const& label : list) {
  80. cmWIXShortcut shortcut;
  81. shortcut.label = label;
  82. shortcut.workingDirectoryId = directoryId;
  83. insert(type, id, shortcut);
  84. }
  85. }