Skip to content

Commit

Permalink
Updated ModSaber updater to reflect new format
Browse files Browse the repository at this point in the history
  • Loading branch information
nike4613 committed Dec 4, 2018
1 parent 9ae2c62 commit 8e8c652
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 26 deletions.
88 changes: 67 additions & 21 deletions IPA.Loader/Updating/ModSaber/ApiEndpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class ApiEndpoint
{
public const string ApiBase = "https://www.modsaber.org/";
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
{
Expand All @@ -36,10 +36,11 @@ public override object ReadJson(JsonReader reader, Type objectType, object exist
}
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)
Expand All @@ -54,7 +55,7 @@ public override void WriteJson(JsonWriter writer, object value, JsonSerializer s
{
throw new JsonSerializationException("Expected byte[] object value");
}
writer.WriteValue(LoneFunctions.ByteArrayToString(value as byte[]));
writer.WriteValue(LoneFunctions.ByteArrayToString((byte[]) value));
}
}
}
Expand All @@ -70,18 +71,58 @@ public class Mod
JsonConverter(typeof(SemverVersionConverter))]
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"),
JsonConverter(typeof(SemverVersionConverter))]
public Version GameVersion;

[JsonProperty("author")]
public string Author;
public GameVersionType GameVersion;

#pragma warning restore CS0649
[Serializable]
Expand All @@ -97,10 +138,8 @@ public class PlatformFile
[JsonProperty("url")]
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]
Expand All @@ -122,18 +161,25 @@ public class Dependency
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))]
public Version[] OldVersions = new Version[0];

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}\"}}";
}
}

Expand Down
6 changes: 3 additions & 3 deletions IPA.Loader/Updating/ModSaber/Updater.cs
Original file line number Diff line number Diff line change
Expand Up @@ -218,8 +218,8 @@ private IEnumerator DependencyResolveFirstPass(Ref<List<DependencyObject>> list)
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>();
Expand Down Expand Up @@ -278,7 +278,7 @@ private IEnumerator DependencyResolveSecondPass(Ref<List<DependencyObject>> list
}

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))
.Select(mod => mod.Version).Max(); // (2.1)
// ReSharper disable once AssignmentInConditionalExpression
Expand Down
2 changes: 1 addition & 1 deletion IPA.Loader/Updating/SelfPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ namespace IPA.Updating
internal class SelfPlugin : IBeatSaberPlugin
{
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();

Expand Down
2 changes: 1 addition & 1 deletion appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
version: 'BSIPA-{branch}-{build}'
environment:
bsipa_version: '3.11.5-b2'
bsipa_version: '3.11.5'
pull_requests:
do_not_increment_build_number: true
install:
Expand Down

0 comments on commit 8e8c652

Please sign in to comment.