summaryrefslogtreecommitdiff
path: root/dslog/LogSet.java
diff options
context:
space:
mode:
Diffstat (limited to 'dslog/LogSet.java')
-rw-r--r--dslog/LogSet.java74
1 files changed, 74 insertions, 0 deletions
diff --git a/dslog/LogSet.java b/dslog/LogSet.java
new file mode 100644
index 0000000..e284eba
--- /dev/null
+++ b/dslog/LogSet.java
@@ -0,0 +1,74 @@
+package dslog;
+
+import java.io.IOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.function.Supplier;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+import java.util.ArrayList;
+
+public class LogSet {
+ public final String name;
+ public LogSet(String name) {
+ this.name = name;
+ }
+ public Path dslogPath, dseventsPath, pdplogPath;
+
+ public String toString() {
+ return name+" "+verstr(this::dslog)+"/"+verstr(this::dsevents)+"/"+verstr(this::pdplog);
+ }
+
+
+ private static final Pattern fmsConnected = Pattern.compile("^FMS Connected: (?<matchname>[A-Za-z].+) - (?<matchnumber>[0-9:]+), Field Time: (?<fieldtime>[0-9/]+ [0-9:]+)$");
+
+ public String[] matches() throws IOException {
+ ArrayList<String> matches = new ArrayList<String>();
+ try (DseventsReader dsevents = dsevents()) {
+ if (dsevents == null) {
+ return matches.toArray(new String[matches.size()]);
+ }
+ while (dsevents.hasNext()) {
+ DseventsReader.Event event = dsevents.next();
+ // do a (cheap) `.startsWith` check before doing an (expensive) regex check.
+ if (event.message.startsWith("FMS Connected:")) {
+ Matcher m = fmsConnected.matcher(event.message);
+ if (m.matches()) {
+ matches.add(m.group("matchname") + " - " + m.group("matchnumber"));
+ }
+ }
+ }
+ }
+ return matches.toArray(new String[matches.size()]);
+ }
+
+ private static String verstr(Versioned.Supplier getter) {
+ try (Versioned thing = getter.get()) {
+ if (thing == null) {
+ return "␕";
+ }
+ return ""+thing.version();
+ } catch (IOException e) {
+ return "☠";
+ }
+ }
+
+ public DslogReader dslog() throws IOException {
+ if (dslogPath == null) {
+ return null;
+ }
+ return new DslogReader(Files.newInputStream(dslogPath));
+ }
+ public DseventsReader dsevents() throws IOException {
+ if (dseventsPath == null) {
+ return null;
+ }
+ return new DseventsReader(Files.newInputStream(dseventsPath));
+ }
+ public PdplogReader pdplog() throws IOException {
+ if (pdplogPath == null) {
+ return null;
+ }
+ return new PdplogReader(Files.newInputStream(pdplogPath));
+ }
+}