feat: add backend for template launching

This commit is contained in:
DecDuck
2025-04-07 13:52:52 +10:00
parent 3e074abc0a
commit 6b9b9e3606
5 changed files with 47 additions and 1 deletions

View File

@ -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<String>,
#[serde(default = "default_template")]
pub launch_command_template: String,
pub setup_command: String,
pub setup_args: Vec<String>,
#[serde(default = "default_template")]
pub setup_command_template: String,
pub only_setup: bool,

View File

@ -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)
}

View File

@ -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")]