|
|
@ -1,6 +1,8 @@
|
|
|
|
using System.Collections.Generic;
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Reflection;
|
|
|
|
using System.Reflection;
|
|
|
|
|
|
|
|
using System.Resources;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using System.Text.RegularExpressions;
|
|
|
|
using DiscordChatExporter.Models;
|
|
|
|
using DiscordChatExporter.Models;
|
|
|
|
using HtmlAgilityPack;
|
|
|
|
using HtmlAgilityPack;
|
|
|
@ -8,13 +10,18 @@ using Tyrrrz.Extensions;
|
|
|
|
|
|
|
|
|
|
|
|
namespace DiscordChatExporter.Services
|
|
|
|
namespace DiscordChatExporter.Services
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public class ExportService
|
|
|
|
public class HtmlExportService
|
|
|
|
{
|
|
|
|
{
|
|
|
|
private HtmlDocument GetTemplate()
|
|
|
|
private HtmlDocument GetTemplate()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const string templateName = "DiscordChatExporter.Services.ExportTemplate.html";
|
|
|
|
string templateName = "DiscordChatExporter.Resources.HtmlExportService.Template.html";
|
|
|
|
|
|
|
|
|
|
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
|
|
using (var stream = assembly.GetManifestResourceStream(templateName))
|
|
|
|
var stream = assembly.GetManifestResourceStream(templateName);
|
|
|
|
|
|
|
|
if (stream == null)
|
|
|
|
|
|
|
|
throw new MissingManifestResourceException("Could not find template resource");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (stream)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var doc = new HtmlDocument();
|
|
|
|
var doc = new HtmlDocument();
|
|
|
|
doc.Load(stream);
|
|
|
|
doc.Load(stream);
|
|
|
@ -22,6 +29,22 @@ namespace DiscordChatExporter.Services
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string GetStyle(Theme theme)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
string styleName = $"DiscordChatExporter.Resources.HtmlExportService.{theme}Theme.css";
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var assembly = Assembly.GetExecutingAssembly();
|
|
|
|
|
|
|
|
var stream = assembly.GetManifestResourceStream(styleName);
|
|
|
|
|
|
|
|
if (stream == null)
|
|
|
|
|
|
|
|
throw new MissingManifestResourceException("Could not find theme style resource");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
using (stream)
|
|
|
|
|
|
|
|
using (var reader = new StreamReader(stream))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return reader.ReadToEnd();
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<MessageGroup> GroupMessages(IEnumerable<Message> messages)
|
|
|
|
private IEnumerable<MessageGroup> GroupMessages(IEnumerable<Message> messages)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var result = new List<MessageGroup>();
|
|
|
|
var result = new List<MessageGroup>();
|
|
|
@ -99,9 +122,14 @@ namespace DiscordChatExporter.Services
|
|
|
|
return content;
|
|
|
|
return content;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Export(string filePath, ChatLog chatLog)
|
|
|
|
public void Export(string filePath, ChatLog chatLog, Theme theme)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var doc = GetTemplate();
|
|
|
|
var doc = GetTemplate();
|
|
|
|
|
|
|
|
string style = GetStyle(theme);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Set theme
|
|
|
|
|
|
|
|
var themeHtml = doc.GetElementbyId("theme");
|
|
|
|
|
|
|
|
themeHtml.InnerHtml = style;
|
|
|
|
|
|
|
|
|
|
|
|
// Info
|
|
|
|
// Info
|
|
|
|
var infoHtml = doc.GetElementbyId("info");
|
|
|
|
var infoHtml = doc.GetElementbyId("info");
|