summaryrefslogtreecommitdiff
path: root/src/SMAPI/Program.cs
diff options
context:
space:
mode:
authorDan Volchek <volchek2@illinois.edu>2018-06-10 14:19:05 -0700
committerDan Volchek <volchek2@illinois.edu>2018-06-10 14:19:05 -0700
commit1fa2632289134c39f268c374bb290549f28751d5 (patch)
tree0348af7c47277123f8bd628c914c422a9f133296 /src/SMAPI/Program.cs
parent5b9e365b5d252e2d1e957303c6b06fa1b3ae2f14 (diff)
downloadSMAPI-1fa2632289134c39f268c374bb290549f28751d5.tar.gz
SMAPI-1fa2632289134c39f268c374bb290549f28751d5.tar.bz2
SMAPI-1fa2632289134c39f268c374bb290549f28751d5.zip
seperate IModMetadata methods, call them correctly when updating
Diffstat (limited to 'src/SMAPI/Program.cs')
-rw-r--r--src/SMAPI/Program.cs31
1 files changed, 22 insertions, 9 deletions
diff --git a/src/SMAPI/Program.cs b/src/SMAPI/Program.cs
index dc034331..e6aafb2d 100644
--- a/src/SMAPI/Program.cs
+++ b/src/SMAPI/Program.cs
@@ -671,34 +671,47 @@ namespace StardewModdingAPI
// handle error
if (remoteInfo.Error != null)
{
- mod.SetUpdateStatus(remoteInfo.Error);
+ if(mod.LatestVersion == null && mod.LatestPreviewVersion == null)
+ mod.SetUpdateError(remoteInfo.Error);
this.Monitor.Log($" {mod.DisplayName} ({result.Key}): update error: {remoteInfo.Error}", LogLevel.Trace);
continue;
}
// 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))
+
+ bool validVersion = SemanticVersion.TryParse(mod.DataRecord?.GetRemoteVersionForUpdateChecks(remoteInfo.Version) ?? remoteInfo.Version, out ISemanticVersion remoteVersion);
+ bool validPreviewVersion = SemanticVersion.TryParse(remoteInfo.PreviewVersion, out ISemanticVersion remotePreviewVersion);
+
+ if (!validVersion && !validPreviewVersion)
{
- string errorInfo = $"Mod has invalid version {remoteInfo.Version}";
+ string errorInfo = $"Mod has invalid versions. version: {remoteInfo.Version}, preview version: {remoteInfo.PreviewVersion}";
- mod.SetUpdateStatus(errorInfo);
+ if (mod.LatestVersion == null && mod.LatestPreviewVersion == null)
+ mod.SetUpdateError(errorInfo);
this.Monitor.Log($" {mod.DisplayName} ({result.Key}): update error: {errorInfo}", LogLevel.Trace);
continue;
}
- SemanticVersion.TryParse(remoteInfo.PreviewVersion, out ISemanticVersion remotePreviewVersion);
- mod.SetUpdateStatus(remoteVersion, remotePreviewVersion);
-
// compare versions
- bool isNonPreviewUpdate = remoteVersion.IsNewerThan(localVersion);
+ bool isNonPreviewUpdate = validVersion && remoteVersion.IsNewerThan(localVersion);
+
bool isUpdate = isNonPreviewUpdate ||
- (localVersion.IsNewerThan(remoteVersion) && remotePreviewVersion.IsNewerThan(localVersion));
+ (validPreviewVersion && localVersion.IsNewerThan(remoteVersion) && remotePreviewVersion.IsNewerThan(localVersion));
this.VerboseLog($" {mod.DisplayName} ({result.Key}): {(isUpdate ? $"{mod.Manifest.Version}{(!localVersion.Equals(mod.Manifest.Version) ? $" [{localVersion}]" : "")} => {(isNonPreviewUpdate ? remoteInfo.Version : remoteInfo.PreviewVersion)}" : "okay")}.");
if (isUpdate)
{
if (!updatesByMod.TryGetValue(mod, out Tuple<ModInfoModel, bool> other) || (isNonPreviewUpdate ? remoteVersion : remotePreviewVersion).IsNewerThan(other.Item2 ? other.Item1.PreviewVersion : other.Item1.Version))
+ {
updatesByMod[mod] = new Tuple<ModInfoModel, bool>(remoteInfo, !isNonPreviewUpdate);
+
+ if (isNonPreviewUpdate)
+ mod.SetUpdateVersion(remoteVersion);
+ else
+ mod.SetPreviewUpdateVersion(remotePreviewVersion);
+
+ mod.SetUpdateError(null);
+ }
}
}