Skip to content

Commit e2a91a2

Browse files
Improved prefix handling + per-profile prefixes
1 parent 2ede63a commit e2a91a2

2 files changed

Lines changed: 62 additions & 32 deletions

File tree

src-tauri/src/lib.rs

Lines changed: 21 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -666,40 +666,34 @@ async fn prep_launch(
666666

667667
#[cfg(not(target_os = "windows"))]
668668
{
669-
// The compat data dir is, in order of priority:
670-
// 1. WINEPREFIX env var in the launch command, if set
671-
// 2. WINEPREFIX env var in the current environment, if set
672-
// 3. The default compat data dir in the app cache
673-
let mut compat_data_dir = None;
674-
for env_var in cmd.get_envs() {
675-
if let (key, Some(value)) = env_var {
676-
if key == "WINEPREFIX" {
677-
compat_data_dir = Some(value.into());
678-
}
679-
}
680-
}
681-
682-
if compat_data_dir.is_none() && env::var("WINEPREFIX").is_ok_and(|val| !val.is_empty())
683-
{
684-
compat_data_dir = Some(env::var("WINEPREFIX").unwrap().into());
685-
}
686-
669+
// Prefix setup
670+
let mut compat_data_dir = util::get_compat_data_dir(&cmd);
687671
if compat_data_dir.is_none() {
688-
compat_data_dir = Some(app_statics.compat_data_dir.clone());
672+
// not specified; use launcher compat data dir
673+
let mut launcher_compat_dir = app_statics.compat_data_dir.clone();
674+
launcher_compat_dir.push(profile.get_id().to_string());
675+
676+
if cmd.get_program().to_string_lossy().ends_with("proton") {
677+
cmd.env(
678+
"STEAM_COMPAT_DATA_PATH",
679+
launcher_compat_dir.to_string_lossy().to_string(),
680+
);
681+
// proton sets WINEPREFIX internally
682+
} else {
683+
// assume wine
684+
cmd.env(
685+
"WINEPREFIX",
686+
launcher_compat_dir.to_string_lossy().to_string(),
687+
);
688+
}
689+
compat_data_dir = Some(launcher_compat_dir);
689690
}
690691

691692
let compat_data_dir = compat_data_dir.unwrap();
692693
if !compat_data_dir.exists() {
694+
debug!("Creating prefix at {}", compat_data_dir.to_string_lossy());
693695
std::fs::create_dir_all(&compat_data_dir)?;
694696
}
695-
696-
#[cfg(target_os = "linux")]
697-
{
698-
if !protontools::is_device_steam_deck() {
699-
// we want to let Proton set this itself on Deck
700-
cmd.env("WINEPREFIX", compat_data_dir.to_string_lossy().to_string());
701-
}
702-
}
703697
}
704698

705699
// Detach stdio so the child doesn't crash from broken pipes

src-tauri/src/util.rs

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,43 @@ 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> {
108+
// Check vars on command first
109+
for env_var in cmd.get_envs() {
110+
if let (key, Some(value)) = env_var {
111+
let value = value.to_string_lossy().to_string();
112+
if key == var && !value.is_empty() {
113+
return Some(value);
114+
}
115+
}
116+
}
117+
118+
// Check env
119+
if let Ok(value) = env::var(var) {
120+
if !value.is_empty() {
121+
return Some(value);
122+
}
123+
}
124+
125+
None
126+
}
127+
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+
107144
#[cfg(target_os = "macos")]
108145
fn find_macos_wine_installs() -> Vec<(String, PathBuf)> {
109146
const CANDIDATES: [&str; 5] = [
@@ -154,7 +191,6 @@ pub(crate) fn get_preset_launch_profiles() -> Vec<LaunchProfile> {
154191
#[cfg(target_os = "linux")]
155192
{
156193
// Find Proton installs
157-
let steam_compat_data_path = get_app_statics().compat_data_dir.clone();
158194
if let Some(steam_compat_client_install_path) = protontools::get_steam_client_path() {
159195
for proton_install in protontools::find_all_proton_installs() {
160196
let proton_path = proton_install.get_exe_path();
@@ -167,12 +203,12 @@ pub(crate) fn get_preset_launch_profiles() -> Vec<LaunchProfile> {
167203
profiles.push(LaunchProfile::new(
168204
&profile_name,
169205
&format!(
170-
"STEAM_COMPAT_DATA_PATH=\"{}\" STEAM_COMPAT_CLIENT_INSTALL_PATH=\"{}\" \"{}\" run {{}}",
171-
steam_compat_data_path.to_string_lossy(),
206+
"STEAM_COMPAT_CLIENT_INSTALL_PATH=\"{}\" \"{}\" run {{}}",
172207
steam_compat_client_install_path.to_string_lossy(),
173208
proton_path.to_string_lossy()
174-
),
175-
true));
209+
),
210+
true,
211+
));
176212
}
177213
}
178214
}

0 commit comments

Comments
 (0)