use sysinfo::{ ProcessExt, SystemExt };\r
-use chrono::{ DateTime, Datelike, Timelike, Utc };\r
+\r
+use std::{ fs, time::SystemTime };\r
+\r
+use chrono::{ DateTime, offset::Local };\r
\r
#[cfg(target_os = "unix")]\r
use systemd::journal;\r
uptime: u64, // [s].\r
world_size: u64, // [B].\r
nb_of_players: u32,\r
- last_backup: DateTime,\r
+ last_backup: Option<SystemTime>,\r
}\r
\r
impl ValheimExe {\r
}\r
\r
pub fn format_last_backup(&self) -> String {\r
- string::from("")\r
+ match self.last_backup {\r
+ Some(t) => {\r
+ let datetime: DateTime<Local> = t.into();\r
+ datetime.format("%d/%m/%Y %T").to_string()\r
+ },\r
+ None => String::from("?")\r
+ }\r
}\r
}\r
\r
0\r
}\r
\r
-fn get_last_backup_datetime(backup_path: &str) -> DateTime {\r
+fn get_last_backup_datetime(backup_path: &str) -> Option<SystemTime> {\r
+ let mut times =\r
+ fs::read_dir(backup_path).ok()?.filter_map(\r
+ |e| {\r
+ let dir = e.ok()?;\r
+ if dir.path().is_file() { Some(dir.metadata().ok()?.created().ok()?) } else { None }\r
+ }\r
+ )\r
+ .collect::<Vec<SystemTime>>();\r
+\r
+ times.sort();\r
\r
+ Some(times.last()?.clone())\r
}\r
\r
pub fn get_valheim_executable_information(world_path: &str, backup_path: &str) -> Option<ValheimExe> {\r