summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Program.cs6
-rw-r--r--src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/WebApiClient.cs34
2 files changed, 35 insertions, 5 deletions
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index e55a96b2..05a3134e 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -577,7 +577,11 @@ namespace StardewModdingAPI
new Thread(() =>
{
// create client
- WebApiClient client = new WebApiClient(this.Settings.WebApiBaseUrl, Constants.ApiVersionForToolkit);
+ string url = this.Settings.WebApiBaseUrl;
+#if !SMAPI_FOR_WINDOWS
+ url = url.Replace("https://", "http://"); // workaround for OpenSSL issues with the game's bundled Mono on Linux/Mac
+#endif
+ WebApiClient client = new WebApiClient(url, Constants.ApiVersionForToolkit);
this.Monitor.Log("Checking for updates...", LogLevel.Trace);
// check SMAPI version
diff --git a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/WebApiClient.cs b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/WebApiClient.cs
index 277fbeeb..d94b0259 100644
--- a/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/WebApiClient.cs
+++ b/src/StardewModdingAPI.Toolkit/Framework/Clients/WebApi/WebApiClient.cs
@@ -1,12 +1,13 @@
using System;
using System.Collections.Generic;
+using System.Linq;
using System.Net;
using Newtonsoft.Json;
namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi
{
/// <summary>Provides methods for interacting with the SMAPI web API.</summary>
- internal class WebApiClient
+ public class WebApiClient
{
/*********
** Properties
@@ -26,9 +27,6 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi
/// <param name="version">The web API version.</param>
public WebApiClient(string baseUrl, ISemanticVersion version)
{
-#if !SMAPI_FOR_WINDOWS
- baseUrl = baseUrl.Replace("https://", "http://"); // workaround for OpenSSL issues with the game's bundled Mono on Linux/Mac
-#endif
this.BaseUrl = new Uri(baseUrl);
this.Version = version;
}
@@ -43,6 +41,34 @@ namespace StardewModdingAPI.Toolkit.Framework.Clients.WebApi
);
}
+ /// <summary>Get the latest version for a mod.</summary>
+ /// <param name="updateKeys">The update keys to search.</param>
+ public ISemanticVersion GetLatestVersion(string[] updateKeys)
+ {
+ if (!updateKeys.Any())
+ return null;
+
+ // fetch update results
+ ModInfoModel[] results = this
+ .GetModInfo(updateKeys)
+ .Values
+ .Where(p => p.Error == null)
+ .ToArray();
+ if (!results.Any())
+ return null;
+
+ ISemanticVersion latest = null;
+ foreach (ModInfoModel result in results)
+ {
+ if (!SemanticVersion.TryParse(result.PreviewVersion ?? result.Version, out ISemanticVersion cur))
+ continue;
+
+ if (latest == null || cur.IsNewerThan(latest))
+ latest = cur;
+ }
+ return latest;
+ }
+
/*********
** Private methods