From 3f7d51150c90cc1819bcc0e28f85715e0daee438 Mon Sep 17 00:00:00 2001 From: Cutieguwu Date: Tue, 25 Mar 2025 22:09:13 -0400 Subject: [PATCH] Working on compatibility. --- src/gamelog.rs | 17 ++++++++--------- src/main.rs | 13 ++++++++++--- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/gamelog.rs b/src/gamelog.rs index a98421d..8860099 100644 --- a/src/gamelog.rs +++ b/src/gamelog.rs @@ -1,4 +1,3 @@ -use semver; use serde::Deserialize; use std::{fmt, fs::File, io, path::PathBuf, u64}; @@ -8,14 +7,19 @@ pub const GAMELOG_MIN_VER: semver::Version = semver::Version::new(0, 2, 0); pub enum LogFileError { FailedToOpen(io::Error), RonSpannedError(ron::error::SpannedError), - CompatibilityCheck, + CompatibilityCheck(semver::Version), } impl fmt::Display for LogFileError { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { Self::FailedToOpen(err) => write!(f, "{}", err), - Self::CompatibilityCheck => write!(f, "Variant was not Down::Kickoff."), + Self::CompatibilityCheck(ver) => write!( + f, + "GameLogs cannot be older than {}, but {} was found in logfile.", + GAMELOG_MIN_VER.to_string(), + ver.to_string() + ), Self::RonSpannedError(err) => write!(f, "{}", err), } } @@ -69,17 +73,12 @@ impl LogFile { self.get_min_ver().cmp_precedence(&GAMELOG_MIN_VER).is_lt() } - /// Attempts to make a gamefile compatible. - pub fn make_compatible(&mut self) -> Result<&mut Self, LogFileError> { - todo!() - } - /// Ensures that the returned gamefile is compatible, else returns Error. pub fn ensure_compatible(&mut self) -> Result<&mut Self, LogFileError> { if self.is_compatible() { Ok(self) } else { - Err(LogFileError::CompatibilityCheck) + Err(LogFileError::CompatibilityCheck(self.get_min_ver())) } } } diff --git a/src/main.rs b/src/main.rs index 48a8e6e..915c6ee 100644 --- a/src/main.rs +++ b/src/main.rs @@ -23,8 +23,15 @@ struct Args { fn main() { let config = Args::parse(); - let mut log: LogFile = match LogFile::try_from(config.logfile_path) { - Ok(f) => f, - Err(err) => panic!("Error: Failed to open logfile: {:?}", err), + let mut log: LogFile = { + let file = match LogFile::try_from(config.logfile_path) { + Ok(f) => f, + Err(err) => panic!("Error: Failed to open logfile: {:?}", err), + }; + + match file.ensure_compatible() { + Ok(f) => f.try_into().expect(msg), + Err(err) => panic!("Error: Failed to ensure logfile compatibility: {:?}", err), + } }; }