From ee86365e274c3a60dee88aaf22a1e020d1d9ba7d Mon Sep 17 00:00:00 2001 From: Florian Stinglmayr Date: Wed, 25 Aug 2021 16:36:57 +0200 Subject: [PATCH] move journal handling to a library --- App.xaml.cs | 9 +- BGS/Cartographics.cs | 8 +- BGS/CombatZone.cs | 8 +- BGS/DiscordLogGenerator.cs | 8 +- BGS/LogEntry.cs | 4 +- BGS/MissionCompleted.cs | 9 +- BGS/NonaDiscordLog.cs | 4 +- BGS/Report.cs | 6 +- BGS/SellMicroResources.cs | 2 +- BGS/Vouchers.cs | 2 +- Journal/Credits.cs | 18 --- Journal/DockedEntry.cs | 13 -- Journal/EliteDangerous.cs | 15 --- Journal/Entry.cs | 95 ------------- Journal/Events.cs | 17 --- Journal/FSDJumpEntry.cs | 23 ---- Journal/JournalException.cs | 11 -- Journal/JournalFile.cs | 119 ----------------- Journal/JournalStream.cs | 87 ------------ Journal/MarketSellEntry.cs | 17 --- Journal/MissionCompletedEntry.cs | 162 ----------------------- Journal/MultiSellExplorationDataEntry.cs | 17 --- Journal/PlayerJournal.cs | 58 -------- Journal/RedeemVoucherEntry.cs | 19 --- Journal/SellMicroResourcesEntry.cs | 17 --- MainWindow.xaml.cs | 3 +- nonabgs.csproj | 18 +-- 27 files changed, 17 insertions(+), 752 deletions(-) delete mode 100644 Journal/Credits.cs delete mode 100644 Journal/DockedEntry.cs delete mode 100644 Journal/EliteDangerous.cs delete mode 100644 Journal/Entry.cs delete mode 100644 Journal/Events.cs delete mode 100644 Journal/FSDJumpEntry.cs delete mode 100644 Journal/JournalException.cs delete mode 100644 Journal/JournalFile.cs delete mode 100644 Journal/JournalStream.cs delete mode 100644 Journal/MarketSellEntry.cs delete mode 100644 Journal/MissionCompletedEntry.cs delete mode 100644 Journal/MultiSellExplorationDataEntry.cs delete mode 100644 Journal/PlayerJournal.cs delete mode 100644 Journal/RedeemVoucherEntry.cs delete mode 100644 Journal/SellMicroResourcesEntry.cs diff --git a/App.xaml.cs b/App.xaml.cs index e7ace89..595adb8 100644 --- a/App.xaml.cs +++ b/App.xaml.cs @@ -1,11 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Configuration; -using System.Data; -using System.Linq; -using System.Threading.Tasks; -using System.Windows; -using NonaBGS.Journal; +using System.Windows; namespace NonaBGS { diff --git a/BGS/Cartographics.cs b/BGS/Cartographics.cs index 14f3d7e..57f4fd6 100644 --- a/BGS/Cartographics.cs +++ b/BGS/Cartographics.cs @@ -1,10 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Linq; +using System.Linq; using System.Text; -using System.Globalization; -using System.Threading.Tasks; -using NonaBGS.Journal; +using EDJournal; namespace NonaBGS.BGS { public class Cartographics : LogEntry { diff --git a/BGS/CombatZone.cs b/BGS/CombatZone.cs index 4c009fa..97abf21 100644 --- a/BGS/CombatZone.cs +++ b/BGS/CombatZone.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NonaBGS.BGS { +namespace NonaBGS.BGS { public class CombatZone { private int level; } diff --git a/BGS/DiscordLogGenerator.cs b/BGS/DiscordLogGenerator.cs index 40974e2..ba620de 100644 --- a/BGS/DiscordLogGenerator.cs +++ b/BGS/DiscordLogGenerator.cs @@ -1,10 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NonaBGS.BGS { +namespace NonaBGS.BGS { public interface IDiscordLogGenerator { string GenerateDiscordLog(Report report); } diff --git a/BGS/LogEntry.cs b/BGS/LogEntry.cs index bc31f7c..4f1c6a7 100644 --- a/BGS/LogEntry.cs +++ b/BGS/LogEntry.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using NonaBGS.Journal; +using EDJournal; namespace NonaBGS.BGS { public class LogEntry : IComparable { diff --git a/BGS/MissionCompleted.cs b/BGS/MissionCompleted.cs index 3e29a24..bbbf20f 100644 --- a/BGS/MissionCompleted.cs +++ b/BGS/MissionCompleted.cs @@ -1,10 +1,5 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using NonaBGS.Journal; -using Newtonsoft.Json.Linq; +using System.Text; +using EDJournal; namespace NonaBGS.BGS { public class MissionCompleted : LogEntry { diff --git a/BGS/NonaDiscordLog.cs b/BGS/NonaDiscordLog.cs index 7d3a34f..9a7d619 100644 --- a/BGS/NonaDiscordLog.cs +++ b/BGS/NonaDiscordLog.cs @@ -2,9 +2,7 @@ using System.Collections.Generic; using System.Linq; using System.Text; -using System.Globalization; -using System.Threading.Tasks; -using NonaBGS.Journal; +using EDJournal; namespace NonaBGS.BGS { public class NonaDiscordLog : IDiscordLogGenerator { diff --git a/BGS/Report.cs b/BGS/Report.cs index 1924e09..3e7fe6e 100644 --- a/BGS/Report.cs +++ b/BGS/Report.cs @@ -1,11 +1,7 @@ using System; -using System.ComponentModel; using System.Collections.Generic; -using System.Collections.Specialized; using System.Linq; -using System.Text; -using System.Threading.Tasks; -using NonaBGS.Journal; +using EDJournal; namespace NonaBGS.BGS { public class Report { diff --git a/BGS/SellMicroResources.cs b/BGS/SellMicroResources.cs index ebb3277..ab52099 100644 --- a/BGS/SellMicroResources.cs +++ b/BGS/SellMicroResources.cs @@ -1,5 +1,5 @@ using System.Linq; -using NonaBGS.Journal; +using EDJournal; namespace NonaBGS.BGS { public class SellMicroResources : LogEntry { diff --git a/BGS/Vouchers.cs b/BGS/Vouchers.cs index a457596..5f79fd7 100644 --- a/BGS/Vouchers.cs +++ b/BGS/Vouchers.cs @@ -1,6 +1,6 @@ using System.Linq; using System.Globalization; -using NonaBGS.Journal; +using EDJournal; namespace NonaBGS.BGS { public class Vouchers : LogEntry { diff --git a/Journal/Credits.cs b/Journal/Credits.cs deleted file mode 100644 index 7b8f7ed..0000000 --- a/Journal/Credits.cs +++ /dev/null @@ -1,18 +0,0 @@ -using System.Globalization; - -namespace NonaBGS.Journal { - public class Credits { - public static string FormatCredits(int amount) { - var format = CultureInfo.CurrentCulture.NumberFormat; - if ((amount % 1000000) == 0) { - amount /= 1000000; - return string.Format("{0}M CR", amount.ToString(format)); - } else if ((amount % 1000) == 0) { - amount /= 1000; - return string.Format("{0}K CR", amount.ToString(format)); - } - - return string.Format("{0} CR", amount.ToString(format)); - } - } -} diff --git a/Journal/DockedEntry.cs b/Journal/DockedEntry.cs deleted file mode 100644 index 40bbdd8..0000000 --- a/Journal/DockedEntry.cs +++ /dev/null @@ -1,13 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NonaBGS.Journal { - public class DockedEntry : Entry { - public string StationName { - get { return JSON.GetValue("StationName").ToString(); } - } - } -} diff --git a/Journal/EliteDangerous.cs b/Journal/EliteDangerous.cs deleted file mode 100644 index 3e99fcd..0000000 --- a/Journal/EliteDangerous.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NonaBGS.Journal { - public class EliteDangerous { - /// - /// The ingame universe is 1286 years in the future. This is needed to convert dates - /// and times to ingame dates and times - /// - public static readonly int YearOffset = 1286; - } -} diff --git a/Journal/Entry.cs b/Journal/Entry.cs deleted file mode 100644 index d6c3c15..0000000 --- a/Journal/Entry.cs +++ /dev/null @@ -1,95 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace NonaBGS.Journal { - /// - /// Base class for a single entry within the player journal. If no specific sub class is available - /// this class gives basic information, such as EventType or date when it happened. It also allows - /// base classes access to the underlying JSON object. Base classes should be named after the event - /// type that they map + Entry. So "FSDJump" event is handled by FSDJumpEntry. - /// - public class Entry { - private static readonly Dictionary classes = new Dictionary { - { Events.Docked, typeof(DockedEntry) }, - { Events.FSDJump, typeof(FSDJumpEntry) }, - { Events.MissionCompleted, typeof(MissionCompletedEntry) }, - { Events.MultiSellExplorationData, typeof(MultiSellExplorationDataEntry) }, - { Events.MarketSell, typeof(MarketSellEntry) }, - { Events.SellMicroResources, typeof(SellMicroResourcesEntry) }, - { Events.RedeemVoucher, typeof(RedeemVoucherEntry) }, - }; - - private string eventtype = null; - private string datetime = null; - private DateTime timestamp; - - private string jsonstr = null; - protected JObject json = null; - - public Entry() { - } - - public static Entry Parse(string journalline) { - var json = JObject.Parse(journalline); - return Parse(json); - } - - public static Entry Parse(JObject json) { - string event_name = json.GetValue("event").ToString(); - - classes.TryGetValue(event_name, out Type classhandler); - if (classhandler == null) { - classhandler = typeof(Entry); - } - - var obj = (Entry)Activator.CreateInstance(classhandler); - obj.InternalInitialise(json); - obj.Initialise(); - return obj; - } - - private void InternalInitialise(JObject jobject) { - this.json = jobject; - this.jsonstr = json.ToString(formatting: Formatting.None); - - this.eventtype = json.GetValue("event").ToString(); - this.datetime = json.GetValue("timestamp").ToString(); - this.timestamp = DateTime.Parse(this.datetime); - } - - protected virtual void Initialise() { - } - - public bool Is(string eventtype) { - if (eventtype == null || this.eventtype == null) { - return false; - } - - return String.Equals(this.eventtype, eventtype, StringComparison.OrdinalIgnoreCase); - } - - public string Event { - get { return eventtype; } - } - - public DateTime Timestamp { - get { return timestamp; } - } - - public JObject JSON { - get { return this.json; } - } - - public override string ToString() { - if (json == null) { - return ""; - } - return json.ToString(); - } - } -} diff --git a/Journal/Events.cs b/Journal/Events.cs deleted file mode 100644 index 3c93a33..0000000 --- a/Journal/Events.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NonaBGS.Journal { - public class Events { - public static readonly string MissionCompleted = "MissionCompleted"; - public static readonly string Docked = "Docked"; - public static readonly string FSDJump = "FSDJump"; - public static readonly string MultiSellExplorationData = "MultiSellExplorationData"; - public static readonly string MarketSell = "MarketSell"; - public static readonly string SellMicroResources = "SellMicroResources"; - public static readonly string RedeemVoucher = "RedeemVoucher"; - } -} diff --git a/Journal/FSDJumpEntry.cs b/Journal/FSDJumpEntry.cs deleted file mode 100644 index 42a8322..0000000 --- a/Journal/FSDJumpEntry.cs +++ /dev/null @@ -1,23 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json.Linq; - -namespace NonaBGS.Journal { - public class FSDJumpEntry : Entry { - private string starsystem = null; - private string systemfaction = null; - protected override void Initialise() { - starsystem = JSON.Value("StarSystem"); - var faction = JSON.Value("SystemFaction"); - if (faction != null) { - systemfaction = faction.Value("Name"); - } - } - public string StarSystem => starsystem; - - public string SystemFaction => systemfaction; - } -} diff --git a/Journal/JournalException.cs b/Journal/JournalException.cs deleted file mode 100644 index 179298b..0000000 --- a/Journal/JournalException.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading.Tasks; - -namespace NonaBGS.Journal { - public class JournalException : Exception { - public JournalException(string message) : base(message) { - } - } -} diff --git a/Journal/JournalFile.cs b/Journal/JournalFile.cs deleted file mode 100644 index dc10c9b..0000000 --- a/Journal/JournalFile.cs +++ /dev/null @@ -1,119 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Text.RegularExpressions; -using System.IO; -using System.Globalization; - -namespace NonaBGS.Journal -{ - public class JournalFile : IComparable - { - private string fullpath = null; - private string part = null; - private int intpart = 0; - private DateTime datetime; - private DateTime normalised; - private List entries = new List(); - - private static Regex fileregex = new Regex("Journal\\.(\\d+)\\.(\\d+)\\.log"); - private static string iso8601 = "yyyyMMddTHHmmss"; - private static string iso8601_notime = "yyyyMMdd"; - - public static bool VerifyFile(string path) { - string filename = Path.GetFileName(path); - - var matches = fileregex.Matches(filename); - return matches.Count != 0; - } - - private void SetFilename(string path) { - string filename = Path.GetFileName(path); - if (!File.Exists(path) || filename == null) { - throw new JournalException(string.Format("Invalid journal file: {0}", filename)); - } - - var matches = fileregex.Matches(filename); - if (matches.Count < 1) { - throw new JournalException(string.Format("Invalid journal file: {0}", filename)); - } - - this.fullpath = path; - this.part = matches[0].Groups[2].ToString(); - this.intpart = int.Parse(part); - // The ISO is not quite correct on journal filenames, so build - // a proper ISO 8601 date time stamp out of it. - var date = new StringBuilder(); - date.Append("20"); // Add the missing century in front. - date.Append(matches[0].Groups[1].ToString()); - date.Insert(8, "T"); // Add the "T" separating date and time - this.datetime = DateTime.ParseExact(date.ToString(), iso8601, CultureInfo.InvariantCulture); - this.normalised = DateTime.Parse(this.datetime.ToShortDateString()); - } - - public int CompareTo(JournalFile other) { - if (datetime == null || other.datetime == null) { - return 0; - } - var comp = DateTime.Compare(datetime, other.datetime); - if (comp == 0) { - /* If we have the exact same datetime we compare by parts. - */ - return intpart - other.intpart; - } else { - return comp; - } - } - - public JournalFile(string path) { - SetFilename(path); - } - - public DateTime Timestamp { - get { return datetime; } - } - - public DateTime NormalisedTimestamp { - get { return normalised; } - } - - public int Part { - get { return intpart; } - } - - public IEnumerable Entries { - get { - if (entries == null || entries.Count == 0) { - try { - LoadEntries(); - } catch (IOException) { - entries = new List(); - } - } - return entries; - } - } - - public void LoadEntries() { - List lines = new List(); - - /* This needs to be done this way, otherwise, if the game is still running the journal files cannot - * be accessed. And it is very much convenient to generate logs while the game is still running. - */ - using (var fs = new FileStream(this.fullpath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) { - using (var sr = new StreamReader(fs, Encoding.UTF8)) { - string line = null; - while ((line = sr.ReadLine()) != null) { - lines.Add(line); - } - } - } - - entries.Clear(); - foreach(var line in lines) { - Entry entry = Entry.Parse(line); - entries.Add(entry); - } - } - } -} diff --git a/Journal/JournalStream.cs b/Journal/JournalStream.cs deleted file mode 100644 index 4d76a1e..0000000 --- a/Journal/JournalStream.cs +++ /dev/null @@ -1,87 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using NonaBGS.Journal; -using System.IO; - -namespace NonaBGS.Journal { - public class JournalStream { - private PlayerJournal journal = null; - private FileSystemWatcher watcher = null; - - private Dictionary streams = new Dictionary(); - - public delegate void NewJournalEntryDelegate(Entry entry); - - public event NewJournalEntryDelegate NewJournalEntry; - - public PlayerJournal Journal { - get => journal; - set => journal = value; - } - - public JournalStream() { - } - - public JournalStream(PlayerJournal journal) { - this.journal = journal; - Open(); - } - - public void Open() { - if (watcher != null) { - return; - } - - watcher = new FileSystemWatcher(journal.Location); - - watcher.NotifyFilter = NotifyFilters.FileName | - NotifyFilters.LastWrite | - NotifyFilters.Size; - - watcher.Changed += Watcher_Changed; - watcher.Created += Watcher_Created; - - watcher.Filter = "*.log"; - watcher.EnableRaisingEvents = true; - } - - public void Close() { - if (watcher != null) { - watcher.EnableRaisingEvents = false; - } - watcher = null; - streams.Clear(); - } - - private void Watcher_Created(object sender, FileSystemEventArgs e) { - if (!streams.ContainsKey(e.FullPath) && JournalFile.VerifyFile(e.FullPath)) { - streams[e.FullPath] = new StreamReader(e.FullPath); - } - } - - private void Watcher_Changed(object sender, FileSystemEventArgs e) { - if (!streams.ContainsKey(e.FullPath) && JournalFile.VerifyFile(e.FullPath)) { - var filestream = new FileStream(e.FullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); - streams[e.FullPath] = new StreamReader(filestream); - } - - var stream = streams[e.FullPath]; - if (stream == null) { - return; - } - - string line; - - while ((line = stream.ReadLine()) != null) { - try { - Entry entry = Entry.Parse(line); - NewJournalEntry?.Invoke(entry); - } catch (Exception) { - } - } - } - } -} diff --git a/Journal/MarketSellEntry.cs b/Journal/MarketSellEntry.cs deleted file mode 100644 index 0551aae..0000000 --- a/Journal/MarketSellEntry.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NonaBGS.Journal { - public class MarketSellEntry : Entry { - private int totalsale = 0; - - protected override void Initialise() { - totalsale = JSON.Value("TotalSale"); - } - - public int TotalSale => totalsale; - } -} diff --git a/Journal/MissionCompletedEntry.cs b/Journal/MissionCompletedEntry.cs deleted file mode 100644 index 2dce31c..0000000 --- a/Journal/MissionCompletedEntry.cs +++ /dev/null @@ -1,162 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using Newtonsoft.Json; -using Newtonsoft.Json.Linq; - -namespace NonaBGS.Journal { - public class MissionCompletedEntry : Entry { - private Dictionary influences = new Dictionary(); - private string readable_name = null; - private bool readable_name_generated = false; - private string name = null; - private string commodity = null; - private int count = 0; - private int donated = 0; - - /* TODO: make this a file at some point for easier editing. - */ - private static readonly Dictionary humanreadable = new Dictionary { - { "Mission_AltruismCredits_name", "Donate Credits" }, - { "Mission_AltruismCredits_Bust_name", "Donate Credits (Bust)" }, - { "Mission_Collect_name", "Provide" }, - { "Mission_Collect_Bust_name", "Provide (Bust)" }, - { "Mission_Collect_CivilLiberty_name", "Provide (Civil Liberty)" }, - { "Mission_Collect_Famine_name", "Provide (Famine)" }, - { "Mission_Courier_Democracy_name", "Courier (Democracy)" }, - { "Mission_Courier_Elections_name", "Courier (Elections)" }, - { "Mission_Courier_Famine_name", "Courier (Famine)" }, - { "Mission_Courier_Lockdown_name", "Courier (Lockdown)" }, - { "Mission_Courier_name", "Courier" }, - { "Mission_Courier_RankEmp_name", "Courier (Empire)" }, - { "Mission_Delivery_Boom_name", "Delivery (Boom)" }, - { "Mission_Delivery_Retreat_name", "Delivery (Retreat)" }, - { "Mission_Delivery_name", "Delivery" }, - { "Mission_Delivery_Agriculture_name", "Delivery (Agriculture)" }, - { "Mission_Delivery_RankEmp_name", "Delivery (Imperial Rank)" }, - { "Mission_HackMegaship_name", "Hack Megaship" }, - { "Mission_Hack_BLOPS_Boom_name", "Hack Megaship (Black Ops)" }, - { "Mission_MassacreWing_name", "Massacre (Wing)" }, - { "Mission_Massacre_RankEmp_name", "Massacre (Imperial Navy)" }, - { "Mission_OnFoot_Collect_MB_name", "On Foot Collection" }, - { "Mission_OnFoot_Onslaught_MB_name", "On Foot Onslaught" }, - { "Mission_OnFoot_Onslaught_Offline_MB_name", "On Foot Onslaught (Offline)" }, - { "Mission_OnFoot_RebootRestore_MB_name", "On Foot Reboot/Restore" }, - { "Mission_OnFoot_Reboot_MB_name", "On Foot Reboot" }, - { "Mission_OnFoot_Salvage_MB_name", "On Foot Salvage" }, - { "Mission_Rescue_Planet_name", "Planet Rescue" }, - { "Mission_Salvage_name", "Salvage" }, - { "MISSION_Salvage_CivilUnrest_name", "Salvage (Civil Unrest)" }, - { "MISSION_Salvage_Illegal_name", "Salvage (Illegal)" }, - { "MISSION_Salvage_Retreat_name", "Salvage (Retreat)" }, - { "MISSION_Salvage_Expansion_name", "Salvage (Expansion)" }, - { "Mission_Salvage_RankEmp_name", "Salvage (Imperial Navy)" }, - { "MISSION_Scan_name", "Scan" }, - }; - - protected override void Initialise() { - MakeHumanReadableName(); - name = JSON.Value("Name"); - if (JSON.ContainsKey("Commodity_Localised")) { - commodity = JSON.Value("Commodity_Localised"); - } - if (JSON.ContainsKey("Count")) { - count = JSON.Value("Count"); - } - if (JSON.ContainsKey("Donated")) { - donated = JSON.Value("Donated"); - } - } - - public string Name => name; - public string Commodity => commodity; - public int Count => count; - - private void MakeHumanReadableName() { - if (readable_name != null && readable_name.Length > 0) { - return; - } - - if (Name == null) { - return; - } - - StringBuilder builder; - - if (humanreadable.ContainsKey(Name)) { - builder = new StringBuilder(humanreadable[Name]); - readable_name_generated = false; - } else { - builder = new StringBuilder(Name); - builder.Replace("Mission_", ""); - builder.Replace("_name", ""); - builder.Replace("_MB", ""); - builder.Replace('_', ' '); - builder.Replace("Illegal", " (Illegal)"); - builder.Replace("OnFoot", "On Foot"); - builder.Replace(" BS", ""); - builder.Replace("HackMegaship", "Hack Megaship"); - builder.Replace("Boom", ""); - builder.Replace("RebootRestore", "Reboot/Restore"); - builder.Replace("CivilLiberty", ""); - readable_name_generated = true; - } - - if (count > 0 && commodity != null) { - builder.AppendFormat(" ({0} {1})", count, commodity); - } - - if (donated > 0) { - builder.AppendFormat(" ({0})", Credits.FormatCredits(donated)); - } - - readable_name = builder.ToString().Trim(); - } - - public string HumanReadableName { - get { - MakeHumanReadableName(); - return readable_name; - } - } - - public bool HumanReadableNameWasGenerated { - get { - MakeHumanReadableName(); - return readable_name_generated; - } - } - - public string GetInfluenceForFaction(string faction) { - if (influences.ContainsKey(faction)) { - return influences[faction]; - } - - var effects = JSON.Value("FactionEffects"); - foreach (var effect in effects.Children()) { - if (effect.GetValue("Faction").ToString() != faction) { - continue; - } - - var influence = effect.Value("Influence"); - if (influence == null || influence.Count == 0) { - // No influence reward, happens on courier missions sometimes. - // There is always one point of rep, even if the mission won't state it - influences.Add(faction, "+"); - } - - foreach (var infl in influence.Children()) { - infl.TryGetValue("Influence", out JToken result); - if (result != null && result.Type == JTokenType.String) { - influences.Add(faction, result.ToString()); - return result.ToString(); - } - } - } - - return ""; - } - } -} diff --git a/Journal/MultiSellExplorationDataEntry.cs b/Journal/MultiSellExplorationDataEntry.cs deleted file mode 100644 index 139a546..0000000 --- a/Journal/MultiSellExplorationDataEntry.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NonaBGS.Journal { - public class MultiSellExplorationDataEntry : Entry { - private int totalearnings = 0; - - protected override void Initialise() { - totalearnings = JSON.Value("TotalEarnings"); - } - - public int TotalEarnings => totalearnings; - } -} diff --git a/Journal/PlayerJournal.cs b/Journal/PlayerJournal.cs deleted file mode 100644 index 850ae30..0000000 --- a/Journal/PlayerJournal.cs +++ /dev/null @@ -1,58 +0,0 @@ -using System; -using System.Collections.Generic; -using System.IO; -using System.Text; -using System.Threading.Tasks; - -namespace NonaBGS.Journal { - public class PlayerJournal { - public static string DefaultPath = "%UserProfile%\\Saved Games\\Frontier Developments\\Elite Dangerous"; - - private List journalfiles = new List(); - private string basepath = null; - - public string Location => basepath; - - public PlayerJournal() { - Initialise(DefaultPath); - } - - public PlayerJournal(string path) { - Initialise(path); - } - - private void Initialise(string path) { - basepath = Environment.ExpandEnvironmentVariables(path); - } - - public List Files { - get { return journalfiles; } - } - - public void Open() { - if (!Directory.Exists(basepath)) { - throw new JournalException("Invalid base path, path could not be found"); - } - this.ScanFiles(); - } - - public void ScanFiles() { - var files = Directory.EnumerateFiles(basepath); - - journalfiles.Clear(); - - foreach (var file in files) { - string full = Path.Combine(basepath, file); - try { - JournalFile journalfile = new JournalFile(full); - journalfiles.Add(journalfile); - } catch (JournalException) { - /* invalid journal file, or one of the other json files in there */ - continue; - } - } - - journalfiles.Sort(); - } - } -} diff --git a/Journal/RedeemVoucherEntry.cs b/Journal/RedeemVoucherEntry.cs deleted file mode 100644 index f172359..0000000 --- a/Journal/RedeemVoucherEntry.cs +++ /dev/null @@ -1,19 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NonaBGS.Journal { - public class RedeemVoucherEntry : Entry { - private int amount = 0; - private string type = null; - protected override void Initialise() { - amount = JSON.Value("Amount"); - type = JSON.Value("Type"); - } - - public int Amount => amount; - public string Type => type; - } -} diff --git a/Journal/SellMicroResourcesEntry.cs b/Journal/SellMicroResourcesEntry.cs deleted file mode 100644 index dc23bda..0000000 --- a/Journal/SellMicroResourcesEntry.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; - -namespace NonaBGS.Journal { - public class SellMicroResourcesEntry : Entry { - private int price; - - protected override void Initialise() { - price = JSON.Value("Price"); - } - - public int Price => price; - } -} diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs index 1127140..e56d84a 100644 --- a/MainWindow.xaml.cs +++ b/MainWindow.xaml.cs @@ -5,7 +5,8 @@ using System.Windows.Controls; using System.Windows.Input; using Ookii.Dialogs.Wpf; -using NonaBGS.Journal; +using EDJournal; + using NonaBGS.BGS; using NonaBGS.Util; using NonaBGS.EDDB; diff --git a/nonabgs.csproj b/nonabgs.csproj index 8630c45..ba234d2 100644 --- a/nonabgs.csproj +++ b/nonabgs.csproj @@ -41,6 +41,9 @@ packages\AutoCompleteTextBox.1.1.1\lib\net472\AutoCompleteTextBox.dll + + ..\edjournal\bin\Debug\netcoreapp3.1\EDJournal.dll + packages\Newtonsoft.Json.13.0.1\lib\net45\Newtonsoft.Json.dll @@ -75,13 +78,6 @@ - - - - - - - @@ -104,15 +100,7 @@ - - - - - - - - MainWindow.xaml Code