Add project files.
This commit is contained in:
70
EDPlayerJournal/BGS/BuyCargo.cs
Normal file
70
EDPlayerJournal/BGS/BuyCargo.cs
Normal file
@@ -0,0 +1,70 @@
|
||||
using System.Text;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
|
||||
public class BuyCargo : Transaction {
|
||||
public BuyCargo() { }
|
||||
|
||||
public BuyCargo(MarketBuyEntry e) {
|
||||
Entries.Add(e);
|
||||
}
|
||||
|
||||
public string? Cargo {
|
||||
get {
|
||||
string? cargo;
|
||||
var sell = Entries.OfType<MarketBuyEntry>().First();
|
||||
|
||||
if (!string.IsNullOrEmpty(sell.TypeLocalised)) {
|
||||
cargo = sell.TypeLocalised;
|
||||
} else {
|
||||
cargo = sell.Type;
|
||||
if (cargo != null && cargo.Length >= 2) {
|
||||
cargo = cargo[0].ToString().ToUpper() + cargo.Substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
return cargo;
|
||||
}
|
||||
}
|
||||
|
||||
public long Amount {
|
||||
get { return Entries.OfType<MarketBuyEntry>().Sum(x => x.Count); }
|
||||
}
|
||||
|
||||
public override int CompareTo(Transaction? other) {
|
||||
if (other == null || other.GetType() != typeof(BuyCargo)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
BuyCargo? buycargo = other as BuyCargo;
|
||||
if (buycargo != null &&
|
||||
buycargo.Cargo == Cargo &&
|
||||
buycargo.System == System &&
|
||||
buycargo.Faction == Faction) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (Entries.Count <= 0) {
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
builder.AppendFormat("Bought {0} {1} at the Commodity Market",
|
||||
Amount,
|
||||
Cargo
|
||||
);
|
||||
|
||||
return builder.ToString().Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selling resources to a market only helps the controlling faction
|
||||
/// </summary>
|
||||
public override bool OnlyControllingFaction => true;
|
||||
}
|
||||
56
EDPlayerJournal/BGS/Cartographics.cs
Normal file
56
EDPlayerJournal/BGS/Cartographics.cs
Normal file
@@ -0,0 +1,56 @@
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
|
||||
public class Cartographics : Transaction {
|
||||
public Cartographics(MultiSellExplorationDataEntry e) {
|
||||
Entries.Add(e);
|
||||
}
|
||||
|
||||
public Cartographics(SellExplorationDataEntry e) {
|
||||
Entries.Add(e);
|
||||
}
|
||||
|
||||
public override int CompareTo(Transaction? other) {
|
||||
if (other == null || other.GetType() != typeof(Cartographics)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Cartographics? b = other as Cartographics;
|
||||
if (b != null &&
|
||||
b.System == System &&
|
||||
b.Faction == Faction &&
|
||||
b.Station == Station) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public long TotalSum {
|
||||
get {
|
||||
/* add multi sell and normal ones together */
|
||||
long total =
|
||||
Entries.OfType<MultiSellExplorationDataEntry>()
|
||||
.Sum(x => x.TotalEarnings)
|
||||
+
|
||||
Entries.OfType<SellExplorationDataEntry>()
|
||||
.Sum(x => x.TotalEarnings)
|
||||
;
|
||||
return total;
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
builder.AppendFormat("Sold {0} worth of Cartographics Data", Credits.FormatCredits(TotalSum));
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Cartographics only help the controlling faction.
|
||||
/// </summary>
|
||||
public override bool OnlyControllingFaction => true;
|
||||
}
|
||||
42
EDPlayerJournal/BGS/CombatZone.cs
Normal file
42
EDPlayerJournal/BGS/CombatZone.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using System;
|
||||
using System.Linq;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
public class CombatZone : Transaction {
|
||||
public string Type { get; set; } = "";
|
||||
public string Grade { get; set; } = "";
|
||||
public int Amount { get; set; } = 0;
|
||||
public DateTime Completed { get; set; } = DateTime.UtcNow;
|
||||
|
||||
public override string CompletedAt {
|
||||
get {
|
||||
return Completed.ToString("dd.MM.yyyy HH:mm UTC");
|
||||
}
|
||||
}
|
||||
|
||||
public override int CompareTo(Transaction? obj) {
|
||||
if (obj == null || obj.GetType() != typeof(CombatZone)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
CombatZone? b = obj as CombatZone;
|
||||
if (b == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (b.Faction != Faction || b.System != System) {
|
||||
return -1; // System and faction don't match
|
||||
}
|
||||
|
||||
if (b.Type != b.Type || b.Grade != b.Grade) {
|
||||
return -1; // grade and type don't match
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format("Won {0} x {1} {2} Combat Zone(s) for {3}",
|
||||
Amount, Grade, Type, Faction);
|
||||
}
|
||||
}
|
||||
42
EDPlayerJournal/BGS/FactionKillBonds.cs
Normal file
42
EDPlayerJournal/BGS/FactionKillBonds.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
public class FactionKillBonds : Transaction {
|
||||
public int TotalSum {
|
||||
get {
|
||||
return Entries
|
||||
.OfType<FactionKillBondEntry>()
|
||||
.Sum(x => x.Reward)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public string? VictimFaction {
|
||||
get {
|
||||
return Entries
|
||||
.OfType<FactionKillBondEntry>()
|
||||
.First()
|
||||
.VictimFaction
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public override int CompareTo(Transaction? other) {
|
||||
if (other == null || other.GetType() != typeof(FactionKillBonds)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FactionKillBonds? b = other as FactionKillBonds;
|
||||
if (b == null || b.VictimFaction == VictimFaction) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format("Faction Kill Bonds: {0} against {1}",
|
||||
Credits.FormatCredits(TotalSum),
|
||||
VictimFaction);
|
||||
}
|
||||
}
|
||||
66
EDPlayerJournal/BGS/FoulMurder.cs
Normal file
66
EDPlayerJournal/BGS/FoulMurder.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using System.Text;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
|
||||
/// <summary>
|
||||
/// 36 Lessons of Vivec, Sermon Thirty Six
|
||||
/// </summary>
|
||||
public class FoulMurder : Transaction {
|
||||
public FoulMurder() { }
|
||||
public FoulMurder (CommitCrimeEntry e) {
|
||||
Entries.Add(e);
|
||||
}
|
||||
|
||||
public string? CrimeType {
|
||||
get { return Entries.OfType<CommitCrimeEntry>().First().CrimeType; }
|
||||
}
|
||||
|
||||
public long Bounties => Entries.OfType<CommitCrimeEntry>().Sum(x => x.Bounty);
|
||||
|
||||
public long Fines => Entries.OfType<CommitCrimeEntry>().Sum(x => x.Fine);
|
||||
|
||||
public override int CompareTo(Transaction? other) {
|
||||
if (other == null || other.GetType() != typeof(FoulMurder)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
FoulMurder? hortator = other as FoulMurder;
|
||||
if (hortator != null &&
|
||||
Faction == hortator.Faction &&
|
||||
CrimeType == hortator.CrimeType) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
string type;
|
||||
|
||||
if (CrimeType == CrimeTypes.Murder) {
|
||||
if (Entries.Count > 1) {
|
||||
type = "ships";
|
||||
} else {
|
||||
type = "ship";
|
||||
}
|
||||
} else {
|
||||
if (Entries.Count > 1) {
|
||||
type = "people";
|
||||
} else {
|
||||
type = "person";
|
||||
}
|
||||
}
|
||||
|
||||
builder.AppendFormat("Murdered {0} {1} of {2} (Bounties: {3}, Fines: {4})",
|
||||
Entries.Count,
|
||||
type,
|
||||
Faction,
|
||||
Credits.FormatCredits(Bounties),
|
||||
Credits.FormatCredits(Fines)
|
||||
);
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
12
EDPlayerJournal/BGS/IncompleteTransaction.cs
Normal file
12
EDPlayerJournal/BGS/IncompleteTransaction.cs
Normal file
@@ -0,0 +1,12 @@
|
||||
namespace EDPlayerJournal.BGS;
|
||||
internal class IncompleteTransaction : Transaction {
|
||||
public Transaction? UnderlyingTransaction { get; set; } = null;
|
||||
public string Reason { get; set; } = "";
|
||||
|
||||
public IncompleteTransaction() { }
|
||||
|
||||
public IncompleteTransaction(Transaction? underlying, string reason) {
|
||||
UnderlyingTransaction = underlying;
|
||||
Reason = reason;
|
||||
}
|
||||
}
|
||||
45
EDPlayerJournal/BGS/InfluenceSupport.cs
Normal file
45
EDPlayerJournal/BGS/InfluenceSupport.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.Text;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
|
||||
/// <summary>
|
||||
/// This class is used when a completed mission gives influence to another
|
||||
/// faction as well. This happens, for example, when you deliver cargo from one
|
||||
/// faction to another. Both sometimes gain influence.
|
||||
/// </summary>
|
||||
public class InfluenceSupport : Transaction {
|
||||
public string Influence { get; set; } = "";
|
||||
public MissionCompletedEntry? RelevantMission { get; set; }
|
||||
|
||||
public override string CompletedAt {
|
||||
get {
|
||||
if (RelevantMission == null) {
|
||||
return "";
|
||||
}
|
||||
return RelevantMission.Timestamp.ToString("dd.MM.yyyy hh:mm UTC");
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
string? missionname;
|
||||
|
||||
if (RelevantMission != null) {
|
||||
missionname = RelevantMission.HumanReadableName;
|
||||
} else {
|
||||
missionname = "UNKNOWN MISSION";
|
||||
}
|
||||
|
||||
if (missionname == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
builder.AppendFormat("Influence gained from \"{0}\": \"{1}\"",
|
||||
missionname,
|
||||
string.IsNullOrEmpty(Influence) ? "NONE" : Influence
|
||||
);
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
64
EDPlayerJournal/BGS/MissionCompleted.cs
Normal file
64
EDPlayerJournal/BGS/MissionCompleted.cs
Normal file
@@ -0,0 +1,64 @@
|
||||
using System.Text;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
|
||||
public class MissionCompleted : Transaction {
|
||||
public MissionCompleted() { }
|
||||
public MissionCompleted(MissionCompletedEntry e) {
|
||||
Entries.Add(e);
|
||||
}
|
||||
|
||||
public string MissionName {
|
||||
get {
|
||||
MissionCompletedEntry? c = Entries[0] as MissionCompletedEntry;
|
||||
if (c == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(c.HumanReadableName)) {
|
||||
return (c.Name ?? "");
|
||||
} else {
|
||||
return c.HumanReadableName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string Influence {
|
||||
get {
|
||||
MissionCompletedEntry? e = (Entries[0] as MissionCompletedEntry);
|
||||
|
||||
if (e == null || Faction == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (SystemAddress == 0) {
|
||||
return (e.GetInfluenceForFaction(Faction) ?? "");
|
||||
} else {
|
||||
return (e.GetInfluenceForFaction(Faction, SystemAddress) ?? "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
if (Faction == null || Entries.Count <= 0) {
|
||||
return "";
|
||||
}
|
||||
|
||||
StringBuilder builder = new StringBuilder();
|
||||
var entry = Entries[0] as MissionCompletedEntry;
|
||||
|
||||
if (entry == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
var influence = entry.GetInfluenceForFaction(Faction, SystemAddress);
|
||||
|
||||
builder.AppendFormat("{0}", MissionName);
|
||||
if (influence != "") {
|
||||
builder.AppendFormat(", Influence: {0}", influence);
|
||||
}
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
55
EDPlayerJournal/BGS/MissionFailed.cs
Normal file
55
EDPlayerJournal/BGS/MissionFailed.cs
Normal file
@@ -0,0 +1,55 @@
|
||||
using System.Text;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
public class MissionFailed : Transaction {
|
||||
public MissionFailedEntry? Failed { get; set; }
|
||||
public MissionAcceptedEntry? Accepted { get; set; }
|
||||
|
||||
public MissionFailed() { }
|
||||
|
||||
public MissionFailed(MissionAcceptedEntry accepted) {
|
||||
Accepted = accepted;
|
||||
Faction = accepted.Faction;
|
||||
}
|
||||
|
||||
public override int CompareTo(Transaction? other) {
|
||||
if (other == null || other.GetType() != typeof(MissionFailed)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
MissionFailed? failed = other as MissionFailed;
|
||||
|
||||
if (failed == null) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* if it is the same mission name, the same faction and the same system,
|
||||
* collate mission failures together */
|
||||
if (failed.Failed?.HumanReadableName == Failed?.HumanReadableName &&
|
||||
failed.Faction == Faction &&
|
||||
failed.System == System) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
// +1 since the other entries are just copies of the one we have in our properties
|
||||
public int Amount => Entries.Count + 1;
|
||||
|
||||
public override string ToString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (Failed == null || Accepted == null) {
|
||||
return "";
|
||||
}
|
||||
|
||||
builder.AppendFormat("{0}x Mission failed: \"{1}\"",
|
||||
Amount,
|
||||
Failed.HumanReadableName != null ? Failed.HumanReadableName : Failed.Name
|
||||
);
|
||||
|
||||
return builder.ToString();
|
||||
}
|
||||
}
|
||||
126
EDPlayerJournal/BGS/Objective.cs
Normal file
126
EDPlayerJournal/BGS/Objective.cs
Normal file
@@ -0,0 +1,126 @@
|
||||
using System.Collections.Generic;
|
||||
using System;
|
||||
using System.Text;
|
||||
using Newtonsoft.Json;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
|
||||
public class Objective : IComparable<Objective> {
|
||||
private List<Transaction> entries = new List<Transaction>();
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsEnabled { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<Transaction> Children {
|
||||
get => entries;
|
||||
}
|
||||
|
||||
[JsonIgnore]
|
||||
public string Name => this.ToString();
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsExpanded { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public List<Transaction> LogEntries {
|
||||
get => entries;
|
||||
set => entries = value;
|
||||
}
|
||||
|
||||
public void Clear() {
|
||||
if (entries == null) {
|
||||
return;
|
||||
}
|
||||
entries.Clear();
|
||||
}
|
||||
|
||||
public int Matches(Transaction e) {
|
||||
int match_count = 0;
|
||||
|
||||
if (e.OnlyControllingFaction) {
|
||||
if (Faction == null || (e.Faction != Faction)) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (e.Faction != null && Faction != null) {
|
||||
if (string.Compare(e.Faction, Faction, true) != 0) {
|
||||
/* if we have a faction, and it doesn't match we don't care.
|
||||
* faction is the most important comparision, so if it doesn't match
|
||||
* it is not the right objective
|
||||
*/
|
||||
return 0;
|
||||
} else {
|
||||
++match_count;
|
||||
}
|
||||
}
|
||||
|
||||
/* system and station only add to the match strength though */
|
||||
if (e.System != null && System != null) {
|
||||
if (string.Compare(e.System, System, true) == 0) {
|
||||
++match_count;
|
||||
}
|
||||
}
|
||||
|
||||
/* if system and faction already match, station is not so important */
|
||||
if (e.Station != null && Station != null) {
|
||||
if (string.Compare(e.Station, Station, true) == 0) {
|
||||
++match_count;
|
||||
}
|
||||
}
|
||||
|
||||
return match_count;
|
||||
}
|
||||
|
||||
public int CompareTo(Objective? other) {
|
||||
if (other == null) {
|
||||
return 0;
|
||||
}
|
||||
return (other.System == System &&
|
||||
other.Station == Station &&
|
||||
other.Faction == Faction) ? 0 : -1;
|
||||
}
|
||||
|
||||
public bool IsValid => (!string.IsNullOrEmpty(System) && !string.IsNullOrEmpty(Faction));
|
||||
|
||||
public string System { get; set; } = "";
|
||||
|
||||
public string Station { get; set; } = "";
|
||||
|
||||
public string Faction { get; set; } = "";
|
||||
|
||||
public override string ToString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
if (System != null && System.Length > 0) {
|
||||
str.AppendFormat("System: {0}", System);
|
||||
}
|
||||
if (Station != null && Station.Length > 0) {
|
||||
if (str.Length > 0) {
|
||||
str.Append(", ");
|
||||
}
|
||||
str.AppendFormat("Station: {0}", Station);
|
||||
}
|
||||
if (Faction != null && Faction.Length > 0) {
|
||||
if (str.Length > 0) {
|
||||
str.Append(", ");
|
||||
}
|
||||
str.AppendFormat("Faction: {0}", Faction);
|
||||
}
|
||||
return str.ToString();
|
||||
}
|
||||
|
||||
public string ToShortString() {
|
||||
StringBuilder str = new StringBuilder();
|
||||
if (System != null && System.Length > 0) {
|
||||
str.AppendFormat("{0}", System);
|
||||
}
|
||||
if (Station != null && Station.Length > 0) {
|
||||
if (str.Length > 0) {
|
||||
str.Append(", ");
|
||||
}
|
||||
str.AppendFormat("{0}", Station);
|
||||
}
|
||||
return str.ToString();
|
||||
}
|
||||
}
|
||||
41
EDPlayerJournal/BGS/OrganicData.cs
Normal file
41
EDPlayerJournal/BGS/OrganicData.cs
Normal file
@@ -0,0 +1,41 @@
|
||||
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
|
||||
public class OrganicData : Transaction {
|
||||
public OrganicData(SellOrganicDataEntry e) {
|
||||
Entries.Add(e);
|
||||
}
|
||||
|
||||
public long TotalValue {
|
||||
get {
|
||||
return Entries.OfType<SellOrganicDataEntry>().Sum(x => x.TotalValue);
|
||||
}
|
||||
}
|
||||
|
||||
public override int CompareTo(Transaction? other) {
|
||||
if (other == null || other.GetType() != typeof(OrganicData)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (other?.Faction == Faction &&
|
||||
other?.System == System &&
|
||||
other?.Station == Station) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format("Sold {0} worth of organic data to Vista Genomics",
|
||||
Credits.FormatCredits(TotalValue)
|
||||
);
|
||||
}
|
||||
|
||||
/* Selling organic data only helps the controlling faction, just like
|
||||
* selling cartographic data.
|
||||
*/
|
||||
public override bool OnlyControllingFaction => true;
|
||||
}
|
||||
672
EDPlayerJournal/BGS/Report.cs
Normal file
672
EDPlayerJournal/BGS/Report.cs
Normal file
@@ -0,0 +1,672 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
|
||||
public class Report {
|
||||
private List<Objective> objectives = new List<Objective>();
|
||||
|
||||
public delegate void OnLogDelegate(string log);
|
||||
|
||||
public event OnLogDelegate? OnLog;
|
||||
|
||||
public List<Objective> Objectives {
|
||||
get { return objectives; }
|
||||
set { objectives = value; }
|
||||
}
|
||||
|
||||
public bool AddObjective(Objective objective) {
|
||||
var found = objectives.Find(x => x.CompareTo(objective) == 0);
|
||||
bool added = false;
|
||||
|
||||
if (found == null) {
|
||||
objectives.Add(objective);
|
||||
added = true;
|
||||
}
|
||||
|
||||
return added;
|
||||
}
|
||||
|
||||
public static bool IsRelevant(Entry e) {
|
||||
return e.Is(Events.CommitCrime) ||
|
||||
e.Is(Events.Docked) ||
|
||||
e.Is(Events.FactionKillBond) ||
|
||||
e.Is(Events.FSDJump) ||
|
||||
e.Is(Events.Location) ||
|
||||
e.Is(Events.MarketBuy) ||
|
||||
e.Is(Events.MarketSell) ||
|
||||
e.Is(Events.MissionAccepted) ||
|
||||
e.Is(Events.MissionFailed) ||
|
||||
e.Is(Events.MultiSellExplorationData) ||
|
||||
e.Is(Events.RedeemVoucher) ||
|
||||
e.Is(Events.SearchAndRescue) ||
|
||||
e.Is(Events.SellExplorationData) ||
|
||||
e.Is(Events.SellMicroResources) ||
|
||||
e.Is(Events.SellOrganicData) ||
|
||||
e.Is(Events.ShipTargeted) ||
|
||||
e.Is(Events.MissionCompleted)
|
||||
;
|
||||
}
|
||||
|
||||
public void Scan(PlayerJournal journal, DateTime start, DateTime end) {
|
||||
/* Log files only get rotated if you restart the game client. This means that there might
|
||||
* be - say - entries from the 4th of May in the file with a timestamp of 3rd of May. This
|
||||
* happens if you happen to play a session late into the night.
|
||||
* At first I tried extracting the first and last line of a file to see the date range, but
|
||||
* if you have a lot of files this becomes quite slow, and quite the memory hog (as journal
|
||||
* files have to be read in their entirety to check this). So we assume that you can't play
|
||||
* three days straight, and keep the code fast.
|
||||
*/
|
||||
DateTime actualstart = start.AddDays(-3);
|
||||
List<Entry> entries = journal.Files
|
||||
.Where(f => f.NormalisedDateTime >= actualstart && f.NormalisedDateTime <= end)
|
||||
.SelectMany(e => e.Entries)
|
||||
.ToList()
|
||||
;
|
||||
// Now further sort the list down to entries that are actually within the given datetime
|
||||
// Note that entry datetimes are not normalised, so we have to sort until end + 1 day
|
||||
DateTime actualend = end.AddDays(1);
|
||||
|
||||
entries = entries
|
||||
.Where(e => e.Timestamp >= start && e.Timestamp < actualend)
|
||||
.ToList()
|
||||
;
|
||||
Scan(entries);
|
||||
}
|
||||
|
||||
public void Scan(List<Entry> entries) {
|
||||
if (entries.Count <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
List<Entry> relevant = entries
|
||||
.Where(x => IsRelevant(x))
|
||||
.ToList()
|
||||
;
|
||||
|
||||
Dictionary<ulong, MissionAcceptedEntry> acceptedMissions = new Dictionary<ulong, MissionAcceptedEntry>();
|
||||
Dictionary<string, long> buyCost = new Dictionary<string, long>();
|
||||
Dictionary<ulong, string> systems = new Dictionary<ulong, string>();
|
||||
Dictionary<string, string> npcfactions = new Dictionary<string, string>();
|
||||
Dictionary<string, List<Faction>> system_factions = new Dictionary<string, List<Faction>>();
|
||||
|
||||
// A dictionary resolving to a station at which each mission was accepted
|
||||
Dictionary<ulong, string> acceptedStations = new Dictionary<ulong, string>();
|
||||
// A dictionary resolving to a system at which each mission was accepted
|
||||
Dictionary<ulong, ulong> acceptedSystems = new Dictionary<ulong, ulong>();
|
||||
|
||||
string? current_system = null;
|
||||
ulong? current_system_address = null;
|
||||
string? current_station = null;
|
||||
string? controlling_faction = null;
|
||||
|
||||
objectives.ForEach(x => x.Clear());
|
||||
|
||||
foreach (Entry e in relevant) {
|
||||
List<Transaction> results = new List<Transaction>();
|
||||
bool collate = false;
|
||||
|
||||
if (e.Is(Events.Docked)) {
|
||||
DockedEntry? docked = e as DockedEntry;
|
||||
if (docked == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* gleem the current station from this message
|
||||
*/
|
||||
current_station = docked.StationName;
|
||||
current_system = docked.StarSystem;
|
||||
controlling_faction = docked.StationFaction;
|
||||
current_system_address = docked.SystemAddress;
|
||||
|
||||
if (current_system_address != null && current_system != null) {
|
||||
if (!systems.ContainsKey(current_system_address.Value)) {
|
||||
systems.Add(current_system_address.Value, current_system);
|
||||
}
|
||||
}
|
||||
} else if (e.Is(Events.FSDJump)) {
|
||||
/* Gleem current system and controlling faction from this message.
|
||||
*/
|
||||
FSDJumpEntry? fsd = e as FSDJumpEntry;
|
||||
|
||||
if (fsd == null || fsd.StarSystem == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
current_system_address = fsd.SystemAddress;
|
||||
current_system = fsd.StarSystem;
|
||||
controlling_faction = fsd.SystemFaction;
|
||||
|
||||
if (!systems.ContainsKey(fsd.SystemAddress)) {
|
||||
systems.Add(fsd.SystemAddress, fsd.StarSystem);
|
||||
}
|
||||
|
||||
if (!system_factions.ContainsKey(fsd.StarSystem) &&
|
||||
fsd.SystemFactions.Count > 0) {
|
||||
system_factions[fsd.StarSystem] = fsd.SystemFactions;
|
||||
}
|
||||
} else if (e.Is(Events.Location)) {
|
||||
/* Get current system, faction name and station from Location message
|
||||
*/
|
||||
LocationEntry? location = e as LocationEntry;
|
||||
|
||||
if (location == null || location.StarSystem == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
current_system = location.StarSystem;
|
||||
current_system_address = location.SystemAddress;
|
||||
|
||||
if (!systems.ContainsKey(location.SystemAddress)) {
|
||||
systems.Add(location.SystemAddress, location.StarSystem);
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(location.SystemFaction)) {
|
||||
controlling_faction = location.SystemFaction;
|
||||
}
|
||||
if (!string.IsNullOrEmpty(location.StationName)) {
|
||||
current_station = location.StationName;
|
||||
}
|
||||
|
||||
if (!system_factions.ContainsKey(location.StarSystem) &&
|
||||
location.SystemFactions.Count > 0) {
|
||||
system_factions[location.StarSystem] = location.SystemFactions;
|
||||
}
|
||||
} else if (e.Is(Events.ShipTargeted)) {
|
||||
ShipTargetedEntry? targeted = e as ShipTargetedEntry;
|
||||
|
||||
if (targeted == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(targeted.PilotNameLocalised) ||
|
||||
string.IsNullOrEmpty(targeted.Faction)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
npcfactions[targeted.PilotNameLocalised] = targeted.Faction;
|
||||
} else if (e.Is(Events.CommitCrime)) {
|
||||
CommitCrimeEntry? crime = e as CommitCrimeEntry;
|
||||
if (crime == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
string? faction = crime.Faction;
|
||||
|
||||
if (faction == null || !crime.IsMurder) {
|
||||
/* we don't care about anything but murder for now */
|
||||
continue;
|
||||
}
|
||||
|
||||
/* use localised victim name if we have it, otherwise use normal name */
|
||||
string? victim = crime.VictimLocalised;
|
||||
if (string.IsNullOrEmpty(victim)) {
|
||||
victim = crime.Victim;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(victim)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!npcfactions.ContainsKey(victim)) {
|
||||
/* The faction in the crime report is the faction that issues the bounty,
|
||||
* and not the faction of the victim.
|
||||
*/
|
||||
OnLog?.Invoke(string.Format(
|
||||
"No faction found for victim \"{0}\", using faction that issued the bounty instead.",
|
||||
victim, crime.Faction
|
||||
));
|
||||
} else {
|
||||
faction = npcfactions[victim];
|
||||
}
|
||||
|
||||
results.Add(new FoulMurder(crime) {
|
||||
System = current_system,
|
||||
Faction = faction,
|
||||
});
|
||||
collate = true;
|
||||
} else if (e.Is(Events.MissionCompleted)) {
|
||||
MissionCompletedEntry? completed = e as MissionCompletedEntry;
|
||||
|
||||
if (completed == null ||
|
||||
completed.MissionID == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
MissionAcceptedEntry? accepted = null;
|
||||
MissionCompleted? main_mission = null;
|
||||
ulong accepted_address;
|
||||
string? accepted_system;
|
||||
|
||||
string? target_faction_name = completed.TargetFaction;
|
||||
string? source_faction_name = completed.Faction;
|
||||
|
||||
if (!acceptedMissions.TryGetValue(completed.MissionID.Value, out accepted)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to find mission acceptance for mission \"{0}\". " +
|
||||
"Please extend range to include the mission acceptance.", completed.HumanReadableName
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!acceptedSystems.TryGetValue(completed.MissionID.Value, out accepted_address)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", completed.HumanReadableName
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!systems.TryGetValue(accepted_address, out accepted_system)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", completed.HumanReadableName
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (completed.HumanReadableNameWasGenerated) {
|
||||
/* If the human readable name was generated, we send a log message. Because the
|
||||
* generated names all sort of suck, we should have more human readable names in
|
||||
* in the lookup dictionary.
|
||||
*/
|
||||
OnLog?.Invoke("Human readable name for mission \"" +
|
||||
completed.Name +
|
||||
"\" was generated, please report this.");
|
||||
}
|
||||
|
||||
foreach (var other in completed.Influences) {
|
||||
string faction = other.Key;
|
||||
if (string.IsNullOrEmpty(faction)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Mission \"{0}\" has empty faction name in influence block, "+
|
||||
"so this influence support was ignored. " +
|
||||
"Please check the README on why this happens.", completed.HumanReadableName)
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
/* Now comes the fun part. Sometimes the influence list is empty for a faction.
|
||||
* This happens if the faction in question
|
||||
*/
|
||||
if (other.Value.Count() == 0) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Mission \"{0}\" gave no influence to \"{1}\", so we assume this is because the " +
|
||||
"faction is in a conflict and cannot gain influence right now. " +
|
||||
"If this assessment is wrong, just remove the entry from the objective list.",
|
||||
completed.HumanReadableName, faction
|
||||
));
|
||||
|
||||
if (string.Compare(target_faction_name, faction, true) == 0) {
|
||||
/* here we assume that if the faction in question is the target faction,
|
||||
* that we gave said target faction no influence in the target system, aka
|
||||
* current system
|
||||
*/
|
||||
if (current_system_address == null) {
|
||||
continue;
|
||||
}
|
||||
other.Value.Add(current_system_address.Value, "");
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Mission \"{0}\" gave no influence to \"{1}\". Since \"{1}\" is the target faction " +
|
||||
"of the mission, we assume the influence was gained in \"{2}\". " +
|
||||
"Please remove the entry if this assumption is wrong.",
|
||||
completed.HumanReadableName, faction, current_system
|
||||
));
|
||||
} else if (string.Compare(source_faction_name, faction, true) == 0) {
|
||||
/* source faction of the mission is not getting any influence. This could be because
|
||||
* the source faction is in an election state in its home system and cannot gain any
|
||||
* influence. It may also very well be that the source and target faction are the same
|
||||
* since the faction is present in both target and source system. In which case we add
|
||||
* both and hope for the best.
|
||||
*/
|
||||
other.Value.Add(accepted_address, "");
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Mission \"{0}\" gave no influence to \"{1}\". Since \"{1}\" is the source faction " +
|
||||
"of the mission, we assume the influence was gained in \"{2}\". " +
|
||||
"Please remove the entry if this assumption is wrong.",
|
||||
completed.HumanReadableName, faction, accepted_system
|
||||
));
|
||||
|
||||
/* check if source/target faction are equal, in which case we also need an entry
|
||||
* for the target system. As said factions can be present in two systems, and can
|
||||
* give missions that target each other.
|
||||
*/
|
||||
if (string.Compare(source_faction_name, target_faction_name, true) == 0 &&
|
||||
current_system_address != null) {
|
||||
other.Value.Add(current_system_address.Value, "");
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Mission \"{0}\" gave no influence to \"{1}\". Since \"{1}\" is the source and target faction " +
|
||||
"of the mission, we assume the influence was also gained in target system \"{2}\". " +
|
||||
"Please remove the entry if this assumption is wrong.",
|
||||
completed.HumanReadableName, faction, current_system
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var influences in other.Value) {
|
||||
ulong system_address = influences.Key;
|
||||
string? system;
|
||||
string? accepted_station;
|
||||
|
||||
if (completed.MissionID == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!systems.TryGetValue(system_address, out system)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unknown system \"{0}\" unable to assign that mission a target.", system_address
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!acceptedStations.TryGetValue(completed.MissionID.Value, out accepted_station)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which station mission \"{0}\" was accepted.", completed.HumanReadableName
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (faction.Equals(source_faction_name) && system_address == accepted_address) {
|
||||
/* This is the influence block for the origin of the mission.
|
||||
*/
|
||||
main_mission = new MissionCompleted(completed) {
|
||||
System = accepted_system,
|
||||
Faction = source_faction_name,
|
||||
SystemAddress = accepted_address,
|
||||
Station = accepted_station,
|
||||
};
|
||||
results.Add(main_mission);
|
||||
} else if (!faction.Equals(source_faction_name) ||
|
||||
(faction.Equals(source_faction_name) && system_address != accepted_address)) {
|
||||
/* This block is for secondary factions (first if), or if the secondary faction
|
||||
* is the same as the mission giver, but in another system (second if).
|
||||
*/
|
||||
results.Add(new InfluenceSupport() {
|
||||
Faction = faction,
|
||||
Influence = influences.Value,
|
||||
System = system,
|
||||
SystemAddress = system_address,
|
||||
RelevantMission = completed
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (e.Is(Events.MissionAccepted)) {
|
||||
MissionAcceptedEntry? accepted = e as MissionAcceptedEntry;
|
||||
|
||||
if (accepted == null ||
|
||||
current_station == null ||
|
||||
current_system_address == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
ulong id = accepted.MissionID;
|
||||
|
||||
if (!acceptedMissions.ContainsKey(id)) {
|
||||
acceptedMissions[id] = accepted;
|
||||
}
|
||||
if (!acceptedStations.ContainsKey(id)) {
|
||||
acceptedStations[id] = current_station;
|
||||
}
|
||||
if (!acceptedSystems.ContainsKey(id)) {
|
||||
acceptedSystems[id] = current_system_address.Value;
|
||||
}
|
||||
} else if (e.Is(Events.MissionFailed)) {
|
||||
MissionFailedEntry? failed = e as MissionFailedEntry;
|
||||
MissionAcceptedEntry? accepted = null;
|
||||
ulong accepted_address = 0;
|
||||
string? accepted_system;
|
||||
string? accepted_station;
|
||||
|
||||
if (failed == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!acceptedMissions.TryGetValue(failed.MissionID, out accepted)) {
|
||||
OnLog?.Invoke("A mission failed which wasn't accepted in the given time frame. " +
|
||||
"Please adjust start date to when the mission was accepted to include it in the list.");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!acceptedSystems.TryGetValue(failed.MissionID, out accepted_address)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", accepted.Name
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!systems.TryGetValue(accepted_address, out accepted_system)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which system mission \"{0}\" was accepted.", accepted.Name
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!acceptedStations.TryGetValue(failed.MissionID, out accepted_station)) {
|
||||
OnLog?.Invoke(string.Format(
|
||||
"Unable to figure out in which station mission \"{0}\" was accepted.", accepted.Name
|
||||
));
|
||||
continue;
|
||||
}
|
||||
|
||||
results.Add(new MissionFailed(accepted) {
|
||||
Failed = failed,
|
||||
System = accepted_system,
|
||||
Station = accepted_station,
|
||||
Faction = accepted.Faction,
|
||||
SystemAddress = accepted_address,
|
||||
});
|
||||
|
||||
if (failed.HumanReadableName == null) {
|
||||
OnLog?.Invoke("Human readable name for mission \"" +
|
||||
failed.Name +
|
||||
"\" was not recognised");
|
||||
}
|
||||
|
||||
/* Mission failed should be collated if they are in the same system/station
|
||||
*/
|
||||
collate = true;
|
||||
} else if (e.Is(Events.SellExplorationData)) {
|
||||
SellExplorationDataEntry? explo = e as SellExplorationDataEntry;
|
||||
|
||||
if (explo == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
results.Add(new Cartographics(explo) {
|
||||
System = current_system,
|
||||
Station = current_station,
|
||||
Faction = controlling_faction,
|
||||
});
|
||||
|
||||
/* colate single cartographic selling into one */
|
||||
collate = true;
|
||||
} else if (e.Is(Events.SellOrganicData)) {
|
||||
SellOrganicDataEntry? organic = e as SellOrganicDataEntry;
|
||||
|
||||
if (organic == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* organic data sold to Vista Genomics */
|
||||
results.Add(new OrganicData(organic) {
|
||||
System = current_system,
|
||||
Station = current_station,
|
||||
Faction = controlling_faction,
|
||||
});
|
||||
|
||||
collate = true;
|
||||
} else if (e.Is(Events.MultiSellExplorationData)) {
|
||||
MultiSellExplorationDataEntry? explo = e as MultiSellExplorationDataEntry;
|
||||
|
||||
if (explo == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
/* For multi-sell-exploraton-data only the controlling faction of the station sold to matters.
|
||||
*/
|
||||
results.Add(new Cartographics(explo) {
|
||||
System = current_system,
|
||||
Station = current_station,
|
||||
Faction = controlling_faction
|
||||
});
|
||||
|
||||
collate = true;
|
||||
} else if (e.Is(Events.RedeemVoucher)) {
|
||||
RedeemVoucherEntry? voucher = e as RedeemVoucherEntry;
|
||||
List<Faction> current_factions = new List<Faction>();
|
||||
|
||||
if (voucher == null || current_system == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (system_factions.ContainsKey(current_system)) {
|
||||
current_factions = system_factions[current_system];
|
||||
} else {
|
||||
OnLog?.Invoke("There are no current system factions, so turned in vouchers were ignored.");
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (string faction in voucher.Factions) {
|
||||
if (current_factions.Find(x => x.Name == faction) == null) {
|
||||
OnLog?.Invoke(
|
||||
string.Format("Vouchers for \"{0}\" were ignored in \"{1}\" since said " +
|
||||
"faction is not present there.", faction, current_system)
|
||||
);
|
||||
continue; /* faction is not present, so it is ignored */
|
||||
}
|
||||
|
||||
/* Same for selling combat vouchers. Only the current controlling faction matters here.
|
||||
*/
|
||||
results.Add(new Vouchers(voucher) {
|
||||
System = current_system,
|
||||
Station = current_station,
|
||||
Faction = faction,
|
||||
ControllingFaction = controlling_faction,
|
||||
});
|
||||
}
|
||||
|
||||
collate = true;
|
||||
} else if (e.Is(Events.SellMicroResources)) {
|
||||
SellMicroResourcesEntry? smr = e as SellMicroResourcesEntry;
|
||||
|
||||
if (smr == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
results.Add(new SellMicroResources(smr) {
|
||||
Faction = controlling_faction,
|
||||
Station = current_station,
|
||||
System = current_system
|
||||
});
|
||||
} else if (e.Is(Events.MarketBuy)) {
|
||||
MarketBuyEntry? buy = e as MarketBuyEntry;
|
||||
|
||||
if (buy == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.IsNullOrEmpty(buy.Type) || buy.BuyPrice == 0) {
|
||||
continue;
|
||||
}
|
||||
buyCost[buy.Type] = buy.BuyPrice;
|
||||
|
||||
results.Add(new BuyCargo(buy) {
|
||||
Faction = controlling_faction,
|
||||
Station = current_station,
|
||||
System = current_system,
|
||||
});
|
||||
|
||||
collate = true;
|
||||
} else if (e.Is(Events.SearchAndRescue)) {
|
||||
SearchAndRescueEntry? sar = e as SearchAndRescueEntry;
|
||||
|
||||
if (sar == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
results.Add(new SearchAndRescue(sar) {
|
||||
Faction = controlling_faction,
|
||||
Station = current_station,
|
||||
System = current_system,
|
||||
});
|
||||
|
||||
collate = true;
|
||||
} else if (e.Is(Events.MarketSell)) {
|
||||
MarketSellEntry? sell = e as MarketSellEntry;
|
||||
long profit = 0;
|
||||
|
||||
if (sell == null || sell.Type == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!buyCost.ContainsKey(sell.Type)) {
|
||||
OnLog?.Invoke("Could not find buy order for the given commodity. Please adjust profit manually.");
|
||||
} else {
|
||||
long avg = buyCost[sell.Type];
|
||||
profit = (long)sell.TotalSale - (avg * sell.Count);
|
||||
}
|
||||
|
||||
results.Add(new SellCargo(sell) {
|
||||
Faction = controlling_faction,
|
||||
Station = current_station,
|
||||
System = current_system,
|
||||
Profit = profit
|
||||
});
|
||||
}
|
||||
|
||||
if (results == null || results.Count <= 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
foreach (Transaction entry in results) {
|
||||
/* Find all objectives that generally match.
|
||||
*/
|
||||
var matches = objectives
|
||||
.Where(x => x.Matches(entry) >= 2)
|
||||
.OrderBy(x => x.Matches(entry))
|
||||
;
|
||||
|
||||
Objective? objective = null;
|
||||
if (matches != null && matches.Count() > 0) {
|
||||
/* Then select the one that matches the most.
|
||||
*/
|
||||
objective = matches
|
||||
.OrderBy(x => x.Matches(entry))
|
||||
.Reverse()
|
||||
.First()
|
||||
;
|
||||
} else {
|
||||
/* create a new objective if we don't have one */
|
||||
objective = new Objective() {
|
||||
Station = (entry.Station ?? ""),
|
||||
Faction = (entry.Faction ?? ""),
|
||||
System = (entry.System ?? ""),
|
||||
};
|
||||
objectives.Add(objective);
|
||||
}
|
||||
|
||||
Transaction? existing = null;
|
||||
|
||||
existing = objective.LogEntries.Find(x => {
|
||||
try {
|
||||
return x.CompareTo(entry) == 0;
|
||||
} catch (NotImplementedException) {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
if (collate && existing != null) {
|
||||
existing.Entries.Add(e);
|
||||
} else if (!collate || existing == null) {
|
||||
objective.LogEntries.Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Scan(PlayerJournal journal) {
|
||||
Scan(journal, DateTime.Now, DateTime.Now);
|
||||
}
|
||||
}
|
||||
53
EDPlayerJournal/BGS/SearchAndRescue.cs
Normal file
53
EDPlayerJournal/BGS/SearchAndRescue.cs
Normal file
@@ -0,0 +1,53 @@
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
public class SearchAndRescue : Transaction {
|
||||
public SearchAndRescue (SearchAndRescueEntry e) {
|
||||
Entries.Add(e);
|
||||
}
|
||||
|
||||
public long Count {
|
||||
get {
|
||||
return Entries.OfType<SearchAndRescueEntry>().Sum(x => x.Count);
|
||||
}
|
||||
}
|
||||
|
||||
public long Reward {
|
||||
get {
|
||||
return Entries.OfType<SearchAndRescueEntry>().Sum(x => x.Reward);
|
||||
}
|
||||
}
|
||||
|
||||
public string? NameLocalised {
|
||||
get {
|
||||
return Entries.OfType<SearchAndRescueEntry>().First().NameLocalised;
|
||||
}
|
||||
}
|
||||
|
||||
public override int CompareTo(Transaction? o) {
|
||||
if (o == null || o.GetType() != typeof(SearchAndRescue)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
SearchAndRescue? other = o as SearchAndRescue;
|
||||
|
||||
if (other?.System == System &&
|
||||
other?.Station == Station &&
|
||||
other?.Faction == Faction &&
|
||||
other?.NameLocalised == NameLocalised) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format("Contributed {0} {1} to Search and Rescue ({2})",
|
||||
Count,
|
||||
NameLocalised,
|
||||
Credits.FormatCredits(Reward)
|
||||
);
|
||||
}
|
||||
|
||||
public override bool OnlyControllingFaction => true;
|
||||
}
|
||||
73
EDPlayerJournal/BGS/SellCargo.cs
Normal file
73
EDPlayerJournal/BGS/SellCargo.cs
Normal file
@@ -0,0 +1,73 @@
|
||||
using System.Text;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
public class SellCargo : Transaction {
|
||||
public long Profit { get; set; }
|
||||
|
||||
public SellCargo() { }
|
||||
|
||||
public SellCargo(MarketSellEntry e) {
|
||||
Entries.Add(e);
|
||||
}
|
||||
|
||||
public string? Cargo {
|
||||
get {
|
||||
string? cargo;
|
||||
var sell = Entries.OfType<MarketSellEntry>().First();
|
||||
|
||||
if (!string.IsNullOrEmpty(sell.TypeLocalised)) {
|
||||
cargo = sell.TypeLocalised;
|
||||
} else {
|
||||
cargo = sell.Type;
|
||||
if (cargo != null && cargo.Length >= 2) {
|
||||
cargo = cargo[0].ToString().ToUpper() + cargo.Substring(1);
|
||||
}
|
||||
}
|
||||
|
||||
return cargo;
|
||||
}
|
||||
}
|
||||
|
||||
public string Market {
|
||||
get {
|
||||
var sell = Entries.OfType<MarketSellEntry>().First();
|
||||
return sell.BlackMarket ? "Black Market" : "Commodity Market";
|
||||
}
|
||||
}
|
||||
|
||||
public long Amount {
|
||||
get { return Entries.OfType<MarketSellEntry>().Sum(x => x.Count); }
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
StringBuilder builder = new StringBuilder();
|
||||
var sold = Entries.OfType<MarketSellEntry>().ToArray();
|
||||
|
||||
if (sold == null || sold.Length == 0) {
|
||||
return builder.ToString();
|
||||
}
|
||||
|
||||
foreach (MarketSellEntry sell in sold) {
|
||||
builder.AppendFormat("Sold {0} {1} to the {2}",
|
||||
sell.Count,
|
||||
Cargo,
|
||||
Market
|
||||
);
|
||||
|
||||
if (Profit != 0) {
|
||||
builder.AppendFormat(" ({0} {1})",
|
||||
Credits.FormatCredits(Profit),
|
||||
Profit < 0 ? "loss" : "profit"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
return builder.ToString().Trim();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Selling resources to a market only helps the controlling faction
|
||||
/// </summary>
|
||||
public override bool OnlyControllingFaction => true;
|
||||
}
|
||||
26
EDPlayerJournal/BGS/SellMicroResources.cs
Normal file
26
EDPlayerJournal/BGS/SellMicroResources.cs
Normal file
@@ -0,0 +1,26 @@
|
||||
using System.Linq;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
public class SellMicroResources : Transaction {
|
||||
public int TotalSum {
|
||||
get {
|
||||
return Entries
|
||||
.OfType<SellMicroResourcesEntry>()
|
||||
.Sum(x => x.Price)
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public SellMicroResources() { }
|
||||
|
||||
public SellMicroResources(SellMicroResourcesEntry e) {
|
||||
Entries.Add(e);
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format("Sell Micro Resources: {0}", Credits.FormatCredits(TotalSum));
|
||||
}
|
||||
|
||||
public override bool OnlyControllingFaction => true;
|
||||
}
|
||||
44
EDPlayerJournal/BGS/Transaction.cs
Normal file
44
EDPlayerJournal/BGS/Transaction.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
|
||||
public class Transaction : IComparable<Transaction> {
|
||||
public List<Entry> Entries { get; } = new List<Entry>();
|
||||
|
||||
public virtual string CompletedAt {
|
||||
get {
|
||||
var items = Entries
|
||||
.OrderBy(x => x.Timestamp)
|
||||
.ToArray()
|
||||
;
|
||||
if (items == null || items.Length == 0) {
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
Entry last = items.Last();
|
||||
return last.Timestamp.ToString("dd.MM.yyyy HH:mm UTC");
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Controlling faction of the station this entry was made/turned into.
|
||||
/// </summary>
|
||||
public string? ControllingFaction { get; set; }
|
||||
public string? Station { get; set; }
|
||||
public string? System { get; set; }
|
||||
public ulong SystemAddress { get; set; }
|
||||
public string? Faction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Whether this transaction type only benefits the controlling faction or not, default: no
|
||||
/// </summary>
|
||||
public virtual bool OnlyControllingFaction {
|
||||
get { return false; }
|
||||
}
|
||||
|
||||
public virtual int CompareTo(Transaction? other) {
|
||||
throw new NotImplementedException("not implemented");
|
||||
}
|
||||
|
||||
public string? Name => ToString();
|
||||
}
|
||||
619
EDPlayerJournal/BGS/TransactionParser.cs
Normal file
619
EDPlayerJournal/BGS/TransactionParser.cs
Normal file
@@ -0,0 +1,619 @@
|
||||
using EDPlayerJournal.Entries;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection.Metadata.Ecma335;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
|
||||
internal class TransactionParserContext {
|
||||
public string? CurrentSystem { get; set; }
|
||||
public ulong? CurrentSystemAddress { get; set; }
|
||||
public string? CurrentStation { get; set; }
|
||||
public string? ControllingFaction { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// A list of accepted missions index by their mission ID
|
||||
/// </summary>
|
||||
public Dictionary<ulong, MissionAcceptedEntry> AcceptedMissions { get; } = new();
|
||||
public Dictionary<ulong, Location> AcceptedMissionLocation { get; } = new();
|
||||
/// <summary>
|
||||
/// A way to lookup a system by its system id
|
||||
/// </summary>
|
||||
public Dictionary<ulong, string> SystemsByID { get; } = new();
|
||||
/// <summary>
|
||||
/// A list of factions present in the given star system
|
||||
/// </summary>
|
||||
public Dictionary<string, List<Faction>> SystemFactions { get; } = new();
|
||||
/// <summary>
|
||||
/// To which faction a given named NPC belonged to.
|
||||
/// </summary>
|
||||
public Dictionary<string, string> NPCFaction { get; } = new();
|
||||
/// <summary>
|
||||
/// Buy costs for a given commodity
|
||||
/// </summary>
|
||||
public Dictionary<string, long> BuyCost = new();
|
||||
|
||||
public void BoughtCargo(string? cargo, long? cost) {
|
||||
if (cargo == null || cost == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
BuyCost[cargo] = cost.Value;
|
||||
}
|
||||
|
||||
public List<Faction>? GetFactions(string? system) {
|
||||
if (system == null || !SystemFactions.ContainsKey(system)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return SystemFactions[system];
|
||||
}
|
||||
|
||||
public void MissionAccepted(MissionAcceptedEntry accepted) {
|
||||
if (CurrentSystem == null || CurrentSystemAddress == null) {
|
||||
throw new Exception("Mission accepted without knowing where.");
|
||||
}
|
||||
|
||||
AcceptedMissions.TryAdd(accepted.MissionID, accepted);
|
||||
|
||||
Location location = new() {
|
||||
StarSystem = CurrentSystem,
|
||||
SystemAddress = CurrentSystemAddress.Value,
|
||||
Station = (CurrentStation ?? ""),
|
||||
};
|
||||
|
||||
AcceptedMissionLocation.TryAdd(accepted.MissionID, location);
|
||||
}
|
||||
}
|
||||
|
||||
public class TransactionList : List<Transaction> {
|
||||
public void AddIncomplete(Transaction underlying, string reason) {
|
||||
Add(new IncompleteTransaction(underlying, reason));
|
||||
}
|
||||
}
|
||||
|
||||
internal interface TransactionParserPart{
|
||||
/// <summary>
|
||||
/// Parse a given entry of the entry type specified when declaring to implement this
|
||||
/// interface. You must add your transaction to the passed list in case you did have
|
||||
/// enough information to parse one or more. You may update the parser context
|
||||
/// with new information in case the entry yielded new information.
|
||||
/// Throw an exception if there was an error or a malformed entry. If you have an
|
||||
/// incomplete entry, i.e. not enough information to complete one, add an
|
||||
/// IncompleteTransaction to the list
|
||||
/// </summary>
|
||||
/// <param name="entry">The entry to parse</param>
|
||||
/// <param name="context">Parsing context that may contain useful information</param>
|
||||
/// <param name="transactions">List of parsed transactions</param>
|
||||
public void Parse(Entry entry, TransactionParserContext context, TransactionList transactions);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The location parser only updates the context with useful information, and does not
|
||||
/// by itself generate any transactions. Location is the best information gatherer here
|
||||
/// as we are getting controlling faction, system factions, address and station name.
|
||||
/// </summary>
|
||||
internal class LocationParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
LocationEntry? entry = e as LocationEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
if (entry.StarSystem == null) {
|
||||
throw new InvalidJournalEntryException();
|
||||
}
|
||||
|
||||
context.CurrentSystem = entry.StarSystem;
|
||||
context.CurrentSystemAddress = entry.SystemAddress;
|
||||
|
||||
context.SystemsByID.TryAdd(entry.SystemAddress, entry.StarSystem);
|
||||
|
||||
if (!string.IsNullOrEmpty(entry.SystemFaction)) {
|
||||
context.ControllingFaction = entry.SystemFaction;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(entry.StationName)) {
|
||||
context.CurrentStation = entry.StationName;
|
||||
}
|
||||
|
||||
if (!context.SystemFactions.ContainsKey(entry.StarSystem) &&
|
||||
entry.SystemFactions != null && entry.SystemFactions.Count > 0) {
|
||||
context.SystemFactions[entry.StarSystem] = entry.SystemFactions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class FSDJumpParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
FSDJumpEntry? entry = e as FSDJumpEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
if (entry.StarSystem == null) {
|
||||
throw new InvalidJournalEntryException();
|
||||
}
|
||||
|
||||
context.CurrentSystem = entry.StarSystem;
|
||||
context.CurrentSystemAddress = entry.SystemAddress;
|
||||
|
||||
context.SystemsByID.TryAdd(entry.SystemAddress, entry.StarSystem);
|
||||
|
||||
if (!string.IsNullOrEmpty(entry.SystemFaction)) {
|
||||
context.ControllingFaction = entry.SystemFaction;
|
||||
}
|
||||
|
||||
if (!context.SystemFactions.ContainsKey(entry.StarSystem) &&
|
||||
entry.SystemFactions != null && entry.SystemFactions.Count > 0) {
|
||||
context.SystemFactions[entry.StarSystem] = entry.SystemFactions;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class DockedParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
DockedEntry? entry = e as DockedEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
if (entry.StarSystem == null || entry.SystemAddress == null) {
|
||||
throw new InvalidJournalEntryException();
|
||||
}
|
||||
|
||||
context.CurrentSystem = entry.StarSystem;
|
||||
context.CurrentSystemAddress = entry.SystemAddress;
|
||||
|
||||
context.SystemsByID.TryAdd(entry.SystemAddress.Value, entry.StarSystem);
|
||||
|
||||
if (!string.IsNullOrEmpty(entry.StationFaction)) {
|
||||
context.ControllingFaction = entry.StationFaction;
|
||||
}
|
||||
|
||||
if (!string.IsNullOrEmpty(entry.StationName)) {
|
||||
context.CurrentStation = entry.StationName;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// With ship targeted we might find out to which faction a given NPC belonged. This is
|
||||
/// useful later when said NPC gets killed or murdered.
|
||||
/// </summary>
|
||||
internal class ShipTargetedParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
ShipTargetedEntry? entry = e as ShipTargetedEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// Scan happens in stages, and sometimes this information is not known
|
||||
// yet. Do now throw an error, this is expected behaviour.
|
||||
if (!string.IsNullOrEmpty(entry.PilotNameLocalised) &&
|
||||
!string.IsNullOrEmpty(entry.Faction)) {
|
||||
context.NPCFaction.TryAdd(entry.PilotNameLocalised, entry.Faction);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Commit crime can result in a transaction, especially if the crime committed is
|
||||
/// murder.
|
||||
/// </summary>
|
||||
internal class CommitCrimeParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
CommitCrimeEntry? entry = e as CommitCrimeEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
// Right now we only care for murder
|
||||
if (!entry.IsMurder) {
|
||||
return;
|
||||
}
|
||||
|
||||
string? victim = entry.Victim;
|
||||
|
||||
if (victim == null) {
|
||||
victim = entry.VictimLocalised;
|
||||
}
|
||||
|
||||
// If they were not properly scanned prior to the murder we do not have
|
||||
// This information. But in the end the name of the NPC does not matter.
|
||||
if (victim == null) {
|
||||
victim = "Unknown";
|
||||
}
|
||||
|
||||
if (!context.NPCFaction.ContainsKey(victim)) {
|
||||
transactions.AddIncomplete(
|
||||
new FoulMurder(),
|
||||
"Crime victim was not properly scanned."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
string faction = context.NPCFaction[victim];
|
||||
|
||||
transactions.Add(new FoulMurder(entry) {
|
||||
System = context.CurrentSystem,
|
||||
Faction = faction,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal class MissionAcceptedParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
MissionAcceptedEntry? entry = e as MissionAcceptedEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
if (context.CurrentSystem == null || context.CurrentSystemAddress == null) {
|
||||
transactions.AddIncomplete(new MissionCompleted(),
|
||||
"Could not determine current location on mission acceptance."
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
context.MissionAccepted(entry);
|
||||
} catch (Exception exception) {
|
||||
transactions.AddIncomplete(new MissionCompleted(),
|
||||
exception.Message
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class MissionCompletedParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
MissionCompletedEntry? entry = e as MissionCompletedEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
if (entry.MissionID == null) {
|
||||
throw new InvalidJournalEntryException("mission completed has no mission ID");
|
||||
}
|
||||
|
||||
MissionAcceptedEntry? accepted = null;
|
||||
Location? accepted_location = null;
|
||||
string? target_faction_name = entry.TargetFaction;
|
||||
string? source_faction_name = entry.Faction;
|
||||
|
||||
// We did not find when the mission was accepted.
|
||||
if (!context.AcceptedMissions.TryGetValue(entry.MissionID.Value, out accepted)) {
|
||||
transactions.AddIncomplete(new MissionCompleted(),
|
||||
String.Format("Mission acceptance for mission id {0} was not found",
|
||||
entry.MissionID.Value));
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.AcceptedMissionLocation.TryGetValue(entry.MissionID.Value, out accepted_location)) {
|
||||
transactions.AddIncomplete(new MissionCompleted(),
|
||||
String.Format("Location for acceptance for mission id {0} was not found",
|
||||
entry.MissionID.Value));
|
||||
return;
|
||||
}
|
||||
|
||||
// This block does some preliminary "repairs" on the influences block of a completed
|
||||
// mission. Sometimes these entries are broken, or are missing information for later
|
||||
// parsing.
|
||||
foreach (var other in entry.Influences) {
|
||||
string faction = other.Key;
|
||||
if (string.IsNullOrEmpty(faction)) {
|
||||
// Target faction might be empty string, in special cases. For example if you
|
||||
// scan a surface installation, and the target faction of the surface installation
|
||||
// gets negative REP, but the surface installation is not owned by anyone.
|
||||
continue;
|
||||
}
|
||||
|
||||
// Fun ahead: sometimes the influence list is empty for a faction entry. Here
|
||||
// we try to repair it.
|
||||
if (other.Value.Count == 0) {
|
||||
if (string.Compare(target_faction_name, faction, true) == 0) {
|
||||
if (context.CurrentSystemAddress == null) {
|
||||
continue;
|
||||
}
|
||||
other.Value.Add(context.CurrentSystemAddress.Value, "");
|
||||
// Mission gave no influence to the target faction, so we assume
|
||||
// the target faction was in the same system.
|
||||
} else if (string.Compare(source_faction_name, faction, true) == 0) {
|
||||
// This happens if the source faction is not getting any influence
|
||||
// This could be if the source faction is in a conflict, and thus does
|
||||
// not gain any influence at all.
|
||||
other.Value.Add(accepted_location.SystemAddress, "");
|
||||
|
||||
// Just check if the target/source faction are the same, in which case
|
||||
// we also have to make an additional entry
|
||||
if (string.Compare(source_faction_name, target_faction_name, true) == 0 &&
|
||||
context.CurrentSystemAddress != null) {
|
||||
other.Value.Add(context.CurrentSystemAddress.Value, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now actually parse completed mission
|
||||
foreach (var influences in other.Value) {
|
||||
ulong system_address = influences.Key;
|
||||
string? system;
|
||||
|
||||
if (!context.SystemsByID.TryGetValue(system_address, out system)) {
|
||||
transactions.AddIncomplete(new MissionCompleted(),
|
||||
string.Format("Unknown system {0}, unable to assign that mission a target", system_address)
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
if (string.Compare(faction, source_faction_name, true) == 0 &&
|
||||
system_address == accepted_location.SystemAddress) {
|
||||
// Source and target faction are the same, and this is the block
|
||||
// for the source system. So we make a full mission completed entry.
|
||||
transactions.Add(new MissionCompleted(entry) {
|
||||
System = accepted_location.StarSystem,
|
||||
Faction = source_faction_name,
|
||||
SystemAddress = accepted_location.SystemAddress,
|
||||
Station = accepted_location.Station,
|
||||
});
|
||||
} else if (string.Compare(faction, source_faction_name, true) != 0 ||
|
||||
(string.Compare(faction, source_faction_name) == 0 &&
|
||||
system_address != accepted_location.SystemAddress)) {
|
||||
// Source or target faction are different, and/or the system
|
||||
// differs. Sometimes missions go to different systems but to
|
||||
// the same faction.
|
||||
transactions.Add(new InfluenceSupport() {
|
||||
Faction = faction,
|
||||
Influence = influences.Value,
|
||||
System = system,
|
||||
SystemAddress = system_address,
|
||||
RelevantMission = entry,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class MissionFailedParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
MissionAcceptedEntry? accepted = null;
|
||||
Location? accepted_location = null;
|
||||
string? accepted_system = null;
|
||||
|
||||
MissionFailedEntry? entry = e as MissionFailedEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
if (!context.AcceptedMissions.TryGetValue(entry.MissionID, out accepted)) {
|
||||
transactions.AddIncomplete(new MissionFailed(),
|
||||
"Mission acceptance was not found"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.AcceptedMissionLocation.TryGetValue(entry.MissionID, out accepted_location)) {
|
||||
transactions.AddIncomplete(new MissionFailed(),
|
||||
"Unable to figure out where failed mission was accepted"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!context.SystemsByID.TryGetValue(accepted_location.SystemAddress, out accepted_system)) {
|
||||
transactions.AddIncomplete(new MissionFailed(),
|
||||
"Unable to figure out in which system failed mission was accepted"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
transactions.Add(new MissionFailed() {
|
||||
Accepted = accepted,
|
||||
Faction = accepted.Faction,
|
||||
Failed = entry,
|
||||
Station = accepted_location.Station,
|
||||
System = accepted_location.StarSystem,
|
||||
SystemAddress = accepted_location.SystemAddress,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal class SellExplorationDataParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
SellExplorationDataEntry? entry = e as SellExplorationDataEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
transactions.Add(new Cartographics(entry) {
|
||||
System = context.CurrentSystem,
|
||||
Station = context.CurrentStation,
|
||||
Faction = context.ControllingFaction,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal class SellOrganicDataParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
SellOrganicDataEntry? entry = e as SellOrganicDataEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
transactions.Add(new OrganicData(entry) {
|
||||
System = context.CurrentSystem,
|
||||
Station = context.CurrentStation,
|
||||
Faction = context.ControllingFaction,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal class MultiSellExplorationDataParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
MultiSellExplorationDataEntry? entry = e as MultiSellExplorationDataEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
transactions.Add(new Cartographics(entry) {
|
||||
System = context.CurrentSystem,
|
||||
Station = context.CurrentStation,
|
||||
Faction = context.ControllingFaction,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal class RedeemVoucherParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
RedeemVoucherEntry? entry = e as RedeemVoucherEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
if (context.CurrentSystem == null) {
|
||||
transactions.AddIncomplete(new Vouchers(),
|
||||
"Could not find out where the vouchers were redeemed"
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
List<Faction>? current_factions = context.GetFactions(context.CurrentSystem);
|
||||
if (current_factions == null) {
|
||||
transactions.AddIncomplete(new Vouchers(),
|
||||
"Current system factions are unknown, so vouchers were ineffective");
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (string faction in entry.Factions) {
|
||||
if (current_factions.Find(x => string.Compare(x.Name, faction, true) == 0) == null) {
|
||||
transactions.AddIncomplete(new Vouchers(),
|
||||
string.Format("Vouchers for {0} were ignored in {1} since said " +
|
||||
"faction is not present here", faction, context.CurrentSystem)
|
||||
);
|
||||
continue;
|
||||
}
|
||||
|
||||
transactions.Add(new Vouchers(entry) {
|
||||
System = context.CurrentSystem,
|
||||
Station = context.CurrentStation,
|
||||
Faction = faction,
|
||||
ControllingFaction = context.ControllingFaction,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
internal class SellMicroResourcesParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
SellMicroResourcesEntry? entry = e as SellMicroResourcesEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
transactions.Add(new SellMicroResources(entry) {
|
||||
System = context.CurrentSystem,
|
||||
Station = context.CurrentStation,
|
||||
Faction = context.ControllingFaction,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal class SearchAndRescueParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
SearchAndRescueEntry? entry = e as SearchAndRescueEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
transactions.Add(new SearchAndRescue(entry) {
|
||||
Faction = context.ControllingFaction,
|
||||
Station = context.CurrentStation,
|
||||
System = context.CurrentSystem,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal class MarketBuyParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
MarketBuyEntry? entry = e as MarketBuyEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
context.BoughtCargo(entry.Type, entry.BuyPrice);
|
||||
|
||||
transactions.Add(new BuyCargo(entry) {
|
||||
Faction = context.ControllingFaction,
|
||||
Station = context.CurrentStation,
|
||||
System = context.CurrentSystem,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
internal class MarketSellParser : TransactionParserPart {
|
||||
public void Parse(Entry e, TransactionParserContext context, TransactionList transactions) {
|
||||
long profit = 0;
|
||||
|
||||
MarketSellEntry? entry = e as MarketSellEntry;
|
||||
if (entry == null) {
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
if (entry.Type == null) {
|
||||
throw new InvalidJournalEntryException("market sell contains no cargo type");
|
||||
}
|
||||
|
||||
if (context.BuyCost.ContainsKey(entry.Type)) {
|
||||
long avg = context.BuyCost[entry.Type];
|
||||
profit = (long)entry.TotalSale - (avg * entry.Count);
|
||||
}
|
||||
|
||||
transactions.Add(new SellCargo(entry) {
|
||||
Faction = context.ControllingFaction,
|
||||
Station = context.CurrentStation,
|
||||
System = context.CurrentSystem,
|
||||
Profit = profit,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public class TransactionParser {
|
||||
private static Dictionary<string, TransactionParserPart> ParserParts { get; } = new()
|
||||
{
|
||||
{ Events.CommitCrime, new CommitCrimeParser() },
|
||||
{ Events.Docked, new DockedParser() },
|
||||
{ Events.FSDJump, new FSDJumpParser() },
|
||||
{ Events.Location, new LocationParser() },
|
||||
{ Events.MarketBuy, new MarketBuyParser() },
|
||||
{ Events.MarketSell, new MarketSellParser() },
|
||||
{ Events.MissionAccepted, new MissionAcceptedParser() },
|
||||
{ Events.MissionCompleted, new MissionCompletedParser() },
|
||||
{ Events.MissionFailed, new MissionFailedParser() },
|
||||
{ Events.MultiSellExplorationData, new MultiSellExplorationDataParser() },
|
||||
{ Events.RedeemVoucher, new RedeemVoucherParser() },
|
||||
{ Events.SearchAndRescue, new SearchAndRescueParser() },
|
||||
{ Events.SellExplorationData, new SellExplorationDataParser() },
|
||||
{ Events.SellMicroResources, new SellMicroResourcesParser() },
|
||||
{ Events.SellOrganicData, new SellOrganicDataParser() },
|
||||
{ Events.ShipTargeted, new ShipTargetedParser() },
|
||||
};
|
||||
|
||||
public List<Transaction>? Parse(IEnumerable<Entry> entries) {
|
||||
TransactionList transactions = new();
|
||||
TransactionParserContext context = new();
|
||||
|
||||
foreach (Entry entry in entries) {
|
||||
if (entry.Event == null) {
|
||||
throw new InvalidJournalEntryException();
|
||||
}
|
||||
|
||||
if (!ParserParts.ContainsKey(entry.Event)) {
|
||||
continue;
|
||||
}
|
||||
|
||||
TransactionParserPart transactionParserPart = ParserParts[entry.Event];
|
||||
transactionParserPart.Parse(entry, context, transactions);
|
||||
}
|
||||
|
||||
return transactions.ToList();
|
||||
}
|
||||
}
|
||||
74
EDPlayerJournal/BGS/Vouchers.cs
Normal file
74
EDPlayerJournal/BGS/Vouchers.cs
Normal file
@@ -0,0 +1,74 @@
|
||||
using System.Globalization;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal.BGS;
|
||||
|
||||
public class Vouchers : Transaction {
|
||||
private string? type = null;
|
||||
|
||||
public Vouchers() {
|
||||
}
|
||||
|
||||
public Vouchers(RedeemVoucherEntry e) {
|
||||
Entries.Add(e);
|
||||
}
|
||||
|
||||
public long TotalSum {
|
||||
get {
|
||||
if (Faction == null) {
|
||||
return 0;
|
||||
}
|
||||
return Entries
|
||||
.OfType<RedeemVoucherEntry>()
|
||||
.Where(x => x.FactionBounties.ContainsKey(Faction))
|
||||
.Sum(x => x.FactionBounties[Faction])
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
public string? Type {
|
||||
get {
|
||||
if (Entries == null) {
|
||||
return null;
|
||||
}
|
||||
if (type == null) {
|
||||
string? v = Entries
|
||||
.OfType<RedeemVoucherEntry>()
|
||||
.GroupBy(x => x.Type)
|
||||
.Select(x => x.Key)
|
||||
.First();
|
||||
if (v == null) {
|
||||
return null;
|
||||
} else if (v == "CombatBond") {
|
||||
type = "Combat Bond";
|
||||
} else if (v == "bounty") {
|
||||
type = "Bounty";
|
||||
} else {
|
||||
type = CultureInfo.CurrentCulture.TextInfo.ToTitleCase(v);
|
||||
}
|
||||
}
|
||||
|
||||
return type;
|
||||
}
|
||||
}
|
||||
|
||||
public override int CompareTo(Transaction? other) {
|
||||
if (other == null || other.GetType() != typeof(Vouchers)) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
Vouchers? b = other as Vouchers;
|
||||
if (b?.Type == Type &&
|
||||
b?.Faction == Faction &&
|
||||
b?.System == System &&
|
||||
b?.Station == Station) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return string.Format("{0} Vouchers: {1}", Type, Credits.FormatCredits(TotalSum));
|
||||
}
|
||||
}
|
||||
33
EDPlayerJournal/Credits.cs
Normal file
33
EDPlayerJournal/Credits.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using System.Globalization;
|
||||
|
||||
namespace EDPlayerJournal;
|
||||
|
||||
public class Credits {
|
||||
public static string FormatCredits(int amount) {
|
||||
return FormatCredits((long)amount);
|
||||
}
|
||||
|
||||
public static string FormatCredits(long amount) {
|
||||
var format = new CultureInfo(CultureInfo.CurrentCulture.Name, true).NumberFormat;
|
||||
format.NumberGroupSeparator = ",";
|
||||
format.NumberDecimalSeparator = ".";
|
||||
format.NumberGroupSizes = new int[1] { 3 };
|
||||
format.NumberDecimalDigits = 0;
|
||||
if (amount > 0 && (amount % 1000000000) == 0) {
|
||||
amount /= 1000000000;
|
||||
return string.Format("{0}M CR", amount.ToString("N", format));
|
||||
} else if (amount > 0 && (amount % 1000000) == 0) {
|
||||
amount /= 1000000;
|
||||
return string.Format("{0}M CR", amount.ToString("N", format));
|
||||
} else if (amount > 0 && (amount % 100000) == 0) {
|
||||
double am = ((double)amount) / 1000000;
|
||||
format.NumberDecimalDigits = 1;
|
||||
return string.Format("{0}M CR", am.ToString("N", format));
|
||||
} else if (amount > 0 && (amount % 1000) == 0) {
|
||||
amount /= 1000;
|
||||
return string.Format("{0}K CR", amount.ToString("N", format));
|
||||
}
|
||||
|
||||
return string.Format("{0} CR", amount.ToString("N", format));
|
||||
}
|
||||
}
|
||||
10
EDPlayerJournal/CrimeTypes.cs
Normal file
10
EDPlayerJournal/CrimeTypes.cs
Normal file
@@ -0,0 +1,10 @@
|
||||
namespace EDPlayerJournal;
|
||||
public class CrimeTypes {
|
||||
public static readonly string Assault = "assault";
|
||||
public static readonly string Murder = "murder";
|
||||
public static readonly string OnFootArcCutterUse = "onFoot_arcCutterUse";
|
||||
public static readonly string OnFootDataTransfer = "onFoot_dataTransfer";
|
||||
public static readonly string OnFootIdentityTheft = "onFoot_identityTheft";
|
||||
public static readonly string OnFootMurder = "onFoot_murder";
|
||||
public static readonly string Piracy = "piracy";
|
||||
}
|
||||
19
EDPlayerJournal/EDPlayerJournal.csproj
Normal file
19
EDPlayerJournal/EDPlayerJournal.csproj
Normal file
@@ -0,0 +1,19 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFramework>net6.0</TargetFramework>
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
<Nullable>enable</Nullable>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Update="MissionNames.xml">
|
||||
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
8
EDPlayerJournal/EliteDangerous.cs
Normal file
8
EDPlayerJournal/EliteDangerous.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace EDPlayerJournal;
|
||||
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;
|
||||
}
|
||||
25
EDPlayerJournal/Entries/BountyEntry.cs
Normal file
25
EDPlayerJournal/Entries/BountyEntry.cs
Normal file
@@ -0,0 +1,25 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
/**
|
||||
* This entry appears whenever a bounty is awarded.
|
||||
*/
|
||||
public class BountyEntry : Entry {
|
||||
private string? victimfaction = null;
|
||||
private string? target = null;
|
||||
private int rewards = 0;
|
||||
|
||||
protected override void Initialise() {
|
||||
rewards = JSON.Value<int?>("TotalReward") ?? 0;
|
||||
victimfaction = JSON.Value<string>("VictimFaction") ?? "";
|
||||
target = JSON.Value<string>("Target_Localised") ?? "";
|
||||
}
|
||||
|
||||
public string? VictimFaction => victimfaction;
|
||||
public string? Target => target;
|
||||
public int Rewards => rewards;
|
||||
}
|
||||
15
EDPlayerJournal/Entries/CommanderEntry.cs
Normal file
15
EDPlayerJournal/Entries/CommanderEntry.cs
Normal file
@@ -0,0 +1,15 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class CommanderEntry : Entry {
|
||||
public string? Name { get; set; }
|
||||
public string? FID { get; set; }
|
||||
protected override void Initialise() {
|
||||
Name = JSON.Value<string>("Name") ?? "";
|
||||
FID = JSON.Value<string>("FID") ?? "";
|
||||
}
|
||||
}
|
||||
22
EDPlayerJournal/Entries/CommitCrimeEntry.cs
Normal file
22
EDPlayerJournal/Entries/CommitCrimeEntry.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class CommitCrimeEntry : Entry {
|
||||
public string? CrimeType { get; set; }
|
||||
public string? Faction { get; set; }
|
||||
public string? Victim { get; set; }
|
||||
public string? VictimLocalised { get; set; }
|
||||
public long Bounty { get; set; }
|
||||
public long Fine { get; set; }
|
||||
|
||||
protected override void Initialise() {
|
||||
CrimeType = JSON.Value<string>("CrimeType") ?? "assault";
|
||||
Faction = JSON.Value<string>("Faction") ?? "";
|
||||
Victim = JSON.Value<string>("Victim") ?? "";
|
||||
VictimLocalised = JSON.Value<string>("Victim_Localised") ?? "";
|
||||
Bounty = JSON.Value<long?>("Bounty") ?? 0;
|
||||
Fine = JSON.Value<long?>("Fine") ?? 0;
|
||||
}
|
||||
|
||||
public bool IsMurder {
|
||||
get { return CrimeType?.CompareTo(CrimeTypes.Murder) == 0 || CrimeType?.CompareTo(CrimeTypes.OnFootMurder) == 0; }
|
||||
}
|
||||
}
|
||||
39
EDPlayerJournal/Entries/DiedEntry.cs
Normal file
39
EDPlayerJournal/Entries/DiedEntry.cs
Normal file
@@ -0,0 +1,39 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class Killer {
|
||||
public string? Name { get; set; }
|
||||
public string? Rank { get; set; }
|
||||
public string? Ship { get; set; }
|
||||
}
|
||||
|
||||
public class DiedEntry : Entry {
|
||||
private readonly List<Killer> killers = new List<Killer>();
|
||||
|
||||
public List<Killer> Killers => killers;
|
||||
public Killer? Killer => killers.Count > 0 ? killers[0] : null;
|
||||
public bool WasWing => killers.Count > 1;
|
||||
|
||||
protected override void Initialise() {
|
||||
var wing = JSON.Value<JArray>("Killers");
|
||||
if (wing != null) {
|
||||
/* a wing killed us */
|
||||
foreach (JObject child in wing.Children<JObject>()) {
|
||||
Killer killer = new Killer {
|
||||
Name = child.Value<string>("Name"),
|
||||
Rank = child.Value<string>("Rank"),
|
||||
Ship = child.Value<string>("Ship")
|
||||
};
|
||||
killers.Add(killer);
|
||||
}
|
||||
} else {
|
||||
/* a single ship killed us */
|
||||
Killer killer = new Killer {
|
||||
Name = JSON.Value<string>("KillerName"),
|
||||
Rank = JSON.Value<string>("KillerRank"),
|
||||
Ship = JSON.Value<string>("KillerShip")
|
||||
};
|
||||
killers.Add(killer);
|
||||
}
|
||||
}
|
||||
}
|
||||
19
EDPlayerJournal/Entries/DockedEntry.cs
Normal file
19
EDPlayerJournal/Entries/DockedEntry.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class DockedEntry : Entry {
|
||||
public string? StationName { get; set; }
|
||||
public string? StarSystem { get; set; }
|
||||
public ulong? SystemAddress { get; set; }
|
||||
public string? StationFaction { get; set; }
|
||||
|
||||
protected override void Initialise() {
|
||||
StationName = JSON.Value<string>("StationName");
|
||||
StarSystem = JSON.Value<string>("StarSystem");
|
||||
SystemAddress = JSON.Value<ulong?>("SystemAddress");
|
||||
JObject? faction = JSON.Value<JObject>("StationFaction");
|
||||
if (faction != null) {
|
||||
StationFaction = faction.Value<string>("Name") ?? "";
|
||||
}
|
||||
}
|
||||
}
|
||||
130
EDPlayerJournal/Entries/Entry.cs
Normal file
130
EDPlayerJournal/Entries/Entry.cs
Normal file
@@ -0,0 +1,130 @@
|
||||
using Newtonsoft.Json;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
|
||||
public class InvalidJournalEntryException : Exception {
|
||||
public InvalidJournalEntryException() { }
|
||||
public InvalidJournalEntryException(string message) : base(message) { }
|
||||
}
|
||||
|
||||
/// <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.Bounty, typeof(BountyEntry) },
|
||||
{ Events.Commander, typeof(CommanderEntry) },
|
||||
{ Events.CommitCrime, typeof(CommitCrimeEntry) },
|
||||
{ Events.Died, typeof(DiedEntry) },
|
||||
{ Events.Docked, typeof(DockedEntry) },
|
||||
{ Events.FactionKillBond, typeof(FactionKillBondEntry) },
|
||||
{ Events.FSDJump, typeof(FSDJumpEntry) },
|
||||
{ Events.HullDamage, typeof(HullDamageEntry) },
|
||||
{ Events.LoadGame, typeof(LoadGameEntry) },
|
||||
{ Events.Location, typeof(LocationEntry) },
|
||||
{ Events.MarketBuy, typeof(MarketBuyEntry) },
|
||||
{ Events.MarketSell, typeof(MarketSellEntry) },
|
||||
{ Events.MissionAbandoned, typeof(MissionAbandonedEntry) },
|
||||
{ Events.MissionAccepted, typeof(MissionAcceptedEntry) },
|
||||
{ Events.MissionCompleted, typeof(MissionCompletedEntry) },
|
||||
{ Events.MissionFailed, typeof(MissionFailedEntry) },
|
||||
{ Events.MissionRedirected, typeof(MissionRedirectedEntry) },
|
||||
{ Events.MultiSellExplorationData, typeof(MultiSellExplorationDataEntry) },
|
||||
{ Events.RedeemVoucher, typeof(RedeemVoucherEntry) },
|
||||
{ Events.SearchAndRescue, typeof(SearchAndRescueEntry) },
|
||||
{ Events.SellExplorationData, typeof(SellExplorationDataEntry) },
|
||||
{ Events.SellMicroResources, typeof(SellMicroResourcesEntry) },
|
||||
{ Events.SellOrganicData, typeof(SellOrganicDataEntry) },
|
||||
{ Events.ShieldState, typeof(ShieldStateEntry) },
|
||||
{ Events.ShipTargeted, typeof(ShipTargetedEntry) },
|
||||
{ Events.UnderAttack, typeof(UnderAttackEntry) },
|
||||
};
|
||||
|
||||
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);
|
||||
if (json == null) {
|
||||
return null;
|
||||
}
|
||||
return Parse(json);
|
||||
}
|
||||
|
||||
public static Entry? Parse(JObject json) {
|
||||
string? event_name = json.Value<string?>("event");
|
||||
|
||||
if (event_name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
classes.TryGetValue(event_name, out Type? classhandler);
|
||||
if (classhandler == null) {
|
||||
// No specific handler available so use base class
|
||||
classhandler = typeof(Entry);
|
||||
}
|
||||
|
||||
Entry? obj = (Entry?)Activator.CreateInstance(classhandler);
|
||||
if (obj == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
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.Value<string>("event");
|
||||
// Do not change this or JSON parser will conver the string to
|
||||
// datetime object and call .ToString() on it which changes the
|
||||
// date and time format
|
||||
this.datetime = json.GetValue("timestamp")?.ToString();
|
||||
|
||||
if (!string.IsNullOrEmpty(this.datetime)) {
|
||||
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 ?? new JObject(); }
|
||||
}
|
||||
|
||||
public override string ToString() {
|
||||
return jsonstr ?? "";
|
||||
}
|
||||
}
|
||||
31
EDPlayerJournal/Entries/Events.cs
Normal file
31
EDPlayerJournal/Entries/Events.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
|
||||
public class Events {
|
||||
public static readonly string Bounty = "Bounty";
|
||||
public static readonly string Commander = "Commander";
|
||||
public static readonly string CommitCrime = "CommitCrime";
|
||||
public static readonly string Died = "Died";
|
||||
public static readonly string Docked = "Docked";
|
||||
public static readonly string FactionKillBond = "FactionKillBond";
|
||||
public static readonly string FighterDestroyed = "FighterDestroyed";
|
||||
public static readonly string FSDJump = "FSDJump";
|
||||
public static readonly string HullDamage = "HullDamage";
|
||||
public static readonly string LoadGame = "LoadGame";
|
||||
public static readonly string Location = "Location";
|
||||
public static readonly string MarketBuy = "MarketBuy";
|
||||
public static readonly string MarketSell = "MarketSell";
|
||||
public static readonly string MissionAbandoned = "MissionAbandoned";
|
||||
public static readonly string MissionAccepted = "MissionAccepted";
|
||||
public static readonly string MissionCompleted = "MissionCompleted";
|
||||
public static readonly string MissionFailed = "MissionFailed";
|
||||
public static readonly string MissionRedirected = "MissionRedirected";
|
||||
public static readonly string MultiSellExplorationData = "MultiSellExplorationData";
|
||||
public static readonly string RedeemVoucher = "RedeemVoucher";
|
||||
public static readonly string SearchAndRescue = "SearchAndRescue";
|
||||
public static readonly string SellExplorationData = "SellExplorationData";
|
||||
public static readonly string SellMicroResources = "SellMicroResources";
|
||||
public static readonly string SellOrganicData = "SellOrganicData";
|
||||
public static readonly string ShieldState = "ShieldState";
|
||||
public static readonly string ShipTargeted = "ShipTargeted";
|
||||
public static readonly string UnderAttack = "UnderAttack";
|
||||
}
|
||||
35
EDPlayerJournal/Entries/FSDJumpEntry.cs
Normal file
35
EDPlayerJournal/Entries/FSDJumpEntry.cs
Normal file
@@ -0,0 +1,35 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class FSDJumpEntry : Entry {
|
||||
protected override void Initialise() {
|
||||
SystemAddress = JSON.Value<ulong?>("SystemAddress") ?? 0;
|
||||
StarSystem = JSON.Value<string>("StarSystem");
|
||||
|
||||
var pos = JSON.Value<JArray>("SarPos");
|
||||
if (pos != null) {
|
||||
StarPos = pos.ToObject<long[]>();
|
||||
}
|
||||
|
||||
var faction = JSON.Value<JObject>("SystemFaction");
|
||||
if (faction != null) {
|
||||
SystemFaction = faction.Value<string>("Name");
|
||||
}
|
||||
|
||||
var factions = JSON.Value<JArray>("Factions");
|
||||
if (factions != null) {
|
||||
foreach (JObject system_faction in factions) {
|
||||
Faction? f = Faction.FromJSON(system_faction);
|
||||
if (f != null) {
|
||||
SystemFactions.Add(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
public long[]? StarPos { get; set; }
|
||||
public string? StarSystem { get; set; }
|
||||
public string? SystemFaction { get; set; }
|
||||
public ulong SystemAddress { get; set; }
|
||||
public List<Faction> SystemFactions { get; set; } = new List<Faction>();
|
||||
}
|
||||
13
EDPlayerJournal/Entries/FactionKillBondEntry.cs
Normal file
13
EDPlayerJournal/Entries/FactionKillBondEntry.cs
Normal file
@@ -0,0 +1,13 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
|
||||
public class FactionKillBondEntry : Entry {
|
||||
public int Reward { get; set; }
|
||||
public string? AwardingFaction { get; set; }
|
||||
public string? VictimFaction { get; set; }
|
||||
|
||||
protected override void Initialise() {
|
||||
Reward = JSON.Value<int?>("Reward") ?? 0;
|
||||
AwardingFaction = JSON.Value<string>("AwardingFaction");
|
||||
VictimFaction = JSON.Value<string>("VictimFaction");
|
||||
}
|
||||
}
|
||||
16
EDPlayerJournal/Entries/HullDamageEntry.cs
Normal file
16
EDPlayerJournal/Entries/HullDamageEntry.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class HullDamageEntry : Entry {
|
||||
private double health = 0;
|
||||
private bool playerpilot = false;
|
||||
private bool fighter = false;
|
||||
|
||||
public double Health => health;
|
||||
public bool PlayerPilot => playerpilot;
|
||||
public bool Fighter => fighter;
|
||||
|
||||
protected override void Initialise() {
|
||||
health = JSON.Value<double?>("Health") ?? 100.0;
|
||||
playerpilot = JSON.Value<bool?>("PlayerPilot") ?? true;
|
||||
fighter = JSON.Value<bool?>("Fighter") ?? false;
|
||||
}
|
||||
}
|
||||
51
EDPlayerJournal/Entries/LoadGameEntry.cs
Normal file
51
EDPlayerJournal/Entries/LoadGameEntry.cs
Normal file
@@ -0,0 +1,51 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class LoadGameEntry : Entry {
|
||||
public string? Commander { get; set; }
|
||||
public string? FID { get; set; }
|
||||
public bool Horizons { get; set; }
|
||||
public bool Odyssey { get; set; }
|
||||
public string? Ship { get; set; }
|
||||
public long ShipID { get; set; }
|
||||
public bool StartLanded { get; set; }
|
||||
public bool StartDead { get; set; }
|
||||
public string? GameMode { get; set; }
|
||||
public string? Group { get; set; }
|
||||
public long Credits { get; set; }
|
||||
public long Loan { get; set; }
|
||||
public string? ShipName { get; set; }
|
||||
public string? ShipIdent { get; set; }
|
||||
public double FuelLevel { get; set; }
|
||||
public double FuelCapacity { get; set; }
|
||||
|
||||
protected override void Initialise() {
|
||||
Commander = JSON.Value<string>("Commander");
|
||||
FID = JSON.Value<string>("FID");
|
||||
// Game
|
||||
Horizons = JSON.Value<bool?>("Horizons") ?? false;
|
||||
Odyssey = JSON.Value<bool?>("Odyssey") ?? false;
|
||||
// Ships
|
||||
Ship = JSON.Value<string>("Ship");
|
||||
ShipID = JSON.Value<long?>("ShipID") ?? 0;
|
||||
ShipName = JSON.Value<string>("ShipName");
|
||||
ShipIdent = JSON.Value<string>("ShipIdent");
|
||||
// Fuel
|
||||
FuelLevel = JSON.Value<double?>("FuelLevel") ?? 0.0;
|
||||
FuelCapacity = JSON.Value<double?>("FuelCapacity") ?? 0.0;
|
||||
// Landed/Dead
|
||||
StartLanded = JSON.Value<bool?>("StartLanded") ?? false;
|
||||
StartDead = JSON.Value<bool?>("StartDead") ?? false;
|
||||
// GameMode
|
||||
GameMode = JSON.Value<string>("GameMode");
|
||||
// Group
|
||||
Group = JSON.Value<string>("Group");
|
||||
// Wealth
|
||||
Credits = JSON.Value<long?>("Credits") ?? 0;
|
||||
Loan = JSON.Value<long?>("Loan") ?? 0;
|
||||
}
|
||||
}
|
||||
46
EDPlayerJournal/Entries/LocationEntry.cs
Normal file
46
EDPlayerJournal/Entries/LocationEntry.cs
Normal file
@@ -0,0 +1,46 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class LocationEntry : Entry {
|
||||
public string? StarSystem { get; set; }
|
||||
public string? SystemFaction { get; set; }
|
||||
public string? StationName { get; set; }
|
||||
public ulong SystemAddress { get; set; }
|
||||
public string? Body { get; set; }
|
||||
public bool Docked { get; set; }
|
||||
public long[]? StarPos { get; set; }
|
||||
|
||||
public List<Faction> SystemFactions { get; set; } = new List<Faction>();
|
||||
|
||||
protected override void Initialise() {
|
||||
StarSystem = JSON.Value<string>("StarSystem") ?? "";
|
||||
SystemAddress = JSON.Value<ulong?>("SystemAddress") ?? 0;
|
||||
Docked = JSON.Value<bool?>("Docked") ?? false;
|
||||
StationName = JSON.Value<string>("StationName") ?? "";
|
||||
|
||||
var pos = JSON.Value<JArray>("StarPos");
|
||||
if (pos != null) {
|
||||
StarPos = pos.ToObject<long[]>();
|
||||
}
|
||||
|
||||
JObject? systemfaction = JSON.Value<JObject>("SystemFaction");
|
||||
if (systemfaction != null) {
|
||||
SystemFaction = systemfaction.Value<string>("Name") ?? "";
|
||||
}
|
||||
|
||||
JArray? factions = JSON.Value<JArray>("Factions");
|
||||
if (factions != null) {
|
||||
foreach (JObject system_faction in factions) {
|
||||
Faction? f = Faction.FromJSON(system_faction);
|
||||
if (f != null) {
|
||||
SystemFactions.Add(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
22
EDPlayerJournal/Entries/MarketBuyEntry.cs
Normal file
22
EDPlayerJournal/Entries/MarketBuyEntry.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class MarketBuyEntry : Entry {
|
||||
public string? Type { get; set; }
|
||||
public string? TypeLocalised { get; set; }
|
||||
public long Count { get; set; }
|
||||
public long BuyPrice { get; set; }
|
||||
public long TotalCost { get; set; }
|
||||
|
||||
protected override void Initialise() {
|
||||
Type = JSON.Value<string>("Type");
|
||||
TypeLocalised = JSON.Value<string>("Type_Localised");
|
||||
Count = JSON.Value<long?>("Count") ?? 0;
|
||||
BuyPrice = JSON.Value<long?>("BuyPrice") ?? 0;
|
||||
TotalCost = JSON.Value<long?>("TotalCost") ?? 0;
|
||||
}
|
||||
}
|
||||
50
EDPlayerJournal/Entries/MarketSellEntry.cs
Normal file
50
EDPlayerJournal/Entries/MarketSellEntry.cs
Normal file
@@ -0,0 +1,50 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class MarketSellEntry : Entry {
|
||||
/// <summary>
|
||||
/// Total value
|
||||
/// </summary>
|
||||
public int TotalSale { get; set; }
|
||||
/// <summary>
|
||||
/// How many.
|
||||
/// </summary>
|
||||
public int Count { get; set; }
|
||||
/// <summary>
|
||||
/// Average price paid
|
||||
/// </summary>
|
||||
public int AvgPricePaid { get; set; }
|
||||
/// <summary>
|
||||
/// Cargo type
|
||||
/// </summary>
|
||||
public string? Type { get; set; }
|
||||
/// <summary>
|
||||
/// Localised name of the cargo sold, may be null.
|
||||
/// </summary>
|
||||
public string? TypeLocalised { get; set; }
|
||||
/// <summary>
|
||||
/// Price per unit
|
||||
/// </summary>
|
||||
public int SellPrice { get; set; }
|
||||
/// <summary>
|
||||
/// Whether the goods were illegal in the target system.
|
||||
/// </summary>
|
||||
public bool IllegalGoods { get; set; }
|
||||
/// <summary>
|
||||
/// Whether the goods were stolen
|
||||
/// </summary>
|
||||
public bool StolenGoods { get; set; }
|
||||
/// <summary>
|
||||
/// Whether the goods were sold to the black market
|
||||
/// </summary>
|
||||
public bool BlackMarket { get; set; }
|
||||
|
||||
protected override void Initialise() {
|
||||
Type = JSON.Value<string>("Type");
|
||||
TypeLocalised = JSON.Value<string>("Type_Localised");
|
||||
TotalSale = JSON.Value<int?>("TotalSale") ?? 0;
|
||||
Count = JSON.Value<int?>("Count") ?? 0;
|
||||
AvgPricePaid = JSON.Value<int?>("AvgPricePaid") ?? 0;
|
||||
IllegalGoods = JSON.Value<bool?>("IllegalGoods") ?? false;
|
||||
StolenGoods = JSON.Value<bool?>("StolenGoods") ?? false;
|
||||
BlackMarket = JSON.Value<bool?>("BlackMarket") ?? false;
|
||||
}
|
||||
}
|
||||
7
EDPlayerJournal/Entries/MissionAbandonedEntry.cs
Normal file
7
EDPlayerJournal/Entries/MissionAbandonedEntry.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class MissionAbandonedEntry : Entry {
|
||||
public ulong MissionID { get; set; }
|
||||
protected override void Initialise() {
|
||||
MissionID = JSON.Value<ulong?>("MissionID") ?? 0;
|
||||
}
|
||||
}
|
||||
22
EDPlayerJournal/Entries/MissionAcceptedEntry.cs
Normal file
22
EDPlayerJournal/Entries/MissionAcceptedEntry.cs
Normal file
@@ -0,0 +1,22 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class MissionAcceptedEntry : Entry {
|
||||
public string? Faction { get; set; }
|
||||
public string? TargetFaction { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? LocalisedName { get; set; }
|
||||
public string? LocalisedTargetType { get; set; }
|
||||
public int KillCount { get; set; }
|
||||
public ulong MissionID { get; set; }
|
||||
public long Reward { get; set; }
|
||||
|
||||
protected override void Initialise() {
|
||||
Faction = JSON.Value<string>("Faction");
|
||||
TargetFaction = JSON.Value<string>("TargetFaction");
|
||||
Name = JSON.Value<string>("Name");
|
||||
LocalisedName = JSON.Value<string>("LocalisedName");
|
||||
LocalisedTargetType = JSON.Value<string>("TargetType_Localised");
|
||||
KillCount = JSON.Value<int?>("KillCount") ?? 0;
|
||||
MissionID = JSON.Value<ulong?>("MissionID") ?? 0;
|
||||
Reward = JSON.Value<long?>("Reward") ?? 0;
|
||||
}
|
||||
}
|
||||
159
EDPlayerJournal/Entries/MissionCompletedEntry.cs
Normal file
159
EDPlayerJournal/Entries/MissionCompletedEntry.cs
Normal file
@@ -0,0 +1,159 @@
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Linq;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class MissionCompletedEntry : Entry {
|
||||
public Dictionary<string, Dictionary<ulong, string>> Influences { get; set; } = new Dictionary<string, Dictionary<ulong, string>>();
|
||||
private List<string> Affected { get; set; } = new List<string>();
|
||||
|
||||
private string? readable_name = null;
|
||||
private bool readable_name_generated = false;
|
||||
|
||||
protected override void Initialise() {
|
||||
MissionID = JSON.Value<ulong?>("MissionID") ?? 0;
|
||||
Name = JSON.Value<string>("Name");
|
||||
Faction = JSON.Value<string>("Faction") ?? "";
|
||||
TargetFaction = JSON.Value<string>("TargetFaction") ?? "";
|
||||
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");
|
||||
}
|
||||
|
||||
MakeHumanReadableName();
|
||||
BuildInfluenceList();
|
||||
}
|
||||
|
||||
private void BuildInfluenceList() {
|
||||
Influences.Clear();
|
||||
Affected.Clear();
|
||||
|
||||
var effects = JSON.Value<JArray>("FactionEffects");
|
||||
if (effects == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (var effect in effects.Children<JObject>()) {
|
||||
string? faction = effect.Value<string>("Faction");
|
||||
|
||||
if (faction == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Affected.Add(faction);
|
||||
|
||||
var influence = effect.Value<JArray>("Influence");
|
||||
if (influence == null || influence.Count == 0) {
|
||||
// No influence reward, happens sometimes, but we have to accept it
|
||||
Influences.Add(faction, new Dictionary<ulong, string>());
|
||||
} else {
|
||||
foreach (var infl in influence.Children<JObject>()) {
|
||||
infl.TryGetValue("Influence", out JToken? result);
|
||||
infl.TryGetValue("SystemAddress", out JToken? systemaddr);
|
||||
|
||||
if (result != null && result.Type == JTokenType.String &&
|
||||
systemaddr != null && systemaddr.Type == JTokenType.Integer) {
|
||||
ulong system = systemaddr.ToObject<ulong?>() ?? 0;
|
||||
string inf = result.ToString();
|
||||
|
||||
if (!Influences.ContainsKey(faction)) {
|
||||
Influences.Add(faction, new Dictionary<ulong, string>());
|
||||
}
|
||||
|
||||
if (!Influences[faction].ContainsKey(system)) {
|
||||
Influences[faction].Add(system, inf);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string? Name { get; set; }
|
||||
public string? Commodity { get; set; }
|
||||
public int? Count { get; set; }
|
||||
public int? Donated { get; set; }
|
||||
public ulong? MissionID { get; set; }
|
||||
public string? Faction { get; set; }
|
||||
public string? TargetFaction { get; set; }
|
||||
|
||||
private void MakeHumanReadableName() {
|
||||
if (readable_name != null || Name == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
string? readable = HumanReadableMissionName.MakeHumanReadableName(Name);
|
||||
StringBuilder builder = new StringBuilder();
|
||||
|
||||
if (readable == null) {
|
||||
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;
|
||||
} else {
|
||||
builder.Append(readable);
|
||||
}
|
||||
|
||||
if (Count > 0 && Commodity != null) {
|
||||
builder.AppendFormat(" ({0} {1})", Count, Commodity);
|
||||
}
|
||||
|
||||
if (Donated != null || Donated > 0) {
|
||||
builder.AppendFormat(" ({0})", Credits.FormatCredits(Donated ?? 0));
|
||||
}
|
||||
|
||||
readable_name = builder.ToString().Trim();
|
||||
}
|
||||
|
||||
public string? HumanReadableName {
|
||||
get {
|
||||
MakeHumanReadableName();
|
||||
return readable_name;
|
||||
}
|
||||
}
|
||||
|
||||
public bool HumanReadableNameWasGenerated {
|
||||
get {
|
||||
MakeHumanReadableName();
|
||||
return readable_name_generated;
|
||||
}
|
||||
}
|
||||
|
||||
public string[] AffectedFactions => Affected.ToArray();
|
||||
|
||||
public string? GetInfluenceForFaction(string faction) {
|
||||
if (Influences == null || !Influences.ContainsKey(faction)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
var inf = Influences[faction];
|
||||
return string.Join("", inf.Values);
|
||||
}
|
||||
|
||||
public string? GetInfluenceForFaction(string faction, ulong systemaddr) {
|
||||
if (!Influences.ContainsKey(faction)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (!Influences[faction].ContainsKey(systemaddr)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return Influences[faction][systemaddr];
|
||||
}
|
||||
}
|
||||
19
EDPlayerJournal/Entries/MissionFailedEntry.cs
Normal file
19
EDPlayerJournal/Entries/MissionFailedEntry.cs
Normal file
@@ -0,0 +1,19 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class MissionFailedEntry : Entry {
|
||||
public string? Name { get; set; }
|
||||
public ulong MissionID { get; set; }
|
||||
public int Fine { get; set; }
|
||||
|
||||
public string? HumanReadableName {
|
||||
get {
|
||||
if (Name == null) return null;
|
||||
return HumanReadableMissionName.MakeHumanReadableName(Name);
|
||||
}
|
||||
}
|
||||
|
||||
protected override void Initialise() {
|
||||
Name = JSON.Value<string>("Name");
|
||||
MissionID = JSON.Value<ulong?>("MissionID") ?? 0;
|
||||
Fine = JSON.Value<int?>("Fine") ?? 0;
|
||||
}
|
||||
}
|
||||
16
EDPlayerJournal/Entries/MissionRedirectedEntry.cs
Normal file
16
EDPlayerJournal/Entries/MissionRedirectedEntry.cs
Normal file
@@ -0,0 +1,16 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class MissionRedirectedEntry : Entry {
|
||||
public int MissionID { get; set; } = 0;
|
||||
public string? Name { get; set; }
|
||||
public string? NewDestinationStation { get; set; }
|
||||
public string? NewDestinationSystem { get; set; }
|
||||
public string? OldDestinationSystem { get; set; }
|
||||
|
||||
protected override void Initialise() {
|
||||
MissionID = (JSON.Value<int?>("MissionID") ?? 0);
|
||||
Name = JSON.Value<string>("Name");
|
||||
NewDestinationStation = JSON.Value<string>("NewDestinationStation");
|
||||
NewDestinationSystem = JSON.Value<string>("NewDestinationSystem");
|
||||
OldDestinationSystem = JSON.Value<string>("OldDestinationSystem");
|
||||
}
|
||||
}
|
||||
8
EDPlayerJournal/Entries/MultiSellExplorationDataEntry.cs
Normal file
8
EDPlayerJournal/Entries/MultiSellExplorationDataEntry.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class MultiSellExplorationDataEntry : Entry {
|
||||
protected override void Initialise() {
|
||||
TotalEarnings = (JSON.Value<int?>("TotalEarnings") ?? 0);
|
||||
}
|
||||
|
||||
public int TotalEarnings { get; set; } = 0;
|
||||
}
|
||||
42
EDPlayerJournal/Entries/RedeemVoucherEntry.cs
Normal file
42
EDPlayerJournal/Entries/RedeemVoucherEntry.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class RedeemVoucherEntry : Entry {
|
||||
protected override void Initialise() {
|
||||
Amount = (JSON.Value<int?>("Amount") ?? 0);
|
||||
Type = JSON.Value<string>("Type");
|
||||
|
||||
/* according to API, there should be a Factions structure */
|
||||
JToken? factions = JSON.GetValue("Factions");
|
||||
if (factions != null) {
|
||||
foreach (JObject faction in factions.Children<JObject>()) {
|
||||
string? faction_name = faction.Value<string>("Faction");
|
||||
long? faction_bounty = faction.Value<long?>("Amount");
|
||||
if (faction_name == null || faction_name.Length <= 0 || faction_bounty == null) {
|
||||
continue;
|
||||
}
|
||||
Factions.Add(faction_name);
|
||||
if (!FactionBounties.ContainsKey(faction_name)) {
|
||||
FactionBounties[faction_name] = 0;
|
||||
}
|
||||
FactionBounties[faction_name] += (faction_bounty ?? 0);
|
||||
}
|
||||
}
|
||||
|
||||
/* but there also might be just a Faction entry */
|
||||
string? single_faction = JSON.Value<string>("Faction");
|
||||
if (single_faction != null) {
|
||||
Factions.Add(single_faction);
|
||||
if (!FactionBounties.ContainsKey(single_faction)) {
|
||||
FactionBounties[single_faction] = 0;
|
||||
}
|
||||
FactionBounties[single_faction] += Amount;
|
||||
}
|
||||
}
|
||||
|
||||
public int Amount { get; set; } = 0;
|
||||
public string? Type { get; set; } = "Bounty";
|
||||
public List<string> Factions { get; set; } = new List<string>();
|
||||
public Dictionary<string, long> FactionBounties { get; set; } = new Dictionary<string, long>();
|
||||
}
|
||||
18
EDPlayerJournal/Entries/SearchAndRescueEntry.cs
Normal file
18
EDPlayerJournal/Entries/SearchAndRescueEntry.cs
Normal file
@@ -0,0 +1,18 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class SearchAndRescueEntry : Entry {
|
||||
public long MarketID { get; set; }
|
||||
public string? Name { get; set; }
|
||||
public string? NameLocalised { get; set; }
|
||||
public long Count { get; set; }
|
||||
public long Reward { get; set; }
|
||||
|
||||
protected override void Initialise() {
|
||||
MarketID = JSON.Value<long?>("MarketID") ?? 0;
|
||||
Name = JSON.Value<string>("Name") ?? "";
|
||||
NameLocalised = JSON.Value<string>("Name_Localised");
|
||||
Count = JSON.Value<long?>("Count") ?? 0;
|
||||
Reward = JSON.Value<long?>("Reward") ?? 0;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
29
EDPlayerJournal/Entries/SellExplorationDataEntry.cs
Normal file
29
EDPlayerJournal/Entries/SellExplorationDataEntry.cs
Normal file
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Linq;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class SellExplorationDataEntry : Entry {
|
||||
public long BaseValue { get; set; }
|
||||
public long Bonus { get; set; }
|
||||
public long TotalEarnings { get; set; }
|
||||
|
||||
public List<string> Systems { get; set; } = new List<string>();
|
||||
public List<string> Discovered { get; set; } = new List<string>();
|
||||
|
||||
protected override void Initialise() {
|
||||
BaseValue = JSON.Value<long?>("BaseValue") ?? 0;
|
||||
Bonus = JSON.Value<long?>("Bonus") ?? 0;
|
||||
TotalEarnings = JSON.Value<long?>("TotalEarnings") ?? 0;
|
||||
|
||||
var sys = JSON.Value<JArray>("Systems");
|
||||
if (sys != null) {
|
||||
Systems = sys.Select(x => x.ToString()).ToList<string>();
|
||||
}
|
||||
|
||||
var dis = JSON.Value<JArray>("Discovered");
|
||||
if (dis != null) {
|
||||
Discovered = dis.Select(x => x.ToString()).ToList<string>();
|
||||
}
|
||||
}
|
||||
}
|
||||
8
EDPlayerJournal/Entries/SellMicroResourcesEntry.cs
Normal file
8
EDPlayerJournal/Entries/SellMicroResourcesEntry.cs
Normal file
@@ -0,0 +1,8 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class SellMicroResourcesEntry : Entry {
|
||||
protected override void Initialise() {
|
||||
Price = JSON.Value<int>("Price");
|
||||
}
|
||||
|
||||
public int Price { get; set; }
|
||||
}
|
||||
42
EDPlayerJournal/Entries/SellOrganicDataEntry.cs
Normal file
42
EDPlayerJournal/Entries/SellOrganicDataEntry.cs
Normal file
@@ -0,0 +1,42 @@
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class BioData {
|
||||
public string? Genus { get; set; }
|
||||
public string? GenusLocalised { get; set; }
|
||||
public string? Species { get; set; }
|
||||
public string? SpeciesLocalised { get; set; }
|
||||
public long Value { get; set; } = 0;
|
||||
public long Bonus { get; set; } = 0;
|
||||
public long TotalValue => Value + Bonus;
|
||||
}
|
||||
public class SellOrganicDataEntry : Entry {
|
||||
public long MarketID { get; set; }
|
||||
public List<BioData> BioData => new List<BioData>();
|
||||
|
||||
protected override void Initialise() {
|
||||
MarketID = JSON.Value<long?>("MarketID") ?? 0;
|
||||
|
||||
var biodata = JSON.Value<JArray>("BioData");
|
||||
if (biodata == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
foreach (JObject item in biodata) {
|
||||
BioData data = new BioData {
|
||||
Bonus = item.Value<long?>("Bonus") ?? 0,
|
||||
Value = item.Value<long?>("Value") ?? 0,
|
||||
Species = item.Value<string>("Species"),
|
||||
Genus = item.Value<string>("Genus"),
|
||||
GenusLocalised = item.Value<string>("Genus_Localised"),
|
||||
SpeciesLocalised = item.Value<string>("Species_Localised")
|
||||
};
|
||||
|
||||
BioData.Add(data);
|
||||
}
|
||||
}
|
||||
|
||||
public long TotalValue {
|
||||
get { return BioData.Sum(x => x.TotalValue); }
|
||||
}
|
||||
}
|
||||
7
EDPlayerJournal/Entries/ShieldStateEntry.cs
Normal file
7
EDPlayerJournal/Entries/ShieldStateEntry.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class ShieldStateEntry : Entry {
|
||||
public bool ShieldsUp { get; set; } = false;
|
||||
protected override void Initialise() {
|
||||
ShieldsUp = JSON.Value<bool?>("ShieldsUp") ?? true;
|
||||
}
|
||||
}
|
||||
31
EDPlayerJournal/Entries/ShipTargetedEntry.cs
Normal file
31
EDPlayerJournal/Entries/ShipTargetedEntry.cs
Normal file
@@ -0,0 +1,31 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class ShipTargetedEntry : Entry {
|
||||
public string? Ship { get; set; }
|
||||
public long ScanStage { get; set; }
|
||||
public string? PilotName { get; set; }
|
||||
public string? PilotNameLocalised { get; set; }
|
||||
public string? PilotRank { get; set; }
|
||||
public double ShieldHealth { get; set; }
|
||||
public double HullHealth { get; set; }
|
||||
public long Bounty { get; set; }
|
||||
public string? LegalStatus { get; set; }
|
||||
public string? Faction { get; set; }
|
||||
public string? Power { get; set; }
|
||||
|
||||
protected override void Initialise() {
|
||||
ScanStage = JSON.Value<long?>("ScanStage") ?? 0;
|
||||
Ship = JSON.Value<string>("Ship_Localised");
|
||||
PilotName = JSON.Value<string>("PilotName");
|
||||
PilotNameLocalised = JSON.Value<string>("PilotName_Localised");
|
||||
PilotRank = JSON.Value<string>("PilotRank");
|
||||
ShieldHealth = JSON.Value<double?>("ShieldHealth") ?? 0.0;
|
||||
HullHealth = JSON.Value<double?>("HullHealth") ?? 0.0;
|
||||
Bounty = JSON.Value<long?>("Bounty") ?? 0;
|
||||
LegalStatus = JSON.Value<string>("LegalStatus") ?? "Clean";
|
||||
Faction = JSON.Value<string>("Faction");
|
||||
Power = JSON.Value<string>("Power");
|
||||
}
|
||||
}
|
||||
7
EDPlayerJournal/Entries/UnderAttackEntry.cs
Normal file
7
EDPlayerJournal/Entries/UnderAttackEntry.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace EDPlayerJournal.Entries;
|
||||
public class UnderAttackEntry : Entry {
|
||||
public string? Target { get; set; }
|
||||
protected override void Initialise() {
|
||||
Target = JSON.Value<string>("Target");
|
||||
}
|
||||
}
|
||||
101
EDPlayerJournal/Faction.cs
Normal file
101
EDPlayerJournal/Faction.cs
Normal file
@@ -0,0 +1,101 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using Newtonsoft.Json.Linq;
|
||||
|
||||
namespace EDPlayerJournal;
|
||||
public class FactionState {
|
||||
public string? State { get; set; }
|
||||
public long? Trend { get; set; }
|
||||
|
||||
public static FactionState? FromJSON(JObject j) {
|
||||
if (j == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FactionState s = new FactionState() {
|
||||
State = j.Value<string>("State"),
|
||||
Trend = j.Value<long?>("Trend"),
|
||||
};
|
||||
|
||||
if (string.IsNullOrEmpty(s.State)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return s;
|
||||
}
|
||||
}
|
||||
|
||||
public class Faction {
|
||||
public string? Name { get; set; }
|
||||
public string? FactionState { get; set; }
|
||||
public string? Government { get; set; }
|
||||
public double Influence { get; set; }
|
||||
public string? Allegiance { get; set; }
|
||||
public string? Happiness { get; set; }
|
||||
public string? HappinessLocalised { get; set; }
|
||||
public double MyReputation { get; set; }
|
||||
public bool SquadronFaction { get; set; } = false;
|
||||
public bool HomeSystem { get; set; } = false;
|
||||
|
||||
public List<FactionState> RecoveringStates { get; set; } = new List<FactionState>();
|
||||
public List<FactionState> ActiveStates { get; set; } = new List<FactionState>();
|
||||
public List<FactionState> PendingStates { get; set; } = new List<FactionState>();
|
||||
|
||||
public static Faction? FromJSON(JObject j) {
|
||||
if (j == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Faction f = new Faction() {
|
||||
Name = j.Value<string>("Name") ?? "",
|
||||
FactionState = j.Value<string>("FactionState") ?? "",
|
||||
Government = j.Value<string>("Government") ?? "",
|
||||
Influence = j.Value<double?>("Influence") ?? 1.0,
|
||||
Allegiance = j.Value<string>("Allegiance") ?? "",
|
||||
Happiness = j.Value<string>("Happiness") ?? "",
|
||||
HappinessLocalised = j.Value<string>("Happiness_Localised") ?? "",
|
||||
MyReputation = j.Value<double?>("MyReputation") ?? 1.0,
|
||||
SquadronFaction = (j.Value<bool?>("SquadronFaction") ?? false),
|
||||
HomeSystem = (j.Value<bool?>("HomeSystem") ?? false),
|
||||
};
|
||||
|
||||
if (string.IsNullOrEmpty(f.Name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
JArray? recovering_states = j.Value<JArray>("RecoveringStates");
|
||||
if (recovering_states != null) {
|
||||
foreach (JObject s in recovering_states) {
|
||||
FactionState? state = EDPlayerJournal.FactionState.FromJSON(s);
|
||||
if (state != null) {
|
||||
f.RecoveringStates.Add(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JArray? active_states = j.Value<JArray>("ActiveStates");
|
||||
if (active_states != null) {
|
||||
foreach (JObject s in active_states) {
|
||||
FactionState? state = EDPlayerJournal.FactionState.FromJSON(s);
|
||||
if (state != null) {
|
||||
f.ActiveStates.Add(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
JArray? pending_states = j.Value<JArray>("PendingStates");
|
||||
if (pending_states != null) {
|
||||
foreach (JObject s in pending_states) {
|
||||
FactionState? state = EDPlayerJournal.FactionState.FromJSON(s);
|
||||
if (state != null) {
|
||||
f.PendingStates.Add(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return f;
|
||||
}
|
||||
}
|
||||
63
EDPlayerJournal/HumanReadableMissionName.cs
Normal file
63
EDPlayerJournal/HumanReadableMissionName.cs
Normal file
@@ -0,0 +1,63 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Xml;
|
||||
|
||||
namespace EDPlayerJournal;
|
||||
|
||||
public class HumanReadableMissionName {
|
||||
private static Dictionary<string, string>? humanreadable = null;
|
||||
|
||||
private static void LoadMissions() {
|
||||
try {
|
||||
string dir = AppDomain.CurrentDomain.BaseDirectory;
|
||||
string file = Path.Combine(dir, "MissionNames.xml");
|
||||
|
||||
XmlDocument document = new XmlDocument();
|
||||
|
||||
using (FileStream stream = new FileStream(file, FileMode.Open)) {
|
||||
document.Load(stream);
|
||||
XmlNode? missions = document.DocumentElement;
|
||||
|
||||
if (missions == null ||
|
||||
missions.Name != "Missions" ||
|
||||
missions.ChildNodes == null) {
|
||||
throw new ApplicationException("Invalid XML");
|
||||
}
|
||||
|
||||
humanreadable = new Dictionary<string, string>();
|
||||
|
||||
foreach (XmlNode mission in missions.ChildNodes) {
|
||||
if (mission.Attributes == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
string? mission_key = mission.Attributes["Name"]?.Value;
|
||||
string? mission_name = mission.InnerText;
|
||||
|
||||
if (mission_key == null || mission_name == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
humanreadable.Add(mission_key, mission_name);
|
||||
}
|
||||
}
|
||||
} catch (Exception) {
|
||||
humanreadable = null;
|
||||
}
|
||||
}
|
||||
|
||||
public static string? MakeHumanReadableName(string name) {
|
||||
LoadMissions();
|
||||
|
||||
if (humanreadable == null || name == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (humanreadable.ContainsKey(name)) {
|
||||
return humanreadable[name];
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
7
EDPlayerJournal/JournalException.cs
Normal file
7
EDPlayerJournal/JournalException.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
using System;
|
||||
|
||||
namespace EDPlayerJournal;
|
||||
public class JournalException : Exception {
|
||||
public JournalException(string message) : base(message) {
|
||||
}
|
||||
}
|
||||
139
EDPlayerJournal/JournalFile.cs
Normal file
139
EDPlayerJournal/JournalFile.cs
Normal file
@@ -0,0 +1,139 @@
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Globalization;
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal;
|
||||
public class JournalFile : IComparable<JournalFile>
|
||||
{
|
||||
public string FullPath { get; set; }
|
||||
public int Part { get; set; }
|
||||
public DateTime? DateTime { get; set; }
|
||||
public DateTime? NormalisedDateTime { get; set; }
|
||||
|
||||
public List<Entry> entries = new List<Entry>();
|
||||
|
||||
private static Regex fileregex = new Regex("Journal\\.(\\d+)\\.(\\d+)\\.log");
|
||||
private static Regex update11regex = new Regex("Journal\\.([^\\.]+)\\.(\\d+).log");
|
||||
private static string iso8601 = "yyyyMMddTHHmmss";
|
||||
|
||||
public static bool VerifyFile(string path) {
|
||||
string filename = Path.GetFileName(path);
|
||||
|
||||
var matches = fileregex.Matches(filename);
|
||||
if (matches.Count != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
matches = update11regex.Matches(filename);
|
||||
if (matches.Count != 0) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
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 == 0) {
|
||||
matches = update11regex.Matches(filename);
|
||||
if (matches.Count == 0) {
|
||||
throw new JournalException(string.Format("invalid file format: {0}", filename));
|
||||
}
|
||||
}
|
||||
|
||||
FullPath = path;
|
||||
var groups = matches[0].Groups;
|
||||
string part = groups[2].ToString();
|
||||
string timestamp = groups[1].ToString();
|
||||
|
||||
if (!timestamp.Contains("T")) {
|
||||
/* pre update 11 file
|
||||
*/
|
||||
|
||||
// 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(timestamp);
|
||||
date.Insert(8, "T"); // Add the "T" separating date and time
|
||||
|
||||
timestamp = date.ToString();
|
||||
} else {
|
||||
/* post update 11 file, remove dashes
|
||||
*/
|
||||
timestamp = timestamp.Replace("-", "");
|
||||
}
|
||||
|
||||
this.DateTime = System.DateTime.ParseExact(timestamp, iso8601, CultureInfo.InvariantCulture);
|
||||
this.Part = int.Parse(part);
|
||||
this.NormalisedDateTime = System.DateTime.Parse(DateTime.Value.ToShortDateString());
|
||||
}
|
||||
|
||||
public int CompareTo(JournalFile? other) {
|
||||
if (other == null || DateTime == null || other.DateTime == null) {
|
||||
return 0;
|
||||
}
|
||||
var comp = System.DateTime.Compare(DateTime.Value, other.DateTime.Value);
|
||||
if (comp == 0) {
|
||||
/* If we have the exact same datetime we compare by parts.
|
||||
*/
|
||||
return Part - other.Part;
|
||||
} else {
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
|
||||
public JournalFile(string path) {
|
||||
FullPath = "";
|
||||
SetFilename(path);
|
||||
}
|
||||
|
||||
public IEnumerable<Entry> Entries {
|
||||
get {
|
||||
if (entries == null || entries.Count == 0) {
|
||||
try {
|
||||
LoadEntries();
|
||||
} catch (IOException) {
|
||||
}
|
||||
if (entries == null) {
|
||||
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(FullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) {
|
||||
using (var sr = new StreamReader(fs, Encoding.UTF8)) {
|
||||
string? line;
|
||||
while ((line = sr.ReadLine()) != null) {
|
||||
lines.Add(line);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
entries.Clear();
|
||||
foreach(var line in lines) {
|
||||
// Skip empty lines
|
||||
if (line.Trim().Length == 0) {
|
||||
continue;
|
||||
}
|
||||
Entry? entry = Entry.Parse(line);
|
||||
if (entry != null) {
|
||||
entries.Add(entry);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
94
EDPlayerJournal/JournalStream.cs
Normal file
94
EDPlayerJournal/JournalStream.cs
Normal file
@@ -0,0 +1,94 @@
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal;
|
||||
public class JournalStream {
|
||||
private FileSystemWatcher? watcher = null;
|
||||
|
||||
private Dictionary<string, StreamReader> streams = new Dictionary<string, StreamReader>();
|
||||
|
||||
public delegate void NewJournalEntryDelegate(Entry entry);
|
||||
|
||||
public event NewJournalEntryDelegate? NewJournalEntry;
|
||||
|
||||
public PlayerJournal? Journal;
|
||||
|
||||
public JournalStream() {
|
||||
}
|
||||
|
||||
public JournalStream(PlayerJournal journal) {
|
||||
Journal = journal;
|
||||
Open();
|
||||
}
|
||||
|
||||
private void AddFileToStreams(string path, bool seekend = false) {
|
||||
if (!streams.ContainsKey(path) && JournalFile.VerifyFile(path)) {
|
||||
var filestream = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
streams[path] = new StreamReader(filestream);
|
||||
|
||||
if (seekend) {
|
||||
streams[path].BaseStream.Seek(0, SeekOrigin.End);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void Open() {
|
||||
if (watcher != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Journal == null || Journal.Location == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (Journal.Files.Count > 0) {
|
||||
JournalFile lastfile = Journal.GetLastFile();
|
||||
/* add last file to stream */
|
||||
AddFileToStreams(lastfile.FullPath, true);
|
||||
}
|
||||
|
||||
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) {
|
||||
AddFileToStreams(e.FullPath);
|
||||
}
|
||||
|
||||
private void Watcher_Changed(object sender, FileSystemEventArgs e) {
|
||||
AddFileToStreams(e.FullPath);
|
||||
|
||||
var stream = streams[e.FullPath];
|
||||
if (stream == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
string? line;
|
||||
|
||||
while ((line = stream.ReadLine()) != null) {
|
||||
try {
|
||||
Entry? entry = Entry.Parse(line);
|
||||
if (entry != null) {
|
||||
NewJournalEntry?.Invoke(entry);
|
||||
}
|
||||
} catch (Exception) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
674
EDPlayerJournal/LICENCE.txt
Normal file
674
EDPlayerJournal/LICENCE.txt
Normal file
@@ -0,0 +1,674 @@
|
||||
GNU GENERAL PUBLIC LICENSE
|
||||
Version 3, 29 June 2007
|
||||
|
||||
Copyright (C) 2007 Free Software Foundation, Inc. <https://fsf.org/>
|
||||
Everyone is permitted to copy and distribute verbatim copies
|
||||
of this license document, but changing it is not allowed.
|
||||
|
||||
Preamble
|
||||
|
||||
The GNU General Public License is a free, copyleft license for
|
||||
software and other kinds of works.
|
||||
|
||||
The licenses for most software and other practical works are designed
|
||||
to take away your freedom to share and change the works. By contrast,
|
||||
the GNU General Public License is intended to guarantee your freedom to
|
||||
share and change all versions of a program--to make sure it remains free
|
||||
software for all its users. We, the Free Software Foundation, use the
|
||||
GNU General Public License for most of our software; it applies also to
|
||||
any other work released this way by its authors. You can apply it to
|
||||
your programs, too.
|
||||
|
||||
When we speak of free software, we are referring to freedom, not
|
||||
price. Our General Public Licenses are designed to make sure that you
|
||||
have the freedom to distribute copies of free software (and charge for
|
||||
them if you wish), that you receive source code or can get it if you
|
||||
want it, that you can change the software or use pieces of it in new
|
||||
free programs, and that you know you can do these things.
|
||||
|
||||
To protect your rights, we need to prevent others from denying you
|
||||
these rights or asking you to surrender the rights. Therefore, you have
|
||||
certain responsibilities if you distribute copies of the software, or if
|
||||
you modify it: responsibilities to respect the freedom of others.
|
||||
|
||||
For example, if you distribute copies of such a program, whether
|
||||
gratis or for a fee, you must pass on to the recipients the same
|
||||
freedoms that you received. You must make sure that they, too, receive
|
||||
or can get the source code. And you must show them these terms so they
|
||||
know their rights.
|
||||
|
||||
Developers that use the GNU GPL protect your rights with two steps:
|
||||
(1) assert copyright on the software, and (2) offer you this License
|
||||
giving you legal permission to copy, distribute and/or modify it.
|
||||
|
||||
For the developers' and authors' protection, the GPL clearly explains
|
||||
that there is no warranty for this free software. For both users' and
|
||||
authors' sake, the GPL requires that modified versions be marked as
|
||||
changed, so that their problems will not be attributed erroneously to
|
||||
authors of previous versions.
|
||||
|
||||
Some devices are designed to deny users access to install or run
|
||||
modified versions of the software inside them, although the manufacturer
|
||||
can do so. This is fundamentally incompatible with the aim of
|
||||
protecting users' freedom to change the software. The systematic
|
||||
pattern of such abuse occurs in the area of products for individuals to
|
||||
use, which is precisely where it is most unacceptable. Therefore, we
|
||||
have designed this version of the GPL to prohibit the practice for those
|
||||
products. If such problems arise substantially in other domains, we
|
||||
stand ready to extend this provision to those domains in future versions
|
||||
of the GPL, as needed to protect the freedom of users.
|
||||
|
||||
Finally, every program is threatened constantly by software patents.
|
||||
States should not allow patents to restrict development and use of
|
||||
software on general-purpose computers, but in those that do, we wish to
|
||||
avoid the special danger that patents applied to a free program could
|
||||
make it effectively proprietary. To prevent this, the GPL assures that
|
||||
patents cannot be used to render the program non-free.
|
||||
|
||||
The precise terms and conditions for copying, distribution and
|
||||
modification follow.
|
||||
|
||||
TERMS AND CONDITIONS
|
||||
|
||||
0. Definitions.
|
||||
|
||||
"This License" refers to version 3 of the GNU General Public License.
|
||||
|
||||
"Copyright" also means copyright-like laws that apply to other kinds of
|
||||
works, such as semiconductor masks.
|
||||
|
||||
"The Program" refers to any copyrightable work licensed under this
|
||||
License. Each licensee is addressed as "you". "Licensees" and
|
||||
"recipients" may be individuals or organizations.
|
||||
|
||||
To "modify" a work means to copy from or adapt all or part of the work
|
||||
in a fashion requiring copyright permission, other than the making of an
|
||||
exact copy. The resulting work is called a "modified version" of the
|
||||
earlier work or a work "based on" the earlier work.
|
||||
|
||||
A "covered work" means either the unmodified Program or a work based
|
||||
on the Program.
|
||||
|
||||
To "propagate" a work means to do anything with it that, without
|
||||
permission, would make you directly or secondarily liable for
|
||||
infringement under applicable copyright law, except executing it on a
|
||||
computer or modifying a private copy. Propagation includes copying,
|
||||
distribution (with or without modification), making available to the
|
||||
public, and in some countries other activities as well.
|
||||
|
||||
To "convey" a work means any kind of propagation that enables other
|
||||
parties to make or receive copies. Mere interaction with a user through
|
||||
a computer network, with no transfer of a copy, is not conveying.
|
||||
|
||||
An interactive user interface displays "Appropriate Legal Notices"
|
||||
to the extent that it includes a convenient and prominently visible
|
||||
feature that (1) displays an appropriate copyright notice, and (2)
|
||||
tells the user that there is no warranty for the work (except to the
|
||||
extent that warranties are provided), that licensees may convey the
|
||||
work under this License, and how to view a copy of this License. If
|
||||
the interface presents a list of user commands or options, such as a
|
||||
menu, a prominent item in the list meets this criterion.
|
||||
|
||||
1. Source Code.
|
||||
|
||||
The "source code" for a work means the preferred form of the work
|
||||
for making modifications to it. "Object code" means any non-source
|
||||
form of a work.
|
||||
|
||||
A "Standard Interface" means an interface that either is an official
|
||||
standard defined by a recognized standards body, or, in the case of
|
||||
interfaces specified for a particular programming language, one that
|
||||
is widely used among developers working in that language.
|
||||
|
||||
The "System Libraries" of an executable work include anything, other
|
||||
than the work as a whole, that (a) is included in the normal form of
|
||||
packaging a Major Component, but which is not part of that Major
|
||||
Component, and (b) serves only to enable use of the work with that
|
||||
Major Component, or to implement a Standard Interface for which an
|
||||
implementation is available to the public in source code form. A
|
||||
"Major Component", in this context, means a major essential component
|
||||
(kernel, window system, and so on) of the specific operating system
|
||||
(if any) on which the executable work runs, or a compiler used to
|
||||
produce the work, or an object code interpreter used to run it.
|
||||
|
||||
The "Corresponding Source" for a work in object code form means all
|
||||
the source code needed to generate, install, and (for an executable
|
||||
work) run the object code and to modify the work, including scripts to
|
||||
control those activities. However, it does not include the work's
|
||||
System Libraries, or general-purpose tools or generally available free
|
||||
programs which are used unmodified in performing those activities but
|
||||
which are not part of the work. For example, Corresponding Source
|
||||
includes interface definition files associated with source files for
|
||||
the work, and the source code for shared libraries and dynamically
|
||||
linked subprograms that the work is specifically designed to require,
|
||||
such as by intimate data communication or control flow between those
|
||||
subprograms and other parts of the work.
|
||||
|
||||
The Corresponding Source need not include anything that users
|
||||
can regenerate automatically from other parts of the Corresponding
|
||||
Source.
|
||||
|
||||
The Corresponding Source for a work in source code form is that
|
||||
same work.
|
||||
|
||||
2. Basic Permissions.
|
||||
|
||||
All rights granted under this License are granted for the term of
|
||||
copyright on the Program, and are irrevocable provided the stated
|
||||
conditions are met. This License explicitly affirms your unlimited
|
||||
permission to run the unmodified Program. The output from running a
|
||||
covered work is covered by this License only if the output, given its
|
||||
content, constitutes a covered work. This License acknowledges your
|
||||
rights of fair use or other equivalent, as provided by copyright law.
|
||||
|
||||
You may make, run and propagate covered works that you do not
|
||||
convey, without conditions so long as your license otherwise remains
|
||||
in force. You may convey covered works to others for the sole purpose
|
||||
of having them make modifications exclusively for you, or provide you
|
||||
with facilities for running those works, provided that you comply with
|
||||
the terms of this License in conveying all material for which you do
|
||||
not control copyright. Those thus making or running the covered works
|
||||
for you must do so exclusively on your behalf, under your direction
|
||||
and control, on terms that prohibit them from making any copies of
|
||||
your copyrighted material outside their relationship with you.
|
||||
|
||||
Conveying under any other circumstances is permitted solely under
|
||||
the conditions stated below. Sublicensing is not allowed; section 10
|
||||
makes it unnecessary.
|
||||
|
||||
3. Protecting Users' Legal Rights From Anti-Circumvention Law.
|
||||
|
||||
No covered work shall be deemed part of an effective technological
|
||||
measure under any applicable law fulfilling obligations under article
|
||||
11 of the WIPO copyright treaty adopted on 20 December 1996, or
|
||||
similar laws prohibiting or restricting circumvention of such
|
||||
measures.
|
||||
|
||||
When you convey a covered work, you waive any legal power to forbid
|
||||
circumvention of technological measures to the extent such circumvention
|
||||
is effected by exercising rights under this License with respect to
|
||||
the covered work, and you disclaim any intention to limit operation or
|
||||
modification of the work as a means of enforcing, against the work's
|
||||
users, your or third parties' legal rights to forbid circumvention of
|
||||
technological measures.
|
||||
|
||||
4. Conveying Verbatim Copies.
|
||||
|
||||
You may convey verbatim copies of the Program's source code as you
|
||||
receive it, in any medium, provided that you conspicuously and
|
||||
appropriately publish on each copy an appropriate copyright notice;
|
||||
keep intact all notices stating that this License and any
|
||||
non-permissive terms added in accord with section 7 apply to the code;
|
||||
keep intact all notices of the absence of any warranty; and give all
|
||||
recipients a copy of this License along with the Program.
|
||||
|
||||
You may charge any price or no price for each copy that you convey,
|
||||
and you may offer support or warranty protection for a fee.
|
||||
|
||||
5. Conveying Modified Source Versions.
|
||||
|
||||
You may convey a work based on the Program, or the modifications to
|
||||
produce it from the Program, in the form of source code under the
|
||||
terms of section 4, provided that you also meet all of these conditions:
|
||||
|
||||
a) The work must carry prominent notices stating that you modified
|
||||
it, and giving a relevant date.
|
||||
|
||||
b) The work must carry prominent notices stating that it is
|
||||
released under this License and any conditions added under section
|
||||
7. This requirement modifies the requirement in section 4 to
|
||||
"keep intact all notices".
|
||||
|
||||
c) You must license the entire work, as a whole, under this
|
||||
License to anyone who comes into possession of a copy. This
|
||||
License will therefore apply, along with any applicable section 7
|
||||
additional terms, to the whole of the work, and all its parts,
|
||||
regardless of how they are packaged. This License gives no
|
||||
permission to license the work in any other way, but it does not
|
||||
invalidate such permission if you have separately received it.
|
||||
|
||||
d) If the work has interactive user interfaces, each must display
|
||||
Appropriate Legal Notices; however, if the Program has interactive
|
||||
interfaces that do not display Appropriate Legal Notices, your
|
||||
work need not make them do so.
|
||||
|
||||
A compilation of a covered work with other separate and independent
|
||||
works, which are not by their nature extensions of the covered work,
|
||||
and which are not combined with it such as to form a larger program,
|
||||
in or on a volume of a storage or distribution medium, is called an
|
||||
"aggregate" if the compilation and its resulting copyright are not
|
||||
used to limit the access or legal rights of the compilation's users
|
||||
beyond what the individual works permit. Inclusion of a covered work
|
||||
in an aggregate does not cause this License to apply to the other
|
||||
parts of the aggregate.
|
||||
|
||||
6. Conveying Non-Source Forms.
|
||||
|
||||
You may convey a covered work in object code form under the terms
|
||||
of sections 4 and 5, provided that you also convey the
|
||||
machine-readable Corresponding Source under the terms of this License,
|
||||
in one of these ways:
|
||||
|
||||
a) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by the
|
||||
Corresponding Source fixed on a durable physical medium
|
||||
customarily used for software interchange.
|
||||
|
||||
b) Convey the object code in, or embodied in, a physical product
|
||||
(including a physical distribution medium), accompanied by a
|
||||
written offer, valid for at least three years and valid for as
|
||||
long as you offer spare parts or customer support for that product
|
||||
model, to give anyone who possesses the object code either (1) a
|
||||
copy of the Corresponding Source for all the software in the
|
||||
product that is covered by this License, on a durable physical
|
||||
medium customarily used for software interchange, for a price no
|
||||
more than your reasonable cost of physically performing this
|
||||
conveying of source, or (2) access to copy the
|
||||
Corresponding Source from a network server at no charge.
|
||||
|
||||
c) Convey individual copies of the object code with a copy of the
|
||||
written offer to provide the Corresponding Source. This
|
||||
alternative is allowed only occasionally and noncommercially, and
|
||||
only if you received the object code with such an offer, in accord
|
||||
with subsection 6b.
|
||||
|
||||
d) Convey the object code by offering access from a designated
|
||||
place (gratis or for a charge), and offer equivalent access to the
|
||||
Corresponding Source in the same way through the same place at no
|
||||
further charge. You need not require recipients to copy the
|
||||
Corresponding Source along with the object code. If the place to
|
||||
copy the object code is a network server, the Corresponding Source
|
||||
may be on a different server (operated by you or a third party)
|
||||
that supports equivalent copying facilities, provided you maintain
|
||||
clear directions next to the object code saying where to find the
|
||||
Corresponding Source. Regardless of what server hosts the
|
||||
Corresponding Source, you remain obligated to ensure that it is
|
||||
available for as long as needed to satisfy these requirements.
|
||||
|
||||
e) Convey the object code using peer-to-peer transmission, provided
|
||||
you inform other peers where the object code and Corresponding
|
||||
Source of the work are being offered to the general public at no
|
||||
charge under subsection 6d.
|
||||
|
||||
A separable portion of the object code, whose source code is excluded
|
||||
from the Corresponding Source as a System Library, need not be
|
||||
included in conveying the object code work.
|
||||
|
||||
A "User Product" is either (1) a "consumer product", which means any
|
||||
tangible personal property which is normally used for personal, family,
|
||||
or household purposes, or (2) anything designed or sold for incorporation
|
||||
into a dwelling. In determining whether a product is a consumer product,
|
||||
doubtful cases shall be resolved in favor of coverage. For a particular
|
||||
product received by a particular user, "normally used" refers to a
|
||||
typical or common use of that class of product, regardless of the status
|
||||
of the particular user or of the way in which the particular user
|
||||
actually uses, or expects or is expected to use, the product. A product
|
||||
is a consumer product regardless of whether the product has substantial
|
||||
commercial, industrial or non-consumer uses, unless such uses represent
|
||||
the only significant mode of use of the product.
|
||||
|
||||
"Installation Information" for a User Product means any methods,
|
||||
procedures, authorization keys, or other information required to install
|
||||
and execute modified versions of a covered work in that User Product from
|
||||
a modified version of its Corresponding Source. The information must
|
||||
suffice to ensure that the continued functioning of the modified object
|
||||
code is in no case prevented or interfered with solely because
|
||||
modification has been made.
|
||||
|
||||
If you convey an object code work under this section in, or with, or
|
||||
specifically for use in, a User Product, and the conveying occurs as
|
||||
part of a transaction in which the right of possession and use of the
|
||||
User Product is transferred to the recipient in perpetuity or for a
|
||||
fixed term (regardless of how the transaction is characterized), the
|
||||
Corresponding Source conveyed under this section must be accompanied
|
||||
by the Installation Information. But this requirement does not apply
|
||||
if neither you nor any third party retains the ability to install
|
||||
modified object code on the User Product (for example, the work has
|
||||
been installed in ROM).
|
||||
|
||||
The requirement to provide Installation Information does not include a
|
||||
requirement to continue to provide support service, warranty, or updates
|
||||
for a work that has been modified or installed by the recipient, or for
|
||||
the User Product in which it has been modified or installed. Access to a
|
||||
network may be denied when the modification itself materially and
|
||||
adversely affects the operation of the network or violates the rules and
|
||||
protocols for communication across the network.
|
||||
|
||||
Corresponding Source conveyed, and Installation Information provided,
|
||||
in accord with this section must be in a format that is publicly
|
||||
documented (and with an implementation available to the public in
|
||||
source code form), and must require no special password or key for
|
||||
unpacking, reading or copying.
|
||||
|
||||
7. Additional Terms.
|
||||
|
||||
"Additional permissions" are terms that supplement the terms of this
|
||||
License by making exceptions from one or more of its conditions.
|
||||
Additional permissions that are applicable to the entire Program shall
|
||||
be treated as though they were included in this License, to the extent
|
||||
that they are valid under applicable law. If additional permissions
|
||||
apply only to part of the Program, that part may be used separately
|
||||
under those permissions, but the entire Program remains governed by
|
||||
this License without regard to the additional permissions.
|
||||
|
||||
When you convey a copy of a covered work, you may at your option
|
||||
remove any additional permissions from that copy, or from any part of
|
||||
it. (Additional permissions may be written to require their own
|
||||
removal in certain cases when you modify the work.) You may place
|
||||
additional permissions on material, added by you to a covered work,
|
||||
for which you have or can give appropriate copyright permission.
|
||||
|
||||
Notwithstanding any other provision of this License, for material you
|
||||
add to a covered work, you may (if authorized by the copyright holders of
|
||||
that material) supplement the terms of this License with terms:
|
||||
|
||||
a) Disclaiming warranty or limiting liability differently from the
|
||||
terms of sections 15 and 16 of this License; or
|
||||
|
||||
b) Requiring preservation of specified reasonable legal notices or
|
||||
author attributions in that material or in the Appropriate Legal
|
||||
Notices displayed by works containing it; or
|
||||
|
||||
c) Prohibiting misrepresentation of the origin of that material, or
|
||||
requiring that modified versions of such material be marked in
|
||||
reasonable ways as different from the original version; or
|
||||
|
||||
d) Limiting the use for publicity purposes of names of licensors or
|
||||
authors of the material; or
|
||||
|
||||
e) Declining to grant rights under trademark law for use of some
|
||||
trade names, trademarks, or service marks; or
|
||||
|
||||
f) Requiring indemnification of licensors and authors of that
|
||||
material by anyone who conveys the material (or modified versions of
|
||||
it) with contractual assumptions of liability to the recipient, for
|
||||
any liability that these contractual assumptions directly impose on
|
||||
those licensors and authors.
|
||||
|
||||
All other non-permissive additional terms are considered "further
|
||||
restrictions" within the meaning of section 10. If the Program as you
|
||||
received it, or any part of it, contains a notice stating that it is
|
||||
governed by this License along with a term that is a further
|
||||
restriction, you may remove that term. If a license document contains
|
||||
a further restriction but permits relicensing or conveying under this
|
||||
License, you may add to a covered work material governed by the terms
|
||||
of that license document, provided that the further restriction does
|
||||
not survive such relicensing or conveying.
|
||||
|
||||
If you add terms to a covered work in accord with this section, you
|
||||
must place, in the relevant source files, a statement of the
|
||||
additional terms that apply to those files, or a notice indicating
|
||||
where to find the applicable terms.
|
||||
|
||||
Additional terms, permissive or non-permissive, may be stated in the
|
||||
form of a separately written license, or stated as exceptions;
|
||||
the above requirements apply either way.
|
||||
|
||||
8. Termination.
|
||||
|
||||
You may not propagate or modify a covered work except as expressly
|
||||
provided under this License. Any attempt otherwise to propagate or
|
||||
modify it is void, and will automatically terminate your rights under
|
||||
this License (including any patent licenses granted under the third
|
||||
paragraph of section 11).
|
||||
|
||||
However, if you cease all violation of this License, then your
|
||||
license from a particular copyright holder is reinstated (a)
|
||||
provisionally, unless and until the copyright holder explicitly and
|
||||
finally terminates your license, and (b) permanently, if the copyright
|
||||
holder fails to notify you of the violation by some reasonable means
|
||||
prior to 60 days after the cessation.
|
||||
|
||||
Moreover, your license from a particular copyright holder is
|
||||
reinstated permanently if the copyright holder notifies you of the
|
||||
violation by some reasonable means, this is the first time you have
|
||||
received notice of violation of this License (for any work) from that
|
||||
copyright holder, and you cure the violation prior to 30 days after
|
||||
your receipt of the notice.
|
||||
|
||||
Termination of your rights under this section does not terminate the
|
||||
licenses of parties who have received copies or rights from you under
|
||||
this License. If your rights have been terminated and not permanently
|
||||
reinstated, you do not qualify to receive new licenses for the same
|
||||
material under section 10.
|
||||
|
||||
9. Acceptance Not Required for Having Copies.
|
||||
|
||||
You are not required to accept this License in order to receive or
|
||||
run a copy of the Program. Ancillary propagation of a covered work
|
||||
occurring solely as a consequence of using peer-to-peer transmission
|
||||
to receive a copy likewise does not require acceptance. However,
|
||||
nothing other than this License grants you permission to propagate or
|
||||
modify any covered work. These actions infringe copyright if you do
|
||||
not accept this License. Therefore, by modifying or propagating a
|
||||
covered work, you indicate your acceptance of this License to do so.
|
||||
|
||||
10. Automatic Licensing of Downstream Recipients.
|
||||
|
||||
Each time you convey a covered work, the recipient automatically
|
||||
receives a license from the original licensors, to run, modify and
|
||||
propagate that work, subject to this License. You are not responsible
|
||||
for enforcing compliance by third parties with this License.
|
||||
|
||||
An "entity transaction" is a transaction transferring control of an
|
||||
organization, or substantially all assets of one, or subdividing an
|
||||
organization, or merging organizations. If propagation of a covered
|
||||
work results from an entity transaction, each party to that
|
||||
transaction who receives a copy of the work also receives whatever
|
||||
licenses to the work the party's predecessor in interest had or could
|
||||
give under the previous paragraph, plus a right to possession of the
|
||||
Corresponding Source of the work from the predecessor in interest, if
|
||||
the predecessor has it or can get it with reasonable efforts.
|
||||
|
||||
You may not impose any further restrictions on the exercise of the
|
||||
rights granted or affirmed under this License. For example, you may
|
||||
not impose a license fee, royalty, or other charge for exercise of
|
||||
rights granted under this License, and you may not initiate litigation
|
||||
(including a cross-claim or counterclaim in a lawsuit) alleging that
|
||||
any patent claim is infringed by making, using, selling, offering for
|
||||
sale, or importing the Program or any portion of it.
|
||||
|
||||
11. Patents.
|
||||
|
||||
A "contributor" is a copyright holder who authorizes use under this
|
||||
License of the Program or a work on which the Program is based. The
|
||||
work thus licensed is called the contributor's "contributor version".
|
||||
|
||||
A contributor's "essential patent claims" are all patent claims
|
||||
owned or controlled by the contributor, whether already acquired or
|
||||
hereafter acquired, that would be infringed by some manner, permitted
|
||||
by this License, of making, using, or selling its contributor version,
|
||||
but do not include claims that would be infringed only as a
|
||||
consequence of further modification of the contributor version. For
|
||||
purposes of this definition, "control" includes the right to grant
|
||||
patent sublicenses in a manner consistent with the requirements of
|
||||
this License.
|
||||
|
||||
Each contributor grants you a non-exclusive, worldwide, royalty-free
|
||||
patent license under the contributor's essential patent claims, to
|
||||
make, use, sell, offer for sale, import and otherwise run, modify and
|
||||
propagate the contents of its contributor version.
|
||||
|
||||
In the following three paragraphs, a "patent license" is any express
|
||||
agreement or commitment, however denominated, not to enforce a patent
|
||||
(such as an express permission to practice a patent or covenant not to
|
||||
sue for patent infringement). To "grant" such a patent license to a
|
||||
party means to make such an agreement or commitment not to enforce a
|
||||
patent against the party.
|
||||
|
||||
If you convey a covered work, knowingly relying on a patent license,
|
||||
and the Corresponding Source of the work is not available for anyone
|
||||
to copy, free of charge and under the terms of this License, through a
|
||||
publicly available network server or other readily accessible means,
|
||||
then you must either (1) cause the Corresponding Source to be so
|
||||
available, or (2) arrange to deprive yourself of the benefit of the
|
||||
patent license for this particular work, or (3) arrange, in a manner
|
||||
consistent with the requirements of this License, to extend the patent
|
||||
license to downstream recipients. "Knowingly relying" means you have
|
||||
actual knowledge that, but for the patent license, your conveying the
|
||||
covered work in a country, or your recipient's use of the covered work
|
||||
in a country, would infringe one or more identifiable patents in that
|
||||
country that you have reason to believe are valid.
|
||||
|
||||
If, pursuant to or in connection with a single transaction or
|
||||
arrangement, you convey, or propagate by procuring conveyance of, a
|
||||
covered work, and grant a patent license to some of the parties
|
||||
receiving the covered work authorizing them to use, propagate, modify
|
||||
or convey a specific copy of the covered work, then the patent license
|
||||
you grant is automatically extended to all recipients of the covered
|
||||
work and works based on it.
|
||||
|
||||
A patent license is "discriminatory" if it does not include within
|
||||
the scope of its coverage, prohibits the exercise of, or is
|
||||
conditioned on the non-exercise of one or more of the rights that are
|
||||
specifically granted under this License. You may not convey a covered
|
||||
work if you are a party to an arrangement with a third party that is
|
||||
in the business of distributing software, under which you make payment
|
||||
to the third party based on the extent of your activity of conveying
|
||||
the work, and under which the third party grants, to any of the
|
||||
parties who would receive the covered work from you, a discriminatory
|
||||
patent license (a) in connection with copies of the covered work
|
||||
conveyed by you (or copies made from those copies), or (b) primarily
|
||||
for and in connection with specific products or compilations that
|
||||
contain the covered work, unless you entered into that arrangement,
|
||||
or that patent license was granted, prior to 28 March 2007.
|
||||
|
||||
Nothing in this License shall be construed as excluding or limiting
|
||||
any implied license or other defenses to infringement that may
|
||||
otherwise be available to you under applicable patent law.
|
||||
|
||||
12. No Surrender of Others' Freedom.
|
||||
|
||||
If conditions are imposed on you (whether by court order, agreement or
|
||||
otherwise) that contradict the conditions of this License, they do not
|
||||
excuse you from the conditions of this License. If you cannot convey a
|
||||
covered work so as to satisfy simultaneously your obligations under this
|
||||
License and any other pertinent obligations, then as a consequence you may
|
||||
not convey it at all. For example, if you agree to terms that obligate you
|
||||
to collect a royalty for further conveying from those to whom you convey
|
||||
the Program, the only way you could satisfy both those terms and this
|
||||
License would be to refrain entirely from conveying the Program.
|
||||
|
||||
13. Use with the GNU Affero General Public License.
|
||||
|
||||
Notwithstanding any other provision of this License, you have
|
||||
permission to link or combine any covered work with a work licensed
|
||||
under version 3 of the GNU Affero General Public License into a single
|
||||
combined work, and to convey the resulting work. The terms of this
|
||||
License will continue to apply to the part which is the covered work,
|
||||
but the special requirements of the GNU Affero General Public License,
|
||||
section 13, concerning interaction through a network will apply to the
|
||||
combination as such.
|
||||
|
||||
14. Revised Versions of this License.
|
||||
|
||||
The Free Software Foundation may publish revised and/or new versions of
|
||||
the GNU General Public License from time to time. Such new versions will
|
||||
be similar in spirit to the present version, but may differ in detail to
|
||||
address new problems or concerns.
|
||||
|
||||
Each version is given a distinguishing version number. If the
|
||||
Program specifies that a certain numbered version of the GNU General
|
||||
Public License "or any later version" applies to it, you have the
|
||||
option of following the terms and conditions either of that numbered
|
||||
version or of any later version published by the Free Software
|
||||
Foundation. If the Program does not specify a version number of the
|
||||
GNU General Public License, you may choose any version ever published
|
||||
by the Free Software Foundation.
|
||||
|
||||
If the Program specifies that a proxy can decide which future
|
||||
versions of the GNU General Public License can be used, that proxy's
|
||||
public statement of acceptance of a version permanently authorizes you
|
||||
to choose that version for the Program.
|
||||
|
||||
Later license versions may give you additional or different
|
||||
permissions. However, no additional obligations are imposed on any
|
||||
author or copyright holder as a result of your choosing to follow a
|
||||
later version.
|
||||
|
||||
15. Disclaimer of Warranty.
|
||||
|
||||
THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
|
||||
APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
|
||||
HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
|
||||
OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
|
||||
THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
|
||||
PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
|
||||
IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
|
||||
ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
|
||||
|
||||
16. Limitation of Liability.
|
||||
|
||||
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
|
||||
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
|
||||
THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
|
||||
GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
|
||||
USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
|
||||
DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
|
||||
PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
|
||||
EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
|
||||
SUCH DAMAGES.
|
||||
|
||||
17. Interpretation of Sections 15 and 16.
|
||||
|
||||
If the disclaimer of warranty and limitation of liability provided
|
||||
above cannot be given local legal effect according to their terms,
|
||||
reviewing courts shall apply local law that most closely approximates
|
||||
an absolute waiver of all civil liability in connection with the
|
||||
Program, unless a warranty or assumption of liability accompanies a
|
||||
copy of the Program in return for a fee.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
How to Apply These Terms to Your New Programs
|
||||
|
||||
If you develop a new program, and you want it to be of the greatest
|
||||
possible use to the public, the best way to achieve this is to make it
|
||||
free software which everyone can redistribute and change under these terms.
|
||||
|
||||
To do so, attach the following notices to the program. It is safest
|
||||
to attach them to the start of each source file to most effectively
|
||||
state the exclusion of warranty; and each file should have at least
|
||||
the "copyright" line and a pointer to where the full notice is found.
|
||||
|
||||
<one line to give the program's name and a brief idea of what it does.>
|
||||
Copyright (C) <year> <name of author>
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
|
||||
Also add information on how to contact you by electronic and paper mail.
|
||||
|
||||
If the program does terminal interaction, make it output a short
|
||||
notice like this when it starts in an interactive mode:
|
||||
|
||||
<program> Copyright (C) <year> <name of author>
|
||||
This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
|
||||
This is free software, and you are welcome to redistribute it
|
||||
under certain conditions; type `show c' for details.
|
||||
|
||||
The hypothetical commands `show w' and `show c' should show the appropriate
|
||||
parts of the General Public License. Of course, your program's commands
|
||||
might be different; for a GUI interface, you would use an "about box".
|
||||
|
||||
You should also get your employer (if you work as a programmer) or school,
|
||||
if any, to sign a "copyright disclaimer" for the program, if necessary.
|
||||
For more information on this, and how to apply and follow the GNU GPL, see
|
||||
<https://www.gnu.org/licenses/>.
|
||||
|
||||
The GNU General Public License does not permit incorporating your program
|
||||
into proprietary programs. If your program is a subroutine library, you
|
||||
may consider it more useful to permit linking proprietary applications with
|
||||
the library. If this is what you want to do, use the GNU Lesser General
|
||||
Public License instead of this License. But first, please read
|
||||
<https://www.gnu.org/licenses/why-not-lgpl.html>.
|
||||
7
EDPlayerJournal/Location.cs
Normal file
7
EDPlayerJournal/Location.cs
Normal file
@@ -0,0 +1,7 @@
|
||||
namespace EDPlayerJournal;
|
||||
public class Location {
|
||||
public string StarSystem { get; set; } = "";
|
||||
public ulong SystemAddress { get; set; } = 0;
|
||||
public string Station { get; set; } = "";
|
||||
public ulong[]? StarPos { get; set; }
|
||||
}
|
||||
84
EDPlayerJournal/MissionNames.xml
Normal file
84
EDPlayerJournal/MissionNames.xml
Normal file
@@ -0,0 +1,84 @@
|
||||
<?xml version="1.0" encoding="utf-8" ?>
|
||||
<Missions>
|
||||
<Mission Name="Chain_FindThePirateLord_name">Assassination (Pirate Lord) (Chain)</Mission>
|
||||
<Mission Name="Chain_RegainFooting_name">Regain Footing (Chain)</Mission>
|
||||
<Mission Name="Chain_SalvageJustice_name">Assassination (Legal) (Chain)</Mission>
|
||||
<Mission Name="Mission_Altruism_name">Donate</Mission>
|
||||
<Mission Name="Mission_AltruismCredits_Bust_name">Donate Credits (Bust)</Mission>
|
||||
<Mission Name="Mission_AltruismCredits_Famine_name">Donate Credits (Famine)</Mission>
|
||||
<Mission Name="Mission_AltruismCredits_name">Donate Credits</Mission>
|
||||
<Mission Name="Mission_Assassinate_Illegal_BLOPS_name">Assassination (Illegal)</Mission>
|
||||
<Mission Name="Mission_Assassinate_Legal_Corporate_name">Corporate Assassination (Legal)</Mission>
|
||||
<Mission Name="Mission_Assassinate_name">Assassination</Mission>
|
||||
<Mission Name="Mission_Assassinate_Planetary_name">Assassination (Planetary Scan)</Mission>
|
||||
<Mission Name="Mission_Collect_Bust_name">Provide (Bust)</Mission>
|
||||
<Mission Name="Mission_Collect_CivilLiberty_name">Provide (Civil Liberty)</Mission>
|
||||
<Mission Name="Mission_Collect_CivilUnrest_name">Provide (Civil Unrest)</Mission>
|
||||
<Mission Name="Mission_Collect_Famine_name">Provide (Famine)</Mission>
|
||||
<Mission Name="Mission_Collect_Industrial_name">Provide (Industrial)</Mission>
|
||||
<Mission Name="Mission_Collect_name">Provide</Mission>
|
||||
<Mission Name="Mission_Collect_RankEmp_name">Provide (Imperial Navy)</Mission>
|
||||
<Mission Name="Mission_Collect_Retreat_name">Provide (Retreat)</Mission>
|
||||
<Mission Name="Mission_Courier_Democracy_name">Courier (Democracy)</Mission>
|
||||
<Mission Name="Mission_Courier_Elections_name">Courier (Elections)</Mission>
|
||||
<Mission Name="Mission_Courier_Expansion_name">Courier (Expansion)</Mission>
|
||||
<Mission Name="Mission_Courier_Famine_name">Courier (Famine)</Mission>
|
||||
<Mission Name="Mission_Courier_Lockdown_name">Courier (Lockdown)</Mission>
|
||||
<Mission Name="Mission_Courier_name">Courier</Mission>
|
||||
<Mission Name="Mission_Courier_RankEmp_name">Courier (Imperial Navy)</Mission>
|
||||
<Mission Name="Mission_Delivery_Agriculture_name">Delivery (Agriculture)</Mission>
|
||||
<Mission Name="Mission_Delivery_Boom_name">Delivery (Boom)</Mission>
|
||||
<Mission Name="Mission_Delivery_Democracy_name">Delivery (Democracy)</Mission>
|
||||
<Mission Name="Mission_Delivery_Investment_name">Delivery (Investment)</Mission>
|
||||
<Mission Name="Mission_Delivery_name">Delivery</Mission>
|
||||
<Mission Name="Mission_Delivery_RankEmp_name">Delivery (Imperial Navy)</Mission>
|
||||
<Mission Name="Mission_Delivery_Retreat_name">Delivery (Retreat)</Mission>
|
||||
<Mission Name="Mission_DeliveryWing_name">Delivery (Wing)</Mission>
|
||||
<Mission Name="Mission_DeliveryWing_War_name">Delivery (Wing) (War)</Mission>
|
||||
<Mission Name="Mission_Hack_BLOPS_Boom_name">Hack Surface Installation (Boom)</Mission>
|
||||
<Mission Name="Mission_Hack_BLOPS_Elections_name">Hack Surface Installation (Elections)</Mission>
|
||||
<Mission Name="Mission_Hack_BLOPS_Expansion_name">Hack Surface Installation (Expansion)</Mission>
|
||||
<Mission Name="MISSION_Hack_BLOPS_name">Hack Surface Installation</Mission>
|
||||
<Mission Name="Mission_HackMegaship_name">Hack Megaship</Mission>
|
||||
<Mission Name="Mission_LongDistanceExpedition_Explorer_Boom_name">Long Distance Expedition (Boom)</Mission>
|
||||
<Mission Name="Mission_LongDistanceExpedition_name">Long Distance Expedition</Mission>
|
||||
<Mission Name="Mission_Massacre_Conflict_CivilWar_name">Massacre (Civil War)</Mission>
|
||||
<Mission Name="Mission_Massacre_name">Massacre</Mission>
|
||||
<Mission Name="Mission_Massacre_RankEmp_name">Massacre (Imperial Navy)</Mission>
|
||||
<Mission Name="Mission_MassacreWing_Legal_Bust_name">Massacre (Wing) (Bust)</Mission>
|
||||
<Mission Name="Mission_MassacreWing_name">Massacre (Wing)</Mission>
|
||||
<Mission Name="Mission_OnFoot_Assassination_MB_name">On Foot Assassination</Mission>
|
||||
<Mission Name="Mission_OnFoot_AssassinationIllegal_MB_name">On Foot Assassination (Illegal)</Mission>
|
||||
<Mission Name="Mission_OnFoot_Collect_Contact_MB_name">On Foot Collect</Mission>
|
||||
<Mission Name="Mission_OnFoot_Collect_MB_name">On Foot Collection</Mission>
|
||||
<Mission Name="Mission_OnFoot_Delivery_Contact_MB_name">On Foot Delivery (Contact)</Mission>
|
||||
<Mission Name="Mission_OnFoot_Hack_Upload_Covert_MB_name">On Foot Hack (Covert Upload)</Mission>
|
||||
<Mission Name="Mission_OnFoot_Hack_Upload_MB_name">On Foot Hack (Upload)</Mission>
|
||||
<Mission Name="Mission_OnFoot_Heist_POI_MB_name">On Foot Heist (POI)</Mission>
|
||||
<Mission Name="Mission_OnFoot_Onslaught_MB_name">On Foot Onslaught</Mission>
|
||||
<Mission Name="Mission_OnFoot_Onslaught_Offline_MB_name">On Foot Onslaught (Offline)</Mission>
|
||||
<Mission Name="Mission_OnFoot_ProductionHeist_Covert_MB_name">On Foot Production Heist (Covert)</Mission>
|
||||
<Mission Name="Mission_OnFoot_ProductionHeist_MB_name">On Foot Production Heist</Mission>
|
||||
<Mission Name="Mission_OnFoot_Reboot_MB_name">On Foot Reboot</Mission>
|
||||
<Mission Name="Mission_OnFoot_RebootRestore_MB_name">On Foot Reboot/Restore</Mission>
|
||||
<Mission Name="Mission_OnFoot_Sabotage_Production_Covert_MB_name">On Foot Sabotage Production (Covert)</Mission>
|
||||
<Mission Name="Mission_OnFoot_Salvage_MB_name">On Foot Salvage</Mission>
|
||||
<Mission Name="Mission_OnFoot_SalvageIllegal_MB_name">On Foot Salvage (Illegal)</Mission>
|
||||
<Mission Name="Mission_PassengerBulk_AIDWORKER_ARRIVING">Aid Workers Seeking Transport</Mission>
|
||||
<Mission Name="Mission_PassengerVIP">Passenger (VIP)</Mission>
|
||||
<Mission Name="Mission_PassengerVIP_Criminal_BOOM_name">Passenger Criminal (VIP) (Boom)</Mission>
|
||||
<Mission Name="Mission_PassengerVIP_name">Passenger (VIP)</Mission>
|
||||
<Mission Name="Mission_PassengerVIP_Scientist_FAMINE_name">Passenger Scientist (VIP) (Famine)</Mission>
|
||||
<Mission Name="Mission_PassengerVIP_Tourist_BOOM_name">Passenger Tourist (VIP) (Boom)</Mission>
|
||||
<Mission Name="Mission_Rescue_Planet_name">Planet Rescue</Mission>
|
||||
<Mission Name="MISSION_Salvage_CivilUnrest_name">Salvage (Civil Unrest)</Mission>
|
||||
<Mission Name="MISSION_Salvage_Expansion_name">Salvage (Expansion)</Mission>
|
||||
<Mission Name="MISSION_Salvage_Illegal_name">Salvage (Illegal)</Mission>
|
||||
<Mission Name="Mission_Salvage_name">Salvage</Mission>
|
||||
<Mission Name="Mission_Salvage_RankEmp_name">Salvage (Imperial Navy)</Mission>
|
||||
<Mission Name="MISSION_Salvage_Refinery_name">Salvage (Refinery)</Mission>
|
||||
<Mission Name="MISSION_Salvage_Retreat_name">Salvage (Retreat)</Mission>
|
||||
<Mission Name="MISSION_Scan_name">Scan</Mission>
|
||||
<Mission Name="Mission_Sightseeing_Criminal_FAMINE_name">Sightseeing (Criminal) (Famine)</Mission>
|
||||
<Mission Name="Mission_Sightseeing_name">Sightseeing</Mission>
|
||||
</Missions>
|
||||
89
EDPlayerJournal/PlayerJournal.cs
Normal file
89
EDPlayerJournal/PlayerJournal.cs
Normal file
@@ -0,0 +1,89 @@
|
||||
using EDPlayerJournal.Entries;
|
||||
|
||||
namespace EDPlayerJournal;
|
||||
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 string? Location => basepath;
|
||||
|
||||
public PlayerJournal() {
|
||||
Initialise(DefaultPath);
|
||||
}
|
||||
|
||||
public PlayerJournal(string path) {
|
||||
Initialise(path);
|
||||
}
|
||||
|
||||
private void Initialise(string path) {
|
||||
basepath = Environment.ExpandEnvironmentVariables(path);
|
||||
ScanFiles();
|
||||
}
|
||||
|
||||
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 JournalFile GetLastFile() {
|
||||
var lastfile = Files
|
||||
.OrderBy(x => x.DateTime)
|
||||
.Last()
|
||||
;
|
||||
return lastfile;
|
||||
}
|
||||
|
||||
public void ScanFiles() {
|
||||
if (basepath == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public Entry? FindMostRecent(string entry) {
|
||||
var entries = journalfiles
|
||||
.OrderByDescending(x => x.DateTime)
|
||||
.ToArray()
|
||||
;
|
||||
|
||||
if (entries == null || entries.Length == 0) {
|
||||
return null;
|
||||
}
|
||||
|
||||
foreach(JournalFile file in entries) {
|
||||
Entry found = file.Entries
|
||||
.OrderByDescending(x => x.Timestamp)
|
||||
.First(x => x.Event == entry)
|
||||
;
|
||||
if (found != null) {
|
||||
return found;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user