Replace 'listenfd' by 'cargo watch'
[valheim_web.git] / backend / src / valheim_controller.rs
index efad791..a483756 100644 (file)
@@ -1,4 +1,4 @@
-use sysinfo::{ComponentExt, ProcessExt, SystemExt};\r
+use sysinfo::{ProcessExt, SystemExt};\r
 \r
 #[derive(Debug)]\r
 pub struct ValheimExe {\r
@@ -31,9 +31,7 @@ const BINARY_PREFIXES: [&str; 8] = ["B", "KiB", "MiB", "GiB", "TiB", "PiB", "EiB
 fn format_byte_size(bytes: u64, precision: usize) -> String {\r
     for i in 0 .. 8 {\r
         let mut size: u64 = 1;\r
-        for j in 0 .. i {\r
-            size *= 1024;\r
-        }\r
+        size *= 1024u64.pow(i as u32);\r
 \r
         if bytes < 1024 {\r
             return format!("{} {}", std::cmp::max(0u64, bytes), BINARY_PREFIXES[i]);\r
@@ -47,9 +45,8 @@ fn format_byte_size(bytes: u64, precision: usize) -> String {
 }\r
 \r
 const VALHEIM_PROCESS_NAME: &str = "valheim_server";\r
-const VALHEIM_WORLD_PATH: &str = "/home/greg/ValheimWorld/pouet.db"; // TODO: Put in conf.\r
 \r
-pub fn get_valheim_executable_information() -> Option<ValheimExe> {\r
+pub fn get_valheim_executable_information(world_path : &str) -> Option<ValheimExe> {\r
     let mut system = sysinfo::System::new_all();\r
     system.refresh_system();\r
     let processes = system.get_process_by_name(VALHEIM_PROCESS_NAME);\r
@@ -57,7 +54,7 @@ pub fn get_valheim_executable_information() -> Option<ValheimExe> {
     if processes.len() >= 1 {\r
         let process = processes.first().unwrap();\r
 \r
-        let world_size = match std::fs::metadata(VALHEIM_WORLD_PATH) { Ok(f) => f.len(), Err(_) => 0u64 };\r
+        let world_size = match std::fs::metadata(world_path) { Ok(f) => f.len(), Err(_) => 0u64 };\r
 \r
         Some(\r
             ValheimExe {\r