Add project files.
This commit is contained in:
13
Journal/DockedEntry.cs
Normal file
13
Journal/DockedEntry.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
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(); }
|
||||
}
|
||||
}
|
||||
}
|
||||
15
Journal/EliteDangerous.cs
Normal file
15
Journal/EliteDangerous.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace NonaBGS.Journal {
|
||||
public class EliteDangerous {
|
||||
/// <summary>
|
||||
/// The ingame universe is 1286 years in the future. This is needed to convert dates
|
||||
/// and times to ingame dates and times
|
||||
/// </summary>
|
||||
public static readonly int YearOffset = 1286;
|
||||
}
|
||||
}
|
||||
88
Journal/Entry.cs
Normal file
88
Journal/Entry.cs
Normal file
@@ -0,0 +1,88 @@
|
||||
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 {
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
public class Entry {
|
||||
private static readonly Dictionary<string, Type> classes = new Dictionary<string, Type> {
|
||||
{ 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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Journal/Events.cs
Normal file
17
Journal/Events.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
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";
|
||||
}
|
||||
}
|
||||
23
Journal/FSDJumpEntry.cs
Normal file
23
Journal/FSDJumpEntry.cs
Normal file
@@ -0,0 +1,23 @@
|
||||
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<string>("StarSystem");
|
||||
var faction = JSON.Value<JObject>("SystemFaction");
|
||||
if (faction != null) {
|
||||
systemfaction = faction.Value<string>("Name");
|
||||
}
|
||||
}
|
||||
public string StarSystem => starsystem;
|
||||
|
||||
public string SystemFaction => systemfaction;
|
||||
}
|
||||
}
|
||||
11
Journal/JournalException.cs
Normal file
11
Journal/JournalException.cs
Normal file
@@ -0,0 +1,11 @@
|
||||
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) {
|
||||
}
|
||||
}
|
||||
}
|
||||
112
Journal/JournalFile.cs
Normal file
112
Journal/JournalFile.cs
Normal file
@@ -0,0 +1,112 @@
|
||||
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<JournalFile>
|
||||
{
|
||||
private string fullpath = null;
|
||||
private string part = null;
|
||||
private int intpart = 0;
|
||||
private DateTime datetime;
|
||||
private DateTime normalised;
|
||||
private List<Entry> entries = new List<Entry>();
|
||||
|
||||
private static Regex fileregex = new Regex("Journal\\.(\\d+)\\.(\\d+)\\.log");
|
||||
private static string iso8601 = "yyyyMMddTHHmmss";
|
||||
private static string iso8601_notime = "yyyyMMdd";
|
||||
|
||||
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<Entry> Entries {
|
||||
get {
|
||||
if (entries == null || entries.Count == 0) {
|
||||
try {
|
||||
LoadEntries();
|
||||
} catch (IOException) {
|
||||
entries = new List<Entry>();
|
||||
}
|
||||
}
|
||||
return entries;
|
||||
}
|
||||
}
|
||||
|
||||
public void LoadEntries() {
|
||||
List<string> lines = new List<string>();
|
||||
|
||||
/* 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Journal/MarketSellEntry.cs
Normal file
17
Journal/MarketSellEntry.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
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<int>("TotalSale");
|
||||
}
|
||||
|
||||
public int TotalSale => totalsale;
|
||||
}
|
||||
}
|
||||
146
Journal/MissionCompletedEntry.cs
Normal file
146
Journal/MissionCompletedEntry.cs
Normal file
@@ -0,0 +1,146 @@
|
||||
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<string, string> influences = new Dictionary<string, string>();
|
||||
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;
|
||||
|
||||
private readonly Dictionary<string, string> humanreadable = new Dictionary<string, string> {
|
||||
{ "Mission_AltruismCredits_name", "Donate Credits" },
|
||||
{ "Mission_Collect_name", "Collect" },
|
||||
{ "Mission_Courier_Elections_name", "Courier (Elections)" },
|
||||
{ "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_HackMegaship_name", "Hack Megaship" },
|
||||
{ "Mission_MassacreWing_name", "Massacre (Wing)" },
|
||||
{ "Mission_OnFoot_Onslaught_MB_name", "On Foot Onslaught" },
|
||||
{ "Mission_OnFoot_RebootRestore_MB_name", "On Foot Reboot/Restore" },
|
||||
{ "Mission_OnFoot_Reboot_MB_name", "On Foot Reboot" },
|
||||
{ "Mission_Rescue_Planet_name", "Planet Rescue" },
|
||||
{ "Mission_Salvage_name", "Salvage" },
|
||||
{ "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<string>("Name");
|
||||
if (JSON.ContainsKey("Commodity_Localised")) {
|
||||
commodity = JSON.Value<string>("Commodity_Localised");
|
||||
}
|
||||
if (JSON.ContainsKey("Count")) {
|
||||
count = JSON.Value<int>("Count");
|
||||
}
|
||||
if (JSON.ContainsKey("Donated")) {
|
||||
donated = JSON.Value<int>("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} CR)", 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<JArray>("FactionEffects");
|
||||
foreach (var effect in effects.Children<JObject>()) {
|
||||
if (effect.GetValue("Faction").ToString() != faction) {
|
||||
continue;
|
||||
}
|
||||
|
||||
var influence = effect.Value<JArray>("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<JObject>()) {
|
||||
infl.TryGetValue("Influence", out JToken result);
|
||||
if (result != null && result.Type == JTokenType.String) {
|
||||
influences.Add(faction, result.ToString());
|
||||
return result.ToString();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return "";
|
||||
}
|
||||
}
|
||||
}
|
||||
17
Journal/MultiSellExplorationDataEntry.cs
Normal file
17
Journal/MultiSellExplorationDataEntry.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
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<int>("TotalEarnings");
|
||||
}
|
||||
|
||||
public int TotalEarnings => totalearnings;
|
||||
}
|
||||
}
|
||||
56
Journal/PlayerJournal.cs
Normal file
56
Journal/PlayerJournal.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
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<JournalFile> journalfiles = new List<JournalFile>();
|
||||
private string basepath = null;
|
||||
|
||||
public PlayerJournal() {
|
||||
Initialise(DefaultPath);
|
||||
}
|
||||
|
||||
public PlayerJournal(string path) {
|
||||
Initialise(path);
|
||||
}
|
||||
|
||||
private void Initialise(string path) {
|
||||
basepath = Environment.ExpandEnvironmentVariables(path);
|
||||
}
|
||||
|
||||
public List<JournalFile> 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();
|
||||
}
|
||||
}
|
||||
}
|
||||
19
Journal/RedeemVoucherEntry.cs
Normal file
19
Journal/RedeemVoucherEntry.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
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<int>("Amount");
|
||||
type = JSON.Value<string>("Type");
|
||||
}
|
||||
|
||||
public int Amount => amount;
|
||||
public string Type => type;
|
||||
}
|
||||
}
|
||||
17
Journal/SellMicroResourcesEntry.cs
Normal file
17
Journal/SellMicroResourcesEntry.cs
Normal file
@@ -0,0 +1,17 @@
|
||||
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<int>("Price");
|
||||
}
|
||||
|
||||
public int Price => price;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user