summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-08-16 17:22:44 -0400
committerJesse Plamondon-Willard <Pathoschild@users.noreply.github.com>2021-08-25 18:18:37 -0400
commit68e629f17c349b685ef3c4836552adcbed0c4976 (patch)
treec17931e92b3914d08d8bdff8e4d35e6ea26bdba6 /src
parentc20fcec169d75b395636b06adcbec8d5101447fd (diff)
downloadSMAPI-68e629f17c349b685ef3c4836552adcbed0c4976.tar.gz
SMAPI-68e629f17c349b685ef3c4836552adcbed0c4976.tar.bz2
SMAPI-68e629f17c349b685ef3c4836552adcbed0c4976.zip
fix data helper's WriteJsonFile not deleting file if data is null (#799)
Diffstat (limited to 'src')
-rw-r--r--src/SMAPI/Framework/ModHelpers/DataHelper.cs6
-rw-r--r--src/SMAPI/IDataHelper.cs2
2 files changed, 6 insertions, 2 deletions
diff --git a/src/SMAPI/Framework/ModHelpers/DataHelper.cs b/src/SMAPI/Framework/ModHelpers/DataHelper.cs
index 0fe3209f..4cbfd73f 100644
--- a/src/SMAPI/Framework/ModHelpers/DataHelper.cs
+++ b/src/SMAPI/Framework/ModHelpers/DataHelper.cs
@@ -58,7 +58,11 @@ namespace StardewModdingAPI.Framework.ModHelpers
throw new InvalidOperationException($"You must call {nameof(IMod.Helper)}.{nameof(IModHelper.Data)}.{nameof(this.WriteJsonFile)} with a relative path (without directory climbing).");
path = Path.Combine(this.ModFolderPath, PathUtilities.NormalizePath(path));
- this.JsonHelper.WriteJsonFile(path, data);
+
+ if (data != null)
+ this.JsonHelper.WriteJsonFile(path, data);
+ else
+ File.Delete(path);
}
/****
diff --git a/src/SMAPI/IDataHelper.cs b/src/SMAPI/IDataHelper.cs
index 4922c8da..901266d7 100644
--- a/src/SMAPI/IDataHelper.cs
+++ b/src/SMAPI/IDataHelper.cs
@@ -21,7 +21,7 @@ namespace StardewModdingAPI
/// <summary>Save data to a JSON file in the mod's folder.</summary>
/// <typeparam name="TModel">The model type. This should be a plain class that has public properties for the data you want. The properties can be complex types.</typeparam>
/// <param name="path">The file path relative to the mod folder.</param>
- /// <param name="data">The arbitrary data to save.</param>
+ /// <param name="data">The arbitrary data to save, or <c>null</c> to delete the file.</param>
/// <exception cref="InvalidOperationException">The <paramref name="path"/> is not relative or contains directory climbing (../).</exception>
void WriteJsonFile<TModel>(string path, TModel data) where TModel : class;