summaryrefslogtreecommitdiff
path: root/src/SMAPI
diff options
context:
space:
mode:
Diffstat (limited to 'src/SMAPI')
-rw-r--r--src/SMAPI/Framework/ModData/ModDataRecord.cs11
-rw-r--r--src/SMAPI/Framework/ModData/ParsedModDataRecord.cs2
-rw-r--r--src/SMAPI/Framework/WebApiClient.cs2
-rw-r--r--src/SMAPI/Program.cs31
4 files changed, 26 insertions, 20 deletions
diff --git a/src/SMAPI/Framework/ModData/ModDataRecord.cs b/src/SMAPI/Framework/ModData/ModDataRecord.cs
index 79a954f7..56275f53 100644
--- a/src/SMAPI/Framework/ModData/ModDataRecord.cs
+++ b/src/SMAPI/Framework/ModData/ModDataRecord.cs
@@ -106,10 +106,10 @@ namespace StardewModdingAPI.Framework.ModData
/// <summary>Get a semantic local version for update checks.</summary>
/// <param name="version">The remote version to normalise.</param>
- public string GetLocalVersionForUpdateChecks(string version)
+ public ISemanticVersion GetLocalVersionForUpdateChecks(ISemanticVersion version)
{
- return this.MapLocalVersions != null && this.MapLocalVersions.TryGetValue(version, out string newVersion)
- ? newVersion
+ return this.MapLocalVersions != null && this.MapLocalVersions.TryGetValue(version.ToString(), out string newVersion)
+ ? new SemanticVersion(newVersion)
: version;
}
@@ -117,6 +117,11 @@ namespace StardewModdingAPI.Framework.ModData
/// <param name="version">The remote version to normalise.</param>
public string GetRemoteVersionForUpdateChecks(string version)
{
+ // normalise version if possible
+ if (SemanticVersion.TryParse(version, out ISemanticVersion parsed))
+ version = parsed.ToString();
+
+ // fetch remote version
return this.MapRemoteVersions != null && this.MapRemoteVersions.TryGetValue(version, out string newVersion)
? newVersion
: version;
diff --git a/src/SMAPI/Framework/ModData/ParsedModDataRecord.cs b/src/SMAPI/Framework/ModData/ParsedModDataRecord.cs
index 7f49790d..deb12bdc 100644
--- a/src/SMAPI/Framework/ModData/ParsedModDataRecord.cs
+++ b/src/SMAPI/Framework/ModData/ParsedModDataRecord.cs
@@ -33,7 +33,7 @@ namespace StardewModdingAPI.Framework.ModData
*********/
/// <summary>Get a semantic local version for update checks.</summary>
/// <param name="version">The remote version to normalise.</param>
- public string GetLocalVersionForUpdateChecks(string version)
+ public ISemanticVersion GetLocalVersionForUpdateChecks(ISemanticVersion version)
{
return this.DataRecord.GetLocalVersionForUpdateChecks(version);
}
diff --git a/src/SMAPI/Framework/WebApiClient.cs b/src/SMAPI/Framework/WebApiClient.cs
index e78ac14b..7f0122cf 100644
--- a/src/SMAPI/Framework/WebApiClient.cs
+++ b/src/SMAPI/Framework/WebApiClient.cs
@@ -40,7 +40,7 @@ namespace StardewModdingAPI.Framework
{
return this.Post<ModSearchModel, Dictionary<string, ModInfoModel>>(
$"v{this.Version}/mods",
- new ModSearchModel(modKeys)
+ new ModSearchModel(modKeys, allowInvalidVersions: true)
);
}
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index 979f6328..1a1b9645 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -604,29 +604,30 @@ namespace StardewModdingAPI
foreach (var result in results)
{
IModMetadata mod = result.Mod;
- ModInfoModel info = result.Info;
+ ModInfoModel remoteInfo = result.Info;
// handle error
- if (info.Error != null)
+ if (remoteInfo.Error != null)
{
- this.Monitor.Log($" {mod.DisplayName} ({result.Key}): update error: {info.Error}", LogLevel.Trace);
+ this.Monitor.Log($" {mod.DisplayName} ({result.Key}): update error: {remoteInfo.Error}", LogLevel.Trace);
continue;
}
- // track update
- ISemanticVersion localVersion = mod.DataRecord != null
- ? new SemanticVersion(mod.DataRecord.GetLocalVersionForUpdateChecks(mod.Manifest.Version.ToString()))
- : mod.Manifest.Version;
- ISemanticVersion latestVersion = new SemanticVersion(mod.DataRecord != null
- ? mod.DataRecord.GetRemoteVersionForUpdateChecks(new SemanticVersion(info.Version).ToString())
- : info.Version
- );
- bool isUpdate = latestVersion.IsNewerThan(localVersion);
- this.VerboseLog($" {mod.DisplayName} ({result.Key}): {(isUpdate ? $"{mod.Manifest.Version}{(!localVersion.Equals(mod.Manifest.Version) ? $" [{localVersion}]" : "")} => {info.Version}{(!latestVersion.Equals(new SemanticVersion(info.Version)) ? $" [{latestVersion}]" : "")}" : "okay")}.");
+ // normalise versions
+ ISemanticVersion localVersion = mod.DataRecord?.GetLocalVersionForUpdateChecks(mod.Manifest.Version) ?? mod.Manifest.Version;
+ if (!SemanticVersion.TryParse(mod.DataRecord?.GetRemoteVersionForUpdateChecks(remoteInfo.Version) ?? remoteInfo.Version, out ISemanticVersion remoteVersion))
+ {
+ this.Monitor.Log($" {mod.DisplayName} ({result.Key}): update error: Mod has invalid version {remoteInfo.Version}", LogLevel.Trace);
+ continue;
+ }
+
+ // compare versions
+ bool isUpdate = remoteVersion.IsNewerThan(localVersion);
+ this.VerboseLog($" {mod.DisplayName} ({result.Key}): {(isUpdate ? $"{mod.Manifest.Version}{(!localVersion.Equals(mod.Manifest.Version) ? $" [{localVersion}]" : "")} => {remoteInfo.Version}{(!remoteVersion.Equals(new SemanticVersion(remoteInfo.Version)) ? $" [{remoteVersion}]" : "")}" : "okay")}.");
if (isUpdate)
{
- if (!updatesByMod.TryGetValue(mod, out ModInfoModel other) || latestVersion.IsNewerThan(other.Version))
- updatesByMod[mod] = info;
+ if (!updatesByMod.TryGetValue(mod, out ModInfoModel other) || remoteVersion.IsNewerThan(other.Version))
+ updatesByMod[mod] = remoteInfo;
}
}