Browse Source

Updated ModSaber updater to reflect new format

pull/1/head
Anairkoen Schno 6 years ago
parent
commit
8e8c652825
4 changed files with 72 additions and 26 deletions
  1. +67
    -21
      IPA.Loader/Updating/ModSaber/ApiEndpoint.cs
  2. +3
    -3
      IPA.Loader/Updating/ModSaber/Updater.cs
  3. +1
    -1
      IPA.Loader/Updating/SelfPlugin.cs
  4. +1
    -1
      appveyor.yml

+ 67
- 21
IPA.Loader/Updating/ModSaber/ApiEndpoint.cs View File

@ -13,7 +13,7 @@ namespace IPA.Updating.ModSaber
{ {
public const string ApiBase = "https://www.modsaber.org/"; public const string ApiBase = "https://www.modsaber.org/";
public const string GetModInfoEndpoint = "registry/{0}/{1}"; public const string GetModInfoEndpoint = "registry/{0}/{1}";
public const string GetModsWithSemver = "api/v1.0/mods/semver/{0}/{1}";
public const string GetModsWithSemver = "api/v1.1/mods/semver/{0}/{1}";
class HexArrayConverter : JsonConverter class HexArrayConverter : JsonConverter
{ {
@ -36,10 +36,11 @@ namespace IPA.Updating.ModSaber
} }
catch (Exception ex) catch (Exception ex)
{ {
throw new Exception(string.Format("Error parsing version string: {0}", reader.Value), ex);
throw new Exception($"Error parsing version string: {reader.Value}", ex);
} }
} }
throw new Exception(string.Format("Unexpected token or value when parsing hex string. Token: {0}, Value: {1}", reader.TokenType, reader.Value));
throw new Exception(
$"Unexpected token or value when parsing hex string. Token: {reader.TokenType}, Value: {reader.Value}");
} }
public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer) public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
@ -54,7 +55,7 @@ namespace IPA.Updating.ModSaber
{ {
throw new JsonSerializationException("Expected byte[] object value"); throw new JsonSerializationException("Expected byte[] object value");
} }
writer.WriteValue(LoneFunctions.ByteArrayToString(value as byte[]));
writer.WriteValue(LoneFunctions.ByteArrayToString((byte[]) value));
} }
} }
} }
@ -70,18 +71,58 @@ namespace IPA.Updating.ModSaber
JsonConverter(typeof(SemverVersionConverter))] JsonConverter(typeof(SemverVersionConverter))]
public Version Version; public Version Version;
[JsonProperty("approved")]
public bool Approved;
[Serializable]
public class AuthorType
{
[JsonProperty("name")]
public string Name;
[JsonProperty("id")]
public string Id;
public override string ToString() => Name;
}
[Serializable]
public class DetailsData
{
[JsonProperty("author")]
public AuthorType Author;
[JsonProperty("title")]
public string Title;
[JsonProperty("description")]
public string Description;
[JsonProperty("published")]
public string Published;
}
[JsonProperty("details")]
public DetailsData Details;
[Serializable]
public class ApprovalStatus
{
[JsonProperty("status")]
public bool Status;
[JsonProperty("modified")]
public string LastModified;
}
[JsonProperty("title")]
public string Title;
[JsonProperty("approval")]
public ApprovalStatus Approval;
[Serializable]
public class GameVersionType
{
[JsonProperty("value"),
JsonConverter(typeof(SemverVersionConverter))]
public Version Version;
[JsonProperty("manifest")]
public string Manifest;
}
[JsonProperty("gameVersion"), [JsonProperty("gameVersion"),
JsonConverter(typeof(SemverVersionConverter))] JsonConverter(typeof(SemverVersionConverter))]
public Version GameVersion;
[JsonProperty("author")]
public string Author;
public GameVersionType GameVersion;
#pragma warning restore CS0649 #pragma warning restore CS0649
[Serializable] [Serializable]
@ -97,10 +138,8 @@ namespace IPA.Updating.ModSaber
[JsonProperty("url")] [JsonProperty("url")]
public string DownloadPath; public string DownloadPath;
public override string ToString()
{
return $"{LoneFunctions.ByteArrayToString(Hash)}@{DownloadPath}({string.Join(",",FileHashes.Select(o=>$"\"{o.Key}\":\"{LoneFunctions.ByteArrayToString(o.Value)}\""))})";
}
public override string ToString() =>
$"{LoneFunctions.ByteArrayToString(Hash)}@{DownloadPath}({string.Join(",", FileHashes.Select(o => $"\"{o.Key}\":\"{LoneFunctions.ByteArrayToString(o.Value)}\""))})";
} }
[Serializable] [Serializable]
@ -122,18 +161,25 @@ namespace IPA.Updating.ModSaber
public Range VersionRange = null; public Range VersionRange = null;
} }
[JsonProperty("dependsOn", ItemConverterType = typeof(ModSaberDependencyConverter))]
public Dependency[] Dependencies = new Dependency[0];
[Serializable]
public class LinksType
{
[JsonProperty("dependencies", ItemConverterType = typeof(ModSaberDependencyConverter))]
public Dependency[] Dependencies = new Dependency[0];
[JsonProperty("conflicts", ItemConverterType = typeof(ModSaberDependencyConverter))]
public Dependency[] Conflicts = new Dependency[0];
}
[JsonProperty("conflictsWith", ItemConverterType = typeof(ModSaberDependencyConverter))]
public Dependency[] Conflicts = new Dependency[0];
[JsonProperty("links")]
public LinksType Links;
[JsonProperty("oldVersions", ItemConverterType = typeof(SemverVersionConverter))] [JsonProperty("oldVersions", ItemConverterType = typeof(SemverVersionConverter))]
public Version[] OldVersions = new Version[0]; public Version[] OldVersions = new Version[0];
public override string ToString() public override string ToString()
{ {
return $"{{\"{Title} ({Name})\"v{Version} for {GameVersion} by {Author} with \"{Files.Steam}\" and \"{Files.Oculus}\"}}";
return $"{{\"{Details.Title} ({Name})\"v{Version} for {GameVersion.Version} by {Details.Author} with \"{Files.Steam}\" and \"{Files.Oculus}\"}}";
} }
} }


