SMAPI - Stardew Modding API

SMAPI - Stardew Modding API

971k Downloads

Expose mod update status through registry API

danvolchek opened this issue ยท 6 comments

commented

It would be useful if there was a way of telling if a mod has a newer version available through the mod registry. Features I envision of the update status would be

  • an enum describing the update state (i.e. UpToDate, OutOfDate, Error)
  • a string describing the new version if the status is OutOfDate
  • a string describing the error reason if the status is Error (i.e. no update keys, or invalid update keys, etc)

I'd be happy to contribute the necessary changes, so please let me know if there's a better way of describing the update status, or any other ideas. :)

commented

SMAPI already collects that info internally for installed mods, and the registry only provides data for installed mods, so that part is fine. There are two main issues with exposing it through the mod registry though:

  • We'd need to change the mod registry methods to return more general types (which would be a breaking change), or introduce similar methods like GetAll and GetAllExtended (which would be confusing).
  • Update checks are performed asynchronously after mods are loaded and entry'd, so there's no guarantee of when the update info would be available.

Getting that info for non-installed mods is more complicated (and the mod registry doesn't support those anyway). Compatibility is mostly checked by analysing the mod code, so that info wouldn't be available unless the target mod was installed. Update checks are asynchronous and slow; since mods would need to do those synchronously, calling the API could cause noticeable game stuttering.

commented

Per our conversation in the discord:

  • The update to the mod registry is breaking, and should be delayed until SMAPI 3.0. This would involve something like a new IModInfo interface that provides version info along with the existing IManifest info.
  • Mod checks for non-installed mods isn't expected of this API - if SMAPI were to provide a helper to do it, it would be provided somewhere else.

Since I was hoping to have my mod update menu mod ready before SMAPI 3.0, Pathos has kindly offered to include the relevant info (like new version and update-check failure reason, if any) inside IModMetadata, that can be accessed through reflection. This would be used as a temporary solution until official registry support is added.

Thanks! :)

commented

The internal metadata is now available in SMAPI 2.6-beta.17 with this field:

/// <summary>The update-check metadata for this mod (if any).</summary>
ModEntryModel UpdateCheckData { get; }

Where ModEntryModel is the update check metadata from the underlying SMAPI toolkit:

/// <summary>Metadata about a mod.</summary>
public class ModEntryModel
{
    /*********
    ** Accessors
    *********/
    /// <summary>The mod's unique ID (if known).</summary>
    public string ID { get; set; }

    /// <summary>The mod name.</summary>
    public string Name { get; set; }

    /// <summary>The mod's latest version number.</summary>
    public string Version { get; set; }

    /// <summary>The mod's web URL.</summary>
    public string Url { get; set; }

    /// <summary>The mod's latest optional release, if newer than <see cref="Version"/>.</summary>
    public string PreviewVersion { get; set; }

    /// <summary>The web URL to the mod's latest optional release, if newer than <see cref="Version"/>.</summary>
    public string PreviewUrl { get; set; }

    /// <summary>The errors that occurred while fetching update data.</summary>
    public string[] Errors { get; set; } = new string[0];
}
commented

(I'll keep this open for the SMAPI 3.0 mod registry API though.)

commented

@danvolchek The metadata isn't fully exposed yet, but it's much easier to access in SMAPI 2.8 if you have a reference to the toolkit:

IModInfo mod = helper.ModRegistry.Get("SomeModID");
ModEntryModel updateData = (ModEntryModel)mod
   .GetType()
   .GetProperty("UpdateCheckData")
   .GetValue(mod);
commented

The update-check data is easy to access using reflection now, but the implementation is subject to change so it's not suitable to a public API. I'll close this ticket as resolved since most of the changes are done in SMAPI 3.0.