OgrePlugins.h 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. /*
  2. * Copyright (C) 2022 The V-Gears Team
  3. *
  4. * This file is part of V-Gears
  5. *
  6. * V-Gears is free software: you can redistribute it and/or modify it under
  7. * terms of the GNU General Public License as published by the Free Software
  8. * Foundation, version 3.0 (GPLv3) of the License.
  9. *
  10. * V-Gears is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. */
  15. #pragma once
  16. #include <string>
  17. #include <vector>
  18. #include <boost/filesystem.hpp>
  19. namespace VGears{
  20. /**
  21. * Locates the Ogre plugins listed in plugins.cfg.
  22. *
  23. * Ogre only looks for the plugins in the single PluginFolder of plugins.cfg, so the same file can't work in a
  24. * build tree, an installed package and a portable folder. V-Gears loads the plugins itself instead, looking for
  25. * each one in several directories (see {@see SearchDirectories}).
  26. *
  27. * It doesn't depend on Ogre, so the installer and the tests can use it.
  28. */
  29. namespace OgrePlugins{
  30. /**
  31. * Contents of a plugins.cfg file.
  32. */
  33. struct Config{
  34. /**
  35. * Value of PluginFolder. Empty if it's not set.
  36. */
  37. std::string folder;
  38. /**
  39. * Names of the plugins, in order (the values of the Plugin lines).
  40. */
  41. std::vector<std::string> plugins;
  42. };
  43. /**
  44. * Reads a plugins.cfg file.
  45. *
  46. * @param[in] file Path to the file.
  47. * @param[out] config The contents of the file.
  48. * @return False if the file can't be read.
  49. */
  50. bool ReadConfig(const boost::filesystem::path& file, Config& config);
  51. /**
  52. * Gets the directories where the plugins are looked for, in order of preference.
  53. *
  54. * They are:
  55. * - The PluginFolder of plugins.cfg, if set (relative to the directory of plugins.cfg).
  56. * - The directory of plugins.cfg (the data directory).
  57. * - The directory of the executable, and "../lib/OGRE" and "../lib" from it (bundles and portable folders).
  58. * - The Ogre plugin directory found when V-Gears was built.
  59. * - The usual system directories of the Ogre plugins.
  60. *
  61. * @param[in] config_directory The directory of plugins.cfg.
  62. * @param[in] config_folder The PluginFolder of plugins.cfg. Can be empty.
  63. * @param[in] executable_directory The directory of the executable. Can be empty.
  64. * @param[in] build_directory The Ogre plugin directory found when V-Gears was built. Can be empty.
  65. * @return The directories, without duplicates. They may not exist.
  66. */
  67. std::vector<boost::filesystem::path> SearchDirectories(
  68. const boost::filesystem::path& config_directory, const std::string& config_folder,
  69. const boost::filesystem::path& executable_directory, const std::string& build_directory
  70. );
  71. /**
  72. * Gets the file names a plugin can have in this system.
  73. *
  74. * In Linux, Ogre loads "<name>.so.<version>". In Windows, "<name>.dll". In macOS, "<name>.dylib" or
  75. * "<name>.framework".
  76. *
  77. * @param[in] name Name of the plugin, as in plugins.cfg.
  78. * @param[in] ogre_version The Ogre version, as "major.minor.patch".
  79. * @return The file names, in order of preference.
  80. */
  81. std::vector<std::string> FileNames(const std::string& name, const std::string& ogre_version);
  82. /**
  83. * Finds a plugin.
  84. *
  85. * @param[in] name Name of the plugin, as in plugins.cfg. If it's an absolute path, it's used as is.
  86. * @param[in] directories The directories to look in, in order of preference.
  87. * @param[in] ogre_version The Ogre version, as "major.minor.patch".
  88. * @return The path of the plugin file, or an empty path if it's not found.
  89. */
  90. boost::filesystem::path Find(
  91. const std::string& name, const std::vector<boost::filesystem::path>& directories,
  92. const std::string& ogre_version
  93. );
  94. }
  95. }