diff --git a/checker.cfg.json b/checker.cfg.json index 9f4e128..d78a02c 100644 --- a/checker.cfg.json +++ b/checker.cfg.json @@ -18,5 +18,7 @@ "name": "variance", "regex": "^variance\\\\variance\\.(cpp|c|pas)$" } - ] + ], + "start_time": "2023-10-18T15:00:00Z", + "end_time": "2023-10-18T16:00:00Z" } diff --git a/src/config.rs b/src/config.rs index 14d00f9..ceb8665 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1,3 +1,6 @@ +use std::collections::HashMap; + +use chrono::{DateTime, Utc}; use regex::Regex; use serde::{Deserialize, Serialize}; @@ -9,6 +12,8 @@ pub struct Problem { pub regex: Regex, #[serde(default)] pub existing_files: Vec, + #[serde(default)] + pub existing_files_date: HashMap>, } #[derive(Debug, Serialize, Deserialize)] @@ -19,6 +24,10 @@ pub struct Contestant { pub regex: Regex, /// 所有题目的配置项 pub problems: Vec, + /// 考试开始时间 + pub start_time: DateTime, + /// 考试结束时间 + pub end_time: DateTime, } mod regex_sd { diff --git a/src/main.rs b/src/main.rs index b07c9d6..b2a4780 100644 --- a/src/main.rs +++ b/src/main.rs @@ -110,8 +110,13 @@ fn build_message(messages: &mut Vec<(String, Color)>) -> Result<()> { .regex .is_match(dir2.path().strip_prefix(&user_directory)?.to_str().unwrap()) { - prob.existing_files - .push(dir2.path().to_str().unwrap().to_string()); + let filepath = dir2.path().to_str().unwrap().to_string(); + prob.existing_files.push(filepath.clone()); + if let Ok(meta) = dir2.metadata() { + if let Ok(modi) = meta.modified() { + prob.existing_files_date.insert(filepath, modi.into()); + } + } } } } @@ -122,15 +127,31 @@ fn build_message(messages: &mut Vec<(String, Color)>) -> Result<()> { if prob.existing_files.is_empty() { messages.push((format!(" 未找到源代码文件."), Color::Black)); } else if prob.existing_files.len() == 1 { - let f = Path::new(&prob.existing_files[0]).strip_prefix(&user_directory)?; + let filename = &prob.existing_files[0]; + let f = Path::new(filename).strip_prefix(&user_directory)?; messages.push(( format!( " 找到文件 {} => 校验码 {}.", f.display(), - result_into_ok_or_err(try_crc32(&prob.existing_files[0])) + result_into_ok_or_err(try_crc32(filename)) ), Color::Black, )); + if let Some(mod_date) = &prob.existing_files_date.get(filename) { + if mod_date >= &&cfg.start_time && mod_date <= &&cfg.end_time { + messages.push(( + format!(" 修改日期有效 {}.", mod_date), + Color::Black, + )); + } else { + messages.push(( + format!(" 修改日期不在考试时间范围内 {}.", mod_date), + Color::Red, + )); + } + } else { + messages.push((format!(" 文件没有修改日期记录."), Color::Yellow)); + } } else { messages.push((format!(" 找到多个源代码文件:"), Color::Red)); for file in prob.existing_files.iter() {