2021-08-25 18:24:44 +02:00
|
|
|
|
using System;
|
2021-08-27 19:33:01 +02:00
|
|
|
|
using System.Linq;
|
2021-08-25 18:24:44 +02:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace EDJournal {
|
|
|
|
|
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);
|
2021-08-27 19:33:01 +02:00
|
|
|
|
ScanFiles();
|
2021-08-25 18:24:44 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-27 19:33:01 +02:00
|
|
|
|
public JournalFile GetLastFile() {
|
|
|
|
|
var lastfile = Files
|
2022-03-15 18:08:09 +01:00
|
|
|
|
.OrderBy(x => x.DateTime)
|
2021-08-27 19:33:01 +02:00
|
|
|
|
.Last()
|
|
|
|
|
;
|
|
|
|
|
return lastfile;
|
|
|
|
|
}
|
|
|
|
|
|
2021-08-25 18:24:44 +02:00
|
|
|
|
public void ScanFiles() {
|
|
|
|
|
var files = Directory.EnumerateFiles(basepath);
|
|
|
|
|
|
|
|
|
|
journalfiles.Clear();
|
|
|
|
|
|
|
|
|
|
foreach (var file in files) {
|
|
|
|
|
string full = Path.Combine(basepath, file);
|
|
|
|
|
try {
|
|
|
|
|
JournalFile journalfile = new JournalFile(full);
|
|
|
|
|
journalfiles.Add(journalfile);
|
|
|
|
|
} catch (JournalException) {
|
|
|
|
|
/* invalid journal file, or one of the other json files in there */
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
journalfiles.Sort();
|
|
|
|
|
}
|
2022-08-24 09:48:56 +02:00
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2021-08-25 18:24:44 +02:00
|
|
|
|
}
|
|
|
|
|
}
|