2016-03-21 05:19:02 +08:00
|
|
|
|
using System;
|
2016-03-27 19:13:16 +08:00
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Linq;
|
|
|
|
|
using Newtonsoft.Json;
|
|
|
|
|
using Newtonsoft.Json.Linq;
|
2016-03-21 05:19:02 +08:00
|
|
|
|
|
|
|
|
|
namespace StardewModdingAPI
|
|
|
|
|
{
|
2016-03-23 08:36:04 +08:00
|
|
|
|
public class Manifest : Config
|
2016-03-21 05:19:02 +08:00
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
2016-03-27 13:09:09 +08:00
|
|
|
|
/// The name of your mod.
|
2016-03-21 05:19:02 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual string Name { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-03-27 13:09:09 +08:00
|
|
|
|
/// The name of the mod's authour.
|
2016-03-21 05:19:02 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual string Authour { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-03-27 13:09:09 +08:00
|
|
|
|
/// The version of the mod.
|
2016-03-21 05:19:02 +08:00
|
|
|
|
/// </summary>
|
2016-03-24 01:43:11 +08:00
|
|
|
|
public virtual Version Version { get; set; }
|
2016-03-21 05:19:02 +08:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-03-27 13:09:09 +08:00
|
|
|
|
/// A description of the mod.
|
2016-03-21 05:19:02 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual string Description { get; set; }
|
|
|
|
|
|
2016-03-23 08:36:04 +08:00
|
|
|
|
/// <summary>
|
2016-03-27 13:09:09 +08:00
|
|
|
|
/// The unique ID of the mod. It doesn't *need* to be anything.
|
2016-03-23 08:36:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual string UniqueID { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-03-27 13:09:09 +08:00
|
|
|
|
/// Whether or not the mod uses per-save-config files.
|
2016-03-23 08:36:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual bool PerSaveConfigs { get; set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
2016-03-27 13:09:09 +08:00
|
|
|
|
/// The name of the DLL in the directory that has the Entry() method.
|
2016-03-23 08:36:04 +08:00
|
|
|
|
/// </summary>
|
|
|
|
|
public virtual string EntryDll { get; set; }
|
|
|
|
|
|
2016-03-24 01:43:11 +08:00
|
|
|
|
public override T GenerateDefaultConfig<T>()
|
2016-03-23 08:36:04 +08:00
|
|
|
|
{
|
|
|
|
|
Name = "";
|
|
|
|
|
Authour = "";
|
2016-03-24 01:43:11 +08:00
|
|
|
|
Version = new Version(0, 0, 0, "");
|
2016-03-23 08:36:04 +08:00
|
|
|
|
Description = "";
|
|
|
|
|
UniqueID = Guid.NewGuid().ToString();
|
|
|
|
|
PerSaveConfigs = false;
|
|
|
|
|
EntryDll = "";
|
2016-03-23 16:22:47 +08:00
|
|
|
|
return this as T;
|
2016-03-23 08:36:04 +08:00
|
|
|
|
}
|
2016-03-27 19:13:16 +08:00
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
{
|
|
|
|
|
//Idgaf speeder can go fuck himself
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return base.LoadConfig<T>();
|
|
|
|
|
}
|
2016-03-21 05:19:02 +08:00
|
|
|
|
}
|
2016-03-27 13:09:09 +08:00
|
|
|
|
}
|