You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

62 lines
1.9 KiB

  1. using SimpleJSON;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Threading.Tasks;
  7. namespace IllusionInjector.Updating.ModsaberML
  8. {
  9. class ApiEndpoint
  10. {
  11. #if DEBUG
  12. public const string ApiBase = "file://Z:/Users/aaron/Source/Repos/IPA-Reloaded-BeatSaber/IPA.Tests/";
  13. public const string GetApprovedEndpoint = "updater_test.json";
  14. #else
  15. public const string ApiBase = "https://www.modsaber.ml/api/";
  16. public const string GetApprovedEndpoint = "public/temp/approved";
  17. #endif
  18. public class Mod
  19. {
  20. public string Name;
  21. public Version Version;
  22. public bool Approved;
  23. public string Title;
  24. public Version GameVersion;
  25. public string Author;
  26. public string SteamFile;
  27. public string OculusFile;
  28. public static Mod DecodeJSON(JSONObject obj)
  29. {
  30. var outp = new Mod
  31. {
  32. Name = obj["name"],
  33. Version = new Version(obj["version"]),
  34. Approved = obj["approved"].AsBool,
  35. Title = obj["title"],
  36. GameVersion = new Version(obj["gameVersion"]),
  37. Author = obj["author"]
  38. };
  39. foreach (var item in obj["files"])
  40. {
  41. var key = item.Key;
  42. if (key == "steam")
  43. outp.SteamFile = item.Value["url"];
  44. if (key == "oculus")
  45. outp.OculusFile = item.Value["url"];
  46. }
  47. return outp;
  48. }
  49. public override string ToString()
  50. {
  51. return $"{{\"{Title} ({Name})\"v{Version} for {GameVersion} by {Author} with \"{SteamFile}\" and \"{OculusFile}\"}}";
  52. }
  53. }
  54. }
  55. }