diff options
| author | Carl <slxxls92@gmail.com> | 2016-05-30 01:33:37 +0100 |
|---|---|---|
| committer | Carl <slxxls92@gmail.com> | 2016-05-30 01:33:37 +0100 |
| commit | fa666f803398e29a7ffec0707cd6a1ec3571d3e9 (patch) | |
| tree | 71099c94fa92196cfb6cdb42a56379e6fdaa4364 /src/StardewModdingAPI/Manifest.cs | |
| parent | 4edee54da20e7655ae24cf1ac2abded5ec1ba2c5 (diff) | |
| parent | 1212222e9f59a68a9f167d20bbddd8a4e1a3cf81 (diff) | |
| download | SMAPI-fa666f803398e29a7ffec0707cd6a1ec3571d3e9.tar.gz SMAPI-fa666f803398e29a7ffec0707cd6a1ec3571d3e9.tar.bz2 SMAPI-fa666f803398e29a7ffec0707cd6a1ec3571d3e9.zip | |
Merge pull request #118 from Gormogon/master
Some Semi-Big Changes
Diffstat (limited to 'src/StardewModdingAPI/Manifest.cs')
| -rw-r--r-- | src/StardewModdingAPI/Manifest.cs | 89 |
1 files changed, 89 insertions, 0 deletions
diff --git a/src/StardewModdingAPI/Manifest.cs b/src/StardewModdingAPI/Manifest.cs new file mode 100644 index 00000000..5eabc01b --- /dev/null +++ b/src/StardewModdingAPI/Manifest.cs @@ -0,0 +1,89 @@ +using System; +using System.IO; +using System.Linq; +using Newtonsoft.Json; +using Newtonsoft.Json.Linq; + +namespace StardewModdingAPI +{ + public class Manifest : Config + { + /// <summary> + /// The name of your mod. + /// </summary> + public virtual string Name { get; set; } + + /// <summary> + /// The name of the mod's authour. + /// </summary> + public virtual string Authour { get; set; } + + /// <summary> + /// The version of the mod. + /// </summary> + public virtual Version Version { get; set; } + + /// <summary> + /// A description of the mod. + /// </summary> + public virtual string Description { get; set; } + + /// <summary> + /// The unique ID of the mod. It doesn't *need* to be anything. + /// </summary> + public virtual string UniqueID { get; set; } + + /// <summary> + /// Whether or not the mod uses per-save-config files. + /// </summary> + public virtual bool PerSaveConfigs { get; set; } + + /// <summary> + /// The name of the DLL in the directory that has the Entry() method. + /// </summary> + public virtual string EntryDll { get; set; } + + public override T GenerateDefaultConfig<T>() + { + Name = ""; + Authour = ""; + Version = new Version(0, 0, 0, ""); + Description = ""; + UniqueID = Guid.NewGuid().ToString(); + PerSaveConfigs = false; + EntryDll = ""; + return this as T; + } + + public override T LoadConfig<T>() + { + if (File.Exists(ConfigLocation)) + { + try + { + Manifest m = JsonConvert.DeserializeObject<Manifest>(File.ReadAllText(ConfigLocation)); + } + catch + { + //Invalid json blob. Try to remove version? + try + { + JObject j = JObject.Parse(File.ReadAllText(ConfigLocation)); + if (!j.GetValue("Version").Contains("{")) + { + Log.AsyncC("INVALID JSON VERSION. TRYING TO REMOVE SO A NEW CAN BE AUTO-GENERATED"); + j.Remove("Version"); + File.WriteAllText(ConfigLocation, j.ToString()); + } + } + catch (Exception) + { + // ignored + } + } + } + + return base.LoadConfig<T>(); + } + } +}
\ No newline at end of file |
