Working on compatibility.
This commit is contained in:
@@ -1,4 +1,3 @@
|
|||||||
use semver;
|
|
||||||
use serde::Deserialize;
|
use serde::Deserialize;
|
||||||
use std::{fmt, fs::File, io, path::PathBuf, u64};
|
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 {
|
pub enum LogFileError {
|
||||||
FailedToOpen(io::Error),
|
FailedToOpen(io::Error),
|
||||||
RonSpannedError(ron::error::SpannedError),
|
RonSpannedError(ron::error::SpannedError),
|
||||||
CompatibilityCheck,
|
CompatibilityCheck(semver::Version),
|
||||||
}
|
}
|
||||||
|
|
||||||
impl fmt::Display for LogFileError {
|
impl fmt::Display for LogFileError {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
match self {
|
match self {
|
||||||
Self::FailedToOpen(err) => write!(f, "{}", err),
|
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),
|
Self::RonSpannedError(err) => write!(f, "{}", err),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -69,17 +73,12 @@ impl LogFile {
|
|||||||
self.get_min_ver().cmp_precedence(&GAMELOG_MIN_VER).is_lt()
|
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.
|
/// Ensures that the returned gamefile is compatible, else returns Error.
|
||||||
pub fn ensure_compatible(&mut self) -> Result<&mut Self, LogFileError> {
|
pub fn ensure_compatible(&mut self) -> Result<&mut Self, LogFileError> {
|
||||||
if self.is_compatible() {
|
if self.is_compatible() {
|
||||||
Ok(self)
|
Ok(self)
|
||||||
} else {
|
} else {
|
||||||
Err(LogFileError::CompatibilityCheck)
|
Err(LogFileError::CompatibilityCheck(self.get_min_ver()))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
13
src/main.rs
13
src/main.rs
@@ -23,8 +23,15 @@ struct Args {
|
|||||||
fn main() {
|
fn main() {
|
||||||
let config = Args::parse();
|
let config = Args::parse();
|
||||||
|
|
||||||
let mut log: LogFile = match LogFile::try_from(config.logfile_path) {
|
let mut log: LogFile = {
|
||||||
Ok(f) => f,
|
let file = match LogFile::try_from(config.logfile_path) {
|
||||||
Err(err) => panic!("Error: Failed to open logfile: {:?}", err),
|
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),
|
||||||
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user