forked from CBLoader/CBLoader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
UpdateLog.cs
95 lines (93 loc) · 2.85 KB
/
UpdateLog.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
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Threading;
using System.Xml.Linq;
namespace CharacterBuilderLoader
{
internal class UpdateLog
{
private FileInfo[] parts;
private string[] Header = new string[]
{
"<html><head>",
"<script>function Show(id) { document.getElementById('more' + id).style.display = \"Block\"; document.getElementById('show' + id).style.display = \"none\"; }</script>",
"</head><body>",
"<h1>CBloader Update log</h1><br/>"
};
private string[] Footer = new string[]
{
"Generated by CBLoader at " + DateTime.Now.ToString(),
"</body></html>"
};
public static bool ShowChangelog = true;
internal void CreateAndShow(List<FileInfo> customFiles)
{
this.parts = (
from f in customFiles
orderby f.LastWriteTime
select f).Reverse<FileInfo>().ToArray<FileInfo>();
new Thread(new ThreadStart(this.Generate)).Start();
}
private void Generate()
{
string html = string.Concat(this.Header);
bool generated = false;
FileInfo[] parts = this.parts;
for (int i = 0; i < parts.Length; i++)
{
FileInfo fileInfo = parts[i];
XDocument xDocument = XDocument.Load(fileInfo.FullName);
XElement xElement = xDocument.Root.Element("Changelog");
if (xElement != null)
{
generated = true;
XElement updateInfo = xDocument.Root.Element("UpdateInfo");
html = html + "\n<h3>" + fileInfo.Name;
if (updateInfo != null)
{
html = html + " (Version " + updateInfo.Element("Version").Value + ")";
}
html += "</h3>";
html = html + "<div id=\"" + fileInfo.Name + "\"><ul>\n";
string[] changes = xElement.Value.Trim().Split(new char[]
{
'\n'
}).Reverse().ToArray();
bool showmore = false;
for (int j = 0; j < changes.Length; j++)
{
if (j == 4)
{
showmore = true;
html = html + String.Format("<li id=\"show{0}\" onclick=\"Show({0});\"><i>Show More</i></li><div id=\"more{0}\" style=\"display:none;\">", i);
}
string text2 = changes[j];
if (text2.Trim() != "")
{
html = html + "<li>" + text2 + "</li>\n";
}
}
if (showmore)
html += "</div>";
html += "</ul></div>\n";
}
}
html += string.Concat(this.Footer);
File.WriteAllText(Path.Combine(FileManager.BasePath, "Changelog.html"), html);
if (generated)
{
try
{
if (ShowChangelog)
Process.Start(Path.Combine(FileManager.BasePath, "Changelog.html"));
}
catch (Exception)
{
}
}
}
}
}