Add command line interface and change solution structure (#26)

This commit is contained in:
Alexey Golub 2018-01-12 20:28:36 +01:00 committed by GitHub
parent 7da82f9ef4
commit 8515efe11b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
74 changed files with 508 additions and 218 deletions

View file

@ -1,3 +1,5 @@
New-Item "$PSScriptRoot\bin" -ItemType Directory -Force New-Item "$PSScriptRoot\bin" -ItemType Directory -Force
$files = Get-ChildItem -Path "$PSScriptRoot\..\DiscordChatExporter\bin\Release\*" -Include "*.exe", "*.dll", "*.config" $files = @()
$files += Get-ChildItem -Path "$PSScriptRoot\..\DiscordChatExporter.Gui\bin\Release\*" -Include "*.exe", "*.dll", "*.config"
$files += Get-ChildItem -Path "$PSScriptRoot\..\DiscordChatExporter.Cli\bin\Release\net45\*" -Include "*.exe", "*.dll", "*.config"
$files | Compress-Archive -DestinationPath "$PSScriptRoot\bin\DiscordChatExporter.zip" -Force $files | Compress-Archive -DestinationPath "$PSScriptRoot\bin\DiscordChatExporter.zip" -Force

View file

@ -0,0 +1,24 @@
using System;
using DiscordChatExporter.Core.Models;
namespace DiscordChatExporter.Cli
{
public class CliOptions
{
public string Token { get; set; }
public string ChannelId { get; set; }
public ExportFormat ExportFormat { get; set; }
public string FilePath { get; set; }
public DateTime? From { get; set; }
public DateTime? To { get; set; }
public string DateFormat { get; set; }
public int MessageGroupLimit { get; set; }
}
}

View file

@ -0,0 +1,37 @@
using DiscordChatExporter.Cli.ViewModels;
using DiscordChatExporter.Core.Services;
using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation;
namespace DiscordChatExporter.Cli
{
public class Container
{
public IMainViewModel MainViewModel => Resolve<IMainViewModel>();
public ISettingsService SettingsService => Resolve<ISettingsService>();
private T Resolve<T>(string key = null)
{
return ServiceLocator.Current.GetInstance<T>(key);
}
public void Init()
{
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Reset();
// Services
SimpleIoc.Default.Register<IDataService, DataService>();
SimpleIoc.Default.Register<IExportService, ExportService>();
SimpleIoc.Default.Register<IMessageGroupService, MessageGroupService>();
SimpleIoc.Default.Register<ISettingsService, SettingsService>();
// View models
SimpleIoc.Default.Register<IMainViewModel, MainViewModel>(true);
}
public void Cleanup()
{
}
}
}

View file

@ -0,0 +1,24 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net45</TargetFramework>
<Version>2.3</Version>
<Company>Tyrrrz</Company>
<Copyright>Copyright (c) 2017-2018 Alexey Golub</Copyright>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommonServiceLocator" Version="1.3" />
<PackageReference Include="Costura.Fody" Version="1.6.2" />
<PackageReference Include="FluentCommandLineParser" Version="1.4.3" />
<PackageReference Include="Fody" Version="2.3.18" />
<PackageReference Include="MvvmLightLibs" Version="5.3.0.0" />
<PackageReference Include="Tyrrrz.Extensions" Version="1.5.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DiscordChatExporter.Core\DiscordChatExporter.Core.csproj" />
</ItemGroup>
</Project>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura />
</Weavers>

View file

@ -0,0 +1,83 @@
using System;
using System.Reflection;
using DiscordChatExporter.Core.Models;
using Fclp;
namespace DiscordChatExporter.Cli
{
public static class Program
{
private static readonly Container Container = new Container();
private static CliOptions ParseOptions(string[] args)
{
var argsParser = new FluentCommandLineParser<CliOptions>();
var settings = Container.SettingsService;
argsParser.Setup(o => o.Token).As('t', "token").Required();
argsParser.Setup(o => o.ChannelId).As('c', "channel").Required();
argsParser.Setup(o => o.ExportFormat).As('f', "format").SetDefault(ExportFormat.HtmlDark);
argsParser.Setup(o => o.FilePath).As('o', "output").SetDefault(null);
argsParser.Setup(o => o.From).As("datefrom").SetDefault(null);
argsParser.Setup(o => o.To).As("dateto").SetDefault(null);
argsParser.Setup(o => o.DateFormat).As("dateformat").SetDefault(settings.DateFormat);
argsParser.Setup(o => o.MessageGroupLimit).As("grouplimit").SetDefault(settings.MessageGroupLimit);
var parsed = argsParser.Parse(args);
// Show help if no arguments
if (parsed.EmptyArgs)
{
var version = Assembly.GetExecutingAssembly().GetName().Version;
Console.WriteLine($"=== Discord Chat Exporter (Command Line Interface) v{version} ===");
Console.WriteLine();
Console.WriteLine("[-t] [--token] Discord authorization token.");
Console.WriteLine("[-c] [--channel] Discord channel ID.");
Console.WriteLine("[-f] [--format] Export format (PlainText/HtmlDark/HtmlLight). Optional.");
Console.WriteLine("[-o] [--output] Output file path. Optional.");
Console.WriteLine(" [--datefrom] Limit to messages after this date. Optional.");
Console.WriteLine(" [--dateto] Limit to messages before this date. Optional.");
Console.WriteLine(" [--dateformat] Date format. Optional.");
Console.WriteLine(" [--grouplimit] Message group limit. Optional.");
Environment.Exit(0);
}
// Show error if there are any
else if (parsed.HasErrors)
{
Console.Error.Write(parsed.ErrorText);
Environment.Exit(-1);
}
return argsParser.Object;
}
public static void Main(string[] args)
{
// Init container
Container.Init();
// Parse options
var options = ParseOptions(args);
// Inject some settings
var settings = Container.SettingsService;
settings.DateFormat = options.DateFormat;
settings.MessageGroupLimit = options.MessageGroupLimit;
// Export
var vm = Container.MainViewModel;
vm.ExportAsync(
options.Token,
options.ChannelId,
options.FilePath,
options.ExportFormat,
options.From,
options.To).GetAwaiter().GetResult();
// Cleanup container
Container.Cleanup();
Console.WriteLine("Export complete.");
}
}
}

View file

@ -0,0 +1,12 @@
using System;
using System.Threading.Tasks;
using DiscordChatExporter.Core.Models;
namespace DiscordChatExporter.Cli.ViewModels
{
public interface IMainViewModel
{
Task ExportAsync(string token, string channelId, string filePath, ExportFormat format, DateTime? from,
DateTime? to);
}
}

View file

@ -0,0 +1,53 @@
using System;
using System.IO;
using System.Threading.Tasks;
using DiscordChatExporter.Core.Models;
using DiscordChatExporter.Core.Services;
using Tyrrrz.Extensions;
namespace DiscordChatExporter.Cli.ViewModels
{
public class MainViewModel : IMainViewModel
{
private readonly IDataService _dataService;
private readonly IMessageGroupService _messageGroupService;
private readonly IExportService _exportService;
public MainViewModel(IDataService dataService, IMessageGroupService messageGroupService,
IExportService exportService)
{
_dataService = dataService;
_messageGroupService = messageGroupService;
_exportService = exportService;
}
public async Task ExportAsync(string token, string channelId, string filePath, ExportFormat format, DateTime? from,
DateTime? to)
{
// Get channel and guild
var channel = await _dataService.GetChannelAsync(token, channelId);
var guild = channel.GuildId == Guild.DirectMessages.Id
? Guild.DirectMessages
: await _dataService.GetGuildAsync(token, channel.GuildId);
// Generate file path if not set
if (filePath.IsBlank())
{
filePath = $"{guild} - {channel}.{format.GetFileExtension()}"
.Replace(Path.GetInvalidFileNameChars(), '_');
}
// Get messages
var messages = await _dataService.GetChannelMessagesAsync(token, channelId, from, to);
// Group them
var messageGroups = _messageGroupService.GroupMessages(messages);
// Create log
var log = new ChannelChatLog(guild, channel, messageGroups, messages.Count);
// Export
await _exportService.ExportAsync(format, filePath, log);
}
}
}

View file

@ -0,0 +1,22 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net45</TargetFramework>
</PropertyGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\ExportService\DarkTheme.css" />
<EmbeddedResource Include="Resources\ExportService\LightTheme.css" />
</ItemGroup>
<ItemGroup>
<Reference Include="System.Net.Http" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="Newtonsoft.Json" Version="10.0.3" />
<PackageReference Include="Tyrrrz.Extensions" Version="1.5.0" />
<PackageReference Include="Tyrrrz.Settings" Version="1.3.2" />
</ItemGroup>
</Project>

View file

@ -1,7 +1,7 @@
using System; using System;
using System.Net; using System.Net;
namespace DiscordChatExporter.Exceptions namespace DiscordChatExporter.Core.Exceptions
{ {
public class HttpErrorStatusCodeException : Exception public class HttpErrorStatusCodeException : Exception
{ {

View file

@ -0,0 +1,23 @@
using System.IO;
using System.Reflection;
using System.Resources;
namespace DiscordChatExporter.Core.Internal
{
internal static class AssemblyHelper
{
public static string GetResourceString(string resourcePath)
{
var assembly = Assembly.GetExecutingAssembly();
var stream = assembly.GetManifestResourceStream(resourcePath);
if (stream == null)
throw new MissingManifestResourceException($"Could not find resource [{resourcePath}].");
using (stream)
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public class Attachment public class Attachment
{ {

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public enum AttachmentType public enum AttachmentType
{ {

View file

@ -1,18 +1,21 @@
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public partial class Channel public partial class Channel
{ {
public string Id { get; } public string Id { get; }
public string GuildId { get; }
public string Name { get; } public string Name { get; }
public string Topic { get; } public string Topic { get; }
public ChannelType Type { get; } public ChannelType Type { get; }
public Channel(string id, string name, string topic, ChannelType type) public Channel(string id, string guildId, string name, string topic, ChannelType type)
{ {
Id = id; Id = id;
GuildId = guildId;
Name = name; Name = name;
Topic = topic; Topic = topic;
Type = type; Type = type;
@ -28,7 +31,7 @@
{ {
public static Channel CreateDeletedChannel(string id) public static Channel CreateDeletedChannel(string id)
{ {
return new Channel(id, "deleted-channel", null, ChannelType.GuildTextChat); return new Channel(id, null, "deleted-channel", null, ChannelType.GuildTextChat);
} }
} }
} }

View file

@ -1,6 +1,6 @@
using System.Collections.Generic; using System.Collections.Generic;
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public class ChannelChatLog public class ChannelChatLog
{ {

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public enum ChannelType public enum ChannelType
{ {

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public enum ExportFormat public enum ExportFormat
{ {

View file

@ -1,6 +1,6 @@
using System; using System;
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public static class Extensions public static class Extensions
{ {
@ -13,7 +13,7 @@ namespace DiscordChatExporter.Models
if (format == ExportFormat.HtmlLight) if (format == ExportFormat.HtmlLight)
return "html"; return "html";
throw new NotImplementedException(); throw new ArgumentOutOfRangeException(nameof(format));
} }
public static string GetDisplayName(this ExportFormat format) public static string GetDisplayName(this ExportFormat format)
@ -25,7 +25,7 @@ namespace DiscordChatExporter.Models
if (format == ExportFormat.HtmlLight) if (format == ExportFormat.HtmlLight)
return "HTML (Light)"; return "HTML (Light)";
throw new NotImplementedException(); throw new ArgumentOutOfRangeException(nameof(format));
} }
} }
} }

View file

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using Tyrrrz.Extensions; using Tyrrrz.Extensions;
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public partial class Guild public partial class Guild
{ {

View file

@ -1,12 +1,14 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public class Message public class Message
{ {
public string Id { get; } public string Id { get; }
public string ChannelId { get; }
public MessageType Type { get; } public MessageType Type { get; }
public User Author { get; } public User Author { get; }
@ -25,13 +27,14 @@ namespace DiscordChatExporter.Models
public IReadOnlyList<Channel> MentionedChannels { get; } public IReadOnlyList<Channel> MentionedChannels { get; }
public Message(string id, MessageType type, User author, public Message(string id, string channelId, MessageType type,
DateTime timeStamp, DateTime? editedTimeStamp, User author, DateTime timeStamp,
string content, IReadOnlyList<Attachment> attachments, DateTime? editedTimeStamp, string content,
IReadOnlyList<User> mentionedUsers, IReadOnlyList<Role> mentionedRoles, IReadOnlyList<Attachment> attachments, IReadOnlyList<User> mentionedUsers,
IReadOnlyList<Channel> mentionedChannels) IReadOnlyList<Role> mentionedRoles, IReadOnlyList<Channel> mentionedChannels)
{ {
Id = id; Id = id;
ChannelId = channelId;
Type = type; Type = type;
Author = author; Author = author;
TimeStamp = timeStamp; TimeStamp = timeStamp;

View file

@ -1,7 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public class MessageGroup public class MessageGroup
{ {

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public enum MessageType public enum MessageType
{ {

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public partial class Role public partial class Role
{ {

View file

@ -1,6 +1,6 @@
using Tyrrrz.Extensions; using Tyrrrz.Extensions;
namespace DiscordChatExporter.Models namespace DiscordChatExporter.Core.Models
{ {
public class User public class User
{ {

View file

@ -4,12 +4,12 @@ using System.Linq;
using System.Net.Http; using System.Net.Http;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using DiscordChatExporter.Exceptions; using DiscordChatExporter.Core.Exceptions;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
using Newtonsoft.Json.Linq; using Newtonsoft.Json.Linq;
using Tyrrrz.Extensions; using Tyrrrz.Extensions;
namespace DiscordChatExporter.Services namespace DiscordChatExporter.Core.Services
{ {
public partial class DataService : IDataService, IDisposable public partial class DataService : IDataService, IDisposable
{ {
@ -51,6 +51,7 @@ namespace DiscordChatExporter.Services
{ {
// Get basic data // Get basic data
var id = token["id"].Value<string>(); var id = token["id"].Value<string>();
var guildId = token["guild_id"]?.Value<string>();
var type = (ChannelType) token["type"].Value<int>(); var type = (ChannelType) token["type"].Value<int>();
var topic = token["topic"]?.Value<string>(); var topic = token["topic"]?.Value<string>();
@ -58,6 +59,7 @@ namespace DiscordChatExporter.Services
string name; string name;
if (type.IsEither(ChannelType.DirectTextChat, ChannelType.DirectGroupTextChat)) if (type.IsEither(ChannelType.DirectTextChat, ChannelType.DirectGroupTextChat))
{ {
guildId = Guild.DirectMessages.Id;
var recipients = token["recipients"].Select(ParseUser); var recipients = token["recipients"].Select(ParseUser);
name = recipients.Select(r => r.Name).JoinToString(", "); name = recipients.Select(r => r.Name).JoinToString(", ");
} }
@ -66,13 +68,14 @@ namespace DiscordChatExporter.Services
name = token["name"].Value<string>(); name = token["name"].Value<string>();
} }
return new Channel(id, name, topic, type); return new Channel(id, guildId, name, topic, type);
} }
private Message ParseMessage(JToken token) private Message ParseMessage(JToken token)
{ {
// Get basic data // Get basic data
var id = token["id"].Value<string>(); var id = token["id"].Value<string>();
var channelId = token["channel_id"].Value<string>();
var timeStamp = token["timestamp"].Value<DateTime>(); var timeStamp = token["timestamp"].Value<DateTime>();
var editedTimeStamp = token["edited_timestamp"]?.Value<DateTime?>(); var editedTimeStamp = token["edited_timestamp"]?.Value<DateTime?>();
var content = token["content"].Value<string>(); var content = token["content"].Value<string>();
@ -132,7 +135,7 @@ namespace DiscordChatExporter.Services
.Select(i => _channelCache.GetOrDefault(i) ?? Channel.CreateDeletedChannel(id)) .Select(i => _channelCache.GetOrDefault(i) ?? Channel.CreateDeletedChannel(id))
.ToArray(); .ToArray();
return new Message(id, type, author, timeStamp, editedTimeStamp, content, attachments, return new Message(id, channelId, type, author, timeStamp, editedTimeStamp, content, attachments,
mentionedUsers, mentionedRoles, mentionedChannels); mentionedUsers, mentionedRoles, mentionedChannels);
} }
@ -168,6 +171,23 @@ namespace DiscordChatExporter.Services
return guild; return guild;
} }
public async Task<Channel> GetChannelAsync(string token, string channelId)
{
// Form request url
var url = $"{ApiRoot}/channels/{channelId}?token={token}";
// Get response
var content = await GetStringAsync(url);
// Parse
var channel = ParseChannel(JToken.Parse(content));
// Add channel to cache
_channelCache[channel.Id] = channel;
return channel;
}
public async Task<IReadOnlyList<Channel>> GetGuildChannelsAsync(string token, string guildId) public async Task<IReadOnlyList<Channel>> GetGuildChannelsAsync(string token, string guildId)
{ {
// Form request url // Form request url

View file

@ -4,10 +4,11 @@ using System.Net;
using System.Text; using System.Text;
using System.Text.RegularExpressions; using System.Text.RegularExpressions;
using System.Threading.Tasks; using System.Threading.Tasks;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Internal;
using DiscordChatExporter.Core.Models;
using Tyrrrz.Extensions; using Tyrrrz.Extensions;
namespace DiscordChatExporter.Services namespace DiscordChatExporter.Core.Services
{ {
public partial class ExportService : IExportService public partial class ExportService : IExportService
{ {
@ -179,12 +180,12 @@ namespace DiscordChatExporter.Services
} }
if (format == ExportFormat.HtmlDark) if (format == ExportFormat.HtmlDark)
{ {
var css = Program.GetResourceString("DiscordChatExporter.Resources.ExportService.DarkTheme.css"); var css = AssemblyHelper.GetResourceString("DiscordChatExporter.Core.Resources.ExportService.DarkTheme.css");
return ExportAsHtmlAsync(filePath, log, css); return ExportAsHtmlAsync(filePath, log, css);
} }
if (format == ExportFormat.HtmlLight) if (format == ExportFormat.HtmlLight)
{ {
var css = Program.GetResourceString("DiscordChatExporter.Resources.ExportService.LightTheme.css"); var css = AssemblyHelper.GetResourceString("DiscordChatExporter.Core.Resources.ExportService.LightTheme.css");
return ExportAsHtmlAsync(filePath, log, css); return ExportAsHtmlAsync(filePath, log, css);
} }

View file

@ -1,14 +1,16 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Threading.Tasks; using System.Threading.Tasks;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
namespace DiscordChatExporter.Services namespace DiscordChatExporter.Core.Services
{ {
public interface IDataService public interface IDataService
{ {
Task<Guild> GetGuildAsync(string token, string guildId); Task<Guild> GetGuildAsync(string token, string guildId);
Task<Channel> GetChannelAsync(string token, string channelId);
Task<IReadOnlyList<Channel>> GetGuildChannelsAsync(string token, string guildId); Task<IReadOnlyList<Channel>> GetGuildChannelsAsync(string token, string guildId);
Task<IReadOnlyList<Guild>> GetUserGuildsAsync(string token); Task<IReadOnlyList<Guild>> GetUserGuildsAsync(string token);

View file

@ -1,7 +1,7 @@
using System.Threading.Tasks; using System.Threading.Tasks;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
namespace DiscordChatExporter.Services namespace DiscordChatExporter.Core.Services
{ {
public interface IExportService public interface IExportService
{ {

View file

@ -1,7 +1,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
namespace DiscordChatExporter.Services namespace DiscordChatExporter.Core.Services
{ {
public interface IMessageGroupService public interface IMessageGroupService
{ {

View file

@ -1,6 +1,6 @@
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
namespace DiscordChatExporter.Services namespace DiscordChatExporter.Core.Services
{ {
public interface ISettingsService public interface ISettingsService
{ {

View file

@ -1,8 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
namespace DiscordChatExporter.Services namespace DiscordChatExporter.Core.Services
{ {
public class MessageGroupService : IMessageGroupService public class MessageGroupService : IMessageGroupService
{ {

View file

@ -1,7 +1,7 @@
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
using Tyrrrz.Settings; using Tyrrrz.Settings;
namespace DiscordChatExporter.Services namespace DiscordChatExporter.Core.Services
{ {
public class SettingsService : SettingsManager, ISettingsService public class SettingsService : SettingsManager, ISettingsService
{ {

View file

@ -1,4 +1,4 @@
Application "DiscordChatExporter.App" { Application "DiscordChatExporter.Gui.App" {
StartupUri: "Views/MainWindow.g.xaml" StartupUri: "Views/MainWindow.g.xaml"
Startup: App_Startup Startup: App_Startup
Exit: App_Exit Exit: App_Exit

View file

@ -1,9 +1,11 @@
using System.Windows; using System.Windows;
namespace DiscordChatExporter namespace DiscordChatExporter.Gui
{ {
public partial class App public partial class App
{ {
private Container Container => (Container) Resources["Container"];
private void App_Startup(object sender, StartupEventArgs e) private void App_Startup(object sender, StartupEventArgs e)
{ {
Container.Init(); Container.Init();

View file

@ -1,24 +1,36 @@
using DiscordChatExporter.Services; using DiscordChatExporter.Core.Services;
using DiscordChatExporter.ViewModels; using DiscordChatExporter.Gui.ViewModels;
using GalaSoft.MvvmLight.Ioc; using GalaSoft.MvvmLight.Ioc;
using Microsoft.Practices.ServiceLocation; using Microsoft.Practices.ServiceLocation;
namespace DiscordChatExporter namespace DiscordChatExporter.Gui
{ {
public class Container public class Container
{ {
public static void Init() public IErrorViewModel ErrorViewModel => Resolve<IErrorViewModel>();
public IExportDoneViewModel ExportDoneViewModel => Resolve<IExportDoneViewModel>();
public IExportSetupViewModel ExportSetupViewModel => Resolve<IExportSetupViewModel>();
public IMainViewModel MainViewModel => Resolve<IMainViewModel>();
public ISettingsViewModel SettingsViewModel => Resolve<ISettingsViewModel>();
private T Resolve<T>(string key = null)
{
return ServiceLocator.Current.GetInstance<T>(key);
}
public void Init()
{ {
ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default);
SimpleIoc.Default.Reset();
// Settings
SimpleIoc.Default.Register<ISettingsService, SettingsService>();
ServiceLocator.Current.GetInstance<ISettingsService>().Load();
// Services // Services
SimpleIoc.Default.Register<IDataService, DataService>(); SimpleIoc.Default.Register<IDataService, DataService>();
SimpleIoc.Default.Register<IExportService, ExportService>(); SimpleIoc.Default.Register<IExportService, ExportService>();
SimpleIoc.Default.Register<IMessageGroupService, MessageGroupService>(); SimpleIoc.Default.Register<IMessageGroupService, MessageGroupService>();
SimpleIoc.Default.Register<ISettingsService, SettingsService>();
// Load settings
Resolve<ISettingsService>().Load();
// View models // View models
SimpleIoc.Default.Register<IErrorViewModel, ErrorViewModel>(true); SimpleIoc.Default.Register<IErrorViewModel, ErrorViewModel>(true);
@ -28,16 +40,10 @@ namespace DiscordChatExporter
SimpleIoc.Default.Register<ISettingsViewModel, SettingsViewModel>(true); SimpleIoc.Default.Register<ISettingsViewModel, SettingsViewModel>(true);
} }
public static void Cleanup() public void Cleanup()
{ {
// Settings // Save settings
ServiceLocator.Current.GetInstance<ISettingsService>().Save(); ServiceLocator.Current.GetInstance<ISettingsService>().Save();
} }
public IErrorViewModel ErrorViewModel => ServiceLocator.Current.GetInstance<IErrorViewModel>();
public IExportDoneViewModel ExportDoneViewModel => ServiceLocator.Current.GetInstance<IExportDoneViewModel>();
public IExportSetupViewModel ExportSetupViewModel => ServiceLocator.Current.GetInstance<IExportSetupViewModel>();
public IMainViewModel MainViewModel => ServiceLocator.Current.GetInstance<IMainViewModel>();
public ISettingsViewModel SettingsViewModel => ServiceLocator.Current.GetInstance<ISettingsViewModel>();
} }
} }

View file

@ -6,7 +6,7 @@
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{732A67AF-93DE-49DF-B10F-FD74710B7863}</ProjectGuid> <ProjectGuid>{732A67AF-93DE-49DF-B10F-FD74710B7863}</ProjectGuid>
<OutputType>WinExe</OutputType> <OutputType>WinExe</OutputType>
<RootNamespace>DiscordChatExporter</RootNamespace> <RootNamespace>DiscordChatExporter.Gui</RootNamespace>
<AssemblyName>DiscordChatExporter</AssemblyName> <AssemblyName>DiscordChatExporter</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion> <TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment> <FileAlignment>512</FileAlignment>
@ -38,10 +38,17 @@
<PropertyGroup> <PropertyGroup>
<ApplicationIcon>..\favicon.ico</ApplicationIcon> <ApplicationIcon>..\favicon.ico</ApplicationIcon>
</PropertyGroup> </PropertyGroup>
<PropertyGroup>
<StartupObject />
</PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="AmmySidekick, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7c1296d24569a67d, processorArchitecture=MSIL"> <Reference Include="AmmySidekick, Version=1.0.0.0, Culture=neutral, PublicKeyToken=7c1296d24569a67d, processorArchitecture=MSIL">
<HintPath>..\packages\Ammy.WPF.1.2.87\lib\net40\AmmySidekick.dll</HintPath> <HintPath>..\packages\Ammy.WPF.1.2.87\lib\net40\AmmySidekick.dll</HintPath>
</Reference> </Reference>
<Reference Include="Costura, Version=1.6.2.0, Culture=neutral, PublicKeyToken=9919ef960d84173d, processorArchitecture=MSIL">
<HintPath>..\packages\Costura.Fody.1.6.2\lib\dotnet\Costura.dll</HintPath>
<Private>False</Private>
</Reference>
<Reference Include="GalaSoft.MvvmLight, Version=5.3.0.19026, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL"> <Reference Include="GalaSoft.MvvmLight, Version=5.3.0.19026, Culture=neutral, PublicKeyToken=e7570ab207bcb616, processorArchitecture=MSIL">
<HintPath>..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.dll</HintPath> <HintPath>..\packages\MvvmLightLibs.5.3.0.0\lib\net45\GalaSoft.MvvmLight.dll</HintPath>
</Reference> </Reference>
@ -60,9 +67,6 @@
<Reference Include="Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL"> <Reference Include="Microsoft.Practices.ServiceLocation, Version=1.3.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
<HintPath>..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll</HintPath> <HintPath>..\packages\CommonServiceLocator.1.3\lib\portable-net4+sl5+netcore45+wpa81+wp8\Microsoft.Practices.ServiceLocation.dll</HintPath>
</Reference> </Reference>
<Reference Include="Newtonsoft.Json, Version=10.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.10.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" /> <Reference Include="System" />
<Reference Include="System.Core" /> <Reference Include="System.Core" />
<Reference Include="System.Net.Http" /> <Reference Include="System.Net.Http" />
@ -73,32 +77,19 @@
<RequiredTargetFramework>4.0</RequiredTargetFramework> <RequiredTargetFramework>4.0</RequiredTargetFramework>
</Reference> </Reference>
<Reference Include="System.Xml" /> <Reference Include="System.Xml" />
<Reference Include="Tyrrrz.Extensions, Version=1.4.1.0, Culture=neutral, processorArchitecture=MSIL"> <Reference Include="Tyrrrz.Extensions, Version=1.5.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Tyrrrz.Extensions.1.4.1\lib\net45\Tyrrrz.Extensions.dll</HintPath> <HintPath>..\packages\Tyrrrz.Extensions.1.5.0\lib\net45\Tyrrrz.Extensions.dll</HintPath>
</Reference>
<Reference Include="Tyrrrz.Settings, Version=1.3.0.0, Culture=neutral, processorArchitecture=MSIL">
<HintPath>..\packages\Tyrrrz.Settings.1.3.0\lib\net45\Tyrrrz.Settings.dll</HintPath>
</Reference> </Reference>
<Reference Include="WindowsBase" /> <Reference Include="WindowsBase" />
<Reference Include="PresentationCore" /> <Reference Include="PresentationCore" />
<Reference Include="PresentationFramework" /> <Reference Include="PresentationFramework" />
</ItemGroup> </ItemGroup>
<ItemGroup> <ItemGroup>
<Compile Include="Exceptions\HttpErrorStatusCodeException.cs" />
<Compile Include="Messages\ShowErrorMessage.cs" /> <Compile Include="Messages\ShowErrorMessage.cs" />
<Compile Include="Messages\ShowExportDoneMessage.cs" /> <Compile Include="Messages\ShowExportDoneMessage.cs" />
<Compile Include="Messages\ShowExportSetupMessage.cs" /> <Compile Include="Messages\ShowExportSetupMessage.cs" />
<Compile Include="Messages\ShowSettingsMessage.cs" /> <Compile Include="Messages\ShowSettingsMessage.cs" />
<Compile Include="Messages\StartExportMessage.cs" /> <Compile Include="Messages\StartExportMessage.cs" />
<Compile Include="Models\AttachmentType.cs" />
<Compile Include="Models\ChannelChatLog.cs" />
<Compile Include="Models\ChannelType.cs" />
<Compile Include="Models\ExportFormat.cs" />
<Compile Include="Models\Extensions.cs" />
<Compile Include="Models\Role.cs" />
<Compile Include="Models\MessageType.cs" />
<Compile Include="Services\IMessageGroupService.cs" />
<Compile Include="Services\MessageGroupService.cs" />
<Compile Include="ViewModels\ErrorViewModel.cs" /> <Compile Include="ViewModels\ErrorViewModel.cs" />
<Compile Include="ViewModels\ExportSetupViewModel.cs" /> <Compile Include="ViewModels\ExportSetupViewModel.cs" />
<Compile Include="ViewModels\IErrorViewModel.cs" /> <Compile Include="ViewModels\IErrorViewModel.cs" />
@ -148,19 +139,7 @@
<DependentUpon>App.ammy</DependentUpon> <DependentUpon>App.ammy</DependentUpon>
</Compile> </Compile>
<Compile Include="Container.cs" /> <Compile Include="Container.cs" />
<Compile Include="Models\Attachment.cs" />
<Compile Include="Models\Channel.cs" />
<Compile Include="Models\Guild.cs" />
<Compile Include="Models\Message.cs" />
<Compile Include="Models\MessageGroup.cs" />
<Compile Include="Models\User.cs" />
<Compile Include="Program.cs" /> <Compile Include="Program.cs" />
<Compile Include="Services\DataService.cs" />
<Compile Include="Services\ExportService.cs" />
<Compile Include="Services\IDataService.cs" />
<Compile Include="Services\IExportService.cs" />
<Compile Include="Services\ISettingsService.cs" />
<Compile Include="Services\SettingsService.cs" />
<Compile Include="ViewModels\IMainViewModel.cs" /> <Compile Include="ViewModels\IMainViewModel.cs" />
<Compile Include="ViewModels\MainViewModel.cs" /> <Compile Include="ViewModels\MainViewModel.cs" />
<Compile Include="Views\MainWindow.ammy.cs"> <Compile Include="Views\MainWindow.ammy.cs">
@ -196,16 +175,18 @@
<None Include="Views\MainWindow.ammy" /> <None Include="Views\MainWindow.ammy" />
<None Include="Views\SettingsDialog.ammy" /> <None Include="Views\SettingsDialog.ammy" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="Resources\ExportService\DarkTheme.css" />
<EmbeddedResource Include="Resources\ExportService\LightTheme.css" />
</ItemGroup>
<ItemGroup> <ItemGroup>
<Resource Include="..\favicon.ico" /> <Resource Include="..\favicon.ico" />
</ItemGroup> </ItemGroup>
<ItemGroup>
<ProjectReference Include="..\DiscordChatExporter.Core\DiscordChatExporter.Core.csproj">
<Project>{707c0cd0-a7e0-4cab-8db9-07a45cb87377}</Project>
<Name>DiscordChatExporter.Core</Name>
</ProjectReference>
</ItemGroup>
<ItemGroup>
<None Include="FodyWeavers.xml" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Import Project="..\packages\Ammy.1.2.87\build\Ammy.targets" Condition="Exists('..\packages\Ammy.1.2.87\build\Ammy.targets')" /> <Import Project="..\packages\Ammy.1.2.87\build\Ammy.targets" Condition="Exists('..\packages\Ammy.1.2.87\build\Ammy.targets')" />
<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild"> <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
@ -213,5 +194,9 @@
<ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText> <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
</PropertyGroup> </PropertyGroup>
<Error Condition="!Exists('..\packages\Ammy.1.2.87\build\Ammy.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Ammy.1.2.87\build\Ammy.targets'))" /> <Error Condition="!Exists('..\packages\Ammy.1.2.87\build\Ammy.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Ammy.1.2.87\build\Ammy.targets'))" />
<Error Condition="!Exists('..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets'))" />
<Error Condition="!Exists('..\packages\Fody.2.3.18\build\Fody.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Fody.2.3.18\build\Fody.targets'))" />
</Target> </Target>
<Import Project="..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets" Condition="Exists('..\packages\Costura.Fody.1.6.2\build\dotnet\Costura.Fody.targets')" />
<Import Project="..\packages\Fody.2.3.18\build\Fody.targets" Condition="Exists('..\packages\Fody.2.3.18\build\Fody.targets')" />
</Project> </Project>

View file

@ -0,0 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<Weavers>
<Costura />
</Weavers>

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.Messages namespace DiscordChatExporter.Gui.Messages
{ {
public class ShowErrorMessage public class ShowErrorMessage
{ {

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.Messages namespace DiscordChatExporter.Gui.Messages
{ {
public class ShowExportDoneMessage public class ShowExportDoneMessage
{ {

View file

@ -1,6 +1,6 @@
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
namespace DiscordChatExporter.Messages namespace DiscordChatExporter.Gui.Messages
{ {
public class ShowExportSetupMessage public class ShowExportSetupMessage
{ {

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.Messages namespace DiscordChatExporter.Gui.Messages
{ {
public class ShowSettingsMessage public class ShowSettingsMessage
{ {

View file

@ -1,7 +1,7 @@
using System; using System;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
namespace DiscordChatExporter.Messages namespace DiscordChatExporter.Gui.Messages
{ {
public class StartExportMessage public class StartExportMessage
{ {

View file

@ -0,0 +1,17 @@
using System;
using AmmySidekick;
namespace DiscordChatExporter.Gui
{
public static class Program
{
[STAThread]
public static void Main()
{
var app = new App();
app.InitializeComponent();
RuntimeUpdateHandler.Register(app, $"/{Ammy.GetAssemblyName(app)};component/App.g.xaml");
app.Run();
}
}
}

View file

@ -8,10 +8,10 @@
// </auto-generated> // </auto-generated>
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
namespace DiscordChatExporter.Properties namespace DiscordChatExporter.Gui.Properties {
{ using System;
/// <summary> /// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc. /// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary> /// </summary>
@ -19,51 +19,43 @@ namespace DiscordChatExporter.Properties
// class via a tool like ResGen or Visual Studio. // class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen // To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project. // with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "15.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()] [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Resources internal class Resources {
{
private static global::System.Resources.ResourceManager resourceMan; private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture; private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Resources() internal Resources() {
{
} }
/// <summary> /// <summary>
/// Returns the cached ResourceManager instance used by this class. /// Returns the cached ResourceManager instance used by this class.
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager internal static global::System.Resources.ResourceManager ResourceManager {
{ get {
get if (object.ReferenceEquals(resourceMan, null)) {
{ global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DiscordChatExporter.Gui.Properties.Resources", typeof(Resources).Assembly);
if ((resourceMan == null))
{
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("DiscordChatExporter.Properties.Resources", typeof(Resources).Assembly);
resourceMan = temp; resourceMan = temp;
} }
return resourceMan; return resourceMan;
} }
} }
/// <summary> /// <summary>
/// Overrides the current thread's CurrentUICulture property for all /// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class. /// resource lookups using this strongly typed resource class.
/// </summary> /// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture internal static global::System.Globalization.CultureInfo Culture {
{ get {
get
{
return resourceCulture; return resourceCulture;
} }
set set {
{
resourceCulture = value; resourceCulture = value;
} }
} }

View file

@ -1,7 +1,7 @@
using DiscordChatExporter.Messages; using DiscordChatExporter.Gui.Messages;
using GalaSoft.MvvmLight; using GalaSoft.MvvmLight;
namespace DiscordChatExporter.ViewModels namespace DiscordChatExporter.Gui.ViewModels
{ {
public class ErrorViewModel : ViewModelBase, IErrorViewModel public class ErrorViewModel : ViewModelBase, IErrorViewModel
{ {

View file

@ -1,9 +1,9 @@
using System.Diagnostics; using System.Diagnostics;
using DiscordChatExporter.Messages; using DiscordChatExporter.Gui.Messages;
using GalaSoft.MvvmLight; using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf; using GalaSoft.MvvmLight.CommandWpf;
namespace DiscordChatExporter.ViewModels namespace DiscordChatExporter.Gui.ViewModels
{ {
public class ExportDoneViewModel : ViewModelBase, IExportDoneViewModel public class ExportDoneViewModel : ViewModelBase, IExportDoneViewModel
{ {

View file

@ -2,14 +2,14 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
using DiscordChatExporter.Messages; using DiscordChatExporter.Core.Models;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Services;
using DiscordChatExporter.Services; using DiscordChatExporter.Gui.Messages;
using GalaSoft.MvvmLight; using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf; using GalaSoft.MvvmLight.CommandWpf;
using Tyrrrz.Extensions; using Tyrrrz.Extensions;
namespace DiscordChatExporter.ViewModels namespace DiscordChatExporter.Gui.ViewModels
{ {
public class ExportSetupViewModel : ViewModelBase, IExportSetupViewModel public class ExportSetupViewModel : ViewModelBase, IExportSetupViewModel
{ {

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.ViewModels namespace DiscordChatExporter.Gui.ViewModels
{ {
public interface IErrorViewModel public interface IErrorViewModel
{ {

View file

@ -1,6 +1,6 @@
using GalaSoft.MvvmLight.CommandWpf; using GalaSoft.MvvmLight.CommandWpf;
namespace DiscordChatExporter.ViewModels namespace DiscordChatExporter.Gui.ViewModels
{ {
public interface IExportDoneViewModel public interface IExportDoneViewModel
{ {

View file

@ -1,9 +1,9 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
using GalaSoft.MvvmLight.CommandWpf; using GalaSoft.MvvmLight.CommandWpf;
namespace DiscordChatExporter.ViewModels namespace DiscordChatExporter.Gui.ViewModels
{ {
public interface IExportSetupViewModel public interface IExportSetupViewModel
{ {

View file

@ -1,8 +1,8 @@
using System.Collections.Generic; using System.Collections.Generic;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
using GalaSoft.MvvmLight.CommandWpf; using GalaSoft.MvvmLight.CommandWpf;
namespace DiscordChatExporter.ViewModels namespace DiscordChatExporter.Gui.ViewModels
{ {
public interface IMainViewModel public interface IMainViewModel
{ {

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.ViewModels namespace DiscordChatExporter.Gui.ViewModels
{ {
public interface ISettingsViewModel public interface ISettingsViewModel
{ {

View file

@ -3,15 +3,15 @@ using System.Collections.Generic;
using System.Diagnostics; using System.Diagnostics;
using System.Linq; using System.Linq;
using System.Net; using System.Net;
using DiscordChatExporter.Exceptions; using DiscordChatExporter.Core.Exceptions;
using DiscordChatExporter.Messages; using DiscordChatExporter.Core.Models;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Services;
using DiscordChatExporter.Services; using DiscordChatExporter.Gui.Messages;
using GalaSoft.MvvmLight; using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.CommandWpf; using GalaSoft.MvvmLight.CommandWpf;
using Tyrrrz.Extensions; using Tyrrrz.Extensions;
namespace DiscordChatExporter.ViewModels namespace DiscordChatExporter.Gui.ViewModels
{ {
public class MainViewModel : ViewModelBase, IMainViewModel public class MainViewModel : ViewModelBase, IMainViewModel
{ {

View file

@ -1,8 +1,8 @@
using DiscordChatExporter.Services; using DiscordChatExporter.Core.Services;
using GalaSoft.MvvmLight; using GalaSoft.MvvmLight;
using Tyrrrz.Extensions; using Tyrrrz.Extensions;
namespace DiscordChatExporter.ViewModels namespace DiscordChatExporter.Gui.ViewModels
{ {
public class SettingsViewModel : ViewModelBase, ISettingsViewModel public class SettingsViewModel : ViewModelBase, ISettingsViewModel
{ {

View file

@ -1,6 +1,6 @@
using MaterialDesignThemes.Wpf using MaterialDesignThemes.Wpf
UserControl "DiscordChatExporter.Views.ErrorDialog" { UserControl "DiscordChatExporter.Gui.Views.ErrorDialog" {
DataContext: bind ErrorViewModel from $resource Container DataContext: bind ErrorViewModel from $resource Container
Width: 250 Width: 250

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.Views namespace DiscordChatExporter.Gui.Views
{ {
public partial class ErrorDialog public partial class ErrorDialog
{ {

View file

@ -1,6 +1,6 @@
using MaterialDesignThemes.Wpf using MaterialDesignThemes.Wpf
UserControl "DiscordChatExporter.Views.ExportDoneDialog" { UserControl "DiscordChatExporter.Gui.Views.ExportDoneDialog" {
DataContext: bind ExportDoneViewModel from $resource Container DataContext: bind ExportDoneViewModel from $resource Container
Width: 250 Width: 250

View file

@ -1,7 +1,7 @@
using System.Windows; using System.Windows;
using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf;
namespace DiscordChatExporter.Views namespace DiscordChatExporter.Gui.Views
{ {
public partial class ExportDoneDialog public partial class ExportDoneDialog
{ {

View file

@ -1,7 +1,7 @@
using DiscordChatExporter.Models using DiscordChatExporter.Core.Models
using MaterialDesignThemes.Wpf using MaterialDesignThemes.Wpf
UserControl "DiscordChatExporter.Views.ExportSetupDialog" { UserControl "DiscordChatExporter.Gui.Views.ExportSetupDialog" {
DataContext: bind ExportSetupViewModel from $resource Container DataContext: bind ExportSetupViewModel from $resource Container
Width: 325 Width: 325

View file

@ -1,10 +1,10 @@
using System.Windows; using System.Windows;
using DiscordChatExporter.Models; using DiscordChatExporter.Core.Models;
using DiscordChatExporter.ViewModels; using DiscordChatExporter.Gui.ViewModels;
using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf;
using Microsoft.Win32; using Microsoft.Win32;
namespace DiscordChatExporter.Views namespace DiscordChatExporter.Gui.Views
{ {
public partial class ExportSetupDialog public partial class ExportSetupDialog
{ {

View file

@ -1,7 +1,7 @@
using MaterialDesignThemes.Wpf using MaterialDesignThemes.Wpf
using MaterialDesignThemes.Wpf.Transitions using MaterialDesignThemes.Wpf.Transitions
Window "DiscordChatExporter.Views.MainWindow" { Window "DiscordChatExporter.Gui.Views.MainWindow" {
Title: "DiscordChatExporter" Title: "DiscordChatExporter"
Width: 600 Width: 600
Height: 550 Height: 550

View file

@ -1,10 +1,10 @@
using System.Reflection; using System.Reflection;
using DiscordChatExporter.Messages; using DiscordChatExporter.Gui.Messages;
using GalaSoft.MvvmLight.Messaging; using GalaSoft.MvvmLight.Messaging;
using MaterialDesignThemes.Wpf; using MaterialDesignThemes.Wpf;
using Tyrrrz.Extensions; using Tyrrrz.Extensions;
namespace DiscordChatExporter.Views namespace DiscordChatExporter.Gui.Views
{ {
public partial class MainWindow public partial class MainWindow
{ {

View file

@ -1,6 +1,6 @@
using MaterialDesignThemes.Wpf using MaterialDesignThemes.Wpf
UserControl "DiscordChatExporter.Views.SettingsDialog" { UserControl "DiscordChatExporter.Gui.Views.SettingsDialog" {
DataContext: bind SettingsViewModel from $resource Container DataContext: bind SettingsViewModel from $resource Container
Width: 250 Width: 250

View file

@ -1,4 +1,4 @@
namespace DiscordChatExporter.Views namespace DiscordChatExporter.Gui.Views
{ {
public partial class SettingsDialog public partial class SettingsDialog
{ {

View file

@ -3,10 +3,10 @@
<package id="Ammy" version="1.2.87" targetFramework="net461" /> <package id="Ammy" version="1.2.87" targetFramework="net461" />
<package id="Ammy.WPF" version="1.2.87" targetFramework="net461" /> <package id="Ammy.WPF" version="1.2.87" targetFramework="net461" />
<package id="CommonServiceLocator" version="1.3" targetFramework="net461" /> <package id="CommonServiceLocator" version="1.3" targetFramework="net461" />
<package id="Costura.Fody" version="1.6.2" targetFramework="net461" developmentDependency="true" />
<package id="Fody" version="2.3.18" targetFramework="net461" developmentDependency="true" />
<package id="MaterialDesignColors" version="1.1.3" targetFramework="net461" /> <package id="MaterialDesignColors" version="1.1.3" targetFramework="net461" />
<package id="MaterialDesignThemes" version="2.3.1.953" targetFramework="net461" /> <package id="MaterialDesignThemes" version="2.3.1.953" targetFramework="net461" />
<package id="MvvmLightLibs" version="5.3.0.0" targetFramework="net461" /> <package id="MvvmLightLibs" version="5.3.0.0" targetFramework="net461" />
<package id="Newtonsoft.Json" version="10.0.3" targetFramework="net461" /> <package id="Tyrrrz.Extensions" version="1.5.0" targetFramework="net461" />
<package id="Tyrrrz.Extensions" version="1.4.1" targetFramework="net461" />
<package id="Tyrrrz.Settings" version="1.3.0" targetFramework="net461" />
</packages> </packages>

View file

@ -1,7 +1,7 @@
 
Microsoft Visual Studio Solution File, Format Version 12.00 Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 15 # Visual Studio 15
VisualStudioVersion = 15.0.26730.15 VisualStudioVersion = 15.0.27130.2010
MinimumVisualStudioVersion = 10.0.40219.1 MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EA305DD5-1F98-415D-B6C4-65053A58F914}" Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{EA305DD5-1F98-415D-B6C4-65053A58F914}"
ProjectSection(SolutionItems) = preProject ProjectSection(SolutionItems) = preProject
@ -9,7 +9,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
Readme.md = Readme.md Readme.md = Readme.md
EndProjectSection EndProjectSection
EndProject EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscordChatExporter", "DiscordChatExporter\DiscordChatExporter.csproj", "{732A67AF-93DE-49DF-B10F-FD74710B7863}" Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscordChatExporter.Gui", "DiscordChatExporter.Gui\DiscordChatExporter.Gui.csproj", "{732A67AF-93DE-49DF-B10F-FD74710B7863}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscordChatExporter.Core", "DiscordChatExporter.Core\DiscordChatExporter.Core.csproj", "{707C0CD0-A7E0-4CAB-8DB9-07A45CB87377}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "DiscordChatExporter.Cli", "DiscordChatExporter.Cli\DiscordChatExporter.Cli.csproj", "{D08624B6-3081-4BCB-91F8-E9832FACC6CE}"
EndProject EndProject
Global Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution GlobalSection(SolutionConfigurationPlatforms) = preSolution
@ -21,6 +25,14 @@ Global
{732A67AF-93DE-49DF-B10F-FD74710B7863}.Debug|Any CPU.Build.0 = Debug|Any CPU {732A67AF-93DE-49DF-B10F-FD74710B7863}.Debug|Any CPU.Build.0 = Debug|Any CPU
{732A67AF-93DE-49DF-B10F-FD74710B7863}.Release|Any CPU.ActiveCfg = Release|Any CPU {732A67AF-93DE-49DF-B10F-FD74710B7863}.Release|Any CPU.ActiveCfg = Release|Any CPU
{732A67AF-93DE-49DF-B10F-FD74710B7863}.Release|Any CPU.Build.0 = Release|Any CPU {732A67AF-93DE-49DF-B10F-FD74710B7863}.Release|Any CPU.Build.0 = Release|Any CPU
{707C0CD0-A7E0-4CAB-8DB9-07A45CB87377}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{707C0CD0-A7E0-4CAB-8DB9-07A45CB87377}.Debug|Any CPU.Build.0 = Debug|Any CPU
{707C0CD0-A7E0-4CAB-8DB9-07A45CB87377}.Release|Any CPU.ActiveCfg = Release|Any CPU
{707C0CD0-A7E0-4CAB-8DB9-07A45CB87377}.Release|Any CPU.Build.0 = Release|Any CPU
{D08624B6-3081-4BCB-91F8-E9832FACC6CE}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D08624B6-3081-4BCB-91F8-E9832FACC6CE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D08624B6-3081-4BCB-91F8-E9832FACC6CE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D08624B6-3081-4BCB-91F8-E9832FACC6CE}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection EndGlobalSection
GlobalSection(SolutionProperties) = preSolution GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE HideSolutionNode = FALSE

View file

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" />
</startup>
</configuration>

View file

@ -1,36 +0,0 @@
using System;
using System.IO;
using System.Reflection;
using System.Resources;
using AmmySidekick;
namespace DiscordChatExporter
{
public static class Program
{
[STAThread]
public static void Main()
{
var app = new App();
app.InitializeComponent();
RuntimeUpdateHandler.Register(app, $"/{Ammy.GetAssemblyName(app)};component/App.g.xaml");
app.Run();
}
public static string GetResourceString(string resourcePath)
{
var assembly = Assembly.GetExecutingAssembly();
var stream = assembly.GetManifestResourceStream(resourcePath);
if (stream == null)
throw new MissingManifestResourceException("Could not find resource");
using (stream)
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}

View file

@ -19,6 +19,7 @@ DiscordChatExporter can be used to export message history from a [Discord](https
## Features ## Features
- Intuitive GUI that displays available guilds and channels - Intuitive GUI that displays available guilds and channels
- Command line interface
- Date ranges to limit messages - Date ranges to limit messages
- Groups messages by author and time - Groups messages by author and time
- Exports to a plain text file - Exports to a plain text file