diff options
author | Dan Volchek <volchek2@illinois.edu> | 2018-06-10 14:19:05 -0700 |
---|---|---|
committer | Dan Volchek <volchek2@illinois.edu> | 2018-06-10 14:19:05 -0700 |
commit | 1fa2632289134c39f268c374bb290549f28751d5 (patch) | |
tree | 0348af7c47277123f8bd628c914c422a9f133296 | |
parent | 5b9e365b5d252e2d1e957303c6b06fa1b3ae2f14 (diff) | |
download | SMAPI-1fa2632289134c39f268c374bb290549f28751d5.tar.gz SMAPI-1fa2632289134c39f268c374bb290549f28751d5.tar.bz2 SMAPI-1fa2632289134c39f268c374bb290549f28751d5.zip |
seperate IModMetadata methods, call them correctly when updating
-rw-r--r-- | src/SMAPI/Framework/IModMetadata.cs | 13 | ||||
-rw-r--r-- | src/SMAPI/Framework/ModLoading/ModMetadata.cs | 18 | ||||
-rw-r--r-- | src/SMAPI/Program.cs | 31 |
3 files changed, 42 insertions, 20 deletions
diff --git a/src/SMAPI/Framework/IModMetadata.cs b/src/SMAPI/Framework/IModMetadata.cs index 673c5b2e..7bf7d98c 100644 --- a/src/SMAPI/Framework/IModMetadata.cs +++ b/src/SMAPI/Framework/IModMetadata.cs @@ -80,14 +80,17 @@ namespace StardewModdingAPI.Framework /// <param name="api">The mod-provided API.</param> IModMetadata SetApi(object api); - /// <summary>Set the update status, indicating no errors happened.</summary> + /// <summary>Set the update version.</summary> /// <param name="latestVersion">The latest version.</param> + IModMetadata SetUpdateVersion(ISemanticVersion latestVersion); + + /// <summary>Set the preview update version.</summary> /// <param name="latestPreviewVersion">The latest preview version.</param> - IModMetadata SetUpdateStatus(ISemanticVersion latestVersion, ISemanticVersion latestPreviewVersion); + IModMetadata SetPreviewUpdateVersion(ISemanticVersion latestPreviewVersion); - /// <summary>Set the update status, indicating an error happened.</summary> - /// <param name="updateCheckError">The error checking for updates, if any.</param> - IModMetadata SetUpdateStatus(string updateCheckError); + /// <summary>Set the error that occured while checking for updates.</summary> + /// <param name="updateCheckError">The error checking for updates.</param> + IModMetadata SetUpdateError(string updateCheckError); /// <summary>Whether the mod manifest was loaded (regardless of whether the mod itself was loaded).</summary> bool HasManifest(); diff --git a/src/SMAPI/Framework/ModLoading/ModMetadata.cs b/src/SMAPI/Framework/ModLoading/ModMetadata.cs index 8f544da3..1ead1387 100644 --- a/src/SMAPI/Framework/ModLoading/ModMetadata.cs +++ b/src/SMAPI/Framework/ModLoading/ModMetadata.cs @@ -124,19 +124,25 @@ namespace StardewModdingAPI.Framework.ModLoading return this; } - /// <summary>Set the update status.</summary> + /// <summary>Set the update version.</summary> /// <param name="latestVersion">The latest version.</param> - /// <param name="latestPreviewVersion">The latest preview version.</param> - public IModMetadata SetUpdateStatus(ISemanticVersion latestVersion, ISemanticVersion latestPreviewVersion) + public IModMetadata SetUpdateVersion(ISemanticVersion latestVersion) { this.LatestVersion = latestVersion; + return this; + } + + /// <summary>Set the preview update version.</summary> + /// <param name="latestPreviewVersion">The latest preview version.</param> + public IModMetadata SetPreviewUpdateVersion(ISemanticVersion latestPreviewVersion) + { this.LatestPreviewVersion = latestPreviewVersion; return this; } - // <summary>Set the update status, indicating an error happened.</summary> - /// <param name="updateCheckError">The error checking for updates, if any.</param> - public IModMetadata SetUpdateStatus(string updateCheckError) + /// <summary>Set the error that occured while checking for updates.</summary> + /// <param name="updateCheckError">The error checking for updates.</param> + public IModMetadata SetUpdateError(string updateCheckError) { this.UpdateCheckError = updateCheckError; return this; 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); + } } } |