cmWIXShortcut.cxx 3.2 KB

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