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.

80 lines
2.6 KiB

  1. using IllusionInjector.Utilities;
  2. using SimpleJSON;
  3. using System;
  4. using System.Collections.Generic;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. namespace IllusionInjector.Updating.ModsaberML
  9. {
  10. class ApiEndpoint
  11. {
  12. #if DEBUG && UPDATETEST
  13. public const string ApiBase = "file://Z:/Users/aaron/Source/Repos/IPA-Reloaded-BeatSaber/IPA.Tests/";
  14. public const string GetApprovedEndpoint = "updater_test.json";
  15. #else
  16. public const string ApiBase = "https://www.modsaber.ml/";
  17. public const string GetApprovedEndpoint = "registry/{0}";
  18. #endif
  19. public class Mod
  20. {
  21. public string Name;
  22. public Version Version;
  23. public bool Approved;
  24. public string Title;
  25. public Version GameVersion;
  26. public string Author;
  27. public class PlatformFile
  28. {
  29. public byte[] Hash = new byte[20]; // 20 byte because sha1 is fucky
  30. public Dictionary<string, byte[]> FileHashes = new Dictionary<string, byte[]>();
  31. public string DownloadPath = null;
  32. }
  33. public PlatformFile SteamFile = null;
  34. public PlatformFile OculusFile = null;
  35. public static Mod DecodeJSON(JSONObject obj)
  36. {
  37. var outp = new Mod
  38. {
  39. Name = obj["name"],
  40. Version = new Version(obj["version"]),
  41. Approved = obj["approved"].AsBool,
  42. Title = obj["title"],
  43. GameVersion = new Version(obj["gameVersion"]),
  44. Author = obj["author"]
  45. };
  46. foreach (var item in obj["files"])
  47. {
  48. var key = item.Key;
  49. var pfile = new PlatformFile()
  50. {
  51. DownloadPath = item.Value["url"],
  52. Hash = LoneFunctions.StringToByteArray(item.Value["hash"])
  53. };
  54. foreach (var file in item.Value["files"])
  55. pfile.FileHashes.Add(file.Key, LoneFunctions.StringToByteArray(file.Value));
  56. if (key == "steam")
  57. outp.SteamFile = pfile;
  58. if (key == "oculus")
  59. outp.OculusFile = pfile;
  60. }
  61. return outp;
  62. }
  63. public override string ToString()
  64. {
  65. return $"{{\"{Title} ({Name})\"v{Version} for {GameVersion} by {Author} with \"{SteamFile}\" and \"{OculusFile}\"}}";
  66. }
  67. }
  68. }
  69. }