mirror of
https://github.com/ALEZ-DEV/Babylonia-terminal.git
synced 2025-12-15 17:08:51 +00:00
can now pass custom launch command with --options "<custom-command> %command%"
and the launcher can now print the output of Proton/Wine, it didn't do that previously
This commit is contained in:
parent
29d8f7dccd
commit
2fe4496040
@ -1,5 +1,6 @@
|
||||
use std::{path::PathBuf, sync::Arc};
|
||||
use std::{path::PathBuf, sync::Arc, process::{Command, Stdio}, io::{BufReader, BufRead}};
|
||||
|
||||
use dirs::config_dir;
|
||||
use downloader::progress::Reporter;
|
||||
use log::{debug, info};
|
||||
use tokio::fs::create_dir_all;
|
||||
@ -11,7 +12,7 @@ use crate::{
|
||||
game_component::GameComponent, proton_component::ProtonComponent,
|
||||
},
|
||||
game_patcher,
|
||||
game_state::GameState,
|
||||
game_state::{GameConfig, GameState},
|
||||
utils::{get_game_name, get_game_name_with_executable, github_requester::GithubRequester},
|
||||
};
|
||||
|
||||
@ -164,16 +165,55 @@ impl GameManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub async fn start_game(proton: &Proton, game_dir: PathBuf) {
|
||||
debug!("Wine version : {:?}", proton.wine().version().unwrap());
|
||||
let mut child = proton
|
||||
.run(
|
||||
game_dir
|
||||
pub async fn start_game(proton: &Proton, game_dir: PathBuf, options: Option<String>) {
|
||||
let proton_version = proton.wine().version().unwrap();
|
||||
let exec_path = game_dir
|
||||
.join(get_game_name())
|
||||
.join(get_game_name_with_executable()),
|
||||
.join(get_game_name_with_executable());
|
||||
|
||||
debug!("Wine version : {:?}", proton_version);
|
||||
|
||||
let mut child = if let Some(custom_command) = options {
|
||||
debug!("Starting game with --options -> {}", custom_command);
|
||||
let mut tokens: Vec<&str> = custom_command.split_whitespace().collect();
|
||||
|
||||
// position of the %command%
|
||||
let index = tokens.iter().position(|&s| s == "%command%").expect("You forget to put %command% in your custom launch command");
|
||||
|
||||
Command::new(tokens.get(0).unwrap())
|
||||
.args(&tokens[0..(index - 1)])
|
||||
.arg(proton.python.as_os_str())
|
||||
.arg(GameState::get_config_directory().await.join("proton").join("proton"))
|
||||
.arg("run")
|
||||
.arg(exec_path)
|
||||
.args(&tokens[(index + 1)..tokens.len()])
|
||||
.envs(proton.get_envs())
|
||||
.stdin(Stdio::piped())
|
||||
.stdout(Stdio::piped())
|
||||
.stderr(Stdio::piped())
|
||||
.spawn()
|
||||
.unwrap()
|
||||
} else {
|
||||
debug!("Starting game without --options");
|
||||
proton
|
||||
.run(
|
||||
exec_path,
|
||||
)
|
||||
.unwrap();
|
||||
child.wait().expect("The game failed to run");
|
||||
.unwrap()
|
||||
};
|
||||
|
||||
let stdout = child.stdout.take().unwrap();
|
||||
let mut bufread = BufReader::new(stdout);
|
||||
let mut buf = String::new();
|
||||
|
||||
while let Ok(n) = bufread.read_line(&mut buf) {
|
||||
if n > 0 {
|
||||
info!("[Wine {:?}] : {}", proton_version, buf.trim());
|
||||
buf.clear();
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user