proton_launch/command/
restore.rs

1use std::{
2    fs::File,
3    path::PathBuf,
4};
5
6use crate::{paths::Paths, steam::SteamData};
7
8use super::{Runnable, RunnableResult};
9
10#[derive(Debug, Clone)]
11#[cfg_attr(feature = "commandline", derive(clap::Args))]
12pub struct Restore {
13    /// Path to the backup file
14    backup: PathBuf,
15
16    /// Optional save name to use
17    /// If not specified, the backup file without the extension will be used
18    #[cfg_attr(feature = "commandline", clap(short, long))]
19    save_name: Option<String>,
20}
21
22impl Runnable for Restore {
23    fn run(&self, paths: &Paths, _steam_data: &SteamData) -> RunnableResult<()> {
24        let save_name = self
25            .save_name
26            .as_deref()
27            .unwrap_or_else(|| self.backup.file_stem().unwrap().to_str().unwrap());
28        let global_compat_dir = paths.compat_dir(save_name);
29        let f = File::open(&self.backup).unwrap();
30        let d = zstd::Decoder::new(f).unwrap();
31        let mut archive = tar::Archive::new(d);
32        archive.unpack(&global_compat_dir).unwrap();
33        Ok(())
34    }
35}