diff --git a/desktop/src-tauri/Cargo.lock b/desktop/src-tauri/Cargo.lock index 59ae5e5a..d8117659 100644 --- a/desktop/src-tauri/Cargo.lock +++ b/desktop/src-tauri/Cargo.lock @@ -1291,6 +1291,7 @@ dependencies = [ "deranged", "directories", "droplet-rs", + "dynfmt", "gethostname 1.0.1", "hex 0.4.3", "http 1.2.0", @@ -1370,6 +1371,20 @@ version = "1.0.17" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "0d6ef0072f8a535281e4876be788938b528e9a1d43900b82c2569af7da799125" +[[package]] +name = "dynfmt" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1c298552016db86f0d49e5de09818dd86c536f66095013cc415f4f85744033f" +dependencies = [ + "erased-serde 0.3.31", + "lazy_static", + "regex", + "serde", + "serde_json", + "thiserror 1.0.69", +] + [[package]] name = "either" version = "1.13.0" @@ -1438,6 +1453,15 @@ version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" +[[package]] +name = "erased-serde" +version = "0.3.31" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c138974f9d5e7fe373eb04df7cae98833802ae4b11c24ac7039a21d5af4b26c" +dependencies = [ + "serde", +] + [[package]] name = "erased-serde" version = "0.4.5" @@ -4561,7 +4585,7 @@ version = "0.1.6" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "2676ba99bd82f75cae5cbd2c8eda6fa0b8760f18978ea840e980dd5567b5c5b6" dependencies = [ - "erased-serde", + "erased-serde 0.4.5", "serde", "typeid", ] diff --git a/desktop/src-tauri/Cargo.toml b/desktop/src-tauri/Cargo.toml index 914a481e..1a21e452 100644 --- a/desktop/src-tauri/Cargo.toml +++ b/desktop/src-tauri/Cargo.toml @@ -59,6 +59,10 @@ deranged = "=0.4.0" droplet-rs = "0.7.3" gethostname = "1.0.1" +[dependencies.dynfmt] +version = "0.1.5" +features = ["curly"] + [dependencies.tauri] version = "2.1.1" features = ["tray-icon"] diff --git a/desktop/src-tauri/src/database/db.rs b/desktop/src-tauri/src/database/db.rs index b0a241e2..44b44b79 100644 --- a/desktop/src-tauri/src/database/db.rs +++ b/desktop/src-tauri/src/database/db.rs @@ -54,6 +54,10 @@ pub enum ApplicationTransientStatus { Running {}, } +fn default_template() -> String { + "{}".to_owned() +} + #[derive(Serialize, Deserialize, Clone, Debug)] #[serde(rename_all = "camelCase")] pub struct GameVersion { @@ -64,9 +68,14 @@ pub struct GameVersion { pub launch_command: String, pub launch_args: Vec, + #[serde(default = "default_template")] + pub launch_command_template: String, pub setup_command: String, pub setup_args: Vec, + #[serde(default = "default_template")] + pub setup_command_template: String, + pub only_setup: bool, diff --git a/desktop/src-tauri/src/error/process_error.rs b/desktop/src-tauri/src/error/process_error.rs index 8afc9dc7..fefa2c33 100644 --- a/desktop/src-tauri/src/error/process_error.rs +++ b/desktop/src-tauri/src/error/process_error.rs @@ -11,6 +11,7 @@ pub enum ProcessError { InvalidID, InvalidVersion, IOError(Error), + FormatError(String), // String errors supremacy InvalidPlatform, } @@ -25,6 +26,7 @@ impl Display for ProcessError { ProcessError::InvalidVersion => "Invalid Game version", ProcessError::IOError(error) => &error.to_string(), ProcessError::InvalidPlatform => "This Game cannot be played on the current platform", + ProcessError::FormatError(e) => &format!("Failed to format template: {}", e), }; write!(f, "{}", s) } diff --git a/desktop/src-tauri/src/process/process_manager.rs b/desktop/src-tauri/src/process/process_manager.rs index 54f3f891..83da24c1 100644 --- a/desktop/src-tauri/src/process/process_manager.rs +++ b/desktop/src-tauri/src/process/process_manager.rs @@ -9,6 +9,8 @@ use std::{ thread::spawn, }; +use dynfmt::Format; +use dynfmt::SimpleCurlyFormat; use log::{debug, info, warn}; use serde::{Deserialize, Serialize}; use shared_child::SharedChild; @@ -259,6 +261,11 @@ impl ProcessManager<'_> { install_dir, ); + let launch_string = SimpleCurlyFormat + .format(&game_version.launch_command_template, &[launch_string]) + .map_err(|e| ProcessError::FormatError(e.to_string()))? + .to_string(); + info!("launching process {} in {}", launch_string, install_dir); #[cfg(target_os = "windows")]