/
Changelog.cs
102 lines (92 loc) · 2.38 KB
/
Changelog.cs
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
90
91
92
93
94
95
96
97
98
99
100
101
102
using System;
using System.Collections.Generic;
using UnityEngine;
namespace KerbalChangelog
{
public class Changelog
{
public string modName { get; private set; }
public string license { get; private set; } = null;
public string author { get; private set; } = null;
public bool showCL { get; private set; } = true;
List<ChangeSet> changeSets = new List<ChangeSet>();
public ChangelogVersion highestVersion
{
get
{
changeSets.Sort();
try
{
return changeSets[0].version;
}
catch (Exception e)
{
Debug.Log("[KCL] No changesets exist.");
return null;
}
}
}
public Changelog(string mn, bool show, List<ChangeSet> cs)
{
modName = mn;
showCL = show;
changeSets = cs;
}
public Changelog(ConfigNode cn, UrlDir.UrlConfig cfgDir)
{
string cfgDirName = cfgDir.url;
string _modname = "";
if (!cn.TryGetValue("modName", ref _modname))
{
Debug.Log("[KCL] Missing mod name for changelog file in directory: " + cfgDirName);
Debug.Log("[KCL] Continuing using directory name as mod name...");
modName = cfgDirName;
}
else
{
modName = _modname;
}
bool _showCL = true;
if (!cn.TryGetValue("showChangelog", ref _showCL))
{
Debug.Log("[KCL] \"showChangelog\" field does not exist in mod ");
Debug.Log("[KCL] Assuming [true] to show changelog, adding field to changelog...");
if (!cn.SetValue("showChangelog", false, true)) //creates a new field for the viewing status, setting it to false
{
Debug.Log("[KCL] Unable to create 'showChangelog' in directory " + cfgDirName + " (field was missing in file)");
}
cfgDir.parent.SaveConfigs();
}
else
{
showCL = _showCL;
}
string _author = "";
if(cn.TryGetValue("author", ref _author))
{
author = _author;
}
string _license = "";
if(cn.TryGetValue("license", ref _license))
{
license = _license;
}
foreach (ConfigNode vn in cn.GetNodes("VERSION"))
{
changeSets.Add(new ChangeSet(vn, cfgDirName));
}
}
public override string ToString()
{
string ret = "";
ret += modName + "\n";
ret += ((author == null) ? "" : "Created by: " + author + "\n");
ret += ((license == null) ? "\n" : "Licensed under the " + license + " license\n\n"); //give a double line break here
foreach (ChangeSet cs in changeSets)
{
ret += cs.ToString();
}
return ret;
}
}
}