whatsnew.hpp 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2023 Dennis Sädtler <[email protected]>
  3. *
  4. * Permission to use, copy, modify, and distribute this software for any
  5. * purpose with or without fee is hereby granted, provided that the above
  6. * copyright notice and this permission notice appear in all copies.
  7. *
  8. * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  9. * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  10. * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  11. * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  12. * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  13. * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  14. * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  15. */
  16. #pragma once
  17. #include <string>
  18. #include <optional>
  19. #include <nlohmann/json.hpp>
  20. /*
  21. * Support for (de-)serialising std::optional
  22. * Adapted from https://github.com/nlohmann/json/issues/1749#issuecomment-1555093802
  23. */
  24. template<typename T> struct nlohmann::adl_serializer<std::optional<T>> {
  25. static std::optional<T> from_json(const json &json)
  26. {
  27. return json.is_null() ? std::nullopt : std::optional{json.get<T>()};
  28. }
  29. static void to_json(json &json, std::optional<T> t)
  30. {
  31. if (t)
  32. json = *t;
  33. else
  34. json = nullptr;
  35. }
  36. };
  37. struct WhatsNewPlatforms {
  38. bool windows = false;
  39. bool macos = false;
  40. bool linux = false;
  41. NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(WhatsNewPlatforms, windows, macos, linux)
  42. };
  43. struct WhatsNewItem {
  44. /* Target OBS version (patch is ignored) */
  45. std::string version;
  46. /* Beta/RC release to target */
  47. int Beta = 0;
  48. int RC = 0;
  49. /* URL of webpage to be displayed */
  50. std::string url;
  51. /* Increment for this version's item */
  52. int increment = 0;
  53. /* Optional OS filter */
  54. std::optional<WhatsNewPlatforms> os = std::nullopt;
  55. NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(WhatsNewItem, version, Beta, RC, url, increment, os)
  56. };
  57. using WhatsNewList = std::vector<WhatsNewItem>;