Added wine sync support and prepared to add debug launch

This commit is contained in:
Observer KRypt0n_ 2022-07-01 13:46:34 +02:00
parent 8bec171c5d
commit 86de977e05
No known key found for this signature in database
GPG key ID: 844DA47BA25FE1E2
2 changed files with 64 additions and 3 deletions

View file

@ -84,6 +84,25 @@ impl Config {
None => None None => None
} }
} }
/// Get environment variables corresponding to used wine sync
pub fn get_wine_sync_env_vars(&self) -> HashMap<&str, &str> {
match self.game.wine.sync.as_str() {
"esync" => HashMap::from([
("WINEESYNC", "1")
]),
"fsync" => HashMap::from([
("WINEESYNC", "1"),
("WINEFSYNC", "1")
]),
"futex2" => HashMap::from([
("WINEESYNC", "1"),
("WINEFSYNC", "1"),
("WINEFSYNC_FUTEX2", "1")
]),
_ => HashMap::new()
}
}
} }
#[derive(Debug, Serialize, Deserialize)] #[derive(Debug, Serialize, Deserialize)]

View file

@ -4,6 +4,45 @@ use std::process::Command;
use super::config; use super::config;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Terminal {
GnomeTerminal,
Konsole,
Xfce4Terminal
}
impl Terminal {
pub fn get_command(&self) -> &str {
match self {
Terminal::GnomeTerminal => "gnome-terminal",
Terminal::Konsole => "konsole",
Terminal::Xfce4Terminal => "xfce4-terminal"
}
}
pub fn iter() -> impl Iterator<Item = Terminal> {
[
Terminal::GnomeTerminal,
Terminal::Konsole,
Terminal::Xfce4Terminal
].into_iter()
}
}
/// Try to get GUI terminal installed in system
pub fn try_get_terminal() -> Option<Terminal> {
for terminal in Terminal::iter() {
if let Ok(output) = Command::new(terminal.get_command()).output() {
if output.status.success() {
return Some(terminal);
}
}
}
None
}
/// Try to run the game
pub fn run() -> Result<(), Error> { pub fn run() -> Result<(), Error> {
let config = config::get()?; let config = config::get()?;
@ -16,9 +55,12 @@ pub fn run() -> Result<(), Error> {
None => return Err(Error::new(ErrorKind::Other, "Couldn't find wine executable")) None => return Err(Error::new(ErrorKind::Other, "Couldn't find wine executable"))
}; };
Command::new(wine_executable) let mut command = Command::new(wine_executable);
.env("WINEPREFIX", config.game.wine.prefix)
.envs(config.game.environment) command.env("WINEPREFIX", &config.game.wine.prefix);
command.envs(config.get_wine_sync_env_vars());
command.envs(config.game.environment)
.current_dir(config.game.path) .current_dir(config.game.path)
.arg("launcher.bat") .arg("launcher.bat")
.spawn()?; .spawn()?;