Files
STARTLINER/rust/src/start.rs

76 lines
2.5 KiB
Rust

use anyhow::Result;
use std::process::Stdio;
use tokio::task::JoinSet;
use tokio::process::Command;
use crate::profile::Profile;
use crate::util;
#[cfg(target_os = "linux")]
pub fn start(p: &Profile) -> Result<Child> {
Ok(Command::new(p.wine_runtime.as_ref().unwrap())
.env(
"SEGATOOLS_CONFIG_PATH",
util::profile_dir(&p).join("segatools.ini"),
)
.env("WINEPREFIX", p.wine_prefix.as_ref().unwrap())
.arg(p.exe_dir.join("start.bat"))
.spawn()?)
}
#[cfg(target_os = "windows")]
pub fn start(p: &Profile) -> Result<()> {
let ini_path = util::profile_dir(&p).join("segatools.ini");
log::debug!("With path {}", ini_path.to_string_lossy());
log::info!("Launching amdaemon");
let mut amd = Command::new("cmd.exe")
.env(
"SEGATOOLS_CONFIG_PATH",
&ini_path,
)
.env("OPENSSL_ia32cap", ":~0x20000000")
.current_dir(&p.exe_dir)
.args(["/C", &util::path_to_str(p.exe_dir.join( "inject.exe"))?, "-d", "-k", "mu3hook.dll", "amdaemon.exe", "-f", "-c", "config_common.json", "config_server.json", "config_client.json"])
// Obviously this is a meme
// Output will be handled properly at a later time
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()?;
log::info!("Launching mu3");
let mut game = Command::new(p.exe_dir.join( "inject.exe"))
.env(
"SEGATOOLS_CONFIG_PATH",
ini_path,
)
.current_dir(&p.exe_dir)
.args(["-d", "-k", "mu3hook.dll", "mu3.exe", "-monitor 1", "-screen-fullscreen", "0", "-popupwindow", "-screen-width", "1080", "-screen-height", "1920"])
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()?;
tauri::async_runtime::spawn(async move {
let mut set = JoinSet::new();
set.spawn(async move {
amd.wait().await.expect("amdaemon failed to run")
});
set.spawn(async move {
game.wait().await.expect("mu3 failed to run")
});
let res = set.join_next().await.expect("No spawn").expect("No result");
log::info!("One of the processes died with return code {}", res);
_ = Command::new("taskkill.exe").arg("/f").arg("/im").arg("amdaemon.exe").output().await;
_ = Command::new("taskkill.exe").arg("/f").arg("/im").arg("mu3.exe").output().await;
set.join_next().await.expect("No spawn").expect("No result");
log::debug!("Fin");
});
Ok(())
//Ok((amd, game))
}