From 27dece2cf445147c5e2848f9ec26f38a101f50fc Mon Sep 17 00:00:00 2001 From: Gormogon Date: Sun, 29 May 2016 18:23:01 -0400 Subject: Attempt to migrate to new directory structure. --- src/StardewModdingAPI/Manifest.cs | 89 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 src/StardewModdingAPI/Manifest.cs (limited to 'src/StardewModdingAPI/Manifest.cs') 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 + { + /// + /// The name of your mod. + /// + public virtual string Name { get; set; } + + /// + /// The name of the mod's authour. + /// + public virtual string Authour { get; set; } + + /// + /// The version of the mod. + /// + public virtual Version Version { get; set; } + + /// + /// A description of the mod. + /// + public virtual string Description { get; set; } + + /// + /// The unique ID of the mod. It doesn't *need* to be anything. + /// + public virtual string UniqueID { get; set; } + + /// + /// Whether or not the mod uses per-save-config files. + /// + public virtual bool PerSaveConfigs { get; set; } + + /// + /// The name of the DLL in the directory that has the Entry() method. + /// + public virtual string EntryDll { get; set; } + + public override T GenerateDefaultConfig() + { + Name = ""; + Authour = ""; + Version = new Version(0, 0, 0, ""); + Description = ""; + UniqueID = Guid.NewGuid().ToString(); + PerSaveConfigs = false; + EntryDll = ""; + return this as T; + } + + public override T LoadConfig() + { + if (File.Exists(ConfigLocation)) + { + try + { + Manifest m = JsonConvert.DeserializeObject(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(); + } + } +} \ No newline at end of file -- cgit