+ 3
- 3
IPA.Loader/Updating/ModSaber/Updater.cs View File

@ -218,8 +218,8 @@ namespace IPA.Updating.ModSaber
continue; continue;
} }
list.Value.AddRange(mod.Value.Dependencies.Select(d => new DependencyObject { Name = d.Name, Requirement = d.VersionRange, Consumers = new HashSet<string> { dep.Name } }));
list.Value.AddRange(mod.Value.Conflicts.Select(d => new DependencyObject { Name = d.Name, Conflicts = d.VersionRange, Consumers = new HashSet<string> { dep.Name } }));
list.Value.AddRange(mod.Value.Links.Dependencies.Select(d => new DependencyObject { Name = d.Name, Requirement = d.VersionRange, Consumers = new HashSet<string> { dep.Name } }));
list.Value.AddRange(mod.Value.Links.Conflicts.Select(d => new DependencyObject { Name = d.Name, Conflicts = d.VersionRange, Consumers = new HashSet<string> { dep.Name } }));
} }
var depNames = new HashSet<string>(); var depNames = new HashSet<string>();
@ -278,7 +278,7 @@ namespace IPA.Updating.ModSaber
} }
var ver = modsMatching.Value.Where(nullCheck => nullCheck != null) var ver = modsMatching.Value.Where(nullCheck => nullCheck != null)
.Where(versionCheck => versionCheck.GameVersion == BeatSaber.GameVersion && versionCheck.Approved)
.Where(versionCheck => versionCheck.GameVersion.Version == BeatSaber.GameVersion && versionCheck.Approval.Status)
.Where(conflictsCheck => dep.Conflicts == null || !dep.Conflicts.IsSatisfied(conflictsCheck.Version)) .Where(conflictsCheck => dep.Conflicts == null || !dep.Conflicts.IsSatisfied(conflictsCheck.Version))
.Select(mod => mod.Version).Max(); // (2.1) .Select(mod => mod.Version).Max(); // (2.1)
// ReSharper disable once AssignmentInConditionalExpression // ReSharper disable once AssignmentInConditionalExpression


+ 1
- 1
IPA.Loader/Updating/SelfPlugin.cs View File

@ -5,7 +5,7 @@ namespace IPA.Updating
internal class SelfPlugin : IBeatSaberPlugin internal class SelfPlugin : IBeatSaberPlugin
{ {
internal const string IPA_Name = "Beat Saber IPA"; internal const string IPA_Name = "Beat Saber IPA";
internal const string IPA_Version = "3.11.5-b2";
internal const string IPA_Version = "3.11.5";
public static SelfPlugin Instance { get; set; } = new SelfPlugin(); public static SelfPlugin Instance { get; set; } = new SelfPlugin();


+ 1
- 1
appveyor.yml View File

@ -1,6 +1,6 @@
version: 'BSIPA-{branch}-{build}' version: 'BSIPA-{branch}-{build}'
environment: environment:
bsipa_version: '3.11.5-b2'
bsipa_version: '3.11.5'
pull_requests: pull_requests:
do_not_increment_build_number: true do_not_increment_build_number: true
install: install:


Loading…
Cancel
Save