can now pass environment variable but not use them

This commit is contained in:
ALEZ-DEV 2025-04-28 20:22:33 +02:00
parent 7d2529588d
commit 0fbed904c6
5 changed files with 41 additions and 8 deletions

View File

@ -13,6 +13,10 @@ pub struct Args {
#[arg(long)]
pub set_options: Option<String>,
/// Pass environment variables to tinker the behavior of the game
#[arg(long, value_name = "VALUE", action = clap::ArgAction::Append)]
pub add_env_var: Vec<String>,
/// Show the logs direcly to the stdout of your terminal
#[arg(long, default_value = "false")]
pub logs: bool,

View File

@ -6,7 +6,7 @@ use babylonia_terminal_sdk::{
proton_component::{ProtonComponent, PROTON_DEV, PROTON_REPO},
},
game_config::GameConfig,
game_manager::GameManager,
game_manager::{EnvironmentVariable, GameManager},
game_state::GameState,
};
@ -16,7 +16,11 @@ use wincompatlib::prelude::*;
use crate::{reporter::DownloadReporter, utils};
pub async fn run(launch_options: Option<String>, show_logs: bool) {
pub async fn run(
launch_options: Option<String>,
env_vars: Vec<EnvironmentVariable>,
show_logs: bool,
) {
let mut proton_component: Option<ProtonComponent> = None;
let mut proton: Option<Proton> = None;
@ -170,6 +174,7 @@ pub async fn run(launch_options: Option<String>, show_logs: bool) {
.await
.expect("Failed to start game, the game directory was not found"),
launch_options,
env_vars,
show_logs,
)
.await;

View File

@ -1,5 +1,5 @@
use arguments::Args;
use babylonia_terminal_sdk::game_config::GameConfig;
use babylonia_terminal_sdk::{game_config::GameConfig, game_manager::EnvironmentVariable};
use clap::Parser;
use log::debug;
@ -24,6 +24,12 @@ pub fn run() {
.expect("Failed to save launch options into the config file");
}
game::run(args.options, args.logs).await;
let vars = args
.add_env_var
.iter()
.map(|v| EnvironmentVariable::parse(v))
.collect();
game::run(args.options, vars, args.logs).await;
});
}

View File

@ -23,6 +23,22 @@ use crate::{
utils::{get_game_name, get_game_name_with_executable, github_requester::GithubRequester},
};
pub struct EnvironmentVariable {
name: String,
value: String,
}
impl EnvironmentVariable {
pub fn parse(variable: &str) -> Self {
let split: Vec<&str> = variable.split('=').collect();
Self {
name: split[0].to_string(),
value: split[1].to_string(),
}
}
}
pub struct GameManager;
impl GameManager {
@ -152,6 +168,7 @@ impl GameManager {
proton: &Proton,
game_dir: PathBuf,
options: Option<String>,
env_variables: Vec<EnvironmentVariable>,
show_logs: bool,
) -> anyhow::Result<()> {
let proton_version = proton.wine().version()?;
@ -162,12 +179,12 @@ impl GameManager {
debug!("Wine version : {:?}", proton_version);
let mut child = if let Some(custom_command) = options {
Self::run(proton, binary_path, Some(custom_command)).await?
Self::run(proton, binary_path, Some(custom_command), env_variables).await?
} else {
if let Some(custom_command) = GameConfig::get_launch_options().await.unwrap() {
Self::run(proton, binary_path, Some(custom_command)).await?
Self::run(proton, binary_path, Some(custom_command), env_variables).await?
} else {
Self::run(proton, binary_path, None).await?
Self::run(proton, binary_path, None, env_variables).await?
}
}?;
@ -278,6 +295,7 @@ impl GameManager {
proton: &Proton,
binary_path: PathBuf,
custom_command: Option<String>,
env_variables: Vec<EnvironmentVariable>,
) -> anyhow::Result<Result<Child, std::io::Error>> {
let mut command: Vec<&str> = vec![];

View File

@ -1,5 +1,5 @@
use clap::Parser;
use log::{info, LevelFilter};
use log::{debug, info, LevelFilter};
use simple_logger::SimpleLogger;
fn main() {