add support for Game.delete

This commit is contained in:
mxve 2024-01-02 11:22:18 +01:00
parent 2261a9a655
commit caaf73e9f3
2 changed files with 20 additions and 0 deletions

View File

@ -358,6 +358,25 @@ async fn update(game: &Game<'_>, dir: &Path, bonus_content: bool, force: bool) {
pb.finish(); pb.finish();
for f in game.delete.iter() {
let file_path = dir.join(f);
if file_path.exists() {
if let Err(_) = fs::remove_file(&file_path) {
println!(
"[{}] Couldn't delete {}",
"Error".bright_red(),
misc::cute_path(&file_path)
);
} else {
println!(
"[{}] {}",
"Removed".bright_red(),
misc::cute_path(&file_path)
);
}
}
}
let mut hash_file_content = String::new(); let mut hash_file_content = String::new();
for (file, hash) in hashes.iter() { for (file, hash) in hashes.iter() {
hash_file_content.push_str(&format!("{} {}\n", hash, file)); hash_file_content.push_str(&format!("{} {}\n", hash, file));

View File

@ -12,6 +12,7 @@ pub struct Game<'a> {
pub references: Vec<&'a str>, pub references: Vec<&'a str>,
pub app_id: u32, pub app_id: u32,
pub bonus: Vec<&'a str>, pub bonus: Vec<&'a str>,
pub delete: Vec<&'a str>,
} }
#[derive(serde::Deserialize, serde::Serialize)] #[derive(serde::Deserialize, serde::Serialize)]