summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <github@jplamondonw.com>2017-01-14 13:03:57 -0500
committerJesse Plamondon-Willard <github@jplamondonw.com>2017-01-14 13:03:57 -0500
commit9d1b6a1af2f21dff9904d03daaf6f1ce6409d7f8 (patch)
tree2e0c03e84f65382ae5c0b906ff40e3299b382981
parent83bdcd28386cebd36890565065912be4e3443603 (diff)
downloadSMAPI-9d1b6a1af2f21dff9904d03daaf6f1ce6409d7f8.tar.gz
SMAPI-9d1b6a1af2f21dff9904d03daaf6f1ce6409d7f8.tar.bz2
SMAPI-9d1b6a1af2f21dff9904d03daaf6f1ce6409d7f8.zip
fix issue where default ICollection<T> values in config.json were duplicated on each load (#209)
-rw-r--r--release-notes.md3
-rw-r--r--src/StardewModdingAPI/Manifest.cs1
-rw-r--r--src/StardewModdingAPI/ModHelper.cs15
3 files changed, 16 insertions, 3 deletions
diff --git a/release-notes.md b/release-notes.md
index 8b4df6d7..1fb72dd1 100644
--- a/release-notes.md
+++ b/release-notes.md
@@ -6,7 +6,8 @@ See [log](https://github.com/Pathoschild/SMAPI/compare/stable...develop).
For players:
* Fixed issue where the installer couldn't find the game for some players on 32-bit Windows.
* Fixed issue where SMAPI couldn't be launched from Steam for some Linux players.
-* Fixed error loading mods if they have a `.cache` folder created on a different platform.
+* Fixed issue where values in `config.json` were duplicated in some cases.
+* Fixed error loading mods that were released with a `.cache` folder from a different platform.
* Updated list of incompatible mods.
For mod developers:
diff --git a/src/StardewModdingAPI/Manifest.cs b/src/StardewModdingAPI/Manifest.cs
index 018b31ae..07dd3541 100644
--- a/src/StardewModdingAPI/Manifest.cs
+++ b/src/StardewModdingAPI/Manifest.cs
@@ -8,6 +8,7 @@ namespace StardewModdingAPI
internal class ManifestImpl : Manifest, IManifest
{
/// <summary>The mod version.</summary>
+ [JsonProperty("Version", ObjectCreationHandling = ObjectCreationHandling.Auto/* avoids issue where Json.NET can't determine concrete type for interface */)]
public new ISemanticVersion Version
{
get { return base.Version; }
diff --git a/src/StardewModdingAPI/ModHelper.cs b/src/StardewModdingAPI/ModHelper.cs
index 7304c5ea..78b3eefa 100644
--- a/src/StardewModdingAPI/ModHelper.cs
+++ b/src/StardewModdingAPI/ModHelper.cs
@@ -11,6 +11,17 @@ namespace StardewModdingAPI
public class ModHelper : IModHelper
{
/*********
+ ** Properties
+ *********/
+ /// <summary>The JSON settings to use when serialising and deserialising files.</summary>
+ private readonly JsonSerializerSettings JsonSettings = new JsonSerializerSettings
+ {
+ Formatting = Formatting.Indented,
+ ObjectCreationHandling = ObjectCreationHandling.Replace // avoid issue where default ICollection<T> values are duplicated each time the config is loaded
+ };
+
+
+ /*********
** Accessors
*********/
/// <summary>The mod directory path.</summary>
@@ -82,7 +93,7 @@ namespace StardewModdingAPI
}
// deserialise model
- TModel model = JsonConvert.DeserializeObject<TModel>(json);
+ TModel model = JsonConvert.DeserializeObject<TModel>(json, this.JsonSettings);
if (model is IConfigFile)
{
var wrapper = (IConfigFile)model;
@@ -108,7 +119,7 @@ namespace StardewModdingAPI
Directory.CreateDirectory(dir);
// write file
- string json = JsonConvert.SerializeObject(model, Formatting.Indented);
+ string json = JsonConvert.SerializeObject(model, this.JsonSettings);
File.WriteAllText(path, json);
}
}