X-Git-Url: http://git.euphorik.ch/?a=blobdiff_plain;f=backend%2Fsrc%2Fvalheim_controller.rs;h=04f75a42b4ef88ce271c307b133e30f258ea55b7;hb=28dede5779342bac9b4767d61badac099b1595c2;hp=3d990331bbd0d5487cacff78e51137d32ebae39f;hpb=9deef63b608b62780a4dfed031410c25e10e477a;p=valheim_web.git diff --git a/backend/src/valheim_controller.rs b/backend/src/valheim_controller.rs index 3d99033..04f75a4 100644 --- a/backend/src/valheim_controller.rs +++ b/backend/src/valheim_controller.rs @@ -1,5 +1,8 @@ use sysinfo::{ ProcessExt, SystemExt }; -use chrono::{ DateTime, Datelike, Timelike, Utc }; + +use std::{ fs, time::SystemTime }; + +use chrono::{ DateTime, offset::Local }; #[cfg(target_os = "unix")] use systemd::journal; @@ -11,7 +14,7 @@ pub struct ValheimExe { uptime: u64, // [s]. world_size: u64, // [B]. nb_of_players: u32, - last_backup: DateTime, + last_backup: Option, } impl ValheimExe { @@ -39,7 +42,13 @@ impl ValheimExe { } pub fn format_last_backup(&self) -> String { - string::from("") + match self.last_backup { + Some(t) => { + let datetime: DateTime = t.into(); + datetime.format("%d/%m/%Y %T").to_string() + }, + None => String::from("?") + } } } @@ -96,8 +105,19 @@ fn get_number_of_players() -> u32 { 0 } -fn get_last_backup_datetime(backup_path: &str) -> DateTime { +fn get_last_backup_datetime(backup_path: &str) -> Option { + let mut times = + fs::read_dir(backup_path).ok()?.filter_map( + |e| { + let dir = e.ok()?; + if dir.path().is_file() { Some(dir.metadata().ok()?.created().ok()?) } else { None } + } + ) + .collect::>(); + + times.sort(); + Some(times.last()?.clone()) } pub fn get_valheim_executable_information(world_path: &str, backup_path: &str) -> Option {