From e8aee89f451f6314db355fc5c9f6cb29418021a9 Mon Sep 17 00:00:00 2001 From: mxve <68632137+mxve@users.noreply.github.com> Date: Wed, 7 Feb 2024 12:53:43 +0100 Subject: [PATCH] check for required files --- src/main.rs | 9 +++++++++ src/structs.rs | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main.rs b/src/main.rs index c6ad688..2a36e85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -300,6 +300,15 @@ async fn update( )) .unwrap(); + if !game.required_files_exist(dir) { + println!( + "{}\nVerify game file integrity on Steam or reinstall the game.", + "Critical game files missing.".bright_red() + ); + std::io::stdin().read_line(&mut String::new()).unwrap(); + std::process::exit(0); + } + let mut hashes = HashMap::new(); let hash_file = dir.join(".sha-sums"); if hash_file.exists() && !force { diff --git a/src/structs.rs b/src/structs.rs index 65faa2a..86934aa 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -1,3 +1,5 @@ +use std::path::Path; + #[derive(serde::Deserialize, serde::Serialize, Clone)] pub struct CdnFile { pub name: String, @@ -13,6 +15,20 @@ pub struct Game<'a> { pub app_id: u32, pub bonus: Vec<&'a str>, pub delete: Vec<&'a str>, + pub required: Vec<&'a str>, +} + +impl<'a> Game<'a> { + pub fn required_files_exist(&self, dir: &Path) -> bool { + for required_file in &self.required { + let file_path = dir.join(required_file); + if !file_path.exists() { + println!("Required file {} does not exist", file_path.display()); + return false; + } + } + true + } } #[derive(serde::Deserialize, serde::Serialize)]