summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2018-08-19 22:35:55 -0400
committerJesse Plamondon-Willard <github@jplamondonw.com>2018-08-19 22:35:55 -0400
commitadf858fde9d3f47223376901fd2ecb2cfd63771d (patch)
tree2d841e0bcd3bd10669d71ffefdbd976149f21f96 /src
parent9f64dd2abb182b588cf5ae11201ca4dfbe26c45f (diff)
downloadSMAPI-adf858fde9d3f47223376901fd2ecb2cfd63771d.tar.gz
SMAPI-adf858fde9d3f47223376901fd2ecb2cfd63771d.tar.bz2
SMAPI-adf858fde9d3f47223376901fd2ecb2cfd63771d.zip
fix mod build package not parsing some valid manifests (#584)
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs57
-rw-r--r--src/SMAPI.ModBuildConfig/StardewModdingAPI.ModBuildConfig.csproj4
-rw-r--r--src/SMAPI.ModBuildConfig/package.nuspec13
3 files changed, 11 insertions, 63 deletions
diff --git a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs
index f4738d71..7ff66695 100644
--- a/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs
+++ b/src/SMAPI.ModBuildConfig/Framework/ModFileManager.cs
@@ -3,8 +3,8 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
-using System.Web.Script.Serialization;
-using StardewModdingAPI.Toolkit;
+using StardewModdingAPI.Toolkit.Serialisation;
+using StardewModdingAPI.Toolkit.Serialisation.Models;
namespace StardewModdingAPI.ModBuildConfig.Framework
{
@@ -107,41 +107,10 @@ namespace StardewModdingAPI.ModBuildConfig.Framework
/// <exception cref="UserErrorException">The manifest is missing or invalid.</exception>
public string GetManifestVersion()
{
- // get manifest file
- if (!this.Files.TryGetValue(this.ManifestFileName, out FileInfo manifestFile))
+ if (!this.Files.TryGetValue(this.ManifestFileName, out FileInfo manifestFile) || !new JsonHelper().ReadJsonFileIfExists(manifestFile.FullName, out Manifest manifest))
throw new InvalidOperationException($"The mod does not have a {this.ManifestFileName} file."); // shouldn't happen since we validate in constructor
- // read content
- string json = File.ReadAllText(manifestFile.FullName);
- if (string.IsNullOrWhiteSpace(json))
- throw new UserErrorException("The mod's manifest must not be empty.");
-
- // parse JSON
- IDictionary<string, object> data;
- try
- {
- data = this.Parse(json);
- }
- catch (Exception ex)
- {
- throw new UserErrorException($"The mod's manifest couldn't be parsed. It doesn't seem to be valid JSON.\n{ex}");
- }
-
- // get version field
- object versionObj = data.ContainsKey("Version") ? data["Version"] : null;
- if (versionObj == null)
- throw new UserErrorException("The mod's manifest must have a version field.");
-
- // get version string
- if (versionObj is IDictionary<string, object> versionFields) // SMAPI 1.x
- {
- int major = versionFields.ContainsKey("MajorVersion") ? (int)versionFields["MajorVersion"] : 0;
- int minor = versionFields.ContainsKey("MinorVersion") ? (int)versionFields["MinorVersion"] : 0;
- int patch = versionFields.ContainsKey("PatchVersion") ? (int)versionFields["PatchVersion"] : 0;
- string tag = versionFields.ContainsKey("Build") ? (string)versionFields["Build"] : null;
- return new SemanticVersion(major, minor, patch, tag).ToString();
- }
- return new SemanticVersion(versionObj.ToString()).ToString(); // SMAPI 2.0+
+ return manifest.Version.ToString();
}
@@ -174,24 +143,6 @@ namespace StardewModdingAPI.ModBuildConfig.Framework
|| ignoreFilePatterns.Any(p => p.IsMatch(relativePath));
}
- /// <summary>Get a case-insensitive dictionary matching the given JSON.</summary>
- /// <param name="json">The JSON to parse.</param>
- private IDictionary<string, object> Parse(string json)
- {
- IDictionary<string, object> MakeCaseInsensitive(IDictionary<string, object> dict)
- {
- foreach (var field in dict.ToArray())
- {
- if (field.Value is IDictionary<string, object> value)
- dict[field.Key] = MakeCaseInsensitive(value);
- }
- return new Dictionary<string, object>(dict, StringComparer.InvariantCultureIgnoreCase);
- }
-
- IDictionary<string, object> data = (IDictionary<string, object>)new JavaScriptSerializer().DeserializeObject(json);
- return MakeCaseInsensitive(data);
- }
-
/// <summary>Get whether a string is equal to another case-insensitively.</summary>
/// <param name="str">The string value.</param>
/// <param name="other">The string to compare with.</param>
diff --git a/src/SMAPI.ModBuildConfig/StardewModdingAPI.ModBuildConfig.csproj b/src/SMAPI.ModBuildConfig/StardewModdingAPI.ModBuildConfig.csproj
index 6a52daac..f068b480 100644
--- a/src/SMAPI.ModBuildConfig/StardewModdingAPI.ModBuildConfig.csproj
+++ b/src/SMAPI.ModBuildConfig/StardewModdingAPI.ModBuildConfig.csproj
@@ -56,6 +56,10 @@
<Content Include="assets\nuget-icon.png" />
</ItemGroup>
<ItemGroup>
+ <ProjectReference Include="..\StardewModdingAPI.Toolkit.CoreInterfaces\StardewModdingAPI.Toolkit.CoreInterfaces.csproj">
+ <Project>{d5cfd923-37f1-4bc3-9be8-e506e202ac28}</Project>
+ <Name>StardewModdingAPI.Toolkit.CoreInterfaces</Name>
+ </ProjectReference>
<ProjectReference Include="..\StardewModdingAPI.Toolkit\StardewModdingAPI.Toolkit.csproj">
<Project>{ea5cfd2e-9453-4d29-b80f-8e0ea23f4ac6}</Project>
<Name>StardewModdingAPI.Toolkit</Name>
diff --git a/src/SMAPI.ModBuildConfig/package.nuspec b/src/SMAPI.ModBuildConfig/package.nuspec
index 04880101..a311d739 100644
--- a/src/SMAPI.ModBuildConfig/package.nuspec
+++ b/src/SMAPI.ModBuildConfig/package.nuspec
@@ -2,7 +2,7 @@
<package xmlns="http://schemas.microsoft.com/packaging/2013/05/nuspec.xsd">
<metadata>
<id>Pathoschild.Stardew.ModBuildConfig</id>
- <version>2.1.1</version>
+ <version>2.2</version>
<title>Build package for SMAPI mods</title>
<authors>Pathoschild</authors>
<owners>Pathoschild</owners>
@@ -12,16 +12,9 @@
<iconUrl>https://raw.githubusercontent.com/Pathoschild/SMAPI/develop/src/SMAPI.ModBuildConfig/assets/nuget-icon.png</iconUrl>
<description>Automates the build configuration for crossplatform Stardew Valley SMAPI mods. For Stardew Valley 1.3 or later.</description>
<releaseNotes>
- 2.1:
- - Added support for Stardew Valley 1.3.
- - Added support for non-mod projects.
- - Added C# analyzers to warn about implicit conversions of Netcode fields in Stardew Valley 1.3.
- - Added option to ignore files by regex pattern.
- - Added reference to new SMAPI DLL.
- - Fixed some game paths not detected by NuGet package.
-
- 2.1.1:
+ 2.2:
- Update for SMAPI 2.8.
+ - Fixed valid manifests marked invalid in some cases.
</releaseNotes>
</metadata>
</package>