From 9277d9694ac0e3edf0f4aa685e66aea2e054f645 Mon Sep 17 00:00:00 2001 From: Christopher Serr Date: Fri, 26 Mar 2021 18:19:00 +0100 Subject: [PATCH] Remove Support for Llanfair 2 When we added support for it, the project was already fairly unmaintained. However since then the repository has even been deleted entirely. The timer was never in a shape where people realistically used it at all, so there neither exist any splits nor will there ever exist any splits for this timer. --- src/run/parser/composite.rs | 13 +- src/run/parser/flitter/s_expressions.rs | 47 ++-- src/run/parser/llanfair2.rs | 214 ----------------- src/run/parser/mod.rs | 1 - src/run/parser/timer_kind.rs | 3 - tests/run_files/llanfair2.xml | 290 ------------------------ tests/run_files/llanfair2_empty.xml | 7 - tests/run_files/mod.rs | 2 - tests/split_parsing.rs | 16 +- 9 files changed, 27 insertions(+), 566 deletions(-) delete mode 100644 src/run/parser/llanfair2.rs delete mode 100644 tests/run_files/llanfair2.xml delete mode 100644 tests/run_files/llanfair2_empty.xml diff --git a/src/run/parser/composite.rs b/src/run/parser/composite.rs index 32afc5af..a7e7dc14 100644 --- a/src/run/parser/composite.rs +++ b/src/run/parser/composite.rs @@ -31,9 +31,9 @@ //! ``` use super::{ - face_split, flitter, livesplit, llanfair, llanfair2, llanfair_gered, portal2_live_timer, - shit_split, source_live_timer, splits_io, splitterino, splitterz, splitty, time_split_tracker, - urn, wsplit, TimerKind, + face_split, flitter, livesplit, llanfair, llanfair_gered, portal2_live_timer, shit_split, + source_live_timer, splits_io, splitterino, splitterz, splitty, time_split_tracker, urn, wsplit, + TimerKind, }; use crate::Run; use core::result::Result as StdResult; @@ -153,13 +153,6 @@ where return Ok(parsed(run, TimerKind::LlanfairGered)); } - // Llanfair 2's format is almost entirely optional so it should be parsed - // after all other XML based formats. - source.seek(SeekFrom::Start(0)).context(SeekBack)?; - if let Ok(run) = llanfair2::parse(&mut source) { - return Ok(parsed(run, TimerKind::Llanfair2)); - } - source.seek(SeekFrom::Start(0)).context(SeekBack)?; if let Ok((run, timer)) = splits_io::parse(&mut source) { return Ok(parsed(run, TimerKind::Generic(timer))); diff --git a/src/run/parser/flitter/s_expressions.rs b/src/run/parser/flitter/s_expressions.rs index d75e1a19..4c8830b9 100644 --- a/src/run/parser/flitter/s_expressions.rs +++ b/src/run/parser/flitter/s_expressions.rs @@ -1,8 +1,7 @@ //! Implements a serde deserializer for S-Expressions. //! http://people.csail.mit.edu/rivest/Sexp.txt -use core::fmt::Display; -use core::num::ParseIntError; +use core::{fmt::Display, num::ParseIntError}; use serde::de::{self, DeserializeOwned, DeserializeSeed, MapAccess, SeqAccess, Visitor}; use std::io::{self, BufRead}; use utf8::{BufReadDecoder, BufReadDecoderError}; @@ -27,7 +26,7 @@ pub enum Error { source: ParseIntError, }, /// Encountered invalid UTF-8 sequence. - InvalidUTF8, + InvalidUtf8, /// Failed to read from the source. Io { /// The underlying error. @@ -44,7 +43,7 @@ pub enum Error { impl From> for Error { fn from(error: BufReadDecoderError<'_>) -> Error { match error { - BufReadDecoderError::InvalidByteSequence(_) => Error::InvalidUTF8, + BufReadDecoderError::InvalidByteSequence(_) => Error::InvalidUtf8, BufReadDecoderError::Io(source) => Error::Io { source }, } } @@ -213,49 +212,49 @@ impl<'de, B: BufRead> de::Deserializer<'de> for &mut Deserializer { where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_bool(self, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_i8(self, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_i16(self, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_i32(self, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_i64(self, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_u8(self, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_u16(self, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_u32(self, visitor: V) -> Result where @@ -267,25 +266,25 @@ impl<'de, B: BufRead> de::Deserializer<'de> for &mut Deserializer { where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_f32(self, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_f64(self, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_char(self, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_str(self, visitor: V) -> Result where @@ -303,13 +302,13 @@ impl<'de, B: BufRead> de::Deserializer<'de> for &mut Deserializer { where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_byte_buf(self, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_option(self, visitor: V) -> Result where @@ -321,19 +320,19 @@ impl<'de, B: BufRead> de::Deserializer<'de> for &mut Deserializer { where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_unit_struct(self, _name: &'static str, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_newtype_struct(self, _name: &'static str, _visitor: V) -> Result where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_seq(mut self, visitor: V) -> Result where @@ -355,7 +354,7 @@ impl<'de, B: BufRead> de::Deserializer<'de> for &mut Deserializer { where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_tuple_struct( self, @@ -366,7 +365,7 @@ impl<'de, B: BufRead> de::Deserializer<'de> for &mut Deserializer { where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_map(mut self, visitor: V) -> Result where @@ -404,7 +403,7 @@ impl<'de, B: BufRead> de::Deserializer<'de> for &mut Deserializer { where V: Visitor<'de>, { - unimplemented!() + unreachable!() } fn deserialize_identifier(self, visitor: V) -> Result where diff --git a/src/run/parser/llanfair2.rs b/src/run/parser/llanfair2.rs deleted file mode 100644 index cfd98f22..00000000 --- a/src/run/parser/llanfair2.rs +++ /dev/null @@ -1,214 +0,0 @@ -//! Provides the parser for splits files used by the Llanfair Rewrite. - -use crate::{ - xml_util::{end_tag, parse_base, parse_children, single_child, text, text_err, text_parsed}, - RealTime, Run, Segment, Time, TimeSpan, -}; -use byteorder::{ByteOrder, BE}; -use core::cmp::min; -use image::{codecs::png, ColorType, ImageBuffer, Rgba}; -use quick_xml::Reader; -use std::io::BufRead; - -use crate::xml_util::Error as XmlError; - -/// The Error type for splits files that couldn't be parsed by the Llanfair -/// Rewrite Parser. -#[derive(Debug, snafu::Snafu, derive_more::From)] -pub enum Error { - /// The underlying XML format couldn't be parsed. - Xml { - /// The underlying error. - source: XmlError, - }, - /// Failed to decode a string slice as UTF-8. - Utf8Str { - /// The underlying error. - source: core::str::Utf8Error, - }, - /// Failed to decode a string as UTF-8. - Utf8String { - /// The underlying error. - source: alloc::string::FromUtf8Error, - }, - /// Failed to parse an integer. - Int { - /// The underlying error. - source: core::num::ParseIntError, - }, - /// Failed to parse an image. - Image, -} - -/// The Result type for the Llanfair Rewrite Parser. -pub type Result = core::result::Result; - -// FIXME: Generalized Type Ascription (GTA 6) -#[inline] -const fn type_hint(v: Result) -> Result { - v -} - -fn time_span(reader: &mut Reader, buf: &mut Vec, mut f: F) -> Result<()> -where - R: BufRead, - F: FnMut(TimeSpan), -{ - single_child(reader, buf, b"value", |reader, tag| { - text_err(reader, tag.into_buf(), |text| { - let milliseconds = text.parse::()?; - f(TimeSpan::from_milliseconds(milliseconds as f64)); - Ok(()) - }) - }) -} - -fn time(reader: &mut Reader, buf: &mut Vec, mut f: F) -> Result<()> -where - R: BufRead, - F: FnMut(Time), -{ - time_span(reader, buf, |t| f(RealTime(Some(t)).into())) -} - -fn image( - reader: &mut Reader, - buf: &mut Vec, - image_buf: &mut Vec, - mut f: F, -) -> Result<()> -where - R: BufRead, - F: FnMut(&[u8]), -{ - let (mut width, mut height) = (None, None); - image_buf.clear(); - - type_hint(single_child( - reader, - buf, - b"javax.swing.ImageIcon", - |reader, tag| { - parse_children(reader, tag.into_buf(), |reader, tag| { - if tag.name() == b"default" { - parse_children(reader, tag.into_buf(), |reader, tag| { - if tag.name() == b"height" { - text_parsed(reader, tag.into_buf(), |t: u32| height = Some(t)) - } else if tag.name() == b"width" { - text_parsed(reader, tag.into_buf(), |t: u32| width = Some(t)) - } else { - end_tag(reader, tag.into_buf()) - } - }) - } else if tag.name() == b"int-array" { - image_buf.clear(); - if let (Some(width), Some(height)) = (width, height) { - let len = width as usize * height as usize * 4; - image_buf.reserve(min(len, 32 << 20)); - } - - let mut tmp = [0; 4]; - - parse_children(reader, tag.into_buf(), |reader, tag| { - text_parsed(reader, tag.into_buf(), |value: i32| { - BE::write_i32(&mut tmp, value); - image_buf.extend_from_slice(&[tmp[1], tmp[2], tmp[3], tmp[0]]); - }) - }) - } else { - end_tag(reader, tag.into_buf()) - } - }) - }, - ))?; - - let height = height.ok_or(Error::Image)?; - let width = width.ok_or(Error::Image)?; - - let image_buf = image_buf.as_slice(); - let image = - ImageBuffer::, _>::from_raw(width, height, image_buf).ok_or(Error::Image)?; - - buf.clear(); - png::PngEncoder::new(&mut *buf) - .encode(image.as_ref(), width, height, ColorType::Rgba8) - .map_err(|_| Error::Image)?; - - f(buf); - - Ok(()) -} - -fn parse_segment( - reader: &mut Reader, - buf: &mut Vec, - image_buf: &mut Vec, -) -> Result { - let mut segment = Segment::new(""); - - parse_children(reader, buf, |reader, tag| { - if tag.name() == b"name" { - text(reader, tag.into_buf(), |t| segment.set_name(t)) - } else if tag.name() == b"icon" { - image(reader, tag.into_buf(), image_buf, |i| segment.set_icon(i)) - } else if tag.name() == b"time" { - time(reader, tag.into_buf(), |t| { - segment.set_personal_best_split_time(t) - }) - } else if tag.name() == b"best" { - time(reader, tag.into_buf(), |t| segment.set_best_segment_time(t)) - } else { - end_tag(reader, tag.into_buf()) - } - })?; - - Ok(segment) -} - -/// Attempts to parse a splits file used by the Llanfair Rewrite. -pub fn parse(source: R) -> Result { - let reader = &mut Reader::from_reader(source); - reader.expand_empty_elements(true); - reader.trim_text(true); - - let mut buf = Vec::with_capacity(4096); - let mut image_buf = Vec::with_capacity(4096); - - let mut run = Run::new(); - - type_hint(parse_base(reader, &mut buf, b"run", |reader, tag| { - parse_children(reader, tag.into_buf(), |reader, tag| { - if tag.name() == b"game" { - text(reader, tag.into_buf(), |t| run.set_game_name(t)) - } else if tag.name() == b"category" { - text(reader, tag.into_buf(), |t| run.set_category_name(t)) - } else if tag.name() == b"platform" { - text(reader, tag.into_buf(), |t| { - run.metadata_mut().set_platform_name(t) - }) - } else if tag.name() == b"region" { - text(reader, tag.into_buf(), |t| { - run.metadata_mut().set_region_name(t) - }) - } else if tag.name() == b"emulated" { - text(reader, tag.into_buf(), |t| { - run.metadata_mut().set_emulator_usage(t == "true") - }) - } else if tag.name() == b"segments" { - parse_children(reader, tag.into_buf(), |reader, tag| { - if tag.name() == b"segment" { - let segment = parse_segment(reader, tag.into_buf(), &mut image_buf)?; - run.push_segment(segment); - Ok(()) - } else { - end_tag(reader, tag.into_buf()) - } - }) - } else { - end_tag(reader, tag.into_buf()) - } - }) - }))?; - - Ok(run) -} diff --git a/src/run/parser/mod.rs b/src/run/parser/mod.rs index 37dbe4ea..9cb4b109 100644 --- a/src/run/parser/mod.rs +++ b/src/run/parser/mod.rs @@ -36,7 +36,6 @@ pub mod face_split; pub mod flitter; pub mod livesplit; pub mod llanfair; -pub mod llanfair2; pub mod llanfair_gered; pub mod portal2_live_timer; pub mod shit_split; diff --git a/src/run/parser/timer_kind.rs b/src/run/parser/timer_kind.rs index b43e11ae..3070971f 100644 --- a/src/run/parser/timer_kind.rs +++ b/src/run/parser/timer_kind.rs @@ -25,8 +25,6 @@ pub enum TimerKind { Llanfair, /// Gered's fork of Llanfair LlanfairGered, - /// The Rewrite of Llanfair - Llanfair2, /// Urn Urn, /// SourceLiveTimer @@ -52,7 +50,6 @@ impl fmt::Display for TimerKind { TimerKind::Flitter => write!(f, "Flitter"), TimerKind::Llanfair => write!(f, "Llanfair"), TimerKind::LlanfairGered => write!(f, "Llanfair (Gered's fork)"), - TimerKind::Llanfair2 => write!(f, "Llanfair Rewrite"), TimerKind::Urn => write!(f, "Urn"), TimerKind::SourceLiveTimer => write!(f, "SourceLiveTimer"), TimerKind::Splitterino => write!(f, "Splitterino"), diff --git a/tests/run_files/llanfair2.xml b/tests/run_files/llanfair2.xml deleted file mode 100644 index 2f60aba6..00000000 --- a/tests/run_files/llanfair2.xml +++ /dev/null @@ -1,290 +0,0 @@ - - Odyssey - Any% - Switch - JP - false - - - - - - 16 - 16 - C:\Users\Christopher Serr\Pictures\1st.png - - 16 - 16 - - 0 - 0 - 0 - 525353492 - 1682586642 - -1723385327 - -1102825455 - -1002359280 - -1035848432 - -1387972335 - -1824114159 - 1464614418 - 391201299 - 0 - 0 - 0 - 0 - 0 - 0 - -194883560 - -10399720 - -10333927 - -10268135 - -10202599 - -10202599 - -10268391 - -10333927 - -10268391 - -1184870889 - 0 - 0 - 0 - 0 - 0 - 0 - -2003204016 - -21851082 - -4941500 - -7309010 - -9216223 - -9215966 - -8426709 - -6782405 - -6651078 - 1903913263 - 0 - 0 - 0 - 0 - 0 - 0 - 1702059289 - -1145792709 - -1517664 - -1385819 - -1649514 - -1583722 - -1253715 - -1122381 - -1413898681 - 1783841808 - 0 - 0 - 0 - 0 - 0 - 0 - 1903978014 - 1486718523 - -2375312 - -1121863 - -2375568 - -3231141 - -18426466 - -69418123 - 935567415 - 1918782744 - 0 - 0 - 0 - 0 - 0 - 0 - 1954309406 - 438836992 - 1372565322 - -271732911 - -5073865 - -5863122 - -322854071 - 1220977979 - 565483051 - 1918782744 - 0 - 0 - 0 - 0 - 0 - 0 - 1954309406 - 558645011 - 0 - 229017901 - -609710535 - -611749330 - 213294672 - 0 - 582391853 - 1918782744 - 0 - 0 - 0 - 0 - 0 - 0 - 1954309406 - 558579475 - 0 - 0 - 2091159371 - 1474941577 - 0 - 0 - 582391853 - 1918782744 - 0 - 0 - 0 - 0 - 0 - 0 - 1954309406 - 558579475 - 0 - 0 - -656158575 - -706490223 - 64271191 - 0 - 582391853 - 1918782744 - 0 - 0 - 0 - 0 - 0 - 0 - 1954309406 - 507655694 - 752203354 - -522139003 - -1715305 - -1780841 - -723531390 - 634564947 - 565548843 - 1918782744 - 0 - 0 - 0 - 0 - 0 - 0 - 1954309406 - 762404647 - -2704800 - -1583195 - -2045050 - -2308476 - -1385038 - -304562844 - 750887478 - 1918782744 - 0 - 0 - 0 - 0 - 0 - 0 - 1920689182 - -510954711 - -2901135 - -2836642 - -2375313 - -4285131 - -3296411 - -2110317 - -1518179552 - 1767722007 - 0 - 0 - 0 - 0 - 0 - 0 - -1031244491 - -7967456 - -2176633 - -2309779 - -2969010 - -2969013 - -2309000 - -1714781 - -8032727 - -1737466332 - 0 - 0 - 0 - 0 - 0 - 0 - -41060296 - -10005479 - -8821724 - -6125770 - -6455258 - -6389721 - -6125253 - -8953310 - -8426709 - -1116446429 - 0 - 0 - 0 - 0 - 0 - 0 - 1615806480 - -6388950 - -6520789 - -8887779 - -9808102 - -9808102 - -9742311 - -8821986 - -9282276 - 1481063185 - 0 - 0 - 0 - 0 - 0 - 0 - 0 - 411857961 - -2019721433 - -1066444005 - -800901359 - -599640560 - -1219476972 - 1667584793 - 0 - 0 - 0 - 0 - 0 - - - - LUL - - - 2500 - false - - - - 20161104 - \ No newline at end of file diff --git a/tests/run_files/llanfair2_empty.xml b/tests/run_files/llanfair2_empty.xml deleted file mode 100644 index e457aefc..00000000 --- a/tests/run_files/llanfair2_empty.xml +++ /dev/null @@ -1,7 +0,0 @@ - - false - - - - 20161104 - diff --git a/tests/run_files/mod.rs b/tests/run_files/mod.rs index e4a5e9e4..9a5cfb6e 100644 --- a/tests/run_files/mod.rs +++ b/tests/run_files/mod.rs @@ -16,8 +16,6 @@ pub const LLANFAIR_GERED_ICONS: &[u8] = include_bytes!("llanfair_gered_icons.lfs pub const LLANFAIR_GERED_WITH_REFS: &[u8] = include_bytes!("llanfair_gered_with_refs.lfs"); pub const LLANFAIR_GERED: &[u8] = include_bytes!("llanfair_gered.lfs"); pub const LLANFAIR: &[u8] = include_bytes!("llanfair"); -pub const LLANFAIR2_EMPTY: &[u8] = include_bytes!("llanfair2_empty.xml"); -pub const LLANFAIR2: &[u8] = include_bytes!("llanfair2.xml"); pub const PORTAL2_LIVE_TIMER1: &[u8] = include_bytes!("portal2_live_timer1.csv"); pub const PORTAL2_LIVE_TIMER2: &[u8] = include_bytes!("portal2_live_timer2.csv"); pub const SOURCE_LIVE_TIMER: &[u8] = include_bytes!("source_live_timer.json"); diff --git a/tests/split_parsing.rs b/tests/split_parsing.rs index b24995fa..8525c4a6 100644 --- a/tests/split_parsing.rs +++ b/tests/split_parsing.rs @@ -5,7 +5,7 @@ mod parse { use livesplit_core::{ analysis::total_playtime, run::parser::{ - composite, flitter, livesplit, llanfair, llanfair2, llanfair_gered, portal2_live_timer, + composite, flitter, livesplit, llanfair, llanfair_gered, portal2_live_timer, source_live_timer, splits_io, splitterino, splitterz, time_split_tracker, urn, wsplit, TimerKind, }, @@ -25,10 +25,6 @@ mod parse { llanfair_gered::parse(file(data)).unwrap(); } - fn parse_llanfair2(data: &[u8]) { - llanfair2::parse(file(data)).unwrap(); - } - #[test] fn livesplit_fuzz_crash() { livesplit::parse(file(run_files::LIVESPLIT_FUZZ_CRASH), None).unwrap_err(); @@ -106,16 +102,6 @@ mod parse { parse_llanfair_gered(run_files::LLANFAIR_GERED_ICONS); } - #[test] - fn llanfair2() { - parse_llanfair2(run_files::LLANFAIR2) - } - - #[test] - fn llanfair2_empty() { - parse_llanfair2(run_files::LLANFAIR2_EMPTY) - } - #[test] fn time_split_tracker() { let run = time_split_tracker::parse(file(run_files::TIME_SPLIT_TRACKER), None).unwrap();