blob: e2526cf3e6b98c0b7caa91033b8d187c1187c1b2 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
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
{
//Idgaf speeder can go fuck himself
}
}
}
return base.LoadConfig<T>();
}
}
}
|