Skip to content

Commit 0815817

Browse files
Refactor compat setup for more fine-grained user overrides
1 parent c81dfa9 commit 0815817

2 files changed

Lines changed: 34 additions & 42 deletions

File tree

src-tauri/src/lib.rs

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -672,45 +672,53 @@ async fn prep_launch(
672672
#[cfg(not(target_os = "windows"))]
673673
{
674674
// Compat setup
675-
let mut compat_data_dir = util::get_compat_data_dir(&cmd);
676-
if compat_data_dir.is_none() {
677-
// not specified; use launcher compat data dir
678-
let mut launcher_compat_dir = app_statics.compat_data_dir.clone();
679-
launcher_compat_dir.push(profile.get_id().to_string());
680-
681-
if cmd.get_program().to_string_lossy().ends_with("proton") {
682-
#[cfg(target_os = "linux")]
683-
{
675+
let mut ensure_compat_dir = true;
676+
let mut compat_data_dir = app_statics.compat_data_dir.clone();
677+
compat_data_dir.push(profile.get_id().to_string());
678+
679+
let compat_program = std::path::Path::new(cmd.get_program())
680+
.file_name()
681+
.and_then(|s| s.to_str())
682+
.unwrap_or("");
683+
684+
if compat_program.contains("proton") {
685+
#[cfg(target_os = "linux")]
686+
{
687+
if util::get_env_var_value(&cmd, "STEAM_COMPAT_CLIENT_INSTALL_PATH").is_none() {
684688
if let Some(steam_client_dir) = protontools::get_steam_client_path() {
685689
cmd.env(
686690
"STEAM_COMPAT_CLIENT_INSTALL_PATH",
687-
steam_client_dir.to_string_lossy().to_string(),
691+
steam_client_dir.into_os_string(),
688692
);
689693
} else {
690694
return Err("Proton requires Steam to be installed".into());
691695
}
696+
}
692697

693-
cmd.env(
694-
"STEAM_COMPAT_DATA_PATH",
695-
launcher_compat_dir.to_string_lossy().to_string(),
696-
);
697-
// proton sets WINEPREFIX internally
698+
if let Some(proton_prefix) =
699+
util::get_env_var_value(&cmd, "STEAM_COMPAT_DATA_PATH")
700+
{
701+
compat_data_dir = proton_prefix.into();
702+
} else {
703+
cmd.env("STEAM_COMPAT_DATA_PATH", &compat_data_dir);
698704
}
705+
// proton sets WINEPREFIX internally
706+
}
699707

700-
#[cfg(not(target_os = "linux"))]
701-
return Err("Proton is only supported on Linux".into());
708+
#[cfg(not(target_os = "linux"))]
709+
return Err("Proton is only supported on Linux".into());
710+
} else if compat_program.contains("wine") {
711+
if let Some(wine_prefix) = util::get_env_var_value(&cmd, "WINEPREFIX") {
712+
compat_data_dir = wine_prefix.into();
702713
} else {
703-
// assume wine
704-
cmd.env(
705-
"WINEPREFIX",
706-
launcher_compat_dir.to_string_lossy().to_string(),
707-
);
714+
cmd.env("WINEPREFIX", &compat_data_dir.clone().into_os_string());
708715
}
709-
compat_data_dir = Some(launcher_compat_dir);
716+
} else {
717+
// unknown compat layer
718+
ensure_compat_dir = false;
710719
}
711720

712-
let compat_data_dir = compat_data_dir.unwrap();
713-
if !compat_data_dir.exists() {
721+
if ensure_compat_dir && !compat_data_dir.exists() {
714722
debug!("Creating prefix at {}", compat_data_dir.to_string_lossy());
715723
std::fs::create_dir_all(&compat_data_dir)?;
716724
}

src-tauri/src/util.rs

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ pub(crate) fn get_default_offline_cache_dir() -> String {
104104
.to_string()
105105
}
106106

107-
fn get_env_var_value(cmd: &Command, var: &str) -> Option<String> {
107+
pub(crate) fn get_env_var_value(cmd: &Command, var: &str) -> Option<String> {
108108
// Check vars on command first
109109
for env_var in cmd.get_envs() {
110110
if let (key, Some(value)) = env_var {
@@ -125,22 +125,6 @@ fn get_env_var_value(cmd: &Command, var: &str) -> Option<String> {
125125
None
126126
}
127127

128-
pub(crate) fn get_compat_data_dir(cmd: &Command) -> Option<PathBuf> {
129-
if cfg!(target_os = "windows") {
130-
return None;
131-
}
132-
133-
if let Some(path) = get_env_var_value(cmd, "STEAM_COMPAT_DATA_PATH") {
134-
return Some(PathBuf::from(path));
135-
}
136-
137-
if let Some(path) = get_env_var_value(cmd, "WINEPREFIX") {
138-
return Some(PathBuf::from(path));
139-
}
140-
141-
None
142-
}
143-
144128
#[cfg(target_os = "macos")]
145129
fn find_macos_wine_installs() -> Vec<(String, PathBuf)> {
146130
const CANDIDATES: [&str; 5] = [

0 commit comments

Comments
 (0)