EliteBGS/Journal/PlayerJournal.cs

57 lines
1.6 KiB
C#

using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
using System.Threading.Tasks;
namespace NonaBGS.Journal {
public class PlayerJournal {
public static string DefaultPath = "%UserProfile%\\Saved Games\\Frontier Developments\\Elite Dangerous";
private List<JournalFile> journalfiles = new List<JournalFile>();
private string basepath = null;
public PlayerJournal() {
Initialise(DefaultPath);
}
public PlayerJournal(string path) {
Initialise(path);
}
private void Initialise(string path) {
basepath = Environment.ExpandEnvironmentVariables(path);
}
public List<JournalFile> Files {
get { return journalfiles; }
}
public void Open() {
if (!Directory.Exists(basepath)) {
throw new JournalException("Invalid base path, path could not be found");
}
this.ScanFiles();
}
public void ScanFiles() {
var files = Directory.EnumerateFiles(basepath);
journalfiles.Clear();
foreach (var file in files) {
string full = Path.Combine(basepath, file);
try {
JournalFile journalfile = new JournalFile(full);
journalfiles.Add(journalfile);
} catch (JournalException) {
/* invalid journal file, or one of the other json files in there */
continue;
}
}
journalfiles.Sort();
}
}
}