umu_wrapper_lib/
command_builder.rs

1use std::{ffi::OsStr, path::PathBuf, process::Command};
2
3
4use crate::command::UmuCommand;
5
6#[derive(Debug, Default, Clone)]
7pub struct UmuCommandBuilder {
8    source: PathBuf,
9
10    program: String,
11    game_id: Option<String>,
12    wineprefix: Option<PathBuf>,
13    proton_path: Option<PathBuf>,
14    launch_args: Option<Vec<String>>,
15    store: Option<String>,
16}
17#[allow(dead_code)]
18impl UmuCommandBuilder {
19    pub fn new<T: Into<PathBuf>, D: Into<String>>(source: T, program: D) -> Self {
20        Self {
21            source: source.into(),
22            program: program.into(),
23            ..Default::default()
24        }
25    }
26    pub fn build(self) -> UmuCommand {
27        let mut command = Command::new(self.source);
28
29        command.arg(self.program);
30        set_env(&mut command, "GAMEID", self.game_id);
31        set_env(&mut command, "PROTONPATH", self.proton_path);
32        set_env(&mut command, "WINEPREFIX", self.wineprefix);
33        //set_env(&mut command, "PROTON_VERB", self.proton_path);
34        set_env(&mut command, "STORE", self.store);
35
36        UmuCommand::new(command)
37    }
38    pub fn game_id(mut self, game_id: String) -> Self {
39        self.game_id = Some(game_id);
40        self
41    }
42    pub fn proton<T: Into<PathBuf>>(mut self, proton_executable: T) -> Self {
43        self.proton_path = Some(proton_executable.into());
44        self
45    }
46    pub fn store(mut self, store: String) -> Self {
47        self.store = Some(store);
48        self
49    }
50    pub fn wineprefix(mut self, wineprefix: PathBuf) -> Self {
51        self.wineprefix = Some(wineprefix);
52        self
53    }
54    pub fn launch_args(mut self, launch_args: Vec<String>) -> Self {
55        self.launch_args = Some(launch_args);
56        self
57    }
58}
59
60fn set_env<K: AsRef<OsStr>, V: AsRef<OsStr>>(command: &mut Command, key: K, variable: Option<V>) {
61    if variable.is_none() { return; }
62    command.env(key, variable.unwrap());
63}