97 lines
2.5 KiB
C#
97 lines
2.5 KiB
C#
using System;
|
|
using System.Linq;
|
|
using System.Collections.Generic;
|
|
using System.IO;
|
|
using Avalonia;
|
|
using Avalonia.Controls;
|
|
using Avalonia.Interactivity;
|
|
using Avalonia.Input;
|
|
using EDPlayerJournal.Entries;
|
|
using EliteBGS.Util;
|
|
using EDPlayerJournal.BGS;
|
|
|
|
namespace EliteBGS;
|
|
|
|
/// <summary>
|
|
/// Interaction logic for LoadEntriesWindow.xaml
|
|
/// </summary>
|
|
public partial class LoadEntriesWindow : Window {
|
|
public delegate void EntriesLoadedDelegate(List<Entry> entries);
|
|
|
|
public event EntriesLoadedDelegate EntriesLoaded;
|
|
|
|
Config config = new Config();
|
|
|
|
public LoadEntriesWindow() {
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void Load_Click(object sender, RoutedEventArgs e) {
|
|
string lines = Lines.Text.Trim();
|
|
if (lines.Length <= 0) {
|
|
return;
|
|
}
|
|
|
|
try {
|
|
List<Entry> entries = new List<Entry>();
|
|
|
|
foreach (string line in lines.Split('\n')) {
|
|
if (string.IsNullOrEmpty(line)) {
|
|
continue;
|
|
}
|
|
Entry entry = Entry.Parse(line);
|
|
entries.Add(entry);
|
|
}
|
|
|
|
if (entries.Count > 0) {
|
|
EntriesLoaded?.Invoke(entries);
|
|
}
|
|
} catch (Exception exception) {
|
|
// TODO: MessageBox
|
|
}
|
|
}
|
|
|
|
private void Clear_Click(object sender, RoutedEventArgs e) {
|
|
Lines.Clear();
|
|
}
|
|
|
|
private void LoadFile_Click(object sender, RoutedEventArgs e) {
|
|
// TODO: OpenFileDialog
|
|
}
|
|
|
|
private void DeleteUnimportant_Click(object sender, RoutedEventArgs e) {
|
|
string lines = Lines.Text.Trim();
|
|
if (lines.Length <= 0) {
|
|
return;
|
|
}
|
|
|
|
TransactionParser parser = new();
|
|
|
|
try {
|
|
List<Entry> entries = new List<Entry>();
|
|
|
|
foreach (string line in lines.Split('\n')) {
|
|
if (string.IsNullOrEmpty(line)) {
|
|
continue;
|
|
}
|
|
Entry entry = Entry.Parse(line);
|
|
if (parser.IsRelevant(entry)) {
|
|
entries.Add(entry);
|
|
}
|
|
}
|
|
|
|
if (entries.Count <= 0) {
|
|
return;
|
|
}
|
|
|
|
string[] text = entries
|
|
.ConvertAll(x => x.JSON.ToString(Newtonsoft.Json.Formatting.None))
|
|
.ToArray()
|
|
;
|
|
Lines.Text = string.Join("\n", text).Trim();
|
|
} catch (Exception exception) {
|
|
// TODO: MessageBox
|
|
}
|
|
}
|
|
}
|