mirror of
https://github.com/Drop-OSS/drop.git
synced 2026-07-26 01:34:38 +10:00
Fix local path and templating issues
This commit is contained in:
@@ -19,6 +19,7 @@ pub enum ProcessError {
|
|||||||
OpenerError(Arc<tauri_plugin_opener::Error>),
|
OpenerError(Arc<tauri_plugin_opener::Error>),
|
||||||
InvalidArguments(String),
|
InvalidArguments(String),
|
||||||
FailedLaunch(String),
|
FailedLaunch(String),
|
||||||
|
NotExecutable(String),
|
||||||
NoCompat,
|
NoCompat,
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -39,6 +40,9 @@ impl Display for ProcessError {
|
|||||||
ProcessError::FailedLaunch(game_id) => {
|
ProcessError::FailedLaunch(game_id) => {
|
||||||
&format!("Drop detected that the game {game_id} may have failed to launch properly")
|
&format!("Drop detected that the game {game_id} may have failed to launch properly")
|
||||||
}
|
}
|
||||||
|
ProcessError::NotExecutable(command) => {
|
||||||
|
&format!("The command '{command}' exists but is not marked as executable")
|
||||||
|
}
|
||||||
ProcessError::RequiredDependency(game_id, version_id) => &format!(
|
ProcessError::RequiredDependency(game_id, version_id) => &format!(
|
||||||
"Missing a required dependency to launch this game: {} {}",
|
"Missing a required dependency to launch this game: {} {}",
|
||||||
game_id, version_id
|
game_id, version_id
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
use std::path::PathBuf;
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
use log::info;
|
||||||
|
|
||||||
use crate::error::ProcessError;
|
use crate::error::ProcessError;
|
||||||
|
|
||||||
@@ -38,6 +40,41 @@ impl ParsedCommand {
|
|||||||
.to_string();
|
.to_string();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn make_command_absolute_if_local(&mut self, base: &Path) {
|
||||||
|
let candidate = base.join(&self.command);
|
||||||
|
if candidate.is_file() {
|
||||||
|
info!(
|
||||||
|
"resolved local command '{}' to absolute path '{}'",
|
||||||
|
self.command,
|
||||||
|
candidate.display()
|
||||||
|
);
|
||||||
|
self.command = candidate.to_string_lossy().to_string();
|
||||||
|
} else {
|
||||||
|
info!(
|
||||||
|
"command '{}' is not a local file in '{}', leaving as-is for PATH resolution",
|
||||||
|
self.command,
|
||||||
|
base.display()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn ensure_executable(&self) -> Result<(), ProcessError> {
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
use std::os::unix::fs::PermissionsExt;
|
||||||
|
|
||||||
|
if let Ok(metadata) = std::fs::metadata(&self.command) {
|
||||||
|
let is_executable =
|
||||||
|
metadata.is_file() && metadata.permissions().mode() & 0o111 != 0;
|
||||||
|
if !is_executable {
|
||||||
|
return Err(ProcessError::NotExecutable(self.command.clone()));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
|
|
||||||
pub fn reconstruct(self) -> String {
|
pub fn reconstruct(self) -> String {
|
||||||
let mut v = vec![];
|
let mut v = vec![];
|
||||||
v.extend(self.env);
|
v.extend(self.env);
|
||||||
|
|||||||
@@ -312,9 +312,12 @@ impl ProcessHandler for UMUNativeLauncher {
|
|||||||
let pfx_dir = pfx_dir.join(meta.id.clone());
|
let pfx_dir = pfx_dir.join(meta.id.clone());
|
||||||
create_dir_all(&pfx_dir)?;
|
create_dir_all(&pfx_dir)?;
|
||||||
|
|
||||||
|
let game_id_env = shell_words::quote(&format!("GAMEID={game_id}")).into_owned();
|
||||||
|
let wineprefix_env =
|
||||||
|
shell_words::quote(&format!("WINEPREFIX={}", pfx_dir.to_string_lossy())).into_owned();
|
||||||
|
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
"GAMEID={game_id} UMU_NO_PROTON=1 WINEPREFIX={} {umu:?} {launch}",
|
"{game_id_env} UMU_NO_PROTON=1 {wineprefix_env} {umu:?} {launch}",
|
||||||
pfx_dir.to_string_lossy(),
|
|
||||||
umu = UMU_LAUNCHER_EXECUTABLE
|
umu = UMU_LAUNCHER_EXECUTABLE
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("Failed to get UMU_LAUNCHER_EXECUTABLE as ref"),
|
.expect("Failed to get UMU_LAUNCHER_EXECUTABLE as ref"),
|
||||||
@@ -388,12 +391,17 @@ impl ProcessHandler for UMUCompatLauncher {
|
|||||||
if !proton_valid {
|
if !proton_valid {
|
||||||
return Err(ProcessError::NoCompat);
|
return Err(ProcessError::NoCompat);
|
||||||
}
|
}
|
||||||
let proton_env = format!("PROTONPATH={}", proton_path);
|
|
||||||
|
// Shell-quote the env assignments so values containing spaces (e.g. a
|
||||||
|
// Proton install named "Proton-GE Latest") aren't split into separate
|
||||||
|
// tokens and misinterpreted as the command by the launch parser.
|
||||||
|
let game_id_env = shell_words::quote(&format!("GAMEID={game_id}")).into_owned();
|
||||||
|
let proton_env = shell_words::quote(&format!("PROTONPATH={proton_path}")).into_owned();
|
||||||
|
let wineprefix_env =
|
||||||
|
shell_words::quote(&format!("WINEPREFIX={}", pfx_dir.to_string_lossy())).into_owned();
|
||||||
|
|
||||||
Ok(format!(
|
Ok(format!(
|
||||||
"GAMEID={game_id} {} WINEPREFIX={} {umu:?} {launch}",
|
"{game_id_env} {proton_env} {wineprefix_env} {umu:?} {launch}",
|
||||||
proton_env,
|
|
||||||
pfx_dir.to_string_lossy(),
|
|
||||||
umu = UMU_LAUNCHER_EXECUTABLE
|
umu = UMU_LAUNCHER_EXECUTABLE
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.expect("Failed to get UMU_LAUNCHER_EXECUTABLE as ref"),
|
.expect("Failed to get UMU_LAUNCHER_EXECUTABLE as ref"),
|
||||||
|
|||||||
@@ -523,6 +523,13 @@ impl ProcessManager<'_> {
|
|||||||
install_dir.into(),
|
install_dir.into(),
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let mut launch_parameters = launch_parameters;
|
||||||
|
launch_parameters
|
||||||
|
.0
|
||||||
|
.make_command_absolute_if_local(&launch_parameters.1);
|
||||||
|
|
||||||
|
launch_parameters.0.ensure_executable()?;
|
||||||
|
|
||||||
info!(
|
info!(
|
||||||
"launching (in {}): {:?}",
|
"launching (in {}): {:?}",
|
||||||
launch_parameters.1.to_string_lossy(),
|
launch_parameters.1.to_string_lossy(),
|
||||||
|
|||||||
Reference in New Issue
Block a user