summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--docs/release-notes.md15
-rw-r--r--src/SMAPI.Web/Controllers/ModsApiController.cs22
-rw-r--r--src/SMAPI.Web/StardewModdingAPI.Web.csproj5
-rw-r--r--src/SMAPI.Web/wwwroot/StardewModdingAPI.metadata.json (renamed from src/SMAPI/StardewModdingAPI.metadata.json)0
-rw-r--r--src/SMAPI/StardewModdingAPI.csproj7
5 files changed, 39 insertions, 10 deletions
diff --git a/docs/release-notes.md b/docs/release-notes.md
index 329ea3ad..062f902e 100644
--- a/docs/release-notes.md
+++ b/docs/release-notes.md
@@ -3,13 +3,16 @@
* For players:
* Updated for Stardew Valley 1.3 (no longer compatible with earlier versions).
* Added a bundled Save Backup mod.
- * Added beta update channel.
* Added prompt when in beta channel and a new version is found.
* Added friendly error when game can't start audio.
- * Added console warning for mods which don't have update checks configured.
- * Added update checks for optional mod files on Nexus.
* Added `player_add name` command, which lets you add items to your inventory by name instead of ID.
* Improved how mod warnings are shown in the console.
+ * Improved update checks:
+ * added beta update channel;
+ * added support for optional files on Nexus;
+ * added console warning for mods which don't have update checks configured;
+ * fixed mod update checks failing if a mod only has prerelease versions on GitHub;
+ * fixed Nexus mod update alerts not showing HTTPS links.
* Fixed `SEHException` errors and performance issues in some cases.
* Fixed console color scheme on Mac or in PowerShell, configurable via `StardewModdingAPI.config.json`.
* Fixed installer error on Linux/Mac in some cases.
@@ -20,9 +23,7 @@
* Fixed `world_setseason` command not running season-change logic.
* Fixed `world_setseason` command not normalising the season value.
* Fixed `world_settime` sometimes breaking NPC schedules (e.g. so they stay in bed).
- * Fixed mod update checks failing if a mod only has prerelease versions on GitHub.
* Fixed launch issue for Linux players with some terminals. (Thanks to HanFox and kurumushi!)
- * Fixed Nexus mod update alerts not showing HTTPS links.
* Fixed issue where a mod crashing in `CanEdit` or `CanLoad` could cause an abort-retry loop.
* Renamed `install.exe` to `install on Windows.exe` to avoid confusion.
* Updated compatibility list.
@@ -79,6 +80,10 @@
* Added Harmony for SMAPI's internal use to patch game functions for events.
* Added metadata dump option in `StardewModdingAPI.config.json` for troubleshooting some cases.
* Rewrote input suppression using new SDV 1.3 APIs.
+ * Rewrote update checks:
+ * Moved most logic into the web API.
+ * Changed web API to require mod ID.
+ * Changed web API to also fetch update keys from SMAPI's internal mod DB.
* Rewrote world/player state tracking:
* much more efficient than previous method;
* uses net field events where available;
diff --git a/src/SMAPI.Web/Controllers/ModsApiController.cs b/src/SMAPI.Web/Controllers/ModsApiController.cs
index c5a1705d..960602f4 100644
--- a/src/SMAPI.Web/Controllers/ModsApiController.cs
+++ b/src/SMAPI.Web/Controllers/ModsApiController.cs
@@ -1,13 +1,16 @@
using System;
using System.Collections.Generic;
+using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
+using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Caching.Memory;
using Microsoft.Extensions.Options;
using StardewModdingAPI.Toolkit;
using StardewModdingAPI.Toolkit.Framework.Clients.WebApi;
+using StardewModdingAPI.Toolkit.Framework.ModData;
using StardewModdingAPI.Web.Framework.Clients.Chucklefish;
using StardewModdingAPI.Web.Framework.Clients.GitHub;
using StardewModdingAPI.Web.Framework.Clients.Nexus;
@@ -39,18 +42,23 @@ namespace StardewModdingAPI.Web.Controllers
/// <summary>A regex which matches SMAPI-style semantic version.</summary>
private readonly string VersionRegex;
+ /// <summary>The internal mod metadata list.</summary>
+ private readonly ModDatabase ModDatabase;
+
/*********
** Public methods
*********/
/// <summary>Construct an instance.</summary>
+ /// <param name="environment">The web hosting environment.</param>
/// <param name="cache">The cache in which to store mod metadata.</param>
/// <param name="configProvider">The config settings for mod update checks.</param>
/// <param name="chucklefish">The Chucklefish API client.</param>
/// <param name="github">The GitHub API client.</param>
/// <param name="nexus">The Nexus API client.</param>
- public ModsApiController(IMemoryCache cache, IOptions<ModUpdateCheckConfig> configProvider, IChucklefishClient chucklefish, IGitHubClient github, INexusClient nexus)
+ public ModsApiController(IHostingEnvironment environment, IMemoryCache cache, IOptions<ModUpdateCheckConfig> configProvider, IChucklefishClient chucklefish, IGitHubClient github, INexusClient nexus)
{
+ this.ModDatabase = new ModToolkit().GetModDatabase(Path.Combine(environment.WebRootPath, "StardewModdingAPI.metadata.json"));
ModUpdateCheckConfig config = configProvider.Value;
this.Cache = cache;
@@ -79,10 +87,20 @@ namespace StardewModdingAPI.Web.Controllers
if (string.IsNullOrWhiteSpace(mod.ID))
continue;
+ // resolve update keys
+ var updateKeys = new HashSet<string>(mod.UpdateKeys ?? new string[0], StringComparer.InvariantCultureIgnoreCase);
+ ModDataRecord record = this.ModDatabase.Get(mod.ID);
+ if (record?.Fields != null)
+ {
+ string defaultUpdateKey = record.Fields.FirstOrDefault(p => p.Key == ModDataFieldKey.UpdateKey && p.IsDefault)?.Value;
+ if (!string.IsNullOrWhiteSpace(defaultUpdateKey))
+ updateKeys.Add(defaultUpdateKey);
+ }
+
// get latest versions
ModEntryModel result = new ModEntryModel { ID = mod.ID };
IList<string> errors = new List<string>();
- foreach (string updateKey in mod.UpdateKeys ?? new string[0])
+ foreach (string updateKey in updateKeys)
{
// fetch data
ModInfoModel data = await this.GetInfoForUpdateKeyAsync(updateKey);
diff --git a/src/SMAPI.Web/StardewModdingAPI.Web.csproj b/src/SMAPI.Web/StardewModdingAPI.Web.csproj
index a409e6eb..6761c7ad 100644
--- a/src/SMAPI.Web/StardewModdingAPI.Web.csproj
+++ b/src/SMAPI.Web/StardewModdingAPI.Web.csproj
@@ -26,5 +26,10 @@
<ItemGroup>
<ProjectReference Include="..\StardewModdingAPI.Toolkit\StardewModdingAPI.Toolkit.csproj" />
</ItemGroup>
+ <ItemGroup>
+ <Content Update="wwwroot\StardewModdingAPI.metadata.json">
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
+ </Content>
+ </ItemGroup>
</Project>
diff --git a/src/SMAPI/StardewModdingAPI.metadata.json b/src/SMAPI.Web/wwwroot/StardewModdingAPI.metadata.json
index 343257f1..343257f1 100644
--- a/src/SMAPI/StardewModdingAPI.metadata.json
+++ b/src/SMAPI.Web/wwwroot/StardewModdingAPI.metadata.json
diff --git a/src/SMAPI/StardewModdingAPI.csproj b/src/SMAPI/StardewModdingAPI.csproj
index f849ee53..c13f5e30 100644
--- a/src/SMAPI/StardewModdingAPI.csproj
+++ b/src/SMAPI/StardewModdingAPI.csproj
@@ -293,16 +293,17 @@
<SubType>Designer</SubType>
</None>
<Content Include="StardewModdingAPI.config.json">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
- <Content Include="StardewModdingAPI.metadata.json">
+ <Content Include="..\SMAPI.Web\wwwroot\StardewModdingAPI.metadata.json">
+ <Link>StardewModdingAPI.metadata.json</Link>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>
<Content Include="icon.ico" />
<Content Include="steam_appid.txt">
- <CopyToOutputDirectory>Always</CopyToOutputDirectory>
+ <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
</ItemGroup>
<ItemGroup>