ModIncompatibility.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. * ModIncompatibility.h, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #pragma once
  11. #include "../lib/texts/CGeneralTextHandler.h"
  12. #include "GameLibrary.h"
  13. VCMI_LIB_NAMESPACE_BEGIN
  14. class DLL_LINKAGE ModIncompatibility: public std::exception
  15. {
  16. public:
  17. using ModList = std::vector<std::string>;
  18. ModIncompatibility(const ModList & _missingMods)
  19. {
  20. std::ostringstream _ss;
  21. for(const auto & m : _missingMods)
  22. _ss << m << std::endl;
  23. messageMissingMods = _ss.str();
  24. }
  25. ModIncompatibility(const ModList & _missingMods, const ModList & _excessiveMods)
  26. : ModIncompatibility(_missingMods)
  27. {
  28. std::ostringstream _ss;
  29. for(const auto & m : _excessiveMods)
  30. _ss << m << std::endl;
  31. messageExcessiveMods = _ss.str();
  32. }
  33. const char * what() const noexcept override
  34. {
  35. static const std::string w("Mod incompatibility exception");
  36. return w.c_str();
  37. }
  38. const std::string & whatMissing() const noexcept
  39. {
  40. return messageMissingMods;
  41. }
  42. const std::string & whatExcessive() const noexcept
  43. {
  44. return messageExcessiveMods;
  45. }
  46. std::string getFullErrorMsg() const noexcept
  47. {
  48. std::string errorMsg;
  49. if(!messageMissingMods.empty())
  50. {
  51. errorMsg += LIBRARY->generaltexth->translate("vcmi.server.errors.modsToEnable") + '\n';
  52. errorMsg += messageMissingMods;
  53. }
  54. if(!messageExcessiveMods.empty())
  55. {
  56. errorMsg += LIBRARY->generaltexth->translate("vcmi.server.errors.modsToDisable") + '\n';
  57. errorMsg += messageExcessiveMods;
  58. }
  59. return errorMsg;
  60. }
  61. private:
  62. std::string messageMissingMods;
  63. std::string messageExcessiveMods;
  64. };
  65. VCMI_LIB_NAMESPACE_END