cmWIXShortcut.cxx 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. /*============================================================================
  2. CMake - Cross Platform Makefile Generator
  3. Copyright 2015 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 "cmWIXShortcut.h"
  11. #include "cmWIXFilesSourceWriter.h"
  12. void cmWIXShortcuts::insert(Type type, std::string const& id,
  13. cmWIXShortcut const& shortcut)
  14. {
  15. this->Shortcuts[type][id].push_back(shortcut);
  16. }
  17. bool cmWIXShortcuts::empty(Type type) const
  18. {
  19. return this->Shortcuts.find(type) == this->Shortcuts.end();
  20. }
  21. bool cmWIXShortcuts::EmitShortcuts(
  22. Type type, std::string const& registryKey,
  23. std::string const& cpackComponentName,
  24. cmWIXFilesSourceWriter& fileDefinitions) const
  25. {
  26. shortcut_type_map_t::const_iterator i = this->Shortcuts.find(type);
  27. if (i == this->Shortcuts.end()) {
  28. return false;
  29. }
  30. shortcut_id_map_t const& id_map = i->second;
  31. std::string shortcutPrefix;
  32. std::string registrySuffix;
  33. switch (type) {
  34. case START_MENU:
  35. shortcutPrefix = "CM_S";
  36. break;
  37. case DESKTOP:
  38. shortcutPrefix = "CM_DS";
  39. registrySuffix = "_desktop";
  40. break;
  41. case STARTUP:
  42. shortcutPrefix = "CM_SS";
  43. registrySuffix = "_startup";
  44. break;
  45. default:
  46. return false;
  47. }
  48. for (shortcut_id_map_t::const_iterator j = id_map.begin(); j != id_map.end();
  49. ++j) {
  50. std::string const& id = j->first;
  51. shortcut_list_t const& shortcutList = j->second;
  52. for (size_t shortcutListIndex = 0; shortcutListIndex < shortcutList.size();
  53. ++shortcutListIndex) {
  54. cmWIXShortcut const& shortcut = shortcutList[shortcutListIndex];
  55. fileDefinitions.EmitShortcut(id, shortcut, shortcutPrefix,
  56. shortcutListIndex);
  57. }
  58. }
  59. fileDefinitions.EmitInstallRegistryValue(registryKey, cpackComponentName,
  60. registrySuffix);
  61. return true;
  62. }
  63. void cmWIXShortcuts::AddShortcutTypes(std::set<Type>& types)
  64. {
  65. for (shortcut_type_map_t::const_iterator i = this->Shortcuts.begin();
  66. i != this->Shortcuts.end(); ++i) {
  67. types.insert(i->first);
  68. }
  69. }
  70. void cmWIXShortcuts::CreateFromProperties(std::string const& id,
  71. std::string const& directoryId,
  72. cmInstalledFile const& installedFile)
  73. {
  74. CreateFromProperty("CPACK_START_MENU_SHORTCUTS", START_MENU, id, directoryId,
  75. installedFile);
  76. CreateFromProperty("CPACK_DESKTOP_SHORTCUTS", DESKTOP, id, directoryId,
  77. installedFile);
  78. CreateFromProperty("CPACK_STARTUP_SHORTCUTS", STARTUP, id, directoryId,
  79. installedFile);
  80. }
  81. void cmWIXShortcuts::CreateFromProperty(std::string const& propertyName,
  82. Type type, std::string const& id,
  83. std::string const& directoryId,
  84. cmInstalledFile const& installedFile)
  85. {
  86. std::vector<std::string> list;
  87. installedFile.GetPropertyAsList(propertyName, list);
  88. for (size_t i = 0; i < list.size(); ++i) {
  89. cmWIXShortcut shortcut;
  90. shortcut.label = list[i];
  91. shortcut.workingDirectoryId = directoryId;
  92. insert(type, id, shortcut);
  93. }
  94. }